Repository: ambari
Updated Branches:
  refs/heads/trunk 2f94036e9 -> bd2bf2543


AMBARI-14015 Different values range for yarn.nodemanager.resource.memory-mb 
property after page refresh. (ababiichuk)


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

Branch: refs/heads/trunk
Commit: bd2bf2543337387d19c844c6f198e5839be7e1ac
Parents: 2f94036
Author: aBabiichuk <[email protected]>
Authored: Mon Nov 23 17:58:24 2015 +0200
Committer: aBabiichuk <[email protected]>
Committed: Mon Nov 23 18:01:19 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/utils/blueprint.js       | 55 +++++++++++++++-------------
 ambari-web/test/utils/blueprint_test.js | 39 +++++++++++++-------
 2 files changed, 56 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bd2bf254/ambari-web/app/utils/blueprint.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/blueprint.js 
b/ambari-web/app/utils/blueprint.js
index cd4b7b2..ea908d1 100644
--- a/ambari-web/app/utils/blueprint.js
+++ b/ambari-web/app/utils/blueprint.js
@@ -379,39 +379,44 @@ module.exports = {
   },
 
   /**
+   * Small helper method to update hostMap
+   * it perform update of object only
+   * if unique component per host is added
+   *
+   * @param {Object} hostMapObject
+   * @param {string[]} hostNames
+   * @param {string} componentName
+   * @returns {Object}
+   * @private
+   */
+  _generateHostMap: function(hostMapObject, hostNames, componentName) {
+    Em.assert('hostMapObject, hostNames, componentName should be defined', 
!!hostMapObject && !!hostNames && !!componentName);
+    if (!hostNames.length) return hostMapObject;
+    hostNames.forEach(function(hostName) {
+      if (!hostMapObject[hostName])
+        hostMapObject[hostName] = [];
+
+      if (!hostMapObject[hostName].contains(componentName))
+        hostMapObject[hostName].push(componentName);
+    });
+    return hostMapObject;
+  },
+
+  /**
    * collect all component names that are present on hosts
    * @returns {object}
    */
   getComponentForHosts: function() {
     var hostsMap = {};
     App.ClientComponent.find().forEach(function(c) {
-      var componentName = c.get('componentName');
-      c.get('hostNames').forEach(function(hostName){
-        if (hostsMap[hostName]) {
-          hostsMap[hostName].push(componentName);
-        } else {
-          hostsMap[hostName] = [componentName];
-        }
-      });
-    });
+      hostsMap = this._generateHostMap(hostsMap, c.get('hostNames'), 
c.get('componentName'));
+    }, this);
     App.SlaveComponent.find().forEach(function (c) {
-      var componentName = c.get('componentName');
-      c.get('hostNames').forEach(function (hostName) {
-        if (hostsMap[hostName]) {
-          hostsMap[hostName].push(componentName);
-        } else {
-          hostsMap[hostName] = [componentName];
-        }
-      });
-    });
+      hostsMap = this._generateHostMap(hostsMap, c.get('hostNames'), 
c.get('componentName'));
+    }, this);
     App.HostComponent.find().forEach(function (c) {
-      var hostName = c.get('hostName');
-      if (hostsMap[hostName]) {
-        hostsMap[hostName].push(c.get('componentName'));
-      } else {
-        hostsMap[hostName] = [c.get('componentName')];
-      }
-    });
+      hostsMap = this._generateHostMap(hostsMap, [c.get('hostName')], 
c.get('componentName'));
+    }, this);
     return hostsMap;
   }
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/bd2bf254/ambari-web/test/utils/blueprint_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/blueprint_test.js 
b/ambari-web/test/utils/blueprint_test.js
index 29072a3..8fa3bcf 100644
--- a/ambari-web/test/utils/blueprint_test.js
+++ b/ambari-web/test/utils/blueprint_test.js
@@ -415,19 +415,32 @@ describe('utils/blueprint', function() {
       App.HostComponent.find.restore();
     });
 
-    it("", function() {
-      expect(blueprintUtils.getComponentForHosts()).to.eql({
-        "host1": [
-          "C1"
-        ],
-        "host2": [
-          "C1",
-          "C2"
-        ],
-        "host3": [
-          "C2",
-          "C3"
-        ]
+    it("generate components to host map", function() {
+      var res = blueprintUtils.getComponentForHosts();
+      expect(res['host1'][0]).to.eql("C1");
+      expect(res['host2'][0]).to.eql("C1");
+      expect(res['host2'][1]).to.eql("C2");
+      expect(res['host3'][0]).to.eql("C2");
+      expect(res['host3'][1]).to.eql("C3");
+    });
+  });
+
+  describe('#_generateHostMap', function() {
+    it('generate map', function() {
+      var map = blueprintUtils._generateHostMap({}, ['h1','h2', 'h1'],'c1');
+      expect(map['h1'][0]).to.eql('c1');
+      expect(map['h2'][0]).to.eql('c1');
+    });
+
+    it('skip generations as hosts is empty', function() {
+      expect(blueprintUtils._generateHostMap({}, [],'c1')).to.eql({});
+    });
+
+    it('skip throws error when data is wrong', function() {
+      it('should assert error if no data returned from server', function () {
+        expect(function () {
+          blueprintUtils._generateHostMap();
+        }).to.throw(Error);
       });
     });
   });

Reply via email to