Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 2daca3ca6 -> 94129bbc8


AMBARI-14987: assign_master_component.js does not show recommendations while 
adding master component for a service which is already installed (mithmatt via 
jaoki)


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

Branch: refs/heads/branch-2.2
Commit: 94129bbc8289647c3e1b9e0d21d84f5d156d13ca
Parents: 2daca3c
Author: Jun Aoki <ja...@apache.org>
Authored: Tue Feb 16 16:42:32 2016 -0800
Committer: Jun Aoki <ja...@apache.org>
Committed: Tue Feb 16 16:42:32 2016 -0800

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   1 +
 .../mixins/wizard/assign_master_components.js   |  58 ++++++-
 .../wizard/assign_master_components_test.js     | 154 +++++++++++++++++++
 3 files changed, 212 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/94129bbc/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js 
b/ambari-web/app/assets/test/tests.js
index 9d5cbc1..25c3f43 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -157,6 +157,7 @@ var files = ['test/init_model_test',
   'test/mixins/main/service/configs/widget_popover_support_test',
   'test/mixins/routers/redirections_test',
   'test/mixins/wizard/addSeccurityConfigs_test',
+  'test/mixins/wizard/assign_master_components_test',
   'test/mixins/wizard/wizard_menu_view_test',
   'test/mixins/wizard/wizardProgressPageController_test',
   'test/mixins/wizard/wizardEnableDone_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/94129bbc/ambari-web/app/mixins/wizard/assign_master_components.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/wizard/assign_master_components.js 
b/ambari-web/app/mixins/wizard/assign_master_components.js
index f6d1b1a..62efdac 100644
--- a/ambari-web/app/mixins/wizard/assign_master_components.js
+++ b/ambari-web/app/mixins/wizard/assign_master_components.js
@@ -95,6 +95,22 @@ App.AssignMasterComponents = Em.Mixin.create({
   showInstalledMastersFirst: false,
 
   /**
+   * Map of component name to list of hostnames for that component
+   * format:
+   * {
+   *   NAMENODE: [
+   *     'c6401.ambari.apache.org'
+   *   ],
+   *   DATANODE: [
+   *     'c6402.ambari.apache.org',
+   *     'c6403.ambari.apache.org',
+   *   ]
+   * }
+   * @type {Object}
+   */
+  recommendedHostsForComponents: {},
+
+  /**
    * Array of <code>servicesMasters</code> objects, that will be shown on the 
page
    * Are filtered using <code>mastersToShow</code>
    * @type {Array}
@@ -738,7 +754,31 @@ App.AssignMasterComponents = Em.Mixin.create({
    * @method loadRecommendationsSuccessCallback
    */
   loadRecommendationsSuccessCallback: function (data) {
-    this.set('content.recommendations', data.resources[0].recommendations);
+    var recommendations = data.resources[0].recommendations;
+    this.set('content.recommendations', recommendations);
+
+    var recommendedHostsForComponent = {};
+    var hostsForHostGroup = {};
+
+    
recommendations.blueprint_cluster_binding.host_groups.forEach(function(hostGroup)
 {
+      hostsForHostGroup[hostGroup.name] = hostGroup.hosts.map(function(host) {
+        return host.fqdn;
+      });
+    });
+
+    recommendations.blueprint.host_groups.forEach(function (hostGroup) {
+      var components = hostGroup.components.map(function (component) {
+        return component.name;
+      });
+      components.forEach(function (componentName) {
+        var hostList = recommendedHostsForComponent[componentName] || [];
+        var hostNames = hostsForHostGroup[hostGroup.name] || [];
+        Array.prototype.push.apply(hostList, hostNames);
+        recommendedHostsForComponent[componentName] = hostList;
+      });
+    });
+
+    this.set('content.recommendedHostsForComponents', 
recommendedHostsForComponent);
   },
 
   /**
@@ -820,6 +860,21 @@ App.AssignMasterComponents = Em.Mixin.create({
    * @returns {*}
    */
   getHostForMaster: function (master, allMasters) {
+    var masterHostList = [];
+
+    allMasters.forEach(function (component) {
+      if (component.component_name === master) {
+        masterHostList.push(component.selectedHost);
+      }
+    });
+
+    var recommendedHostsForMaster = 
this.get('content.recommendedHostsForComponents')[master] || [];
+    for (var k = 0; k < recommendedHostsForMaster.length; k++) {
+      if(!masterHostList.contains(recommendedHostsForMaster[k])) {
+        return recommendedHostsForMaster[k];
+      }
+    }
+
     var usedHosts = allMasters.filterProperty('component_name', 
master).mapProperty('selectedHost');
     var allHosts = this.get('hosts');
     for (var i = 0; i < allHosts.length; i++) {
@@ -827,6 +882,7 @@ App.AssignMasterComponents = Em.Mixin.create({
         return allHosts[i].get('host_name');
       }
     }
+
     return false;
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/94129bbc/ambari-web/test/mixins/wizard/assign_master_components_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/wizard/assign_master_components_test.js 
b/ambari-web/test/mixins/wizard/assign_master_components_test.js
new file mode 100644
index 0000000..a3ffb22
--- /dev/null
+++ b/ambari-web/test/mixins/wizard/assign_master_components_test.js
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+require('mixins/wizard/assign_master_components');
+var c;
+
+describe('App.AssignMasterComponents', function () {
+  var baseObject = Em.Object.extend(App.AssignMasterComponents);
+  var data;
+
+  beforeEach(function () {
+    c = baseObject.create();
+    c.set('content', {});
+
+    var hosts = [];
+    for(var i = 1; i <= 4; ++i) {
+      hosts.push(App.Host.createRecord({
+        'host_name': 'h' + i
+      }));
+    }
+    c.set('hosts', hosts);
+
+    data = {
+      "resources": [
+        {
+          "recommendations": {
+            "blueprint": {
+              "host_groups": [
+                {
+                  "name": "host-group-1",
+                  "components": [{"name": "c1"}, {"name": "c3"}, {"name": 
"c2"}]
+                },
+                {
+                  "name": "host-group-2",
+                  "components": [{"name": "c1"}, {"name": "c2"}]
+                },
+                {
+                  "name": "host-group-3",
+                  "components": [{"name": "c1"}]
+                }
+              ]
+            },
+            "blueprint_cluster_binding": {
+              "host_groups": [
+                {
+                  "name": "host-group-1",
+                  "hosts": [{"fqdn": "h1"}]
+                },
+                {
+                  "name": "host-group-3",
+                  "hosts": [{"fqdn": "h3"}]
+                },
+                {
+                  "name": "host-group-2",
+                  "hosts": [{"fqdn": "h2"}, {"fqdn": "h4"}]
+                }
+              ]
+            }
+          }
+        }
+      ]
+    };
+  });
+
+  describe('#loadRecommendationsSuccessCallback', function () {
+
+    it('should set recommendations', function() {
+      c.loadRecommendationsSuccessCallback(data);
+      
expect(c.get('content.recommendations')).to.eq(data.resources[0].recommendations);
+    });
+
+    it('should set recommendedHostsForComponents', function() {
+      c.loadRecommendationsSuccessCallback(data);
+      var expected = {
+        "c1": ["h1", "h2", "h4", "h3"],
+        "c3": ["h1"],
+        "c2": ["h1", "h2", "h4"]
+      };
+
+      
expect(c.get('content.recommendedHostsForComponents')).to.deep.equal(expected);
+    });
+  });
+
+  describe('#getHostForMaster', function () {
+
+    var allMasters;
+
+    beforeEach(function () {
+      allMasters = [
+        {
+          "component_name": "c1",
+          "selectedHost": "h1"
+        },
+        {
+          "component_name": "c1",
+          "selectedHost": "h2"
+        },
+        {
+          "component_name": "c1",
+          "selectedHost": "h3"
+        },
+        {
+          "component_name": "c1",
+          "selectedHost": "h4"
+        },
+        {
+          "component_name": "c2",
+          "selectedHost": "h1"
+        },
+        {
+          "component_name": "c5",
+          "selectedHost": "h1"
+        }
+      ];
+    });
+
+    it('should return the recommended host', function() {
+      c.loadRecommendationsSuccessCallback(data);
+      expect(c.getHostForMaster('c2', allMasters)).to.eq('h2');
+    });
+
+    it('should return the first available host from the list of existing 
hosts', function() {
+      c.loadRecommendationsSuccessCallback(data);
+      expect(c.getHostForMaster('c6', allMasters)).to.eq('h1');
+    });
+
+    it('should return the next available host from the list of existing 
hosts', function() {
+      c.loadRecommendationsSuccessCallback(data);
+      expect(c.getHostForMaster('c5', allMasters)).to.eq('h2');
+    });
+
+    it('should return false if the component is already on all hosts', 
function() {
+      c.loadRecommendationsSuccessCallback(data);
+      expect(c.getHostForMaster('c1', allMasters)).to.eq(false);
+    });
+
+  });
+});
\ No newline at end of file

Reply via email to