浏览代码

HUE-6043 [metadata] Explicit handling of authentication error

In both interactive or search:
{"status": -2, "message": "Failed to authenticate."}
Romain Rigaux 8 年之前
父节点
当前提交
967de2be7f

+ 1 - 0
apps/metastore/src/metastore/views.py

@@ -528,6 +528,7 @@ def read_partition(request, database, table, partition_spec):
   except Exception, e:
     raise PopupException(_('Cannot read partition'), detail=e.message)
 
+
 @require_http_methods(["GET", "POST"])
 @check_has_write_access_permission
 def drop_partition(request, database, table):

+ 1 - 1
desktop/libs/metadata/src/metadata/metadata_sites.py

@@ -59,7 +59,7 @@ def get_navigator_audit_max_file_size():
 
 
 def get_navigator_hue_server_name():
-  return get_conf('navigator-lineage').get(_CONF_NAVIGATOR_HUE_SERVER_NAME, '')
+  return get_conf('navigator-lineage').get(_CONF_NAVIGATOR_HUE_SERVER_NAME, 'Cluster 1')
 
 
 def _parse_sites():

+ 7 - 3
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -34,7 +34,8 @@ from desktop.lib.django_util import JsonResponse
 from desktop.lib.i18n import force_unicode, smart_str
 
 from metadata.conf import has_navigator, NAVIGATOR
-from metadata.navigator_client import NavigatorApi, NavigatorApiException, EntityDoesNotExistException
+from metadata.navigator_client import NavigatorApi, NavigatorApiException, EntityDoesNotExistException,\
+  NavigathorAuthException
 
 
 LOG = logging.getLogger(__name__)
@@ -63,12 +64,15 @@ def error_handler(view_fn):
       response['message'] = e.message
       response['status'] = -3
       status = 200
+    except NavigathorAuthException, e:
+      response['message'] = force_unicode(e.message)
+      response['status'] = -2
     except NavigatorApiException, e:
       try:
         response['message'] = json.loads(e.message)
         response['status'] = -2
-      except Exception, ex:
-        response['message'] = e.message
+      except Exception:
+        response['message'] = force_unicode(e.message)
     except Exception, e:
       status = 500
       message = force_unicode(e)

+ 21 - 8
desktop/libs/metadata/src/metadata/navigator_client.py

@@ -23,6 +23,7 @@ import re
 from itertools import islice
 
 from django.core.cache import cache
+from django.utils.translation import ugettext as _
 
 from desktop.lib.i18n import smart_unicode
 from desktop.lib.rest import resource
@@ -55,7 +56,7 @@ def get_cluster_source_ids(api):
     if get_navigator_hue_server_name():
       sources = api.get_cluster_source_ids()
       if sources:
-        CLUSTER_SOURCE_IDS = '(' + ' OR '.join(['sourceId:%(sourceId)s' % _id for _id in api.get_cluster_source_ids()]) + ') AND '
+        CLUSTER_SOURCE_IDS = '(' + ' OR '.join(['sourceId:%s' % _id.get('sourceId') or _id.get('identity') for _id in api.get_cluster_source_ids()]) + ') AND '
       else:
         CLUSTER_SOURCE_IDS = 'sourceId:0 AND'
 
@@ -87,6 +88,14 @@ class EntityDoesNotExistException(Exception):
     return smart_unicode(self.message)
 
 
+class NavigathorAuthException(Exception):
+  def __init__(self, message=None):
+    self.message = message or _('No error message, please check the logs.')
+
+  def __unicode__(self):
+    return smart_unicode(self.message)
+
+
 class NavigatorApi(object):
   """
   http://cloudera.github.io/navigator/apidocs/v3/index.html
@@ -155,7 +164,7 @@ class NavigatorApi(object):
           name, val = term.split(':')
           if val:
             if name == 'type':
-              term = '%s:%s' % (name, val.upper().strip('*'))
+              term = '%s:"%s"' % (name, val.upper().strip('*'))
               default_entity_types = entity_types # Make sure type value still makes sense for the source
             user_filters.append(term + '*') # Manual filter allowed e.g. type:VIE* ca
 
@@ -190,9 +199,11 @@ class NavigatorApi(object):
 
       return response
     except RestException, e:
-      msg = 'Failed to search for entities with search query: %s' % query_s
-      LOG.error(msg)
-      raise NavigatorApiException(e)
+      LOG.error('Failed to search for entities with search query: %s' % query_s)
+      if e.code == 401:
+        raise NavigathorAuthException(_('Failed to authenticate.'))
+      else:
+        raise NavigatorApiException(e)
 
 
   def search_entities_interactive(self, query_s=None, limit=100, offset=0, facetFields=None, facetPrefix=None, facetRanges=None, filterQueries=None, firstClassEntitiesOnly=None, sources=None):
@@ -260,9 +271,11 @@ class NavigatorApi(object):
 
       return response
     except RestException, e:
-      msg = 'Failed to search for entities with search query %s' % json.dumps(body)
-      LOG.error(msg)
-      raise NavigatorApiException(e.message)
+      LOG.error('Failed to search for entities with search query: %s' % json.dumps(body))
+      if e.code == 401:
+        raise NavigathorAuthException(_('Failed to authenticate.'))
+      else:
+        raise NavigatorApiException(e.message)
 
 
   def _secure_results(self, results, checker=None):