This is an automated email from the ASF dual-hosted git repository.

atkach pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2525a2a  AMBARI-23392 Duplicate websocket subscription on Configs page
2525a2a is described below

commit 2525a2af01d9e44694ee5aa5fb24c6ad8e15db7d
Author: Andrii Tkach <[email protected]>
AuthorDate: Wed Mar 28 17:28:18 2018 +0300

    AMBARI-23392 Duplicate websocket subscription on Configs page
---
 .../app/controllers/main/service/info/configs.js   | 11 -------
 ambari-web/app/routes/main.js                      | 12 ++------
 ambari-web/app/utils/stomp_client.js               | 35 ++++++++++++++++------
 ambari-web/test/utils/stomp_client_test.js         |  8 ++++-
 4 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/ambari-web/app/controllers/main/service/info/configs.js 
b/ambari-web/app/controllers/main/service/info/configs.js
index c0b6b5b..4ca73a2 100644
--- a/ambari-web/app/controllers/main/service/info/configs.js
+++ b/ambari-web/app/controllers/main/service/info/configs.js
@@ -352,7 +352,6 @@ App.MainServiceInfoConfigsController = 
Em.Controller.extend(App.AddSecurityConfi
    */
   loadStep: function () {
     var serviceName = this.get('content.serviceName'), self = this;
-    App.router.get('mainController').stopPolling();
     this.clearStep();
     this.set('dependentServiceNames', 
this.getServicesDependencies(serviceName));
     this.trackRequestChain(this.loadConfigTheme(serviceName).always(function 
() {
@@ -366,16 +365,6 @@ App.MainServiceInfoConfigsController = 
Em.Controller.extend(App.AddSecurityConfi
   },
 
   /**
-   * Turn on polling when all requests are finished
-   */
-  trackRequestsDidChange: function() {
-    var allCompleted = 
this.get('requestsInProgress').everyProperty('completed', true);
-    if (this.get('requestsInProgress').length && allCompleted) {
-      App.router.get('mainController').startPolling();
-    }
-  }.observes('[email protected]'),
-
-  /**
    * Generate "finger-print" for current <code>stepConfigs[0]</code>
    * Used to determine, if user has some unsaved changes (comparing with 
<code>hash</code>)
    * @returns {string|null}
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index a5f9345..6f20aa1 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -282,7 +282,6 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
           });
         },
         exitRoute: function (router, context, callback) {
-          router.get('mainController').startPolling();
           callback();
         }
       }),
@@ -819,7 +818,6 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
             //if service is not existed then route to default service
             if (item.get('isLoaded')) {
               if (router.get('mainServiceItemController.isConfigurable')) {
-                router.get('mainController').stopPolling();
                 
router.get('mainServiceItemController').connectOutlet('mainServiceInfoConfigs', 
item);
               }
               else {
@@ -834,17 +832,11 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
         },
         exitRoute: function (router, nextRoute, callback) {
           var controller = router.get('mainServiceInfoConfigsController');
-          var exitCallback = function() {
-            if (!/\/main\/services\/\w+\/configs$/.test(nextRoute)) {
-              router.get('mainController').startPolling();
-            }
-            callback();
-          };
           // If another user is running some wizard, current user can't save 
configs
           if (controller.hasUnsavedChanges() && 
!router.get('wizardWatcherController.isWizardRunning')) {
-            controller.showSavePopup(exitCallback);
+            controller.showSavePopup(callback);
           } else {
-            exitCallback();
+            callback();
           }
         }
       }),
diff --git a/ambari-web/app/utils/stomp_client.js 
b/ambari-web/app/utils/stomp_client.js
index 2003559..36377c4 100644
--- a/ambari-web/app/utils/stomp_client.js
+++ b/ambari-web/app/utils/stomp_client.js
@@ -18,6 +18,18 @@
 
 var App = require('app');
 
+/**
+ * Example:
+ *
+ * stompClient.connect();
+ * stompClient.subscribe('topic1', handlerFunc1);
+ * stompClient.addHandler('topic1', 'handler2-name', handlerFunc2);
+ * stompClient.removeHandler('topic1', 'handler2-name');
+ * stompClient.unsubscribe('topic1');
+ * stompClient.disconnect();
+ *
+ */
+
 module.exports = Em.Object.extend({
   /**
    * @type {Stomp}
@@ -171,15 +183,20 @@ module.exports = Em.Object.extend({
     if (!this.get('client.connected')) {
       return null;
     }
-    const subscription = this.get('client').subscribe(destination, (message) 
=> {
-      for (var i in handlers) {
-        handlers[i](JSON.parse(message.body));
-      }
-    });
-    subscription.destination = destination;
-    subscription.handlers = handlers;
-    this.get('subscriptions')[destination] = subscription;
-    return subscription;
+    if (this.get('subscriptions')[destination]) {
+      console.error(`Subscription with default handler for ${destination} 
already exists`);
+      return this.get('subscriptions')[destination];
+    } else {
+      const subscription = this.get('client').subscribe(destination, (message) 
=> {
+        for (const i in handlers) {
+          handlers[i](JSON.parse(message.body));
+        }
+      });
+      subscription.destination = destination;
+      subscription.handlers = handlers;
+      this.get('subscriptions')[destination] = subscription;
+      return subscription;
+    }
   },
 
   /**
diff --git a/ambari-web/test/utils/stomp_client_test.js 
b/ambari-web/test/utils/stomp_client_test.js
index c2cb3dc..3f2e8ba 100644
--- a/ambari-web/test/utils/stomp_client_test.js
+++ b/ambari-web/test/utils/stomp_client_test.js
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-var App = require('app');
 var stompClientClass = require('utils/stomp_client');
 
 describe('App.StompClient', function () {
@@ -174,6 +173,13 @@ describe('App.StompClient', function () {
       expect(stomp.subscribe('foo')).to.be.null;
       expect(stomp.get('subscriptions')).to.be.empty;
     });
+    it('should not subscribe when subscription already exist', function() {
+      stomp.set('client', {connected: true});
+      stomp.set('subscriptions', {
+        'foo': {}
+      });
+      expect(stomp.subscribe('foo')).to.be.eql({});
+    });
     it('should subscribe when client connected', function() {
       var client = {
         connected: true,

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to