You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Seokyun-Ha (via GitHub)" <gi...@apache.org> on 2023/09/05 00:46:43 UTC

[GitHub] [airflow] Seokyun-Ha commented on a diff in pull request #34071: Databricks ClusteState & Clsuter get, activate

Seokyun-Ha commented on code in PR #34071:
URL: https://github.com/apache/airflow/pull/34071#discussion_r1315247736


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -114,6 +116,57 @@ def from_json(cls, data: str) -> RunState:
         return RunState(**json.loads(data))
 
 
+class ClusterState:
+    """
+    Utility class for the cluster state concept of Databricks cluster.
+    """
+
+    CLUSTER_LIFE_CYCLE_STATES = [
+        "PENDING",
+        "RUNNING",
+        "RESTARTING",
+        "RESIZING",
+        "TERMINATING",
+        "TERMINATED",
+        "ERROR",
+        "UNKNOWN",
+    ]
+
+    def __init__(self, state: str = "", state_message: str = "", *args, **kwargs) -> None:
+        self.state = state
+        self.state_message = state_message
+
+    @property
+    def is_terminal(self) -> bool:
+        """True if the current state is a terminal state."""
+        if self.state not in self.CLUSTER_LIFE_CYCLE_STATES:
+            raise AirflowException(
+                f"Unexpected cluster life cycle state: {self.state}"
+            )
+        return self.state in (
+            "TERMINATING", "TERMINATED", "ERROR", "UNKNOWN"
+        )
+
+    @property
+    def is_running(self) -> bool:
+        """True if the current state is running."""
+        return self.state in ("RUNNING", "RESIZING")
+
+    def __eq__(self, other) -> bool:
+        return self.state == other.state and \
+            self.state_message == other.state_message
+
+    def __repr__(self) -> str:
+        return str(self.__dict__)
+
+    def to_json(self) -> str:
+        return json.dumps(self.__dict__)

Review Comment:
   these two methods: `__repr__()` and `to_json()` are exist on `RunState` class. For match the class pattern, I added it to `ClusterState` too. Do you think these are not needed? Then, I will remove the methods.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org