Repository: ambari
Updated Branches:
  refs/heads/branch-3.0-perf ada8f83b7 -> 08ff5a22b


AMBARI-22324 Update handler for topology topic. (atkach)


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

Branch: refs/heads/branch-3.0-perf
Commit: 08ff5a22bb20e29bc03653922b792db240fd8b55
Parents: ada8f83
Author: Andrii Tkach <atk...@apache.org>
Authored: Fri Oct 27 14:26:41 2017 +0300
Committer: Andrii Tkach <atk...@apache.org>
Committed: Fri Oct 27 14:26:41 2017 +0300

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js |  4 +--
 ambari-web/app/mappers/server_data_mapper.js    |  8 +++---
 .../app/mappers/socket/topology_mapper.js       | 28 +++++++++++++-------
 .../global/update_controller_test.js            |  3 +--
 .../test/mappers/socket/topology_mapper_test.js | 12 +++++++--
 5 files changed, 37 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/08ff5a22/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 38e20b6..5bd89ea 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -189,7 +189,7 @@ App.UpdateController = Em.Controller.extend({
     if (this.get('isWorking') && !App.get('isOnlyViewUser')) {
       App.StompClient.subscribe('/events/hostcomponents', 
App.hostComponentStatusMapper.map.bind(App.hostComponentStatusMapper));
       App.StompClient.subscribe('/events/alerts', 
App.alertSummaryMapper.map.bind(App.alertSummaryMapper));
-      App.StompClient.subscribe('/events/topologies', 
App.topologyMapper.map.bind(App.topologyMapper));
+      App.StompClient.subscribe('/events/ui_topologies', 
App.topologyMapper.map.bind(App.topologyMapper));
       App.StompClient.subscribe('/events/configs', 
this.makeCallForClusterEnv.bind(this));
       App.StompClient.subscribe('/events/services', 
App.serviceStateMapper.map.bind(App.serviceStateMapper));
       App.StompClient.subscribe('/events/hosts', 
App.hostStateMapper.map.bind(App.hostStateMapper));
@@ -210,7 +210,7 @@ App.UpdateController = Em.Controller.extend({
     } else {
       App.StompClient.unsubscribe('/events/hostcomponents');
       App.StompClient.unsubscribe('/events/alerts');
-      App.StompClient.unsubscribe('/events/topologies');
+      // "/events/ui_topologies" topic should listen to topology changes when 
wizard running
       App.StompClient.unsubscribe('/events/configs');
       App.StompClient.unsubscribe('/events/services');
       App.StompClient.unsubscribe('/events/hosts');

http://git-wip-us.apache.org/repos/asf/ambari/blob/08ff5a22/ambari-web/app/mappers/server_data_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/server_data_mapper.js 
b/ambari-web/app/mappers/server_data_mapper.js
index e31881d..54de21b 100644
--- a/ambari-web/app/mappers/server_data_mapper.js
+++ b/ambari-web/app/mappers/server_data_mapper.js
@@ -179,9 +179,11 @@ App.QuickDataMapper = App.ServerDataMapper.extend({
    * @param item
    */
   deleteRecord: function (item) {
-    item.deleteRecord();
-    App.store.fastCommit();
-    item.get('stateManager').transitionTo('loading');
+    if (item.get('isLoaded')) {
+      item.deleteRecord();
+      App.store.fastCommit();
+      item.get('stateManager').transitionTo('loading');
+    }
   },
   /**
    * check mutable fields whether they have been changed and if positive

http://git-wip-us.apache.org/repos/asf/ambari/blob/08ff5a22/ambari-web/app/mappers/socket/topology_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/socket/topology_mapper.js 
b/ambari-web/app/mappers/socket/topology_mapper.js
index d46fa5e..00bac66 100644
--- a/ambari-web/app/mappers/socket/topology_mapper.js
+++ b/ambari-web/app/mappers/socket/topology_mapper.js
@@ -25,11 +25,22 @@ App.topologyMapper = App.QuickDataMapper.create({
    * @param {object} event
    */
   map: function(event) {
+    const hosts = event.clusters[App.get('clusterId')].hosts;
+
     if (event.clusters[App.get('clusterId')].components) {
       
this.applyComponentTopologyChanges(event.clusters[App.get('clusterId')].components,
 event.eventType);
     }
-    if (event.clusters[App.get('clusterId')].hosts) {
-      //TODO test hosts add/remove when hosts registration will be fixed
+    if (hosts) {
+      const hostNames = 
hosts.filterProperty('hostName').mapProperty('hostName');
+      if (event.eventType === 'DELETE') {
+        App.get('allHostNames').removeObjects(hostNames);
+      } else if (event.eventType === 'UPDATE') {
+        App.get('allHostNames').pushObjects(hostNames);
+      }
+      /**
+       * Since event message doesn't contain entire data of host and UI model 
doesn't contain all hosts of cluster,
+       * App.Host model should be updated only through <code>updateHost</code> 
request.
+       */
       App.router.get('updateController').updateHost(Em.K, null, true);
     }
   },
@@ -107,10 +118,9 @@ App.topologyMapper = App.QuickDataMapper.create({
    */
   createHostComponent: function(component, hostName, publicHostName) {
     const id = App.HostComponent.getId(component.componentName, hostName);
-    if (!App.Host.find(hostName).get('isLoaded')) {
-      //App.Host does not contain all hosts of cluster
-      return;
-    }
+    const host = App.Host.find(hostName);
+    const service = App.Service.find(component.serviceName);
+
     App.store.safeLoad(App.HostComponent, {
       id: id,
       host_id: hostName,
@@ -122,10 +132,10 @@ App.topologyMapper = App.QuickDataMapper.create({
       public_host_name: publicHostName,
       component_name: component.componentName
     });
-    const host = App.Host.find(hostName);
-    this.updateHostComponentsOfHost(host, 
host.get('hostComponents').mapProperty('id').concat(id));
 
-    const service = App.Service.find(component.serviceName);
+    if (host.get('isLoaded')) {
+      this.updateHostComponentsOfHost(host, 
host.get('hostComponents').mapProperty('id').concat(id));
+    }
     this.updateHostComponentsOfService(service, 
service.get('hostComponents').mapProperty('id').concat(id));
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/08ff5a22/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 44b6c36..3c17bc3 100644
--- a/ambari-web/test/controllers/global/update_controller_test.js
+++ b/ambari-web/test/controllers/global/update_controller_test.js
@@ -71,7 +71,6 @@ describe('App.UpdateController', function () {
       expect(App.updater.run.called).to.equal(false);
       
expect(App.StompClient.unsubscribe.calledWith('/events/hostcomponents')).to.be.true;
       
expect(App.StompClient.unsubscribe.calledWith('/events/alerts')).to.be.true;
-      
expect(App.StompClient.unsubscribe.calledWith('/events/topologies')).to.be.true;
       
expect(App.StompClient.unsubscribe.calledWith('/events/configs')).to.be.true;
       
expect(App.StompClient.unsubscribe.calledWith('/events/services')).to.be.true;
       
expect(App.StompClient.unsubscribe.calledWith('/events/hosts')).to.be.true;
@@ -82,7 +81,7 @@ describe('App.UpdateController', function () {
       expect(App.updater.run.callCount).to.equal(10);
       
expect(App.StompClient.subscribe.calledWith('/events/hostcomponents')).to.be.true;
       
expect(App.StompClient.subscribe.calledWith('/events/alerts')).to.be.true;
-      
expect(App.StompClient.subscribe.calledWith('/events/topologies')).to.be.true;
+      
expect(App.StompClient.subscribe.calledWith('/events/ui_topologies')).to.be.true;
       
expect(App.StompClient.subscribe.calledWith('/events/configs')).to.be.true;
       
expect(App.StompClient.subscribe.calledWith('/events/services')).to.be.true;
       expect(App.StompClient.subscribe.calledWith('/events/hosts')).to.be.true;

http://git-wip-us.apache.org/repos/asf/ambari/blob/08ff5a22/ambari-web/test/mappers/socket/topology_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/socket/topology_mapper_test.js 
b/ambari-web/test/mappers/socket/topology_mapper_test.js
index 7ebaf75..1f66f36 100644
--- a/ambari-web/test/mappers/socket/topology_mapper_test.js
+++ b/ambari-web/test/mappers/socket/topology_mapper_test.js
@@ -41,9 +41,17 @@ describe('App.topologyMapper', function () {
       mapper.map({clusters: {1: {components: []}}, eventType: 'UPDATE'});
       expect(mapper.applyComponentTopologyChanges.calledWith([], 
'UPDATE')).to.be.true;
     });
-    it('updateHost should be called', function () {
-      mapper.map({clusters: {1: {hosts: []}}, eventType: 'UPDATE'});
+    it('updateHost should be called on UPDATE event', function () {
+      App.set('allHostNames', []);
+      mapper.map({clusters: {1: {hosts: [{hostName: 'host1'}]}}, eventType: 
'UPDATE'});
       expect(mockCtrl.updateHost.calledWith(Em.K, null, true)).to.be.true;
+      
expect(JSON.stringify(App.get('allHostNames'))).to.be.equal(JSON.stringify(['host1']));
+    });
+    it('updateHost should be called on DELETE event', function () {
+      App.set('allHostNames', ['host2']);
+      mapper.map({clusters: {1: {hosts: [{hostName: 'host2'}]}}, eventType: 
'DELETE'});
+      expect(mockCtrl.updateHost.calledWith(Em.K, null, true)).to.be.true;
+      expect(App.get('allHostNames')).to.be.empty;
     });
   });
 

Reply via email to