瀏覽代碼

[core][computes] Improved error handling in sync code

Added a try/except to log error and continue if one of the namespaces
runs into and error.

Change-Id: I25d5ba71e0d6032e513465de1fa616dfe4ea0878
Amit Srivastava 2 年之前
父節點
當前提交
cd0f6bf7b6

+ 20 - 16
desktop/core/src/desktop/management/commands/sync_warehouses.py

@@ -95,22 +95,26 @@ def get_computes_from_k8s():
   computes = []
 
   for n in core_v1.list_namespace().items:
-    namespace = n.metadata.name
-    item = {
-      'name': n.metadata.labels.get('displayname'),
-      'description': '%s (%s)' % (n.metadata.labels.get('displayname'), n.metadata.name),
-      'external_id': namespace,
-      #'creation_timestamp': n.metadata.labels.get('creation_timestamp'),
-    }
-
-    if namespace.startswith('warehouse-'):
-      catalogs.append(item)
-    elif namespace.startswith('compute-'):
-      computes.append(item)
-      update_hive_configs(namespace, item, 'hiveserver2-service.%s.svc.cluster.local' % namespace)
-    elif namespace.startswith('impala-'):
-      computes.append(item)
-      populate_impala(namespace, item)
+    try:
+      namespace = n.metadata.name
+      LOG.info('Getting details for ns: %s' % namespace)
+      item = {
+        'name': n.metadata.labels.get('displayname'),
+        'description': '%s (%s)' % (n.metadata.labels.get('displayname'), n.metadata.name),
+        'external_id': namespace,
+        #'creation_timestamp': n.metadata.labels.get('creation_timestamp'),
+      }
+
+      if namespace.startswith('warehouse-'):
+        catalogs.append(item)
+      elif namespace.startswith('compute-'):
+        update_hive_configs(namespace, item, 'hiveserver2-service.%s.svc.cluster.local' % namespace)
+        computes.append(item)
+      elif namespace.startswith('impala-'):
+        populate_impala(namespace, item)
+        computes.append(item)
+    except Exception as e:
+      LOG.exception('Could not get details for ns: %s' % n)
 
   return computes
 

+ 1 - 1
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -437,7 +437,7 @@ def get_api(request, snippet):
     interpreter = snippet.get('interpreter')
   elif get_cluster_config(request.user).get('has_computes'):
     if snippet.get('type') in ('hive-compute', 'impala-compute') and snippet.get('id'):
-      LOG.debug("Loading the compute from db using snippet['id']: %" % snippet['id'])
+      LOG.debug("Loading the compute from db using snippet['id']: %s" % snippet['id'])
       interpreter = Compute.objects.get(id=snippet['id']).to_dict()
     if snippet.get('compute'):
       LOG.debug("Using the compute as is from snippet['compute']")