浏览代码

HUE-6274 [metadata] Add flag to enable file search

Romain Rigaux 8 年之前
父节点
当前提交
83e7bcc872

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

@@ -1124,8 +1124,8 @@
   # Show Upload Button for HDFS file browser.
   ## show_upload_button=false
 
-  ## Flag to enable the extraction of a uploaded archive in HDFS.
-  # enable_extract_uploaded_archive=false
+  # Flag to enable the extraction of a uploaded archive in HDFS.
+  ## enable_extract_uploaded_archive=false
 
 
 ###########################################################################
@@ -1681,3 +1681,6 @@
 
     # Max number of items to fetch in one call in object search autocomplete.
     ## fetch_size_search_interactive=450
+
+    # If metadata search is enabled, also show the search box in the left assist.
+    ## enable_file_search=false

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

@@ -1126,8 +1126,8 @@
   # Show Upload Button for HDFS file browser.
   ## show_upload_button=false
 
-  ## Flag to enable the extraction of a uploaded archive in HDFS.
-  # enable_extract_uploaded_archive=false
+  # Flag to enable the extraction of a uploaded archive in HDFS.
+  ## enable_extract_uploaded_archive=false
 
 
 ###########################################################################
@@ -1685,3 +1685,6 @@
 
     # Max number of items to fetch in one call in object search autocomplete.
     ## fetch_size_search_interactive=450
+
+    # If metadata search is enabled, also show the search box in the left assist.
+    ## enable_file_search=false

+ 1 - 1
desktop/core/src/desktop/api2.py

@@ -646,7 +646,7 @@ def search_entities_interactive(request):
 
     return JsonResponse(response)
   else:
-    if has_navigator(request.user) and False:
+    if has_navigator(request.user):
       return metadata_search_entities_interactive(request)
     else:
       return JsonResponse({'status': 1, 'message': _('Navigator not enabled')})

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1704,7 +1704,7 @@ var ApiHelper = (function () {
       $.post('/desktop/api/search/entities_interactive', {
         query_s: ko.mapping.toJSON(options.query),
         limit: 5,
-        sources: '["*"]'
+        sources: '["sql", "hdfs", "s3"]'
       }),
       $.post('/desktop/api/search/entities_interactive', {
           query_s: ko.mapping.toJSON(options.query),

+ 7 - 13
desktop/core/src/desktop/templates/assist.mako

@@ -23,7 +23,7 @@ from desktop.conf import USE_NEW_SIDE_PANELS, VCS
 from desktop.lib.i18n import smart_unicode
 from desktop.views import _ko
 
-from metadata.conf import has_navigator
+from metadata.conf import has_navigator, has_navigator_file_search
 from metastore.conf import ENABLE_NEW_CREATE_TABLE
 from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING
 from notebook.conf import get_ordered_interpreters
@@ -150,13 +150,7 @@ from notebook.conf import get_ordered_interpreters
     <li><a href="javascript:void(0);" data-bind="hueLink: definition.url"><i class="fa fa-fw" data-bind="css: {'fa-folder-open-o': definition.type === 'dir', 'fa-file-text-o': definition.type === 'file'}"></i> ${ _('Open in File Browser') }</a></li>
     <!-- ko if: $currentApp() === 'editor' -->
     <li><a href="javascript:void(0);" data-bind="click: dblClick"><i class="fa fa-fw fa-paste"></i> ${ _('Insert at cursor') }</a></li>
-    ## Generate create table statement
     <!-- /ko -->
-    ## ------
-    ## Move
-    ## Copy
-    ## Rename
-    ## Delete
   </script>
 
   <script type="text/html" id="document-context-items">
@@ -166,12 +160,6 @@ from notebook.conf import get_ordered_interpreters
     <!-- ko if: definition().type !== 'directory' -->
     <li><a href="javascript: void(0);" data-bind="click: open"><i class="fa fa-fw fa-edit"></i> ${ _('Open document') }</a></li>
     <!-- /ko -->
-    ## Share
-    ## -----
-    ## Move
-    ## Copy
-    ## Rename
-    ## Delete
   </script>
 
   <script type="text/html" id="hbase-context-items">
@@ -1496,6 +1484,9 @@ from notebook.conf import get_ordered_interpreters
                   type: 'hdfs',
                   icon: 'fa-folder-o',
                   minHeight: 50
+                  % if not has_navigator_file_search(user):
+                    , showNavSearch: false
+                  % endif
                 }));
               }
 
@@ -1509,6 +1500,9 @@ from notebook.conf import get_ordered_interpreters
                   type: 's3',
                   icon: 'fa-cubes',
                   minHeight: 50
+                  % if not has_navigator_file_search(user):
+                    , showNavSearch: false
+                  % endif
                 }));
               }
 

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

@@ -183,6 +183,10 @@ def get_navigator_saml_password():
   return NAVIGATOR.AUTH_SAML_PASSWORD_SCRIPT.get()
 
 
+def has_navigator_file_search(user):
+  return has_navigator(user) and NAVIGATOR.ENABLE_FILE_SEARCH.get()
+
+
 NAVIGATOR = ConfigSection(
   key='navigator',
   help=_t("""Configuration options for Navigator API"""),
@@ -267,6 +271,13 @@ NAVIGATOR = ConfigSection(
       default=450,
       type=int
     ),
+
+    ENABLE_FILE_SEARCH = Config(
+      key="enable_file_search",
+      help=_t("Enable to search HDFS, S3 files."),
+      type=coerce_bool,
+      default=False
+    )
   )
 )
 

+ 6 - 1
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -33,7 +33,7 @@ from django.views.decorators.http import require_POST
 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.conf import has_navigator, NAVIGATOR, has_navigator_file_search
 from metadata.navigator_client import NavigatorApi, NavigatorApiException, EntityDoesNotExistException,\
   NavigathorAuthException
 
@@ -95,6 +95,8 @@ def search_entities(request):
   offset = request.POST.get('offset', 0)
   limit = int(request.POST.get('limit', 100))
   sources = json.loads(request.POST.get('sources') or '[]')
+  if sources and not has_navigator_file_search(request.user):
+    sources = ['sql']
 
   query_s = query_s.strip() or '*'
 
@@ -128,6 +130,9 @@ def search_entities_interactive(request):
   field_facets = json.loads(request.POST.get('field_facets') or '[]')
   sources = json.loads(request.POST.get('sources') or '[]')
 
+  if sources and not has_navigator_file_search(request.user):
+    sources = ['sql']
+
   f = {
       "outputFormat" : {
         "type" : "dynamic"

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

@@ -33,7 +33,7 @@ from hadoop.conf import HDFS_CLUSTERS
 from libsentry.privilege_checker import get_checker
 from libsentry.sentry_site import get_hive_sentry_provider
 
-from metadata.conf import NAVIGATOR, get_navigator_auth_password, get_navigator_auth_username
+from metadata.conf import NAVIGATOR, get_navigator_auth_password, get_navigator_auth_username, has_navigator_file_search
 from metadata.metadata_sites import get_navigator_hue_server_name
 
 
@@ -237,7 +237,7 @@ class NavigatorApi(object):
       if sources:
         default_entity_types, entity_types = self._get_types_from_sources(sources)
 
-        if 'hive' in sources or 'impala' in sources:
+        if 'sql' in sources or 'hive' in sources or 'impala' in sources:
           fq_type = default_entity_types
           filterQueries.append('sourceType:HIVE OR sourceType:IMPALA')
         elif 'hdfs' in sources: