Browse Source

HUE-8330 [metadata] Get cluster id API from environment id

     $.post("/metadata/api/workload_analytics/get_environment/", {
        "crn": ko.mapping.toJSON("crn:altus:environments:us-west-1:12a0079b-1591-4ca0-b721-a446bda74e67:environment:Hue-0711/e3a57af6-aa14-4935-a372-30dbc5015454")
      }, function(data) {
        console.log(ko.mapping.toJSON(data));
      });
Romain Rigaux 7 years ago
parent
commit
b27a333ea3

+ 1 - 0
desktop/libs/metadata/src/metadata/urls.py

@@ -84,4 +84,5 @@ urlpatterns += [
 urlpatterns += [
   url(r'^api/workload_analytics/get_operation_execution_details/?$', metadata_workload_analytics_api.get_operation_execution_details, name='get_operation_execution_details'),
   url(r'^api/workload_analytics/get_impala_query/?$', metadata_workload_analytics_api.get_impala_query, name='get_impala_query'),
+  url(r'^api/workload_analytics/get_environment/?$', metadata_workload_analytics_api.get_environment, name='get_environment'),
 ]

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

@@ -64,6 +64,28 @@ def get_impala_query(request):
   return JsonResponse(response)
 
 
+@require_POST
+@error_handler
+def get_environment(request):
+  response = {'status': -1}
+
+  crn = json.loads(request.POST.get('crn'))
+
+  client = WorkfloadAnalyticsClient(request.user)
+  data = client.list_environments()
+
+  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

+ 10 - 3
desktop/libs/metadata/src/metadata/workload_analytics_client.py

@@ -30,15 +30,18 @@ class WorkfloadAnalyticsClient():
   def __init__(self, user):
     self.user = user
 
+  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_environments(self):
+    return WorkloadAnalytics(self.user).list_environments()
+
   def get_operation_execution_details(self, operation_id):
     return WorkloadAnalytics(self.user).get_operation_execution_details(operation_id=operation_id, include_tree=True)
 
   def get_mr_task_attempt_log(self, operation_execution_id, attempt_id):
     return WorkloadAnalytics(self.user).get_mr_task_attempt_log(operation_execution_id=operation_execution_id, attempt_id=attempt_id)
 
-  def get_impala_query(self, cluster_id, query_id):
-    return WorkloadAnalytics(self.user).get_impala_query(cluster_id=cluster_id, query_id=query_id)
-
 
 
 class WorkloadAnalytics():
@@ -51,6 +54,10 @@ class WorkloadAnalytics():
     return _exec('wa', 'getImpalaQuery', parameters=parameters)
 
 
+  def list_environments(self):
+    return _exec('wa', 'listEnvironments')
+
+
   def get_operation_execution_details(self, operation_id, include_tree=False):
     parameters = {'id': operation_id}