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 2017/05/19 10:11:47 UTC

ambari git commit: AMBARI-21061 Integrate Config History page with with websocket events. (atkach)

Repository: ambari
Updated Branches:
  refs/heads/branch-3.0-perf cef3f245e -> 2eb7844b7


AMBARI-21061 Integrate Config History page with with websocket events. (atkach)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2eb7844b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2eb7844b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2eb7844b

Branch: refs/heads/branch-3.0-perf
Commit: 2eb7844b7025d52a641c61cccb3ad9f835de45f4
Parents: cef3f24
Author: Andrii Tkach <at...@apache.org>
Authored: Thu May 18 19:54:10 2017 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Thu May 18 19:54:10 2017 +0300

----------------------------------------------------------------------
 ambari-web/app/controllers/main.js              |  1 +
 .../main/dashboard/config_history_controller.js | 19 +++------
 .../mixins/common/table_server_view_mixin.js    |  2 +-
 ambari-web/app/utils/stomp_client.js            | 15 +++----
 .../views/main/dashboard/config_history_view.js |  6 +--
 .../dashboard/config_history_controller_test.js | 45 +++++++++++---------
 ambari-web/test/utils/stomp_client_test.js      |  4 +-
 .../main/dashboard/config_history_view_test.js  | 26 ++++++-----
 8 files changed, 56 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/app/controllers/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main.js b/ambari-web/app/controllers/main.js
index 499df74..18018d9 100644
--- a/ambari-web/app/controllers/main.js
+++ b/ambari-web/app/controllers/main.js
@@ -51,6 +51,7 @@ App.MainController = Em.Controller.extend({
     App.store.defaultTransaction.reopen({
       removeCleanRecords: Em.K
     });
+    App.StompClient.connect();
     App.router.get('clusterController').loadClusterData();
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/app/controllers/main/dashboard/config_history_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/dashboard/config_history_controller.js b/ambari-web/app/controllers/main/dashboard/config_history_controller.js
index 5197ad9..197a88b 100644
--- a/ambari-web/app/controllers/main/dashboard/config_history_controller.js
+++ b/ambari-web/app/controllers/main/dashboard/config_history_controller.js
@@ -22,10 +22,8 @@ App.MainConfigHistoryController = Em.ArrayController.extend(App.TableServerMixin
   name: 'mainConfigHistoryController',
 
   content: App.ServiceConfigVersion.find(),
-  isPolling: false,
   totalCount: 0,
   filteredCount: 0,
-  timeoutRef: null,
   resetStartIndex: true,
   mockUrl: '/data/configurations/service_versions.json',
   realUrl: function () {
@@ -234,19 +232,12 @@ App.MainConfigHistoryController = Em.ArrayController.extend(App.TableServerMixin
     }
   },
 
-  /**
-   * request latest data from server and update content
-   */
-  doPolling: function () {
-    var self = this;
+  subscribeToUpdates: function() {
+    App.StompClient.subscribe('/events/configs', this.load.bind(this));
+  },
 
-    this.set('timeoutRef', setTimeout(function () {
-      if (self.get('isPolling')) {
-        self.load().done(function () {
-          self.doPolling();
-        })
-      }
-    }, App.componentsUpdateInterval));
+  unsubscribeOfUpdates: function() {
+    App.StompClient.unsubscribe('/events/configs');
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/app/mixins/common/table_server_view_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/table_server_view_mixin.js b/ambari-web/app/mixins/common/table_server_view_mixin.js
index a4e6db7..9695579 100644
--- a/ambari-web/app/mixins/common/table_server_view_mixin.js
+++ b/ambari-web/app/mixins/common/table_server_view_mixin.js
@@ -58,7 +58,7 @@ App.TableServerViewMixin = Em.Mixin.create({
     return content.sort(function (a, b) {
       return a.get('index') - b.get('index');
     });
-  }.property('filteredContent'),
+  }.property('filteredContent.length'),
 
   /**
    * compute applied filter and run content update from server

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/app/utils/stomp_client.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/stomp_client.js b/ambari-web/app/utils/stomp_client.js
index 53fb2ce..1e63164 100644
--- a/ambari-web/app/utils/stomp_client.js
+++ b/ambari-web/app/utils/stomp_client.js
@@ -28,10 +28,10 @@ module.exports = Em.Object.extend({
    * TODO set actual url
    * @type string
    */
-  webSocketUrl: 'ws://localhost:11080/stomp',
+  webSocketUrl: 'ws://{hostname}:8080/api/stomp/v1',
 
   //TODO set actual url
-  sockJsUrl: 'http://localhost:11080/stomp',
+  sockJsUrl: 'http://{hostname}:8080/api/stomp/v1',
 
   /**
    * @type {boolean}
@@ -54,11 +54,7 @@ module.exports = Em.Object.extend({
    * default headers
    * @type {object}
    */
-  headers: {
-    "Authorization": "Basic " + btoa("admin:admin"),
-    "correlationId": 1,
-    "content-type": "text/plain"
-  },
+  headers: {},
 
   connect: function(useSockJS) {
     const dfd = $.Deferred();
@@ -84,11 +80,12 @@ module.exports = Em.Object.extend({
    * @returns {*}
    */
   getSocket: function(useSockJS) {
+    const hostname = window.location.hostname;
     if (!WebSocket || useSockJS) {
       this.set('isWebSocketSupported', false);
-      return new SockJS(this.get('sockJsUrl'));
+      return new SockJS(this.get('sockJsUrl').replace('{hostname}', hostname));
     } else {
-      return new WebSocket(this.get('webSocketUrl'));
+      return new WebSocket(this.get('webSocketUrl').replace('{hostname}', hostname));
     }
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/app/views/main/dashboard/config_history_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/dashboard/config_history_view.js b/ambari-web/app/views/main/dashboard/config_history_view.js
index 4afd73b..9be1c8d 100644
--- a/ambari-web/app/views/main/dashboard/config_history_view.js
+++ b/ambari-web/app/views/main/dashboard/config_history_view.js
@@ -60,16 +60,14 @@ App.MainConfigHistoryView = App.TableView.extend(App.TableServerViewMixin, {
     this.addObserver('displayLength', this, 'updatePagination');
     this.set('isInitialRendering', true);
     this.refresh();
-    this.set('controller.isPolling', true);
-    this.get('controller').doPolling();
+    this.get('controller').subscribeToUpdates();
   },
 
   /**
    * stop polling after leaving config history page
    */
   willDestroyElement: function () {
-    this.set('controller.isPolling', false);
-    clearTimeout(this.get('controller.timeoutRef'));
+    this.get('controller').unsubscribeOfUpdates();
   },
 
   updateFilter: function (iColumn, value, type) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/test/controllers/main/dashboard/config_history_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/dashboard/config_history_controller_test.js b/ambari-web/test/controllers/main/dashboard/config_history_controller_test.js
index db3d10f..771fd16 100644
--- a/ambari-web/test/controllers/main/dashboard/config_history_controller_test.js
+++ b/ambari-web/test/controllers/main/dashboard/config_history_controller_test.js
@@ -131,28 +131,31 @@ describe('MainConfigHistoryController', function () {
     });
   });
 
-  describe('#doPolling()', function () {
-    beforeEach(function () {
-      sinon.stub(controller, 'load', function(){
-        return {done: Em.K};
-      });
-      this.clock = sinon.useFakeTimers();
+  describe('#subscribeToUpdates', function() {
+    beforeEach(function() {
+      sinon.stub(App.StompClient, 'subscribe');
     });
-    afterEach(function () {
-      this.clock.restore();
-      controller.load.restore();
-    });
-    it('isPolling false', function () {
-      controller.set('isPolling', false);
-      controller.doPolling();
-      this.clock.tick(App.componentsUpdateInterval);
-      expect(controller.load.called).to.be.false;
-    });
-    it('isPolling true', function () {
-      controller.set('isPolling', true);
-      controller.doPolling();
-      this.clock.tick(App.componentsUpdateInterval);
-      expect(controller.load.calledOnce).to.be.true;
+    afterEach(function() {
+      App.StompClient.subscribe.restore();
+    });
+
+    it('App.StompClient.subscribe should be called', function() {
+      controller.subscribeToUpdates();
+      expect(App.StompClient.subscribe.calledWith('/events/configs')).to.be.true;
+    });
+  });
+
+  describe('#unsubscribeOfUpdates', function() {
+    beforeEach(function() {
+      sinon.stub(App.StompClient, 'unsubscribe');
+    });
+    afterEach(function() {
+      App.StompClient.unsubscribe.restore();
+    });
+
+    it('App.StompClient.subscribe should be called', function() {
+      controller.unsubscribeOfUpdates();
+      expect(App.StompClient.unsubscribe.calledWith('/events/configs')).to.be.true;
     });
   });
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/test/utils/stomp_client_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/stomp_client_test.js b/ambari-web/test/utils/stomp_client_test.js
index 450ab70..a85e6cc 100644
--- a/ambari-web/test/utils/stomp_client_test.js
+++ b/ambari-web/test/utils/stomp_client_test.js
@@ -66,10 +66,10 @@ describe('App.StompClient', function () {
 
   describe('#getSocket', function() {
     it('should return WebSocket instance', function() {
-      expect(stomp.getSocket().URL).to.be.equal('ws://localhost:11080/stomp');
+      expect(stomp.getSocket().URL).to.be.equal('ws://:8080/api/stomp/v1');
     });
     it('should return SockJS instance', function() {
-      expect(stomp.getSocket(true).url).to.be.equal('http://localhost:11080/stomp');
+      expect(stomp.getSocket(true).url).to.be.equal('http://:8080/api/stomp/v1');
     });
   });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2eb7844b/ambari-web/test/views/main/dashboard/config_history_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/dashboard/config_history_view_test.js b/ambari-web/test/views/main/dashboard/config_history_view_test.js
index 979aefc..d43f0c1 100644
--- a/ambari-web/test/views/main/dashboard/config_history_view_test.js
+++ b/ambari-web/test/views/main/dashboard/config_history_view_test.js
@@ -36,7 +36,8 @@ describe('App.MainConfigHistoryView', function() {
           name: 'startIndex'
         }
       ],
-      doPolling: Em.K,
+      subscribeToUpdates: Em.K,
+      unsubscribeOfUpdates: Em.K,
       load: function () {
         return {done: Em.K};
       },
@@ -262,13 +263,13 @@ describe('App.MainConfigHistoryView', function() {
 
     beforeEach(function () {
       sinon.stub(view, 'addObserver', Em.K);
-      sinon.spy(view.get('controller'), 'doPolling');
+      sinon.stub(view.get('controller'), 'subscribeToUpdates');
       view.didInsertElement();
     });
 
     afterEach(function () {
+      view.get('controller').subscribeToUpdates.restore();
       view.addObserver.restore();
-      view.get('controller').doPolling.restore();
     });
 
     it('addObserver is called twice', function() {
@@ -279,12 +280,8 @@ describe('App.MainConfigHistoryView', function() {
       expect(view.get('isInitialRendering')).to.be.true;
     });
 
-    it('controller.isPolling is true', function() {
-      expect(view.get('controller.isPolling')).to.be.true;
-    });
-
-    it('controller.doPolling is true', function() {
-      expect(view.get('controller').doPolling.calledOnce).to.be.true;
+    it('subscribeToUpdates should be called', function() {
+      expect(view.get('controller').subscribeToUpdates.calledOnce).to.be.true;
     });
   });
 
@@ -318,9 +315,16 @@ describe('App.MainConfigHistoryView', function() {
   });
 
   describe('#willDestroyElement()', function() {
-    it('controller.isPolling is false', function() {
+    beforeEach(function () {
+      sinon.stub(view.get('controller'), 'unsubscribeOfUpdates');
+    });
+    afterEach(function () {
+      view.get('controller').unsubscribeOfUpdates.restore();
+    });
+
+    it('unsubscribeOfUpdates should be called', function() {
       view.willDestroyElement();
-      expect(view.get('controller.isPolling')).to.be.false;
+      expect(view.get('controller').unsubscribeOfUpdates.calledOnce).to.be.true;
     });
   });