浏览代码

HUE-8591 [cluster] Plug in the list of clusters

Romain Rigaux 7 年之前
父节点
当前提交
242744cc7b

+ 21 - 1
apps/jobbrowser/src/jobbrowser/apis/data_warehouse.py

@@ -35,6 +35,7 @@ class DataWarehouseClusterApi(Api):
   def __init__(self, user, version=1):
     super(DataWarehouseClusterApi, self).__init__(user)
 
+    self.version = version
     self.api = DataWarehouse2Api(self.user) if version == 2 else AnalyticDbApi(self.user) 
 
 
@@ -60,8 +61,27 @@ class DataWarehouseClusterApi(Api):
 
 
   def app(self, appid):
-    return {'name': 'name'}
+    handle = self.api.describe_cluster(cluster_id=appid)
+
+    cluster = handle['cluster']
+
+    common = {
+        'id': cluster['crn'],
+        'name': cluster['clusterName'],
+        'status': cluster['status'],
+        'apiStatus': self._api_status(cluster['status']),
+        'progress': 50 if self._api_status(cluster['status']) == 'RUNNING' else 100,
+        'duration': 10 * 3600,
+        'submitted': cluster['creationDate'],
+        'type': 'dataware2-cluster' if self.version == 2 else 'dataware-cluster',
+        'canWrite': True
+    }
+
+    common['properties'] = {
+      'properties': cluster
+    }
 
+    return common
 
   def action(self, appid, action):
     message = {'message': '', 'status': 0}

+ 23 - 5
desktop/libs/notebook/src/notebook/connectors/altus.py

@@ -269,11 +269,14 @@ class AnalyticDbApi():
   def delete_cluster(self, cluster_id):
     return _exec('dataware', 'deleteCluster', {'clusterName': cluster_id})
 
+  def describe_cluster(self, cluster_id):
+    return _exec('dataware', 'describeCluster', {'clusterName': cluster_id})
+
 
 class DataWarehouse2Api():
 
   def __init__(self, user=None):
-    self._api_url = '/warehouse/api'
+    self._api_url = 'http://172.16.34.61:4747/dw'
 
     self.user = user
     self._client = HttpClient(self._api_url, logger=LOG)
@@ -293,9 +296,19 @@ class DataWarehouse2Api():
     return _exec('dw', 'createCluster', params)
 
   def list_clusters(self):
+#     {"clusters":[
+#       {"clusterName":"fake-tristan",
+#        "crn":"crn:altus:datawa44eed-a1f3-4935-89c1-71eb56889581",
+#        "creationDate":"2018-09-19T22:27:28.740Z","cdhVersion":"CDH6.3","workerCpuCores":4,"workerMemoryInGib":8,"workerReplicas":4,"workerReplicasOnline":4}]}
+
     try:
-      return self._root.post('listClusters', contenttype="application/json")
-    except:
+      clusters = self._root.post('listClusters', contenttype="application/json")
+      for cluster in clusters['clusters']:
+        cluster['workersGroupSize'] = cluster['workerReplicas']
+        cluster['instanceType'] = 'Medium'
+      return clusters
+    except Exception, e:
+      print e
       return {'clusters': [
         {'crn': 'crn1', 'clusterName': 'clusterName1', 'status': 'CREATED', 'workersGroupSize': 1, 'instanceType': 'Medium', 'cdhVersion': '6.0', 'creationDate': 'September 14, 2018 12:48 PM'}
       ]}
@@ -303,8 +316,13 @@ class DataWarehouse2Api():
   def delete_cluster(self, cluster_id):
     return _exec('dw', 'deleteCluster', {'clusterName': cluster_id})
 
-  def describe_cluster(self, clusterName):
-    return _exec('dw', 'listClusters', {'clusterName': clusterName})
+  def describe_cluster(self, cluster_id):
+    try:
+      return self._root.post('describeCluster', contenttype="application/json")
+    except:
+      return {'cluster':
+        {'crn': 'crn1', 'clusterName': 'clusterName1', 'status': 'CREATED', 'workersGroupSize': 1, 'instanceType': 'Medium', 'cdhVersion': '6.0', 'creationDate': 'September 14, 2018 12:48 PM'}
+      }
 
   def update_cluster(self, cluster_name, cdh_version, cpu_minimum, cpu_maximum, memory_minimum, memory_maximum):
     params = {