Browse Source

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

aBabiichuk 10 năm trước cách đây
mục cha
commit
bd2bf25433
2 tập tin đã thay đổi với 56 bổ sung38 xóa
  1. 30 25
      ambari-web/app/utils/blueprint.js
  2. 26 13
      ambari-web/test/utils/blueprint_test.js

+ 30 - 25
ambari-web/app/utils/blueprint.js

@@ -378,6 +378,30 @@ module.exports = {
     return recommendations;
   },
 
+  /**
+   * 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}
@@ -385,33 +409,14 @@ module.exports = {
   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;
   }
 };

+ 26 - 13
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);
       });
     });
   });