소스 검색

HUE-8758 [connectors] List computes via the connector name

Romain 6 년 전
부모
커밋
bdca8acd17
2개의 변경된 파일20개의 추가작업 그리고 16개의 파일을 삭제
  1. 18 14
      desktop/core/src/desktop/api2.py
  2. 2 2
      desktop/libs/notebook/src/notebook/connectors/base.py

+ 18 - 14
desktop/core/src/desktop/api2.py

@@ -36,7 +36,7 @@ from django.views.decorators.http import require_POST
 from metadata.conf import has_catalog
 from metadata.catalog_api import search_entities as metadata_search_entities, _highlight, search_entities_interactive as metadata_search_entities_interactive
 from notebook.connectors.altus import SdxApi, AnalyticDbApi, DataEngApi, DataWarehouse2Api
-from notebook.connectors.base import Notebook
+from notebook.connectors.base import Notebook, get_interpreter
 from notebook.views import upgrade_session_properties
 
 from desktop.lib.django_util import JsonResponse
@@ -156,19 +156,23 @@ def get_context_computes(request, interface):
     } for cluster in clusters if cluster.get('type') == 'direct'
   ])
 
-  if get_cluster_config(request.user)['has_computes']:
-    if interface == 'impala' or interface == 'report':
-      if IS_K8S_ONLY.get():
-        dw_clusters = DataWarehouse2Api(request.user).list_clusters()['clusters']
-        computes.extend([{
-            'id': cluster.get('crn'),
-            'name': cluster.get('clusterName'),
-            'status': cluster.get('status'),
-            'namespace': cluster.get('namespaceCrn', cluster.get('crn')),
-            'compute_end_point': IS_K8S_ONLY.get() and '%(publicHost)s' % cluster['coordinatorEndpoint'] or '',
-            'type': 'altus-dw'
-          } for cluster in dw_clusters]
-        )
+  if get_cluster_config(request.user)['has_computes']: # TODO: only based on interface selected?
+    interpreter = get_interpreter(connector_type=interface, user=request.user)
+    if interpreter['dialect'] == 'impala':
+      # dw_clusters = DataWarehouse2Api(request.user).list_clusters()['clusters']
+      dw_clusters = [
+        {'crn': 'c1', 'clusterName': 'c1', 'status': 'created', 'endpoint': 'c1.gethue.com:10000'},
+        {'crn': 'c2', 'clusterName': 'c2', 'status': 'created', 'endpoint': 'c2.gethue.com:10000'},
+      ]
+      computes.extend([{
+          'id': cluster.get('crn'),
+          'name': cluster.get('clusterName'),
+          'status': cluster.get('status'),
+          'namespace': cluster.get('namespaceCrn', cluster.get('crn')),
+          'compute_end_point': IS_K8S_ONLY.get() and '%(publicHost)s' % cluster['coordinatorEndpoint'] or '',
+          'type': 'altus-dw'
+        } for cluster in dw_clusters]
+      )
 
   response[interface] = computes
   response['status'] = 0

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

@@ -303,9 +303,9 @@ def get_interpreter(connector_type, user=None):
         'is_sql': False
       }]
     else:
-      raise PopupException(_('Snippet type %(type)s is not configured.') % snippet)
+      raise PopupException(_('Snippet type %s is not configured.') % connector_type)
   elif len(interpreter) > 1:
-    raise PopupException(_('Snippet type %(type)s matching more than one interpreter: %s') % (snippet, len(interpreter)))
+    raise PopupException(_('Snippet type %s matching more than one interpreter: %s') % (connector_type, len(interpreter)))
 
   return interpreter[0]