ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [1/2] ambari git commit: AMBARI-17624. Host service mapping has incorrect default mapping (aonishuk)
Date Mon, 11 Jul 2016 15:35:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 e8fe6f2ba -> ad11d50b0
  refs/heads/trunk e8bfdb924 -> 6c03848a7


AMBARI-17624. Host service mapping has incorrect default mapping (aonishuk)


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

Branch: refs/heads/trunk
Commit: 6c03848a724ea3cf004f49f6ef09f0f0f164802c
Parents: e8bfdb9
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Mon Jul 11 18:35:34 2016 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Mon Jul 11 18:35:34 2016 +0300

----------------------------------------------------------------------
 .../src/main/resources/stacks/stack_advisor.py  | 34 +++++++++++++++-----
 .../stacks/2.0.6/common/test_stack_advisor.py   |  8 +++++
 2 files changed, 34 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6c03848a/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 7c6470f..47f4500 100644
--- a/ambari-server/src/main/resources/stacks/stack_advisor.py
+++ b/ambari-server/src/main/resources/stacks/stack_advisor.py
@@ -487,15 +487,9 @@ class DefaultStackAdvisor(StackAdvisor):
     componentName = component["StackServiceComponents"]["component_name"]
     if self.isSlaveComponent(component):
       cardinality = str(component["StackServiceComponents"]["cardinality"])
+      hostsMin, hostsMax = self.parseCardinality(cardinality, len(hostsList))
+      hostsMin, hostsMax = (0 if hostsMin is None else hostsMin, len(hostsList) if hostsMax
is None else hostsMax)
       if self.isComponentUsingCardinalityForLayout(componentName) and cardinality:
-        # cardinality types: 1+, 1-2, 1
-        if "+" in cardinality:
-          hostsMin = int(cardinality[:-1])
-        elif "-" in cardinality:
-          nums = cardinality.split("-")
-          hostsMin = int(nums[0])
-        else:
-          hostsMin = int(cardinality)
         if hostsMin > len(hostsForComponent):
           hostsForComponent.extend(freeHosts[0:hostsMin-len(hostsForComponent)])
 
@@ -504,6 +498,10 @@ class DefaultStackAdvisor(StackAdvisor):
         if not hostsForComponent:  # hostsForComponent is empty
           hostsForComponent = hostsList[-1:]
       hostsForComponent = list(set(hostsForComponent))  # removing duplicates
+      if len(hostsForComponent) < hostsMin:
+        hostsForComponent = list(set(hostsList))[0:hostsMin]
+      elif len(hostsForComponent) > hostsMax:
+        hostsForComponent = list(set(hostsList))[0:hostsMax]
     elif self.isClientComponent(component):
       hostsForComponent = freeHosts[0:1]
       if not hostsForComponent:  # hostsForComponent is empty
@@ -1052,3 +1050,23 @@ class DefaultStackAdvisor(StackAdvisor):
     return "cluster-env" in services["configurations"] \
            and "security_enabled" in services["configurations"]["cluster-env"]["properties"]
\
            and services["configurations"]["cluster-env"]["properties"]["security_enabled"].lower()
== "true"
+
+  def parseCardinality(self, cardinality, hostsCount):
+    """
+    Cardinality types: 1+, 1-2, 1, ALL
+    @return: a tuple: (minHosts, maxHosts) or (None, None) if cardinality string is invalid
+    """
+    if not cardinality:
+      return (None, None)
+
+    if "+" in cardinality:
+      return (int(cardinality[:-1]), int(hostsCount))
+    elif "-" in cardinality:
+      nums = cardinality.split("-")
+      return (int(nums[0]), int(nums[1]))
+    elif "ALL" == cardinality:
+      return (int(hostsCount), int(hostsCount))
+    elif cardinality.isdigit():
+      return (int(cardinality),int(cardinality))
+
+    return (None, None)

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c03848a/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 931d59b..1feeed2 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
@@ -1984,6 +1984,14 @@ class TestHDP206StackAdvisor(TestCase):
     self.assertEquals(self.stack_advisor_impl.getMountPointForDir("hdfs:///hdfs_path", ["/var",
"/"]), None)
     self.assertEquals(self.stack_advisor_impl.getMountPointForDir("relative/path", ["/var",
"/"]), None)
 
+  def test_parseCardinality(self):
+    self.assertEquals(self.stackAdvisor.parseCardinality("ALL", 5), (5, 5))
+    self.assertEquals(self.stackAdvisor.parseCardinality("2+", 5), (2, 5))
+    self.assertEquals(self.stackAdvisor.parseCardinality("1-3", 5), (1, 3))
+    self.assertEquals(self.stackAdvisor.parseCardinality("3", 5), (3, 3))
+    self.assertEquals(self.stackAdvisor.parseCardinality(None, 5), (None, None))
+    self.assertEquals(self.stackAdvisor.parseCardinality("invalid", 3), (None, None))
+
   def test_getValidatorEqualsToRecommendedItem(self):
     properties = {"property1": "value1"}
     recommendedDefaults = {"property1": "value1"}


Mime
View raw message