You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2018/05/07 09:51:27 UTC

[ambari] branch trunk updated: AMBARI-23763 Subscriptions should be bound to WebSocket connection

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 12084e8  AMBARI-23763 Subscriptions should be bound to WebSocket connection
12084e8 is described below

commit 12084e810d9b829a32c1bdec625321852bd52257
Author: Andrii Tkach <at...@apache.org>
AuthorDate: Fri May 4 16:58:04 2018 +0300

    AMBARI-23763 Subscriptions should be bound to WebSocket connection
---
 ambari-web/app/controllers/main.js       |  6 ++++--
 ambari-web/app/utils/stomp_client.js     |  5 ++---
 ambari-web/test/controllers/main_test.js | 14 ++++++++------
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/ambari-web/app/controllers/main.js b/ambari-web/app/controllers/main.js
index a34e199..9264801 100644
--- a/ambari-web/app/controllers/main.js
+++ b/ambari-web/app/controllers/main.js
@@ -51,7 +51,10 @@ App.MainController = Em.Controller.extend({
     App.store.defaultTransaction.reopen({
       removeCleanRecords: Em.K
     });
-    App.StompClient.connect();
+    const startSubscription = App.router.get('updateController').startSubscriptions.bind(App.router.get('updateController'));
+    App.StompClient.connect()
+      .done(startSubscription)
+      .fail((dfd) => {dfd.always(startSubscription)});
     App.router.get('clusterController').loadClusterData();
   },
 
@@ -101,7 +104,6 @@ App.MainController = Em.Controller.extend({
   startPolling: function () {
     if (App.router.get('applicationController.isExistingClusterDataLoaded')) {
       App.router.get('updateController').set('isWorking', true);
-      App.router.get('updateController').startSubscriptions();
       App.router.get('backgroundOperationsController').set('isWorking', true);
     }
   }.observes('App.router.applicationController.isExistingClusterDataLoaded'),
diff --git a/ambari-web/app/utils/stomp_client.js b/ambari-web/app/utils/stomp_client.js
index c8e47cf..3b8c78b 100644
--- a/ambari-web/app/utils/stomp_client.js
+++ b/ambari-web/app/utils/stomp_client.js
@@ -105,8 +105,7 @@ module.exports = Em.Object.extend({
       this.onConnectionSuccess();
       dfd.resolve();
     }, () => {
-      this.onConnectionError(useSockJS);
-      dfd.reject();
+      dfd.reject(this.onConnectionError(useSockJS));
     });
     client.debug = Em.K;
     this.set('client', client);
@@ -151,7 +150,7 @@ module.exports = Em.Object.extend({
       this.reconnect(useSockJS);
     } else if (!useSockJS) {//if SockJs connection failed too the stop trying to connect
       //if webSocket failed on initial connect then switch to SockJS
-      this.connect(true);
+      return this.connect(true);
     }
   },
 
diff --git a/ambari-web/test/controllers/main_test.js b/ambari-web/test/controllers/main_test.js
index 8adb1fd..460a667 100644
--- a/ambari-web/test/controllers/main_test.js
+++ b/ambari-web/test/controllers/main_test.js
@@ -31,9 +31,16 @@ describe('App.MainController', function () {
       sinon.stub(App.router, 'get').returns({
         loadClusterData: function() {
           initialize = true;
+        },
+        startSubscriptions: Em.K
+      });
+      sinon.stub(App.StompClient, 'connect').returns({
+        done: function() {
+          return {
+            fail: Em.K
+          }
         }
       });
-      sinon.stub(App.StompClient, 'connect');
     });
     afterEach(function () {
       App.router.get.restore();
@@ -105,7 +112,6 @@ describe('App.MainController', function () {
   describe('#startPolling', function() {
     var mock,
         updateController = Em.Object.create({
-          startSubscriptions: sinon.spy(),
           isWorking: false
         }),
         backgroundOperationsController = Em.Object.create({
@@ -129,10 +135,6 @@ describe('App.MainController', function () {
     it('backgroundOperationsController should be working', function() {
       expect(backgroundOperationsController.get('isWorking')).to.be.true;
     });
-
-    it('startSubscriptions should be called', function() {
-      expect(updateController.startSubscriptions.called).to.be.true;
-    });
   });
 
 });

-- 
To stop receiving notification emails like this one, please contact
atkach@apache.org.