Browse Source

HUE-8330 [metadata] Add API to list uploads

Romain Rigaux 7 years ago
parent
commit
222e683262

+ 23 - 0
desktop/libs/metadata/src/metadata/workload_analytics_api.py

@@ -64,6 +64,29 @@ def get_impala_query(request):
   return JsonResponse(response)
 
 
+@require_POST
+@error_handler
+def get_cluster_id(request):
+  response = {'status': -1}
+
+  crn = json.loads(request.POST.get('crn'))
+
+  client = WorkfloadAnalyticsClient(request.user)
+  data = client.list_uploads()
+
+  if data:
+    env = [_env for _env in data['environments'] if _env['crn'] == crn]
+    if not env:
+      response['message'] = 'Workload Analytics: %s environment not found' % crn
+    else:
+      response['status'] = 0
+      response['data'] = env[0]
+  else:
+    response['message'] = 'Workload Analytics: %s' % data['details']
+
+  return JsonResponse(response)
+
+
 @require_POST
 @error_handler
 def get_environment(request):

+ 7 - 0
desktop/libs/metadata/src/metadata/workload_analytics_client.py

@@ -33,6 +33,9 @@ class WorkfloadAnalyticsClient():
   def get_impala_query(self, cluster_id, query_id):
     return WorkloadAnalytics(self.user).get_impala_query(cluster_id=cluster_id, query_id=query_id)
 
+  def list_uploads(self):
+    return WorkloadAnalytics(self.user).list_uploads()
+
   def list_environments(self):
     return WorkloadAnalytics(self.user).list_environments()
 
@@ -54,6 +57,10 @@ class WorkloadAnalytics():
     return _exec('wa', 'getImpalaQuery', parameters=parameters)
 
 
+  def list_uploads(self):
+    return _exec('wa', 'listUploads')
+
+
   def list_environments(self):
     return _exec('wa', 'listEnvironments')