Просмотр исходного кода

HUE-5145 [metadata] Get top tables from optimization API

Romain Rigaux 9 лет назад
Родитель
Сommit
943a75a

+ 1 - 2
desktop/libs/metadata/src/metadata/optimizer_api.py

@@ -59,7 +59,6 @@ def get_tenant(request):
   email = request.POST.get('email')
 
   api = OptimizerApi()
-
   data = api.get_tenant(email=email)
 
   if data['status'] == 'success':
@@ -103,7 +102,7 @@ def top_tables(request):
         'patternCount': table['patternCount'],
         'total': table['total'],
         'is_fact': table['type'] != 'Dimension'
-        } for table in data['details']
+        } for table in data['results']
     ]
 
   response['top_tables'] = tables

+ 13 - 19
desktop/libs/metadata/src/metadata/optimizer_client.py

@@ -49,7 +49,7 @@ class OptimizerApi(object):
 
   def __init__(self, api_url=None, product_name=None, product_secret=None, ssl_cert_ca_verify=OPTIMIZER.SSL_CERT_CA_VERIFY.get(), product_auth_secret=None):
     self._api_url = (api_url or get_optimizer_url()).strip('/')
-    self._product_name = product_name if product_name else OPTIMIZER.PRODUCT_NAME.get()
+    self._product_name = product_name if product_name else OPTIMIZER.PRODUCT_NAME.get() # Aka "tenant"
     self._product_secret = product_secret if product_secret else OPTIMIZER.PRODUCT_SECRET.get()
     self._product_auth_secret = product_auth_secret if product_auth_secret else OPTIMIZER.PRODUCT_AUTH_SECRET.get()
     self._email = OPTIMIZER.EMAIL.get()
@@ -68,19 +68,19 @@ class OptimizerApi(object):
 
     return self._token
 
-
-  def get_tenant(self, email):
+  
+  def _exec(self, command, args):
     try:
       data = subprocess.check_output([
           'cws',
           'navopt',
           '--endpoint-url=%s' % self._api_url,
-          'get-tenant',
-          '--email',
-          email,
+          command,
           '--auth-config',
           self._product_secret
-      ])
+         ] +
+         args
+      )
     except RestException, e:
       raise PopupException(e, title=_('Error while accessing Optimizer'))
     
@@ -89,6 +89,10 @@ class OptimizerApi(object):
     return response
 
 
+  def get_tenant(self, email):
+    return self._exec('get-tenant', ['--email', email])
+
+
   def create_product(self, product_name=None, product_secret=None, authCode=None):
     try:
       data = {
@@ -166,18 +170,8 @@ class OptimizerApi(object):
       raise PopupException(e, title=_('Error while accessing Optimizer'))
 
 
-  def top_tables(self, token=None, email=None):
-    if token is None:
-      token = self._authenticate()
-
-    try:
-      data = {
-          'email': email if email is not None else self._email,
-          'token': token,
-      }
-      return self._root.post('/api/topTables', data=json.dumps(data), contenttype=_JSON_CONTENT_TYPE)
-    except RestException, e:
-      raise PopupException(e, title=_('Error while accessing Optimizer'))
+  def top_tables(self, workfloadId=None):
+    return self._exec('get-top-tables', ['--tenant', self._product_name])
 
 
   def table_details(self, table_name, token=None, email=None):

+ 2 - 14
desktop/libs/metadata/src/metadata/optimizer_tests.py

@@ -121,21 +121,9 @@ class TestOptimizerApi(object):
 
 
   def test_top_tables(self):
-    resp = self.api.authenticate()
-    token = resp['token']
-
-    resp = self.api.top_tables(token=token)
+    resp = self.api.top_tables()
 
-    assert_true(isinstance(resp, list), resp) # No status code currently
-
-
-  def test_table_details(self):  # Requires test_upload to run before
-    resp = self.api.authenticate()
-    token = resp['token']
-
-    resp = self.api.table_details(table_name='store_sales', token=token)
-
-    assert_equal('success', resp['status'], resp)
+    assert_true(isinstance(resp['results'], list), resp) # No status code currently
 
 
   def test_table_details(self):  # Requires test_upload to run before