AMBARI-19652. Allow to override service check timeout via ambari.properties. (mpapirkovskyy)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8abda6ce Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8abda6ce Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8abda6ce Branch: refs/heads/trunk Commit: 8abda6ce1a75917f4db5df95f3485b17d71e84dd Parents: ed157b1 Author: Myroslav Papirkovskyi <[email protected]> Authored: Thu Jan 19 18:12:17 2017 +0200 Committer: Myroslav Papirkovskyi <[email protected]> Committed: Fri Jan 20 17:45:44 2017 +0200 ---------------------------------------------------------------------- .../server/configuration/Configuration.java | 22 ++++++++++ .../AmbariCustomCommandExecutionHelper.java | 6 +++ .../AmbariCustomCommandExecutionHelperTest.java | 46 ++++++++++++++++++++ 3 files changed, 74 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8abda6ce/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java index 35d16ba..df1b627 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java @@ -1917,6 +1917,13 @@ public class Configuration { "agent.task.timeout", 900L); /** + * The time, in {@link TimeUnit#SECONDS}, before agent service check commands are killed. + */ + @Markdown(description = "The time, in seconds, before agent service check commands are killed.") + public static final ConfigurationProperty<Long> AGENT_SERVICE_CHECK_TASK_TIMEOUT = new ConfigurationProperty<>( + "agent.service.check.task.timeout", 0L); + + /** * The time, in {@link TimeUnit#SECONDS}, before package installation commands are killed. */ @Markdown(description = "The time, in seconds, before package installation commands are killed.") @@ -4490,6 +4497,21 @@ public class Configuration { } /** + * @return overridden service check task timeout in seconds. This value + * is used at python (agent) code. + */ + public Long getAgentServiceCheckTaskTimeout() { + String value = getProperty(AGENT_SERVICE_CHECK_TASK_TIMEOUT); + if (StringUtils.isNumeric(value)) { + return Long.parseLong(value); + } else { + LOG.warn("Value of {} ({}) should be a number, falling back to default value ({})", + AGENT_SERVICE_CHECK_TASK_TIMEOUT.getKey(), value, AGENT_SERVICE_CHECK_TASK_TIMEOUT.getDefaultValue()); + return AGENT_SERVICE_CHECK_TASK_TIMEOUT.getDefaultValue(); + } + } + + /** * @return default server-side task timeout in seconds. */ public Integer getDefaultServerTaskTimeout() { http://git-wip-us.apache.org/repos/asf/ambari/blob/8abda6ce/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 923a796..8b851ac 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 @@ -743,6 +743,12 @@ public class AmbariCustomCommandExecutionHelper { // We don't need package/repo information to perform service check } + // Try to apply overridden service check timeout value if available + Long overriddenTimeout = configs.getAgentServiceCheckTaskTimeout(); + if (!overriddenTimeout.equals(Configuration.AGENT_SERVICE_CHECK_TASK_TIMEOUT.getDefaultValue())) { + commandTimeout = String.valueOf(overriddenTimeout); + } + commandParams.put(COMMAND_TIMEOUT, commandTimeout); commandParams.put(SERVICE_PACKAGE_FOLDER, serviceInfo.getServicePackageFolder()); commandParams.put(HOOKS_FOLDER, stackInfo.getStackHooksFolder()); http://git-wip-us.apache.org/repos/asf/ambari/blob/8abda6ce/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java index 246c628..8c87f0f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java @@ -94,6 +94,7 @@ public class AmbariCustomCommandExecutionHelperTest { private Clusters clusters; private AmbariManagementController ambariManagementController; private Capture<Request> requestCapture = EasyMock.newCapture(); + private static final String OVERRIDDEN_SERVICE_CHECK_TIMEOUT_VALUE = "550"; @Before @@ -103,6 +104,8 @@ public class AmbariCustomCommandExecutionHelperTest { InMemoryDefaultTestModule module = new InMemoryDefaultTestModule(){ @Override protected void configure() { + getProperties().setProperty(Configuration.AGENT_SERVICE_CHECK_TASK_TIMEOUT.getKey(), + OVERRIDDEN_SERVICE_CHECK_TIMEOUT_VALUE); super.configure(); bind(ActionManager.class).toInstance(actionManager); } @@ -376,6 +379,49 @@ public class AmbariCustomCommandExecutionHelperTest { Assert.fail("Expected an exception since there are no hosts which can run the Flume service check"); } + @Test + public void testServiceCheckWithOverriddenTimeout() throws Exception { + AmbariCustomCommandExecutionHelper ambariCustomCommandExecutionHelper = injector.getInstance(AmbariCustomCommandExecutionHelper.class); + + Cluster c1 = clusters.getCluster("c1"); + Service s = c1.getService("ZOOKEEPER"); + ServiceComponent sc = s.getServiceComponent("ZOOKEEPER_CLIENT"); + Assert.assertTrue(sc.getServiceComponentHosts().keySet().size() > 1); + + // There are multiple hosts with ZK Client. + List<RequestResourceFilter> requestResourceFilter = new ArrayList<RequestResourceFilter>() {{ + add(new RequestResourceFilter("ZOOKEEPER", "ZOOKEEPER_CLIENT", Arrays.asList(new String[]{"c1-c6401"}))); + }}; + ActionExecutionContext actionExecutionContext = new ActionExecutionContext("c1", "SERVICE_CHECK", requestResourceFilter); + Stage stage = EasyMock.niceMock(Stage.class); + ExecutionCommandWrapper execCmdWrapper = EasyMock.niceMock(ExecutionCommandWrapper.class); + ExecutionCommand execCmd = EasyMock.niceMock(ExecutionCommand.class); + Capture<Map<String,String>> timeOutCapture = EasyMock.newCapture(); + + EasyMock.expect(stage.getClusterName()).andReturn("c1"); + + EasyMock.expect(stage.getExecutionCommandWrapper(EasyMock.eq("c1-c6401"), EasyMock.anyString())).andReturn(execCmdWrapper); + EasyMock.expect(execCmdWrapper.getExecutionCommand()).andReturn(execCmd); + execCmd.setCommandParams(EasyMock.capture(timeOutCapture)); + EasyMock.expectLastCall(); + + HashSet<String> localComponents = new HashSet<>(); + EasyMock.expect(execCmd.getLocalComponents()).andReturn(localComponents).anyTimes(); + EasyMock.replay(stage, execCmdWrapper, execCmd); + + ambariCustomCommandExecutionHelper.addExecutionCommandsToStage(actionExecutionContext, stage, new HashMap<String, String>()); + Map<String, String> configMap = timeOutCapture.getValues().get(0); + for (Map.Entry<String, String> config : configMap.entrySet()) { + if (config.getKey().equals(ExecutionCommand.KeyNames.COMMAND_TIMEOUT)) { + Assert.assertEquals("Service check timeout should be equal to populated in configs", + OVERRIDDEN_SERVICE_CHECK_TIMEOUT_VALUE, + config.getValue()); + return; + } + } + Assert.fail("Expected \"command_timeout\" config not found in execution command configs"); + } + /** * Perform a Service Check for ZOOKEEPER/ZOOKEEPER_CLIENT without specifying a host to run in the request. * This should cause Ambari to randomly pick one of the ZOOKEEPER_CLIENT hosts.
