Browse Source

HUE-8330 [impala] Skeleton to get prettier query profile

     $.post("/metadata/api/workload_analytics/get_impala_query/", {
        "cluster_id": ko.mapping.toJSON("6bfa86a8-55a2-4466-9003-2b222a9be137"),
        "query_id": ko.mapping.toJSON("56433486cd84d475:3a86f97000000000")
      }, function(data) {
        console.log(ko.mapping.toJSON(data));
      });
Romain Rigaux 7 years ago
parent
commit
199965e6f2

+ 4 - 0
desktop/libs/metadata/src/metadata/conf.py

@@ -174,6 +174,10 @@ ALTUS = ConfigSection(
       key='hostname_dataeng',
       help=_t('Hostname prefix to Altus DE API or compatible service.'),
       default='dataengapi.us-west-1.altus.cloudera.com'),
+    HOSTNAME_WA=Config(
+      key='hostname_wa',
+      help=_t('Hostname prefix to Altus WA API or compatible service.'),
+      default='waapi.us-west-1.altus.cloudera.com'),
     AUTH_KEY_ID=Config(
       key="auth_key_id",
       help=_t("The name of the key of the service."),

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

@@ -83,4 +83,5 @@ urlpatterns += [
 # Workload Analytics API
 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'),
 ]

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

@@ -44,6 +44,27 @@ def error_handler(view_fn):
   return decorator
 
 
+@require_POST
+@error_handler
+def get_impala_query(request):
+  response = {'status': -1}
+
+  cluster_id = json.loads(request.POST.get('cluster_id'))
+  query_id = json.loads(request.POST.get('query_id'))
+
+  client = WorkfloadAnalyticsClient(request.user)
+  data = client.get_impala_query(cluster_id=cluster_id, query_id=query_id)
+
+  if data:
+    response['status'] = 0
+    response['data'] = data
+  else:
+    response['message'] = 'Workload Analytics: %s' % data['details']
+
+  return JsonResponse(response)
+
+
+
 @require_POST
 @error_handler
 def get_operation_execution_details(request):

+ 17 - 24
desktop/libs/metadata/src/metadata/workload_analytics_client.py

@@ -16,33 +16,15 @@
 # limitations under the License.
 
 import logging
-import json
-import subprocess
 
 from django.utils.translation import ugettext as _
 
-from desktop.lib.exceptions_renderable import PopupException
+from notebook.connectors.altus import _exec
 
 
 LOG = logging.getLogger(__name__)
 
 
-def _exec(args):
-  try:
-    data = subprocess.check_output([
-        'altus',
-        'wa',
-       ] +
-       args
-    )
-  except Exception, e:
-    raise PopupException(e, title=_('Error accessing'))
-
-  response = json.loads(data)
-
-  return response
-
-
 class WorkfloadAnalyticsClient():
 
   def __init__(self, user):
@@ -54,20 +36,31 @@ class WorkfloadAnalyticsClient():
   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():
 
   def __init__(self, user): pass
 
+  def get_impala_query(self, cluster_id, query_id):
+    parameters = {'clusterId': cluster_id, 'queryId': query_id}
+
+    return _exec('wa', 'getImpalaQuery', parameters=parameters)
+
+
   def get_operation_execution_details(self, operation_id, include_tree=False):
-    args = ['get-operation-execution-details', '--id', operation_id]
+    parameters = {'id': operation_id}
 
     if include_tree:
-      args.append('--include-tree')
+      parameters['includeTree'] = ''
+
+    return _exec('wa', 'getOperationExecutionDetails', parameters=parameters)
 
-    return _exec(args)
 
   def get_mr_task_attempt_log(self, operation_execution_id, attempt_id):
-    args = ['get-mr-task-attempt-log', '--operation-execution-id', operation_execution_id, '--attempt-id', attempt_id]
+    parameters = {'operationExecutionId': operation_execution_id, 'attemptId': attempt_id}
 
-    return _exec(args)
+    return _exec('wa', 'getMrTaskAttemptLog', parameters=parameters)

+ 4 - 2
desktop/libs/notebook/src/notebook/connectors/altus.py

@@ -37,14 +37,16 @@ DATE_FORMAT = "%Y-%m-%d"
 def _exec(service, command, parameters=None):
   if parameters is None:
     parameters = {}
-  
+
   if service == 'analyticdb':
     hostname = ALTUS.HOSTNAME_ANALYTICDB.get()
   elif service == 'dataeng':
     hostname = ALTUS.HOSTNAME_DATAENG.get()
+  elif service == 'wa':
+    hostname = ALTUS.HOSTNAME_WA.get()
   else:
     hostname = ALTUS.HOSTNAME.get()
-    
+
   try:
     api = ApiLib(service, hostname, ALTUS.AUTH_KEY_ID.get(), ALTUS.AUTH_KEY_SECRET.get().replace('\\n', '\n'))
     resp = api.call_api(command, parameters)