ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject ambari git commit: AMBARI-17443. Allow commands to specify if they should be auto-retried upon failure (smohanty)
Date Thu, 30 Jun 2016 00:13:01 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 3fdf16ed6 -> 7ad4e4c07


AMBARI-17443. Allow commands to specify if they should be auto-retried upon failure (smohanty)


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

Branch: refs/heads/branch-2.4
Commit: 7ad4e4c07f6edc7162597d1377375ddaad28d8d4
Parents: 3fdf16e
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Wed Jun 29 17:10:06 2016 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Wed Jun 29 17:10:55 2016 -0700

----------------------------------------------------------------------
 .../AmbariCustomCommandExecutionHelper.java     | 15 ++++++++
 .../ambari/server/state/ConfigHelper.java       |  3 +-
 .../AmbariManagementControllerTest.java         | 38 ++++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7ad4e4c0/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index 9526077..8bb6225 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -72,6 +72,7 @@ import org.apache.ambari.server.state.stack.OsFamily;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -990,6 +991,20 @@ public class AmbariCustomCommandExecutionHelper {
           actionExecutionContext.getParameters().put(KeyNames.REFRESH_ADITIONAL_COMPONENT_TAGS,
requestParams.get(KeyNames.REFRESH_ADITIONAL_COMPONENT_TAGS));
         }
 
+        // If command should be retried upon failure then add the option and also the default
duration for retry
+        if (requestParams.containsKey(KeyNames.COMMAND_RETRY_ENABLED)) {
+          extraParams.put(KeyNames.COMMAND_RETRY_ENABLED, requestParams.get(KeyNames.COMMAND_RETRY_ENABLED));
+          String commandRetryDuration = ConfigHelper.COMMAND_RETRY_MAX_TIME_IN_SEC_DEFAULT;
+          if (requestParams.containsKey(KeyNames.MAX_DURATION_OF_RETRIES)) {
+            String commandRetryDurationStr = requestParams.get(KeyNames.MAX_DURATION_OF_RETRIES);
+            Integer commandRetryDurationInt = NumberUtils.toInt(commandRetryDurationStr,
0);
+            if (commandRetryDurationInt > 0) {
+              commandRetryDuration = Integer.toString(commandRetryDurationInt);
+            }
+          }
+          extraParams.put(KeyNames.MAX_DURATION_OF_RETRIES, commandRetryDuration);
+        }
+
         if(requestParams.containsKey(KeyNames.REFRESH_CONFIG_TAGS_BEFORE_EXECUTION)){
           actionExecutionContext.getParameters().put(KeyNames.REFRESH_CONFIG_TAGS_BEFORE_EXECUTION,
requestParams.get(KeyNames.REFRESH_CONFIG_TAGS_BEFORE_EXECUTION));
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7ad4e4c0/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index ecb4a75..46a3f3e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -101,6 +101,7 @@ public class ConfigHelper {
   public static final String CLUSTER_ENV_RETRY_ENABLED = "command_retry_enabled";
   public static final String CLUSTER_ENV_RETRY_COMMANDS = "commands_to_retry";
   public static final String CLUSTER_ENV_RETRY_MAX_TIME_IN_SEC = "command_retry_max_time_in_sec";
+  public static final String COMMAND_RETRY_MAX_TIME_IN_SEC_DEFAULT = "600";
   public static final String CLUSTER_ENV_STACK_FEATURES_PROPERTY = "stack_features";
   public static final String CLUSTER_ENV_STACK_TOOLS_PROPERTY = "stack_tools";
 
@@ -565,7 +566,7 @@ public class ConfigHelper {
    */
   public Set<String> findConfigTypesByPropertyName(StackId stackId, String propertyName,
String clusterName) throws AmbariException {
     StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(),
-        stackId.getStackVersion());
+                                              stackId.getStackVersion());
 
     Set<String> result = new HashSet<String>();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7ad4e4c0/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 29cdbdf..4aa5ea4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -6675,6 +6675,7 @@ public class AmbariManagementControllerTest {
 
     Map<String, String> requestProperties = new HashMap<String, String>();
     requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");
+    requestProperties.put("command_retry_enabled", "true");
 
     // Test multiple restarts
     List<RequestResourceFilter> resourceFilters = new ArrayList<RequestResourceFilter>();
@@ -6696,6 +6697,12 @@ public class AmbariManagementControllerTest {
     for (HostRoleCommand hrc : storedTasks) {
       Assert.assertEquals("RESTART", hrc.getCustomCommandName());
 
+      Map<String, String> cParams = hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
+      Assert.assertEquals("Expect retry to be set", true, cParams.containsKey("command_retry_enabled"));
+      Assert.assertEquals("Expect max duration to be set", true, cParams.containsKey("max_duration_for_retries"));
+      Assert.assertEquals("Expect max duration to be 600", "600", cParams.get("max_duration_for_retries"));
+      Assert.assertEquals("Expect retry to be true", "true", cParams.get("command_retry_enabled"));
+
       if (hrc.getHostName().equals(host1) && hrc.getRole().equals(Role.DATANODE))
{
         expectedRestartCount++;
       } else if(hrc.getHostName().equals(host2)) {
@@ -6711,6 +6718,37 @@ public class AmbariManagementControllerTest {
         expectedRestartCount);
     Assert.assertEquals(requestProperties.get(REQUEST_CONTEXT_PROPERTY), response.getRequestContext());
 
+    requestProperties.put("max_duration_for_retries", "423");
+    response = controller.createAction(request, requestProperties);
+    Assert.assertEquals(3, response.getTasks().size());
+    storedTasks = actionDB.getRequestTasks(response.getRequestId());
+
+    Assert.assertNotNull(storedTasks);
+    for (HostRoleCommand hrc : storedTasks) {
+      Assert.assertEquals("RESTART", hrc.getCustomCommandName());
+
+      Map<String, String> cParams = hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
+      Assert.assertEquals("Expect retry to be set", true, cParams.containsKey("command_retry_enabled"));
+      Assert.assertEquals("Expect max duration to be set", true, cParams.containsKey("max_duration_for_retries"));
+      Assert.assertEquals("Expect max duration to be 423", "423", cParams.get("max_duration_for_retries"));
+      Assert.assertEquals("Expect retry to be true", "true", cParams.get("command_retry_enabled"));
+    }
+
+    requestProperties.remove("max_duration_for_retries");
+    requestProperties.remove("command_retry_enabled");
+    response = controller.createAction(request, requestProperties);
+    Assert.assertEquals(3, response.getTasks().size());
+    storedTasks = actionDB.getRequestTasks(response.getRequestId());
+
+    Assert.assertNotNull(storedTasks);
+    for (HostRoleCommand hrc : storedTasks) {
+      Assert.assertEquals("RESTART", hrc.getCustomCommandName());
+
+      Map<String, String> cParams = hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
+      Assert.assertEquals("Expect retry to be set", false, cParams.containsKey("command_retry_enabled"));
+      Assert.assertEquals("Expect max duration to be set", false, cParams.containsKey("max_duration_for_retries"));
+    }
+
     // Test service checks - specific host
     resourceFilters.clear();
     resourceFilter = new RequestResourceFilter("HDFS", null,


Mime
View raw message