Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 366ca5beb -> 3974c9943


AMBARI-14325. Storm nimbus.seeds property not handled correctly in Blueprint 
processor resulting Storm not being able to start. (Sebastian Toader via 
rnettleton)


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

Branch: refs/heads/branch-2.2
Commit: 3974c9943a7395e37f6b02054b63aa3177421351
Parents: 366ca5b
Author: Bob Nettleton <rnettle...@hortonworks.com>
Authored: Thu Dec 10 16:44:34 2015 -0500
Committer: Bob Nettleton <rnettle...@hortonworks.com>
Committed: Thu Dec 10 16:45:04 2015 -0500

----------------------------------------------------------------------
 .../BlueprintConfigurationProcessor.java        | 27 ++++--
 .../BlueprintConfigurationProcessorTest.java    | 87 ++++++++++++++++++++
 2 files changed, 107 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3974c994/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
index ee0aaff..286eb0b 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
@@ -1520,7 +1520,7 @@ public class BlueprintConfigurationProcessor {
    * Topology based updater which replaces original host names (possibly more 
than one) contained in a property
    * value with the host names which runs the associated component in the new 
cluster.
    */
-  private static class MultipleHostTopologyUpdater implements PropertyUpdater {
+  protected static class MultipleHostTopologyUpdater implements 
PropertyUpdater {
 
     private static final Character DEFAULT_SEPARATOR = ',';
 
@@ -1621,15 +1621,28 @@ public class BlueprintConfigurationProcessor {
         }
       }
 
+      return sb.append(resolveHostGroupPlaceholder(origValue, prefix, 
hostStrings)).toString();
+    }
+
+    /**
+     * Resolves the host group place holders in the passed in original value.
+     * @param originalValue The original value containing the place holders to 
be resolved.
+     * @param prefix The prefix to be added to the returned value.
+     * @param hostStrings The collection of host names that are mapped to the 
host groups to be resolved
+     * @return The new value with place holders resolved.
+     */
+    protected String resolveHostGroupPlaceholder(String originalValue, String 
prefix, Collection<String> hostStrings) {
       String suffix = null;
+      StringBuilder sb = new StringBuilder();
+
       // parse out prefix if one exists
-      Matcher matcher = HOSTGROUP_PORT_REGEX.matcher(origValue);
+      Matcher matcher = HOSTGROUP_PORT_REGEX.matcher(originalValue);
       if (matcher.find()) {
         int indexOfStart = matcher.start();
         // handle the case of a YAML config property
-        if ((indexOfStart > 0) && (!origValue.substring(0, 
indexOfStart).equals("['"))) {
+        if ((indexOfStart > 0) && (!originalValue.substring(0, 
indexOfStart).equals("['")) && (!originalValue.substring(0, 
indexOfStart).equals("[")) ) {
           // append prefix before adding host names
-          prefix = origValue.substring(0, indexOfStart);
+          prefix = originalValue.substring(0, indexOfStart);
           sb.append(prefix);
         }
 
@@ -1639,8 +1652,8 @@ public class BlueprintConfigurationProcessor {
           indexOfEnd = matcher.end();
         } while (matcher.find());
 
-        if (indexOfEnd < (origValue.length() - 1)) {
-          suffix = origValue.substring(indexOfEnd);
+        if (indexOfEnd < (originalValue.length())) {
+          suffix = originalValue.substring(indexOfEnd);
         }
       }
 
@@ -1659,7 +1672,7 @@ public class BlueprintConfigurationProcessor {
         sb.append(host);
       }
 
-      if ((suffix != null) && (!suffix.equals("']"))) {
+      if ((suffix != null) && (!suffix.equals("']")) && (!suffix.equals("]")) 
) {
         sb.append(suffix);
       }
       return sb.toString();

http://git-wip-us.apache.org/repos/asf/ambari/blob/3974c994/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index 83b2d81..635d74f 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
@@ -6097,6 +6098,92 @@ public class BlueprintConfigurationProcessorTest {
     assertEquals(expectedValue, newValue);
   }
 
+  @Test
+  public void testMultipleHostTopologyUpdaterWithYamlPropertySingleHostValue() 
throws Exception {
+    // Given
+    String component = "test_component";
+    BlueprintConfigurationProcessor.MultipleHostTopologyUpdater mhtu = new 
BlueprintConfigurationProcessor.MultipleHostTopologyUpdater(component);
+
+    String propertyOriginalValue1 = "['%HOSTGROUP::group_1%']";
+    String propertyOriginalValue2 = "[%HOSTGROUP::group_1%]";
+
+    // When
+    String updatedValue1 = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue1, null, 
ImmutableList.<String>of("host1:100"));
+    String updatedValue2 = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue2, null, 
ImmutableList.<String>of("host1:100"));
+
+    // Then
+    assertEquals("host1:100", updatedValue1);
+
+    assertEquals("host1:100", updatedValue2);
+  }
+
+
+
+  @Test
+  public void testMultipleHostTopologyUpdaterWithYamlPropertyMultiHostValue() 
throws Exception {
+    // Given
+    String component = "test_component";
+    BlueprintConfigurationProcessor.MultipleHostTopologyUpdater mhtu = new 
BlueprintConfigurationProcessor.MultipleHostTopologyUpdater(component);
+
+    String propertyOriginalValue1 = "['%HOSTGROUP::group_1%', 
'%HOSTGROUP::group_2%']";
+    String propertyOriginalValue2 = "[%HOSTGROUP::group_1%, 
%HOSTGROUP::group_2%]";
+
+    // When
+    String updatedValue1 = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue1, null, 
ImmutableList.<String>of("host1:100", "host2:200"));
+    String updatedValue2 = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue2, null, 
ImmutableList.<String>of("host1:100", "host2:200"));
+
+    // Then
+    assertEquals("host1:100,host2:200", updatedValue1);
+
+    assertEquals("host1:100,host2:200", updatedValue2);
+  }
+
+
+  @Test
+  public void testMultipleHostTopologyUpdaterWithSingleHostWithSuffixValue() 
throws Exception {
+    // Given
+    String component = "test_component";
+    BlueprintConfigurationProcessor.MultipleHostTopologyUpdater mhtu = new 
BlueprintConfigurationProcessor.MultipleHostTopologyUpdater(component);
+
+    String propertyOriginalValue = "http://%HOSTGROUP::group_1%#";;
+
+    // When
+    String updatedValue = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue, null, 
ImmutableList.<String>of("host1:100"));
+
+    // Then
+    assertEquals("http://host1:100#";, updatedValue);
+  }
+
+  @Test
+  public void testMultipleHostTopologyUpdaterWithMultiHostWithSuffixValue() 
throws Exception {
+    // Given
+    String component = "test_component";
+    BlueprintConfigurationProcessor.MultipleHostTopologyUpdater mhtu = new 
BlueprintConfigurationProcessor.MultipleHostTopologyUpdater(component);
+
+    String propertyOriginalValue = 
"http://%HOSTGROUP::group_1,HOSTGROUP::group_2%/resource";;
+
+    // When
+    String updatedValue = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue, null, 
ImmutableList.<String>of("host1:100", "host2:200"));
+
+    // Then
+    assertEquals("http://host1:100,host2:200/resource";, updatedValue);
+  }
+
+  @Test
+  public void testMultipleHostTopologyUpdaterWithMultiHostValue() throws 
Exception {
+    // Given
+    String component = "test_component";
+    BlueprintConfigurationProcessor.MultipleHostTopologyUpdater mhtu = new 
BlueprintConfigurationProcessor.MultipleHostTopologyUpdater(component);
+
+    String propertyOriginalValue = 
"%HOSTGROUP::group_1%:11,%HOSTGROUP::group_2%:11";
+
+    // When
+    String updatedValue = 
mhtu.resolveHostGroupPlaceholder(propertyOriginalValue, null, 
ImmutableList.<String>of("host1:100", "host2:200"));
+
+    // Then
+    assertEquals("host1:100,host2:200", updatedValue);
+  }
+
 
   private Map<String, AdvisedConfiguration> createAdvisedConfigMap() {
     Map<String, AdvisedConfiguration> advMap = new HashMap<String, 
AdvisedConfiguration>();

Reply via email to