This is an automated email from the ASF dual-hosted git repository.

lfrolov pushed a commit to branch DATALAB-1408
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git


The following commit(s) were added to refs/heads/DATALAB-1408 by this push:
     new 413ef0843 [DATALAB-1408]: added cluster termination during project and 
ssn node termination
413ef0843 is described below

commit 413ef0843b13ff8ecc4ef36cd31c1763bc65a3a9
Author: leonidfrolov <[email protected]>
AuthorDate: Wed Sep 7 13:27:35 2022 +0300

    [DATALAB-1408]: added cluster termination during project and ssn node 
termination
---
 .../src/general/lib/azure/actions_lib.py                 |  2 +-
 .../src/general/scripts/azure/project_terminate.py       | 16 ++++++++++++++++
 .../src/general/scripts/azure/ssn_terminate.py           | 10 ++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/infrastructure-provisioning/src/general/lib/azure/actions_lib.py 
b/infrastructure-provisioning/src/general/lib/azure/actions_lib.py
index 4ea7037dc..1559a7468 100644
--- a/infrastructure-provisioning/src/general/lib/azure/actions_lib.py
+++ b/infrastructure-provisioning/src/general/lib/azure/actions_lib.py
@@ -1193,7 +1193,7 @@ class AzureActions:
 
     def terminate_hdinsight_cluster(self, resource_group_name, cluster_name):
         try:
-            print('Starting to terminate HDInsight Spark cluster 
{}'.format(cluster_name))
+            print('Starting to terminate HDInsight cluster 
{}'.format(cluster_name))
             result = 
self.hdinsight_client.clusters.begin_delete(resource_group_name, cluster_name)
             cluster_status = 
datalab.meta_lib.AzureMeta().get_hdinsight_cluster(resource_group_name, 
cluster_name)
             while cluster_status:
diff --git 
a/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py 
b/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py
index 23e152aaf..bd400ac43 100644
--- a/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py
+++ b/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py
@@ -33,6 +33,22 @@ import traceback
 
 
 def terminate_edge_node(resource_group_name, service_base_name, project_tag, 
subnet_name, vpc_name, endpoint_name):
+    logging.info("Terminating Dataengine-service clusters")
+    try:
+        clusters_list = AzureMeta.list_hdinsight_clusters(resource_group_name)
+        if clusters_list:
+            for cluster in clusters_list:
+                if "sbn" in cluster.tags and service_base_name == 
cluster.tags["sbn"] and \
+                        "project" in cluster.tags and cluster.tags['project'] 
== project_tag:
+                    print(cluster.name + ' found for termination')
+                    #AzureActions.terminate_hdinsight_cluster(cluster.name, 
region)
+                    logging.info('The HDinsight cluster {} has been terminated 
successfully'.format(cluster.name))
+        else:
+            logging.info("There are no HDinsight clusters to terminate.")
+    except Exception as err:
+        datalab.fab.append_result("Failed to terminate dataengine-service", 
str(err))
+        sys.exit(1)
+
     logging.info("Terminating EDGE, notebook and dataengine virtual machines")
     try:
         for vm in 
AzureMeta.compute_client.virtual_machines.list(resource_group_name):
diff --git 
a/infrastructure-provisioning/src/general/scripts/azure/ssn_terminate.py 
b/infrastructure-provisioning/src/general/scripts/azure/ssn_terminate.py
index 0ae2f2344..18e6711ce 100644
--- a/infrastructure-provisioning/src/general/scripts/azure/ssn_terminate.py
+++ b/infrastructure-provisioning/src/general/scripts/azure/ssn_terminate.py
@@ -35,6 +35,16 @@ from fabric import *
 
 
 def terminate_ssn_node(resource_group_name, service_base_name, vpc_name, 
region):
+    logging.info("Terminating HDINSIGHT clusters")
+    try:
+        for cluster in AzureMeta.list_hdinsight_clusters(resource_group_name):
+            if "sbn" in cluster.tags and service_base_name == 
cluster.tags["sbn"]:
+                AzureActions.terminate_hdinsight_cluster(resource_group_name, 
cluster.name)
+                logging.info("Cluster {} has been 
terminated".format(cluster.name))
+    except Exception as err:
+        datalab.fab.append_result("Failed to terminate HDINSIGHT clusters", 
str(err))
+        sys.exit(1)
+
     logging.info("Terminating instances")
     try:
         for vm in 
AzureMeta.compute_client.virtual_machines.list(resource_group_name):


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to