Browse Source

HUE-8589 [core] Split cluster listing to its own API

Romain Rigaux 7 years ago
parent
commit
3860649678
2 changed files with 39 additions and 20 deletions
  1. 38 20
      desktop/core/src/desktop/api2.py
  2. 1 0
      desktop/core/src/desktop/urls.py

+ 38 - 20
desktop/core/src/desktop/api2.py

@@ -167,26 +167,7 @@ def get_context_computes(request, interface):
       # TODO if interface == 'spark2' keep only SPARK type
 
   if interface == 'jobs':
-    for cluster in clusters:
-      cluster = {
-        'id': cluster.get('id'),
-        'name': cluster.get('name'),
-        'status': 'CREATED',
-        'environmentType': cluster.get('type'),
-        'serviceType': cluster.get('interface'),
-        'namespace': '',
-        'type': cluster.get('type')
-      }
-        
-      if cluster.get('type') == 'altus':
-        cluster['name'] = 'Altus DE'
-        cluster['type'] = 'altus-de'
-        computes.append(cluster)
-        cluster = cluster.copy()
-        cluster['name'] = 'Altus Data Warehouse'
-        cluster['type'] = 'altus-dw'
-
-      computes.append(cluster)
+    return get_context_clusters(request, interface) # TODO remove when UI changed
 
   response[interface] = computes
   response['status'] = 0
@@ -194,6 +175,43 @@ def get_context_computes(request, interface):
   return JsonResponse(response)
 
 
+@api_error_handler
+def get_context_clusters(request, interface):
+  response = {}
+  clusters = []
+
+  cluster_configs = get_clusters(request.user).values()
+
+  for cluster in cluster_configs:
+    cluster = {
+      'id': cluster.get('id'),
+      'name': cluster.get('name'),
+      'status': 'CREATED',
+      'environmentType': cluster.get('type'),
+      'serviceType': cluster.get('interface'),
+      'namespace': '',
+      'type': cluster.get('type')
+    }
+
+    if cluster.get('type') == 'altus':
+      cluster['name'] = 'Altus DE'
+      cluster['type'] = 'altus-de'
+      clusters.append(cluster)
+      cluster = cluster.copy()
+      cluster['name'] = 'Altus Data Warehouse'
+      cluster['type'] = 'altus-dw'
+    elif cluster.get('type') == 'altusv2':
+      cluster['name'] = 'Data Warehouse'
+      cluster['type'] = 'altus-dw2'
+
+    clusters.append(cluster)
+
+  response[interface] = clusters
+  response['status'] = 0
+
+  return JsonResponse(response)
+
+
 @api_error_handler
 def search_documents(request):
   """

+ 1 - 0
desktop/core/src/desktop/urls.py

@@ -157,6 +157,7 @@ dynamic_patterns += [
   url(r'^desktop/api2/get_config/?$', desktop_api2.get_config),
   url(r'^desktop/api2/context/namespaces/(?P<interface>\w+)/?$', desktop_api2.get_context_namespaces),
   url(r'^desktop/api2/context/computes/(?P<interface>\w+)/?$', desktop_api2.get_context_computes),
+  url(r'^desktop/api2/context/clusters/(?P<interface>\w+)/?$', desktop_api2.get_context_clusters),
   url(r'^desktop/api2/user_preferences/(?P<key>\w+)?$', desktop_api2.user_preferences, name="desktop.api2.user_preferences"),
 
   url(r'^desktop/api2/doc/export/?$', desktop_api2.export_documents),