AMBARI-18415. Stack definition: service component 'cardinality' inheritance not 
working properly (aonishuk)


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

Branch: refs/heads/branch-2.5
Commit: f4cb404d7244e380c6788e222ee06cb5ac6fd187
Parents: 24ec848
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Mon Sep 19 16:54:48 2016 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Mon Sep 19 16:54:48 2016 +0300

----------------------------------------------------------------------
 .../apache/ambari/server/stack/ComponentModule.java  |  3 +++
 .../apache/ambari/server/state/ComponentInfo.java    |  2 +-
 .../ambari/server/stack/ComponentModuleTest.java     | 15 ++++++++++-----
 3 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f4cb404d/ambari-server/src/main/java/org/apache/ambari/server/stack/ComponentModule.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/stack/ComponentModule.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/stack/ComponentModule.java
index 537ae32..a90ea1a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/stack/ComponentModule.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/stack/ComponentModule.java
@@ -122,6 +122,9 @@ public class ComponentModule extends 
BaseModule<ComponentModule, ComponentInfo>
               componentInfo.getCustomCommands());
 
       mergeLogs(parentInfo.getLogs(), componentInfo.getLogs());
+    } else {
+      //set cardinality with default value "0+" if it was not provided and 
parent is absent.
+      componentInfo.setCardinality("0+");
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4cb404d/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
index 2dae526..1e494b4 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ComponentInfo.java
@@ -36,7 +36,7 @@ public class ComponentInfo {
   private String displayName;
   private String category;
   private boolean deleted;
-  private String cardinality = "0+";
+  private String cardinality;
   
   @XmlElement(name="versionAdvertised")
   private Boolean versionAdvertisedField;

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4cb404d/ambari-server/src/test/java/org/apache/ambari/server/stack/ComponentModuleTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/stack/ComponentModuleTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/stack/ComponentModuleTest.java
index 905707c..519e5f3 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/stack/ComponentModuleTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/stack/ComponentModuleTest.java
@@ -155,11 +155,14 @@ public class ComponentModuleTest {
     String cardinality = "foo";
 
     ComponentInfo info = new ComponentInfo();
-    ComponentInfo parentInfo = new ComponentInfo();
+    // parent is null, child cardinality is null
+    assertEquals("0+", resolveComponent(info, 
null).getModuleInfo().getCardinality());
 
+    ComponentInfo parentInfo = new ComponentInfo();
+    info = new ComponentInfo();
     // parent has value set, child value is null
     parentInfo.setCardinality(cardinality);
-    assertEquals("0+", resolveComponent(info, 
parentInfo).getModuleInfo().getCardinality());
+    assertEquals("foo", resolveComponent(info, 
parentInfo).getModuleInfo().getCardinality());
 
     // child has value set, parent value is null
     info.setCardinality(cardinality);
@@ -552,10 +555,12 @@ public class ComponentModuleTest {
 
   private ComponentModule resolveComponent(ComponentInfo info, ComponentInfo 
parentInfo) {
     info.setName("FOO");
-    parentInfo.setName("FOO");
-
     ComponentModule component = new ComponentModule(info);
-    ComponentModule parentComponent = new ComponentModule(parentInfo);
+    ComponentModule parentComponent = null;
+    if (parentInfo != null) {
+      parentInfo.setName("FOO");
+      parentComponent = new ComponentModule(parentInfo);
+    }
 
     component.resolve(parentComponent, Collections.<String, 
StackModule>emptyMap(), Collections.<String, ServiceModule>emptyMap(), 
Collections.<String, ExtensionModule>emptyMap());
 

Reply via email to