ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atk...@apache.org
Subject ambari git commit: AMBARI-21073 Integrate host-component status with websocket events. (atkach)
Date Fri, 19 May 2017 15:08:31 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-3.0-perf c4c2ec79b -> b094c753e


AMBARI-21073 Integrate host-component status 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/b094c753
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b094c753
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b094c753

Branch: refs/heads/branch-3.0-perf
Commit: b094c753e9652c7bf866bec18caf41de90c4a8d8
Parents: c4c2ec7
Author: Andrii Tkach <atkach@apache.org>
Authored: Fri May 19 16:38:14 2017 +0300
Committer: Andrii Tkach <atkach@apache.org>
Committed: Fri May 19 16:38:14 2017 +0300

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js | 14 ++++++++
 .../global/update_controller_test.js            | 37 ++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b094c753/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index 8a3f984..28fac62 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -187,6 +187,8 @@ App.UpdateController = Em.Controller.extend({
    */
   updateAll: function () {
     if (this.get('isWorking') && !App.get('isOnlyViewUser')) {
+      this.subscribeToHostComponentsStatus();
+
       App.updater.run(this, 'updateServices', 'isWorking');
       App.updater.run(this, 'updateHost', 'isWorking');
       App.updater.run(this, 'updateServiceMetric', 'isWorking', App.componentsUpdateInterval,
'\/main\/(dashboard|services).*');
@@ -203,9 +205,21 @@ App.UpdateController = Em.Controller.extend({
       App.updater.run(this, 'updateClusterEnv', 'isWorking', App.clusterEnvUpdateInterval);
       App.updater.run(this, 'updateUpgradeState', 'isWorking', App.bgOperationsUpdateInterval);
       App.updater.run(this, 'updateWizardWatcher', 'isWorking', App.bgOperationsUpdateInterval);
+    } else {
+      App.StompClient.unsubscribe('/events/hostcomponents');
     }
   }.observes('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
 
+  subscribeToHostComponentsStatus: function() {
+    //TODO limit updates by location
+    App.StompClient.subscribe('/events/hostcomponents', (event) => {
+      const hostComponent = App.HostComponent.find(event.componentName + '_' + event.hostName);
+      if (hostComponent.get('isLoaded')) {
+        hostComponent.set('workStatus', event.currentState);
+      }
+    });
+  },
+
   /**
    *
    * @param {Function} callback

http://git-wip-us.apache.org/repos/asf/ambari/blob/b094c753/ambari-web/test/controllers/global/update_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/update_controller_test.js b/ambari-web/test/controllers/global/update_controller_test.js
index 2a9d020..4c50444 100644
--- a/ambari-web/test/controllers/global/update_controller_test.js
+++ b/ambari-web/test/controllers/global/update_controller_test.js
@@ -56,15 +56,52 @@ describe('App.UpdateController', function () {
   });
 
   describe('#updateAll()', function () {
+    beforeEach(function() {
+      sinon.stub(controller, 'subscribeToHostComponentsStatus');
+      sinon.stub(App.StompClient, 'unsubscribe');
+    });
+    afterEach(function() {
+      controller.subscribeToHostComponentsStatus.restore();
+      App.StompClient.unsubscribe.restore();
+    });
 
     it('isWorking = false', function () {
       controller.set('isWorking', false);
+      controller.updateAll();
       expect(App.updater.run.called).to.equal(false);
+      expect(App.StompClient.unsubscribe.calledWith('/events/hostcomponents')).to.be.true;
     });
 
     it('isWorking = true', function () {
       controller.set('isWorking', true);
       expect(App.updater.run.callCount).to.equal(13);
+      expect(controller.subscribeToHostComponentsStatus.calledOnce).to.be.true;
+    });
+  });
+
+  describe('#subscribeToHostComponentsStatus', function() {
+    var hc = Em.Object.create({
+      workStatus: 'INSTALLED',
+      isLoaded: true
+    });
+    beforeEach(function() {
+      sinon.stub(App.StompClient, 'subscribe', function(topic, callback) {
+        callback({
+          componentName: 'C1',
+          hostName: 'host1',
+          currentState: 'STARTED'
+        });
+      });
+      sinon.stub(App.HostComponent, 'find').returns(hc);
+    });
+    afterEach(function() {
+      App.StompClient.subscribe.restore();
+      App.HostComponent.find.restore();
+    });
+
+    it('host-component should have STARTED status', function() {
+      controller.subscribeToHostComponentsStatus();
+      expect(hc.get('workStatus')).to.be.equal('STARTED');
     });
   });
 


Mime
View raw message