Selaa lähdekoodia

HUE-6412 [optimizer] Remove email parameter of get_tenant

Romain Rigaux 8 vuotta sitten
vanhempi
commit
2c01b9c

+ 2 - 2
desktop/conf.dist/hue.ini

@@ -1632,8 +1632,8 @@
 [metadata]
 
   [[optimizer]]
-    # Base URL to Optimizer API or compatible service.
-    ## api_url=https://navoptapi.optimizer.cloudera.com/
+    # Hostname to Optimizer API or compatible service.
+    ## hostname=navoptapi.optimizer.cloudera.com
 
     # The name of the key of the service.
     ## auth_key=e0819f3a-1e6f-4904-be69-5b704bacd1245

+ 2 - 2
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1636,8 +1636,8 @@
 [metadata]
 
   [[optimizer]]
-    # Base URL to Optimizer API or compatible service.
-    ## api_url=https://navoptapi.optimizer.cloudera.com/
+    # Hostnameto Optimizer API or compatible service.
+    ## hostname=navoptapi.optimizer.cloudera.com
 
     # The name of the key of the service.
     ## auth_key=e0819f3a-1e6f-4904-be69-5b704bacd1245

+ 5 - 10
desktop/libs/metadata/src/metadata/conf.py

@@ -46,7 +46,7 @@ def default_navigator_url():
 
 
 def get_optimizer_url():
-  return OPTIMIZER.API_URL.get() and OPTIMIZER.API_URL.get().strip('/')
+  return OPTIMIZER.HOSTNAME.get() and OPTIMIZER.HOSTNAME.get().strip('/')
 
 def has_optimizer():
   return bool(OPTIMIZER.AUTH_KEY.get())
@@ -72,10 +72,10 @@ OPTIMIZER = ConfigSection(
   key='optimizer',
   help=_t("""Configuration options for Optimizer API"""),
   members=dict(
-    API_URL=Config(
-      key='api_url',
-      help=_t('Base URL to Optimizer API or compatible service.'),
-      default='https://"navoptapi.optimizer.cloudera.com/'),
+    HOSTNAME=Config(
+      key='hostname',
+      help=_t('Hostname to Optimizer API or compatible service.'),
+      default='navoptapi.optimizer.cloudera.com'),
 
     AUTH_KEY=Config(
       key="auth_key",
@@ -103,11 +103,6 @@ OPTIMIZER = ConfigSection(
       help=_t("The name of the cluster used to determine the tenant id when this one is not specified. Defaults to the cluster Id or 'default'."),
       private=True,
       default=DEFAULT_CLUSTER_ID.get()),
-    EMAIL=Config(
-      key="email",
-      help=_t("The email of the Optimizer account to use (deprecated)."),
-      private=True,
-      default=None),
 
     APPLY_SENTRY_PERMISSIONS = Config(
       key="apply_sentry_permissions",

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

@@ -77,10 +77,10 @@ def error_handler(view_fn):
 def get_tenant(request):
   response = {'status': -1}
 
-  email = request.POST.get('email')
+  cluster_id = request.POST.get('cluster_id')
 
   api = OptimizerApi(request.user)
-  data = api.get_tenant(email=email)
+  data = api.get_tenant(cluster_id=cluster_id)
 
   if data:
     response['status'] = 0

+ 8 - 11
desktop/libs/metadata/src/metadata/optimizer_client.py

@@ -22,7 +22,6 @@ import os
 import uuid
 
 from tempfile import NamedTemporaryFile
-from urlparse import urlparse
 
 from django.core.cache import cache
 from django.utils.functional import wraps
@@ -90,9 +89,8 @@ class OptimizerApi(object):
     self._api_url = (api_url or get_optimizer_url()).strip('/')
     self._auth_key = auth_key if auth_key else OPTIMIZER.AUTH_KEY.get()
     self._auth_key_secret = auth_key_secret if auth_key_secret else (OPTIMIZER.AUTH_KEY_SECRET.get() and OPTIMIZER.AUTH_KEY_SECRET.get().replace('\\n', '\n'))
-    self._email = OPTIMIZER.EMAIL.get()
 
-    self._api = ApiLib("navopt", urlparse(self._api_url).hostname, self._auth_key, self._auth_key_secret)
+    self._api = ApiLib("navopt", self._api_url, self._auth_key, self._auth_key_secret)
 
     self._tenant_id = tenant_id if tenant_id else _get_tenant_id(self) # Aka "workload"
 
@@ -112,13 +110,8 @@ class OptimizerApi(object):
       return data
 
 
-  def get_tenant(self, email=None, cluster_id=None):
-    if cluster_id is not None:
-      args = {'clusterId' : cluster_id}
-    else:
-      args = {'email': email or self._email}
-
-    return self._call('getTenant', args)
+  def get_tenant(self, cluster_id='default'):
+    return self._call('getTenant', {'clusterId' : cluster_id})
 
 
   def upload(self, data, data_type='queries', source_platform='generic', workload_id=None):
@@ -399,6 +392,10 @@ def _secure_results(results, user, action='SELECT'):
 def _get_tenant_id(api):
   tenant_id = OPTIMIZER.TENANT_ID.get() or cache.get(OPTIMIZER_TENANT_ID_CACHE_KEY)
   if not tenant_id:
-    tenant_id = api.get_tenant(cluster_id=OPTIMIZER.CLUSTER_ID.get())['tenant']
+    tenant = api.get_tenant(cluster_id=OPTIMIZER.CLUSTER_ID.get())
+    if 'tenant' in tenant:
+      tenant_id = tenant['tenant']
+    else:
+      raise PopupException(_('Could not get tenant id from cluster id %s: %s') % (OPTIMIZER.CLUSTER_ID.get(), tenant))
     cache.set(OPTIMIZER_TENANT_ID_CACHE_KEY, tenant_id, 60 * 60 * 24 * 30)
   return tenant_id