Repository: ambari
Updated Branches:
  refs/heads/trunk d6900c1b2 -> dc25acbc9


AMBARI-11866. Blueprints processor should enable command retry by default. 
(rnettleton)


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

Branch: refs/heads/trunk
Commit: dc25acbc953d0c6895e7fd6fee69618108fcbb8d
Parents: d6900c1
Author: Bob Nettleton <[email protected]>
Authored: Thu Jun 11 17:41:19 2015 -0400
Committer: Bob Nettleton <[email protected]>
Committed: Thu Jun 11 17:41:46 2015 -0400

----------------------------------------------------------------------
 .../BlueprintConfigurationProcessor.java        | 43 ++++++++++++++
 .../BlueprintConfigurationProcessorTest.java    | 62 ++++++++++++++++++++
 2 files changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/dc25acbc/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 4f747f2..af14529 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
@@ -50,6 +50,20 @@ public class BlueprintConfigurationProcessor {
 
   protected final static Logger LOG = 
LoggerFactory.getLogger(BlueprintConfigurationProcessor.class);
 
+  private final static String COMMAND_RETRY_ENABLED_PROPERTY_NAME = 
"command_retry_enabled";
+
+  private final static String COMMANDS_TO_RETRY_PROPERTY_NAME = 
"commands_to_retry";
+
+  private final static String COMMAND_RETRY_MAX_TIME_IN_SEC_PROPERTY_NAME = 
"command_retry_max_time_in_sec";
+
+  private final static String COMMAND_RETRY_ENABLED_DEFAULT = "true";
+
+  private final static String COMMANDS_TO_RETRY_DEFAULT = "INSTALL,START";
+
+  private final static String COMMAND_RETRY_MAX_TIME_IN_SEC_DEFAULT = "600";
+
+  private final static String CLUSTER_ENV_CONFIG_TYPE_NAME = "cluster-env";
+
   /**
    * Single host topology updaters
    */
@@ -2002,6 +2016,8 @@ public class BlueprintConfigurationProcessor {
     // AMBARI-5206
     final Map<String , String> userProps = new HashMap<String , String>();
 
+    setRetryConfiguration(configuration);
+
     Collection<String> services = clusterTopology.getBlueprint().getServices();
     // only add user properties to the map for
     // services actually included in the blueprint definition
@@ -2044,6 +2060,33 @@ public class BlueprintConfigurationProcessor {
   }
 
   /**
+   * This method ensures that Ambari command retry is enabled if not 
explicitly overridden in
+   * cluster-env by the Blueprint or Cluster Creation template.  The new 
dynamic provisioning model
+   * requires that retry be enabled for most multi-node clusters, to this 
method sets reasonable defaults
+   * in order to preserve backwards compatibility and to simplify Blueprint 
creation.
+   *
+   * If the retry-specific properties in cluster-env are not set, then the 
config processor
+   * will set these values to defaults in cluster-env.
+   *
+   * @param configuration cluster configuration
+   */
+  private static void setRetryConfiguration(Configuration configuration) {
+
+    if (configuration.getPropertyValue(CLUSTER_ENV_CONFIG_TYPE_NAME, 
COMMAND_RETRY_ENABLED_PROPERTY_NAME) == null) {
+      configuration.setProperty(CLUSTER_ENV_CONFIG_TYPE_NAME, 
COMMAND_RETRY_ENABLED_PROPERTY_NAME, COMMAND_RETRY_ENABLED_DEFAULT);
+    }
+
+    if (configuration.getPropertyValue(CLUSTER_ENV_CONFIG_TYPE_NAME, 
COMMANDS_TO_RETRY_PROPERTY_NAME) == null) {
+      configuration.setProperty(CLUSTER_ENV_CONFIG_TYPE_NAME, 
COMMANDS_TO_RETRY_PROPERTY_NAME, COMMANDS_TO_RETRY_DEFAULT);
+    }
+
+    if (configuration.getPropertyValue(CLUSTER_ENV_CONFIG_TYPE_NAME, 
COMMAND_RETRY_MAX_TIME_IN_SEC_PROPERTY_NAME) == null) {
+      configuration.setProperty(CLUSTER_ENV_CONFIG_TYPE_NAME, 
COMMAND_RETRY_MAX_TIME_IN_SEC_PROPERTY_NAME, 
COMMAND_RETRY_MAX_TIME_IN_SEC_DEFAULT);
+    }
+  }
+
+
+  /**
    * Ensure that the specified property exists.
    * If not, set a default value.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc25acbc/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 9b1e786..fc6ec4b 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
@@ -2077,6 +2077,68 @@ public class BlueprintConfigurationProcessorTest {
   }
 
   @Test
+  public void testDoUpdateForClusterVerifyRetrySettingsDefault() throws 
Exception {
+    Map<String, Map<String, String>> configProperties =
+      new HashMap<String, Map<String, String>>();
+
+    HashMap<String, String> clusterEnvProperties = new HashMap<String, 
String>();
+    configProperties.put("cluster-env", clusterEnvProperties);
+
+    Configuration clusterConfig = new Configuration(configProperties, 
Collections.<String, Map<String, Map<String, String>>>emptyMap());
+
+    TestHostGroup testHostGroup = new TestHostGroup("test-host-group-one", 
Collections.<String>emptySet(), Collections.<String>emptySet());
+    ClusterTopology topology = createClusterTopology(bp, clusterConfig, 
Collections.singleton(testHostGroup));
+
+    BlueprintConfigurationProcessor updater = new 
BlueprintConfigurationProcessor(topology);
+
+    updater.doUpdateForClusterCreate();
+
+    // after update, verify that the retry properties for commands and 
installs are set as expected
+    assertEquals("Incorrect number of properties added to cluster-env for 
retry",
+      3, clusterEnvProperties.size());
+    assertEquals("command_retry_enabled was not set to the expected default",
+      "true", clusterEnvProperties.get("command_retry_enabled"));
+    assertEquals("commands_to_retry was not set to the expected default",
+      "INSTALL,START", clusterEnvProperties.get("commands_to_retry"));
+    assertEquals("command_retry_max_time_in_sec was not set to the expected 
default",
+      "600", clusterEnvProperties.get("command_retry_max_time_in_sec"));
+  }
+
+  @Test
+  public void testDoUpdateForClusterVerifyRetrySettingsCustomized() throws 
Exception {
+    Map<String, Map<String, String>> configProperties =
+      new HashMap<String, Map<String, String>>();
+
+    HashMap<String, String> clusterEnvProperties = new HashMap<String, 
String>();
+    configProperties.put("cluster-env", clusterEnvProperties);
+
+    clusterEnvProperties.put("command_retry_enabled", "false");
+    clusterEnvProperties.put("commands_to_retry", "TEST");
+    clusterEnvProperties.put("command_retry_max_time_in_sec", "1");
+
+
+    Configuration clusterConfig = new Configuration(configProperties, 
Collections.<String, Map<String, Map<String, String>>>emptyMap());
+
+    TestHostGroup testHostGroup = new TestHostGroup("test-host-group-one", 
Collections.<String>emptySet(), Collections.<String>emptySet());
+    ClusterTopology topology = createClusterTopology(bp, clusterConfig, 
Collections.singleton(testHostGroup));
+
+    BlueprintConfigurationProcessor updater = new 
BlueprintConfigurationProcessor(topology);
+
+    updater.doUpdateForClusterCreate();
+
+    // after update, verify that the retry properties for commands and 
installs are set as expected
+    // in this case, the customer-provided overrides should be honored, rather 
than the retry defaults
+    assertEquals("Incorrect number of properties added to cluster-env for 
retry",
+      3, clusterEnvProperties.size());
+    assertEquals("command_retry_enabled was not set to the expected default",
+      "false", clusterEnvProperties.get("command_retry_enabled"));
+    assertEquals("commands_to_retry was not set to the expected default",
+      "TEST", clusterEnvProperties.get("commands_to_retry"));
+    assertEquals("command_retry_max_time_in_sec was not set to the expected 
default",
+      "1", clusterEnvProperties.get("command_retry_max_time_in_sec"));
+  }
+
+  @Test
   public void 
testDoUpdateForClusterWithNameNodeHAEnabledSpecifyingHostNamesDirectly() throws 
Exception {
     final String expectedNameService = "mynameservice";
     final String expectedHostName = "c6401.apache.ambari.org";

Reply via email to