Browse Source

HUE-8330 [cluster] Add a list of computes to each namespace in the namespace API

Romain Rigaux 7 years ago
parent
commit
60bea21f57
1 changed files with 10 additions and 3 deletions
  1. 10 3
      desktop/core/src/desktop/api2.py

+ 10 - 3
desktop/core/src/desktop/api2.py

@@ -87,22 +87,29 @@ def get_context_namespaces(request, interface):
   if interface == 'hive' or interface == 'impala':
     namespaces.extend([{
         'id': cluster['id'],
-        'name': cluster['name']
+        'name': cluster['name'],
+        'status': 'RUNNING',
+        'computes': [cluster]
       } for cluster in clusters if cluster.get('type') == 'direct' # and interface == 'hive'
     ])
 
     # From Altus SDX
     if [cluster for cluster in clusters if cluster['type'] == 'altus']:
+      # Note: attaching computes to namespaces might be done via the frontend in the future
+      if interface == 'impala':
+        adb_clusters = AnalyticDbApi(request.user).list_clusters()['clusters']
+      else:
+        adb_clusters = []
+
       namespaces.extend([{
           'id': namespace.get('crn', 'None'),
           'name': namespace.get('namespaceName', 'Unknown'),
           'status': namespace.get('status'),
+          'computes': [_cluster for _cluster in adb_clusters if _cluster.get('namespaceCrn') == namespace.get('crn')]
         } for namespace in SdxApi(request.user).list_namespaces()]
       )
       response['dynamicClusters'] = True
 
-      # TODO, if impala, tag namespaces with computes
-
   response[interface] = namespaces
   response['status'] = 0