Browse Source

HUE-8330 [assist] Only enable namespace refresh when there are multiple clusters configured

Johan Ahlen 7 years ago
parent
commit
65fce15ae1

+ 1 - 1
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -150,7 +150,7 @@ var MetastoreViewModel = (function () {
         var params = {
           source: self.source().type
         };
-        if (self.source().namespaces().length > 1) {
+        if (self.source().namespaces().length > 1 || self.source().namespaceRefreshEnabled()) {
           params.namespace = self.source().namespace().id
         }
         if (self.source().namespace().database() && self.source().namespace().database().table()) {

+ 4 - 5
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -25,12 +25,10 @@ var MetastoreSource = (function () {
     self.reloading = ko.observable(false);
     self.loading = ko.observable(false);
 
-    self.namespace = ko.observable();
-    self.namespaces = ko.observableArray();
-
     self.lastLoadNamespacesDeferred = $.Deferred();
     self.namespace = ko.observable();
     self.namespaces = ko.observableArray();
+    self.namespaceRefreshEnabled = ko.observable();
 
     self.namespace.subscribe(function () {
       if (self.namespace() && self.namespace().databases().length === 0) {
@@ -132,8 +130,9 @@ var MetastoreSource = (function () {
   MetastoreSource.prototype.loadNamespaces = function () {
     var self = this;
     self.loading(true);
-    ContextCatalog.getNamespaces({ sourceType: self.type }).done(function (namespaces) {
-      self.namespaces($.map(namespaces, function (namespace) {
+    ContextCatalog.getNamespaces({ sourceType: self.type }).done(function (context) {
+      self.namespaceRefreshEnabled(context.dynamic);
+      self.namespaces($.map(context.namespaces, function (namespace) {
         return new MetastoreNamespace({
           metastoreViewModel: self.metastoreViewModel,
           sourceType: self.type,

+ 1 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -85,7 +85,7 @@ ${ components.menubar(is_embeddable) }
   <div style="font-size: 14px; margin: 0 12px; line-height: 27px;">
     <div data-bind="component: { name: 'hue-drop-down', params: { value: source, entries: sources, onChanged: sourceChanged, labelAttribute: 'name', searchable: true, linkTitle: '${ _ko('Source') }' } }" style="display: inline-block"></div>
     <!-- ko with: source -->
-    <!-- ko if: namespaces().length > 1 -->
+    <!-- ko if: namespaces().length > 1 || namespaceRefreshEnabled() -->
     <div class="margin-left-10" data-bind="component: { name: 'hue-drop-down', params: { value: namespace, entries: namespaces, onChanged: namespaceChanged, labelAttribute: 'name', searchable: true, linkTitle: '${ _ko('Namespace') }' } }" style="display: inline-block"></div>
     <!-- /ko -->
     <!-- /ko -->

+ 1 - 1
apps/oozie/src/oozie/static/oozie/js/workflow-editor.ko.js

@@ -531,7 +531,7 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
   self.availableComputes = ko.observableArray();
   self.compute = ko.observable();
 
-  ContextCatalog.getNamespaces({ sourceType: 'oozie' }).done(self.availableNamespaces);
+  ContextCatalog.getNamespaces({ sourceType: 'oozie' }).done(function (context) { self.availableNamespaces(context.namespaces) });
   ContextCatalog.getComputes({ sourceType: 'oozie' }).done(self.availableComputes);
 
 

+ 2 - 2
apps/pig/src/pig/templates/app.mako

@@ -1020,9 +1020,9 @@ ${ commonshare() | n,unicode }
       var apiHelper = ApiHelper.getInstance({
         user: '${ user }'
       });
-      ContextCatalog.getNamespaces({ sourceType: 'hive' }).done(function (namespaces) {
+      ContextCatalog.getNamespaces({ sourceType: 'hive' }).done(function (context) {
         // TODO: Namespace selection
-        DataCatalog.getChildren({ namespace: namespaces[0], sourceType: 'hive', path: ['default'], silenceErrors: true }).done(function (childEntries) {
+        DataCatalog.getChildren({ namespace: context.namespaces[0], sourceType: 'hive', path: ['default'], silenceErrors: true }).done(function (childEntries) {
           availableTables = $.map(childEntries, function (entry) { return entry.name }).join(' ');
         });
       });

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

@@ -79,7 +79,7 @@ def get_config(request):
 
 @api_error_handler
 def get_context_namespaces(request, interface):
-  response = {'hasMulticluser': False}
+  response = {'dynamicClusters': False}
   namespaces = []
 
   clusters = get_clusters(request.user).values()
@@ -99,7 +99,7 @@ def get_context_namespaces(request, interface):
           'status': namespace.get('status'),
         } for namespace in SdxApi(request.user).list_namespaces()]
       )
-      response['hasMulticluser'] = True
+      response['dynamicClusters'] = True
 
   response[interface] = namespaces
   response['status'] = 0

+ 7 - 5
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -35,6 +35,7 @@ var AssistDbSource = (function () {
 
     self.selectedNamespace = ko.observable();
     self.namespaces = ko.observableArray();
+    self.namespaceRefreshEnabled = ko.observable(false);
 
     self.loadedDeferred = $.Deferred();
     self.loading = ko.observable(false);
@@ -82,13 +83,13 @@ var AssistDbSource = (function () {
 
   AssistDbSource.prototype.loadNamespaces = function () {
     var self = this;
-
     self.loading(true);
 
-    ContextCatalog.getNamespaces({ sourceType: self.sourceType }).done(function (namespaces) {
+    ContextCatalog.getNamespaces({ sourceType: self.sourceType }).done(function (context) {
       var assistNamespaces = [];
       var activeNamespace;
-      namespaces.forEach(function (namespace) {
+      self.namespaceRefreshEnabled(context.dynamic);
+      context.namespaces.forEach(function (namespace) {
         var assistNamespace = new AssistDbNamespace({
           sourceType: self.sourceType,
           namespace: namespace,
@@ -123,13 +124,14 @@ var AssistDbSource = (function () {
   AssistDbSource.prototype.triggerRefresh = function (data, event) {
     var self = this;
     self.loading(true);
-    ContextCatalog.getNamespaces({ sourceType: self.sourceType, clearCache: true }).done(function (namespaces) {
+    ContextCatalog.getNamespaces({ sourceType: self.sourceType, clearCache: true }).done(function (context) {
       var newNamespaces = [];
       var existingNamespaceIndex = {};
+      self.namespaceRefreshEnabled(context.dynamic);
       self.namespaces().forEach(function (assistNamespace) {
         existingNamespaceIndex[assistNamespace.namespace.id] = assistNamespace;
       });
-      namespaces.forEach(function(newNamespace) {
+      context.namespaces.forEach(function(newNamespace) {
         if (existingNamespaceIndex[newNamespace.id]) {
           existingNamespaceIndex[newNamespace.id].namespace = newNamespace;
           existingNamespaceIndex[newNamespace.id].name = newNamespace.name;

+ 4 - 3
desktop/core/src/desktop/static/desktop/js/contextCatalog.js

@@ -23,7 +23,7 @@
 var ContextCatalog = (function () {
 
   var STORAGE_POSTFIX = LOGGED_USERNAME;
-  var CONTEXT_CATALOG_VERSION = 1;
+  var CONTEXT_CATALOG_VERSION = 2;
   var NAMESPACES_CONTEXT_TYPE = 'namespaces';
   var COMPUTES_CONTEXT_TYPE = 'computes';
 
@@ -103,10 +103,11 @@ var ContextCatalog = (function () {
         ApiHelper.getInstance().fetchContextNamespaces(options).done(function (namespaces) {
           if (namespaces[options.sourceType]) {
             var namespaces = namespaces[options.sourceType];
+            var dynamic = namespaces.hasMultiCluster;
             if (namespaces) {
-              self.namespaces[self.sourceType] = namespaces;
+              self.namespaces[self.sourceType] = { namespaces: namespaces, dynamic: dynamic };
               deferred.resolve(self.namespaces[self.sourceType]);
-              self.saveLater(NAMESPACES_CONTEXT_TYPE, options.sourceType, namespaces);
+              self.saveLater(NAMESPACES_CONTEXT_TYPE, options.sourceType, self.namespaces[self.sourceType]);
             } else {
               deferred.reject();
             }

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/jquery.hiveautocomplete.js

@@ -53,9 +53,9 @@
     if (self.options.activeNamespace) {
       self.activeContextNamespaceDeferred.resolve(self.options.activeNamespace);
     } else {
-      ContextCatalog.getNamespaces({ sourceType: 'hive' }).done(function (namespaces) {
+      ContextCatalog.getNamespaces({ sourceType: 'hive' }).done(function (context) {
         // TODO: Namespace selection in caller
-        self.activeContextNamespaceDeferred.resolve(namespaces[0]);
+        self.activeContextNamespaceDeferred.resolve(context.namespaces[0]);
       })
     }
 

+ 14 - 3
desktop/core/src/desktop/templates/assist.mako

@@ -309,12 +309,21 @@ from desktop.views import _ko
       </a>
       <!-- /ko -->
       <!-- ko ifnot: selectedSource().selectedNamespace().selectedDatabase() -->
+      <!-- ko if: selectedSource().namespaceRefreshEnabled() || selectedSource().namespaces().length > 1-->
       <a data-bind="click: back">
         <i class="fa fa-chevron-left assist-breadcrumb-back"></i>
-        <i class="fa assist-breadcrumb-text" data-bind="css: { 'fa-snowflake-o': selectedSource().namespaces().length > 1, 'fa-server': selectedSource().namespaces().length <= 1 }"></i>
+        <i class="fa fa-snowflake-o assist-breadcrumb-text"></i>
         <span class="assist-breadcrumb-text" data-bind="text: breadcrumb, attr: {'title': breadcrumb() + ' (' + selectedSource().sourceType + ')' }"></span>
       </a>
       <!-- /ko -->
+      <!-- ko if: !selectedSource().namespaceRefreshEnabled() && selectedSource().namespaces().length <= 1 -->
+      <a data-bind="click: back">
+        <i class="fa fa-chevron-left assist-breadcrumb-back"></i>
+        <i class="fa fa-server assist-breadcrumb-text"></i>
+        <span class="assist-breadcrumb-text" data-bind="text: breadcrumb"></span>
+      </a>
+      <!-- /ko -->
+      <!-- /ko -->
       <!-- /ko -->
       <!-- ko ifnot: selectedSource().selectedNamespace() -->
       <a data-bind="click: back">
@@ -771,8 +780,10 @@ from desktop.views import _ko
     <div class="assist-db-header-actions">
       <!-- ko ifnot: loading -->
       <span class="assist-tables-counter">(<span data-bind="text: filteredNamespaces().length"></span>)</span>
+      <!-- ko if: namespaceRefreshEnabled -->
       <a class="inactive-action" href="javascript:void(0)" data-bind="click: triggerRefresh"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : loading }" title="${_('Refresh')}"></i></a>
       <!-- /ko -->
+      <!-- /ko -->
       <!-- ko if: loading -->
       <i class="fa fa-refresh fa-spin blue" title="${_('Refresh')}"></i>
       <!-- /ko -->
@@ -1336,7 +1347,7 @@ from desktop.views import _ko
               if (self.selectedSource().selectedNamespace().selectedDatabase()) {
                 return self.selectedSource().selectedNamespace().selectedDatabase().catalogEntry.name
               }
-              if (self.selectedSource().namespaces().length > 1) {
+              if (self.selectedSource().namespaceRefreshEnabled() || self.selectedSource().namespaces().length > 1) {
                 return self.selectedSource().selectedNamespace().name
               }
             }
@@ -1352,7 +1363,7 @@ from desktop.views import _ko
           if (self.selectedSource() && self.selectedSource().selectedNamespace()) {
             if (self.selectedSource().selectedNamespace().selectedDatabase()) {
               self.selectedSource().selectedNamespace().selectedDatabase(null);
-            } else if (self.selectedSource().namespaces().length > 1) {
+            } else if (self.selectedSource().namespaceRefreshEnabled() || self.selectedSource().namespaces().length > 1) {
               self.selectedSource().selectedNamespace(null)
             } else {
               self.selectedSource(null);

+ 2 - 2
desktop/core/src/desktop/templates/ko_components/ko_context_popover.mako

@@ -1470,9 +1470,9 @@ from metadata.conf import has_navigator
         }
 
         if (self.isCatalogEntry) {
-          ContextCatalog.getNamespaces({ sourceType: sourceType }).done(function (namespaces) {
+          ContextCatalog.getNamespaces({ sourceType: sourceType }).done(function (context) {
             // TODO: Namespace selection for global search results?
-            DataCatalog.getEntry({ sourceType: sourceType, namespace: namespaces[0], path: path, definition: { type: params.data.type.toLowerCase() }}).done(function (catalogEntry) {
+            DataCatalog.getEntry({ sourceType: sourceType, namespace: context.namespaces[0], path: path, definition: { type: params.data.type.toLowerCase() }}).done(function (catalogEntry) {
               catalogEntry.navigatorMeta = params.data;
               catalogEntry.navigatorMetaPromise = $.Deferred().resolve(catalogEntry.navigatorMeta);
               catalogEntry.saveLater();

+ 2 - 2
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -558,9 +558,9 @@ var Collection = function (vm, collection) {
   self.suggest = ko.mapping.fromJS(collection.suggest);
   self.activeNamespace = ko.observable();
 
-  ContextCatalog.getNamespaces({ sourceType: collection.engine || 'solr' }).done(function (namespaces) {
+  ContextCatalog.getNamespaces({ sourceType: collection.engine || 'solr' }).done(function (context) {
     // TODO: Namespace selection
-    self.activeNamespace(namespaces[0]);
+    self.activeNamespace(context.namespaces[0]);
   });
 
   self.engine = ko.observable(typeof collection.engine != "undefined" && collection.engine != null ? collection.engine : "solr");

+ 2 - 2
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -2093,9 +2093,9 @@ ${ assist.assistPanel() }
       self.activeNamespace = ko.observable();
 
       // TODO: sourceType? --> self.apiHelperType
-      ContextCatalog.getNamespaces({ sourceType: 'hive' }).done(function (namespaces) {
+      ContextCatalog.getNamespaces({ sourceType: 'hive' }).done(function (context) {
         // TODO: Namespace selection for create wizard
-        self.activeNamespace(namespaces[0]);
+        self.activeNamespace(context.namespaces[0]);
       });
 
       self.fileType = ko.observable();

+ 2 - 2
desktop/libs/indexer/src/indexer/templates/indexes.mako

@@ -650,9 +650,9 @@ ${ assist.assistPanel() }
       self.activeNamespace = ko.observable();
 
 
-      ContextCatalog.getNamespaces({ sourceType: 'solr' }).done(function (namespaces) {
+      ContextCatalog.getNamespaces({ sourceType: 'solr' }).done(function (context) {
         // TODO: Namespace selection
-        self.activeNamespace(namespaces[0]);
+        self.activeNamespace(context.namespaces[0]);
       });
 
       self.assistAvailable = ko.observable(true);

+ 2 - 2
desktop/libs/indexer/src/indexer/templates/topics.mako

@@ -624,9 +624,9 @@ ${ assist.assistPanel() }
 
       self.activeNamespace = ko.observable();
 
-      ContextCatalog.getNamespaces({ sourceType: 'solr' }).done(function (namespaces) {
+      ContextCatalog.getNamespaces({ sourceType: 'solr' }).done(function (context) {
         // TODO: Namespace selection
-        self.activeNamespace(namespaces[0]);
+        self.activeNamespace(context.namespaces[0]);
       });
 
       self.assistAvailable = ko.observable(true);

+ 4 - 4
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -373,14 +373,14 @@ var EditorViewModel = (function() {
       }
     });
 
-    var namespacesPromise = ContextCatalog.getNamespaces({ sourceType: self.type() }).done(function (namespaces) {
-      self.availableNamespaces(namespaces);
-      if (!snippet.namespace || !namespaces.some(function (namespace) {
+    var namespacesPromise = ContextCatalog.getNamespaces({ sourceType: self.type() }).done(function (context) {
+      self.availableNamespaces(context.namespaces);
+      if (!snippet.namespace || !context.namespaces.some(function (namespace) {
         if (namespace.id === snippet.namespace.id) {
           self.namespace(namespace);
           return true;
         }})) {
-        self.namespace(namespaces[0]);
+        self.namespace(context.namespaces[0]);
       }
     });