Prechádzať zdrojové kódy

HUE-8645 [assist] Poll for namespace status change when a namespace is starting

This also adds a spinner in the assist next to namespaces that are starting.
Johan Ahlen 7 rokov pred
rodič
commit
bb0fe68

+ 2 - 0
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -106,6 +106,7 @@ var AssistDbSource = (function () {
           if (existingNamespaceIndex[newNamespace.id]) {
             existingNamespaceIndex[newNamespace.id].namespace = newNamespace;
             existingNamespaceIndex[newNamespace.id].name = newNamespace.name;
+            existingNamespaceIndex[newNamespace.id].status(newNamespace.status);
             newNamespaces.push(existingNamespaceIndex[newNamespace.id]);
           } else {
             newNamespaces.push(new AssistDbNamespace({
@@ -245,6 +246,7 @@ var AssistDbNamespace = (function () {
     self.nonSqlType = options.nonSqlType;
 
     self.namespace = options.namespace;
+    self.status = ko.observable(options.namespace.status);
     // TODO: Compute selection in assist?
     self.compute = ko.observable();
     if (self.namespace.computes.length) {

+ 43 - 0
desktop/core/src/desktop/static/desktop/js/contextCatalog.js

@@ -140,6 +140,49 @@ var ContextCatalog = (function () {
 
       self.namespacePromises[options.sourceType] = deferred.promise();
 
+      var startingNamespaces = {};
+      var pollTimeout = -1;
+
+      var pollForStarted = function () {
+        window.clearTimeout(pollTimeout);
+        window.setTimeout(function () {
+          if (Object.keys(startingNamespaces).length) {
+            ApiHelper.getInstance().fetchContextNamespaces(options).done(function (namespaces) {
+              if (namespaces[options.sourceType]) {
+                var namespaces = namespaces[options.sourceType];
+                if (namespaces) {
+                  var statusChanged = false;
+                  namespaces.forEach(function (namespace) {
+                    if (startingNamespaces[namespace.id] && namespace.status !== 'STARTING') {
+                      startingNamespaces[namespace.id].status = namespace.status;
+                      delete startingNamespaces[namespace.id];
+                      statusChanged = true;
+                    }
+                  });
+                  if (statusChanged) {
+                    huePubSub.publish('context.catalog.namespaces.refreshed', options.sourceType);
+                  }
+                  if (Object.keys(startingNamespaces).length) {
+                    pollForStarted();
+                  }
+                }
+              }
+            });
+          }
+        }, 2000);
+      };
+
+      deferred.done(function (context) {
+        context.namespaces.forEach(function (namespace) {
+          if (namespace.status === 'STARTING') {
+            startingNamespaces[namespace.id] = namespace;
+          }
+        });
+        if (Object.keys(startingNamespaces).length) {
+          pollForStarted();
+        }
+      });
+
       var fetchNamespaces = function () {
         ApiHelper.getInstance().fetchContextNamespaces(options).done(function (namespaces) {
           if (namespaces[options.sourceType]) {

+ 5 - 0
desktop/core/src/desktop/templates/assist.mako

@@ -930,12 +930,17 @@ from desktop.views import _ko
       <!-- /ko -->
       <ul class="assist-tables" data-bind="foreach: filteredNamespaces">
         <li class="assist-table">
+          <!-- ko if: status() === 'STARTING' -->
+          <span class="assist-table-link" title="${_('Starting')}" data-bind="tooltip: { placement: 'bottom' }"><i class="fa fa-fw fa-spinner fa-spin muted valign-middle"></i> <span data-bind="text: name"></span></span>
+          <!-- /ko -->
+          <!-- ko if: status() !== 'STARTING' -->
           <!-- ko if: namespace.computes.length -->
           <a class="assist-table-link" href="javascript: void(0);" data-bind="click: function () { $parent.selectedNamespace($data); }"><i class="fa fa-fw fa-snowflake-o muted valign-middle"></i> <span data-bind="text: name"></span></a>
           <!-- /ko -->
           <!-- ko ifnot: namespace.computes.length -->
           <span class="assist-table-link" title="${_('No related computes')}" data-bind="tooltip: { placement: 'bottom' }"><i class="fa fa-fw fa-warning muted valign-middle"></i> <span data-bind="text: name"></span></span>
           <!-- /ko -->
+          <!-- /ko -->
         </li>
       </ul>
     </div>