swapz-z commented on code in PR #28282:
URL: https://github.com/apache/airflow/pull/28282#discussion_r1050767976


##########
airflow/providers/amazon/aws/hooks/emr.py:
##########
@@ -202,6 +202,74 @@ def get_ui_field_behaviour() -> dict[str, Any]:
             },
         }
 
+    def is_cluster_available(self, emr_cluster_id, cluster_states):
+        response = self.get_conn().list_clusters(ClusterStates=cluster_states)
+        matching_clusters = list(
+            filter(lambda cluster: cluster["Id"] == emr_cluster_id, 
response["Clusters"])
+        )
+
+        if len(matching_clusters) == 1:
+            emr_cluster_name = matching_clusters[0]["Name"]
+            self.log.info("Found cluster name = %s id = %s", emr_cluster_name, 
emr_cluster_id)
+            return True
+        elif len(matching_clusters) > 1:
+            raise AirflowException(f"More than one cluster found for Id 
{emr_cluster_id}")
+        else:
+            self.log.info("No cluster found for Id %s", emr_cluster_id)
+            return False
+
+    def _get_list_of_steps_already_triggered(
+        self, cluster_id: str, step_states: list[str]
+    ) -> list[tuple[str, str]]:
+
+        response = self.get_conn().list_steps(
+            ClusterId=cluster_id,
+            StepStates=step_states,
+        )
+        steps_name_id = [(step["Name"], step["Id"]) for step in 
response["Steps"]]
+        print(steps_name_id)
+        return steps_name_id
+
+    def _cancel_list_of_steps_already_triggered(
+        self, steps: list[dict], cluster_id: str, step_states: list[str]
+    ):
+        names_list = self._get_list_of_steps_already_triggered(cluster_id, 
step_states)
+
+        self.log.info(steps)
+
+        steps_name_list = [step["Name"] for step in steps if "Name" in step]

Review Comment:
   Because of this, it got me looking and found that boto3 actually enforces it 
as a mandatory paramater while creation of steps. So we can expect them to also 
have a Name. 
   Backed it up with a test case for this . Find it 
[here](https://github.com/apache/airflow/pull/28282/files#diff-12403a99d050969934d307ac584b2a414382e29c3a49d535be55bdc59e411213R232)
 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to