瀏覽代碼

HUE-5955 [metadata] Returns cause of error in interactive search

e.g. putting 'aas:dd' in the search box:

{"status": -2, "message": {"message": "undefined field aas"}}
Romain Rigaux 8 年之前
父節點
當前提交
21ed22a

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

@@ -788,7 +788,7 @@
 [dashboard]
 
   ## Activate the Dashboard link in the menu.
-  # is_enabled=false
+  # is_enabled=true
 
   [[engines]]
 

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

@@ -790,7 +790,7 @@
 [dashboard]
 
   ## Activate the Dashboard link in the menu.
-  # is_enabled=false
+  # is_enabled=true
 
   [[engines]]
 

+ 1 - 2
desktop/libs/dashboard/src/dashboard/conf.py

@@ -17,7 +17,6 @@
 
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
-from desktop.conf import is_hue4
 from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_bool
 from desktop.appmanager import get_apps_dict
 from notebook.conf import get_ordered_interpreters
@@ -26,7 +25,7 @@ from notebook.conf import get_ordered_interpreters
 IS_ENABLED = Config(
   key="is_enabled",
   help=_t("Activate the Dashboard link in the menu."),
-  dynamic_default=is_hue4,
+  default=True,
   private=True,
   type=coerce_bool
 )

+ 14 - 5
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -34,7 +34,7 @@ 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
+from metadata.navigator_client import NavigatorApi, NavigatorApiException
 
 
 LOG = logging.getLogger(__name__)
@@ -46,6 +46,12 @@ class MetadataApiException(Exception):
 
 def error_handler(view_fn):
   def decorator(*args, **kwargs):
+    status = 200
+    response = {
+      'status': -1,
+      'message': ''
+    }
+
     try:
       if has_navigator(args[0].user):
         return view_fn(*args, **kwargs)
@@ -53,6 +59,12 @@ def error_handler(view_fn):
         raise MetadataApiException('Navigator API is not configured.')
     except Http404, e:
       raise e
+    except NavigatorApiException, e:
+      try:
+        response['message'] = json.loads(e.message)
+        response['status'] = -2
+      except Exception, e:
+        response['message'] = LOG.error(str(e))
     except Exception, e:
       status = 500
       message = force_unicode(e)
@@ -60,11 +72,8 @@ def error_handler(view_fn):
 
       if 'Could not find' in message:
         status = 200
+      response['message'] = message
 
-      response = {
-        'status': -1,
-        'message': message
-      }
     return JsonResponse(response, status=status)
   return decorator
 

+ 22 - 16
desktop/libs/metadata/src/metadata/navigator_client.py

@@ -24,9 +24,11 @@ from itertools import islice
 
 from django.core.cache import cache
 
+from desktop.lib.i18n import smart_unicode
 from desktop.lib.rest import resource
 from desktop.lib.rest.http_client import HttpClient, RestException
 
+
 from hadoop.conf import HDFS_CLUSTERS
 from libsentry.conf import PRIVILEGE_CHECKER_CACHING
 from libsentry.privilege_checker import PrivilegeChecker, SENTRY_PRIVILEGE_CACHE_KEY
@@ -70,7 +72,11 @@ def get_filesystem_host():
 
 
 class NavigatorApiException(Exception):
-  pass
+  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):
@@ -173,8 +179,8 @@ class NavigatorApi(object):
       return response
     except RestException, e:
       msg = 'Failed to search for entities with search query: %s' % query_s
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      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):
@@ -241,10 +247,10 @@ class NavigatorApi(object):
       response['results'] = list(islice(self._secure_results(response['results']), limit)) # Apply Sentry perms
 
       return response
-    except RestException:
+    except RestException, e:
       msg = 'Failed to search for entities with search query %s' % json.dumps(body)
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      raise NavigatorApiException(e.message)
 
 
   def _secure_results(self, results, checker=None):
@@ -284,8 +290,8 @@ class NavigatorApi(object):
       return self._root.get('interactive/suggestions?query=%s' % (prefix or '*'))
     except RestException, e:
       msg = 'Failed to search for entities with search query: %s' % prefix
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      raise NavigatorApiException(e.message)
 
 
   def find_entity(self, source_type, type, name, **filters):
@@ -328,8 +334,8 @@ class NavigatorApi(object):
       return response[0]
     except RestException, e:
       msg = 'Failed to find entity: %s' % str(e)
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      raise NavigatorApiException(e.message)
 
 
   def get_entity(self, entity_id):
@@ -341,8 +347,8 @@ class NavigatorApi(object):
       return self._root.get('entities/%s' % entity_id, headers=self.__headers, params=self.__params)
     except RestException, e:
       msg = 'Failed to get entity %s: %s' % (entity_id, str(e))
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      raise NavigatorApiException(e.message)
 
 
   def update_entity(self, entity_id, **metadata):
@@ -355,8 +361,8 @@ class NavigatorApi(object):
       return self._root.put('entities/%s' % entity_id, params=self.__params, data=data, allow_redirects=True, clear_cookies=True)
     except RestException, e:
       msg = 'Failed to update entity %s: %s' % (entity_id, str(e))
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      raise NavigatorApiException(e.message)
 
 
   def get_cluster_source_ids(self):
@@ -444,8 +450,8 @@ class NavigatorApi(object):
       return self._root.get('lineage', headers=self.__headers, params=params)
     except RestException, e:
       msg = 'Failed to get lineage for entity ID %s: %s' % (entity_id, str(e))
-      LOG.exception(msg)
-      raise NavigatorApiException(msg)
+      LOG.error(msg)
+      raise NavigatorApiException(e.message)