utkarsharma2 commented on code in PR #34643:
URL: https://github.com/apache/airflow/pull/34643#discussion_r1340046067


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -116,6 +118,55 @@ 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:
+        if state not in self.CLUSTER_LIFE_CYCLE_STATES:
+            raise AirflowException(
+                f"Unexpected cluster life cycle state: {state}: If the state 
has "
+                "been introduced recently, please check the Databricks user "
+                "guide for troubleshooting information"
+            )
+
+        self.state = state
+        self.state_message = state_message
+
+    @property
+    def is_terminal(self) -> bool:
+        """True if the current state is a terminal state."""
+        return self.state in ("TERMINATING", "TERMINATED", "ERROR", "UNKNOWN")

Review Comment:
   Not a blocker, you can probably also do something like this to not redefine 
the states in function  `is_running` and `is_terminal`
   ```
   CLUSTER_TERMINAL_STATE = ["TERMINATING", "TERMINATED", "ERROR", "UNKNOWN"]
   CLUSTER_RUNNING_STATE = ["RUNNING", "RESIZING"]
   CLUSTER_LIFE_CYCLE_STATES = [
           "PENDING",
           "RESTARTING",
           *CLUSTER_RUNNING_STATE,
           *CLUSTER_TERMINAL_STATE
       ]
   ```
   and then use CLUSTER_RUNNING_STATE in `is_running` and 
CLUSTER_TERMINAL_STATE in `is_terminal`



-- 
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