Repository: ambari Updated Branches: refs/heads/branch-2.2 14f3b3124 -> 56403ce9a
AMBARI-14966: Stack Advisor incorrectly recommends Slave component on a host which does not have it installed during Add service wizard (bhuvnesh2703 via jaoki) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/56403ce9 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/56403ce9 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/56403ce9 Branch: refs/heads/branch-2.2 Commit: 56403ce9a33b6888e9130728faec6438cac1b545 Parents: 14f3b31 Author: Jun Aoki <ja...@apache.org> Authored: Thu Feb 11 17:04:33 2016 -0800 Committer: Jun Aoki <ja...@apache.org> Committed: Thu Feb 11 17:04:33 2016 -0800 ---------------------------------------------------------------------- .../src/main/resources/stacks/stack_advisor.py | 3 +- .../stacks/2.0.6/common/test_stack_advisor.py | 59 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/56403ce9/ambari-server/src/main/resources/stacks/stack_advisor.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/stack_advisor.py b/ambari-server/src/main/resources/stacks/stack_advisor.py index d993feb..539bd25 100644 --- a/ambari-server/src/main/resources/stacks/stack_advisor.py +++ b/ambari-server/src/main/resources/stacks/stack_advisor.py @@ -409,7 +409,8 @@ class DefaultStackAdvisor(StackAdvisor): hostsMin = int(cardinality) if hostsMin > len(hostsForComponent): hostsForComponent.extend(freeHosts[0:hostsMin-len(hostsForComponent)]) - else: + # Components which are already installed, keep the recommendation as the existing layout + elif not componentIsPopulated: hostsForComponent.extend(freeHosts) if not hostsForComponent: # hostsForComponent is empty hostsForComponent = hostsList[-1:] http://git-wip-us.apache.org/repos/asf/ambari/blob/56403ce9/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py index c41d136..2f1959a 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py +++ b/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py @@ -1903,3 +1903,62 @@ class TestHDP206StackAdvisor(TestCase): siteProperties = stack_advisor.getServicesSiteProperties(services, "ranger-admin-site") self.assertEquals(siteProperties, expected) + def test_createComponentLayoutRecommendations_addService_1freeHost(self): + """ + Test that already installed slaves are not added to any free hosts (not having any component installed) + as part of recommendation received during Add service operation. + For already installed services, recommendation for installed components should match the existing layout + """ + + services = { + "services" : [ + { + "StackServices" : { + "service_name" : "HDFS" + }, + "components" : [ { + "StackServiceComponents" : { + "cardinality" : "1+", + "component_category" : "SLAVE", + "component_name" : "DATANODE", + "hostnames" : [ "c6401.ambari.apache.org" ] + } + } ] + } ] + } + + hosts = self.prepareHosts(["c6401.ambari.apache.org", "c6402.ambari.apache.org"]) + recommendations = self.stackAdvisor.createComponentLayoutRecommendations(services, hosts) + """ + Recommendation received should be as below: + { + 'blueprint': { + 'host_groups': [{ + 'name': 'host-group-1', + 'components': [] + }, { + 'name': 'host-group-2', + 'components': [{ + 'name': 'DATANODE' + }] + }] + }, + 'blueprint_cluster_binding': { + 'host_groups': [{ + 'hosts': [{ + 'fqdn': 'c6402.ambari.apache.org' + }], + 'name': 'host-group-1' + }, { + 'hosts': [{ + 'fqdn': 'c6401.ambari.apache.org' + }], + 'name': 'host-group-2' + }] + } + } + """ + # Assert that the list is empty for host-group-1 + self.assertFalse(recommendations['blueprint']['host_groups'][0]['components']) + # Assert that DATANODE is placed on host-group-2 + self.assertEquals(recommendations['blueprint']['host_groups'][1]['components'][0]['name'], 'DATANODE')