@Test(expected = AmbariException.class) public void testServiceCheckComponentWithEmptyHosts() throws Exception { AmbariCustomCommandExecutionHelper ambariCustomCommandExecutionHelper = injector.getInstance(AmbariCustomCommandExecutionHelper.class); List<RequestResourceFilter> requestResourceFilter = new ArrayList<RequestResourceFilter>() {{ add(new RequestResourceFilter("FLUME", null, null)); }}; ActionExecutionContext actionExecutionContext = new ActionExecutionContext("c1", "SERVICE_CHECK", requestResourceFilter); Stage stage = EasyMock.niceMock(Stage.class); ambariCustomCommandExecutionHelper.addExecutionCommandsToStage(actionExecutionContext, stage, new HashMap<String, String>()); Assert.fail("Expected an exception since there are no hosts which can run the Flume service check"); }
public void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext, Stage stage, Map<String, String> requestParams) throws AmbariException { List<RequestResourceFilter> resourceFilters = actionExecutionContext.getResourceFilters(); for (RequestResourceFilter resourceFilter : resourceFilters) { LOG.debug("Received a command execution request" + ", clusterName=" + actionExecutionContext.getClusterName() + ", serviceName=" + resourceFilter.getServiceName() + ", request=" + actionExecutionContext.toString()); String actionName = actionExecutionContext.getActionName(); if (actionName.contains(SERVICE_CHECK_COMMAND_NAME)) { findHostAndAddServiceCheckAction(actionExecutionContext, resourceFilter, stage); } else if (actionName.equals(DECOMMISSION_COMMAND_NAME)) { addDecommissionAction(actionExecutionContext, resourceFilter, stage); } else if (isValidCustomCommand(actionExecutionContext, resourceFilter)) { String commandDetail = getReadableCustomCommandDetail(actionExecutionContext, resourceFilter); Map<String, String> extraParams = new HashMap<>(); String componentName = (null == resourceFilter.getComponentName()) ? null : resourceFilter.getComponentName().toLowerCase(); if (null != componentName && requestParams.containsKey(componentName)) { extraParams.put(componentName, requestParams.get(componentName)); } 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.LOG_OUTPUT)) { extraParams.put(KeyNames.LOG_OUTPUT, requestParams.get(KeyNames.LOG_OUTPUT)); } 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)); } RequestOperationLevel operationLevel = actionExecutionContext.getOperationLevel(); if (operationLevel != null) { String clusterName = operationLevel.getClusterName(); String serviceName = operationLevel.getServiceName(); if (isTopologyRefreshRequired(actionName, clusterName, serviceName)) { extraParams.put(KeyNames.REFRESH_TOPOLOGY, "True"); } } addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams, commandDetail); } else { throw new AmbariException("Unsupported action " + actionName); } } }
AmbariCustomCommandExecutionHelper { public void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext, Stage stage, Map<String, String> requestParams) throws AmbariException { List<RequestResourceFilter> resourceFilters = actionExecutionContext.getResourceFilters(); for (RequestResourceFilter resourceFilter : resourceFilters) { LOG.debug("Received a command execution request" + ", clusterName=" + actionExecutionContext.getClusterName() + ", serviceName=" + resourceFilter.getServiceName() + ", request=" + actionExecutionContext.toString()); String actionName = actionExecutionContext.getActionName(); if (actionName.contains(SERVICE_CHECK_COMMAND_NAME)) { findHostAndAddServiceCheckAction(actionExecutionContext, resourceFilter, stage); } else if (actionName.equals(DECOMMISSION_COMMAND_NAME)) { addDecommissionAction(actionExecutionContext, resourceFilter, stage); } else if (isValidCustomCommand(actionExecutionContext, resourceFilter)) { String commandDetail = getReadableCustomCommandDetail(actionExecutionContext, resourceFilter); Map<String, String> extraParams = new HashMap<>(); String componentName = (null == resourceFilter.getComponentName()) ? null : resourceFilter.getComponentName().toLowerCase(); if (null != componentName && requestParams.containsKey(componentName)) { extraParams.put(componentName, requestParams.get(componentName)); } 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.LOG_OUTPUT)) { extraParams.put(KeyNames.LOG_OUTPUT, requestParams.get(KeyNames.LOG_OUTPUT)); } 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)); } RequestOperationLevel operationLevel = actionExecutionContext.getOperationLevel(); if (operationLevel != null) { String clusterName = operationLevel.getClusterName(); String serviceName = operationLevel.getServiceName(); if (isTopologyRefreshRequired(actionName, clusterName, serviceName)) { extraParams.put(KeyNames.REFRESH_TOPOLOGY, "True"); } } addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams, commandDetail); } else { throw new AmbariException("Unsupported action " + actionName); } } } }
AmbariCustomCommandExecutionHelper { public void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext, Stage stage, Map<String, String> requestParams) throws AmbariException { List<RequestResourceFilter> resourceFilters = actionExecutionContext.getResourceFilters(); for (RequestResourceFilter resourceFilter : resourceFilters) { LOG.debug("Received a command execution request" + ", clusterName=" + actionExecutionContext.getClusterName() + ", serviceName=" + resourceFilter.getServiceName() + ", request=" + actionExecutionContext.toString()); String actionName = actionExecutionContext.getActionName(); if (actionName.contains(SERVICE_CHECK_COMMAND_NAME)) { findHostAndAddServiceCheckAction(actionExecutionContext, resourceFilter, stage); } else if (actionName.equals(DECOMMISSION_COMMAND_NAME)) { addDecommissionAction(actionExecutionContext, resourceFilter, stage); } else if (isValidCustomCommand(actionExecutionContext, resourceFilter)) { String commandDetail = getReadableCustomCommandDetail(actionExecutionContext, resourceFilter); Map<String, String> extraParams = new HashMap<>(); String componentName = (null == resourceFilter.getComponentName()) ? null : resourceFilter.getComponentName().toLowerCase(); if (null != componentName && requestParams.containsKey(componentName)) { extraParams.put(componentName, requestParams.get(componentName)); } 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.LOG_OUTPUT)) { extraParams.put(KeyNames.LOG_OUTPUT, requestParams.get(KeyNames.LOG_OUTPUT)); } 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)); } RequestOperationLevel operationLevel = actionExecutionContext.getOperationLevel(); if (operationLevel != null) { String clusterName = operationLevel.getClusterName(); String serviceName = operationLevel.getServiceName(); if (isTopologyRefreshRequired(actionName, clusterName, serviceName)) { extraParams.put(KeyNames.REFRESH_TOPOLOGY, "True"); } } addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams, commandDetail); } else { throw new AmbariException("Unsupported action " + actionName); } } }  }
AmbariCustomCommandExecutionHelper { public void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext, Stage stage, Map<String, String> requestParams) throws AmbariException { List<RequestResourceFilter> resourceFilters = actionExecutionContext.getResourceFilters(); for (RequestResourceFilter resourceFilter : resourceFilters) { LOG.debug("Received a command execution request" + ", clusterName=" + actionExecutionContext.getClusterName() + ", serviceName=" + resourceFilter.getServiceName() + ", request=" + actionExecutionContext.toString()); String actionName = actionExecutionContext.getActionName(); if (actionName.contains(SERVICE_CHECK_COMMAND_NAME)) { findHostAndAddServiceCheckAction(actionExecutionContext, resourceFilter, stage); } else if (actionName.equals(DECOMMISSION_COMMAND_NAME)) { addDecommissionAction(actionExecutionContext, resourceFilter, stage); } else if (isValidCustomCommand(actionExecutionContext, resourceFilter)) { String commandDetail = getReadableCustomCommandDetail(actionExecutionContext, resourceFilter); Map<String, String> extraParams = new HashMap<>(); String componentName = (null == resourceFilter.getComponentName()) ? null : resourceFilter.getComponentName().toLowerCase(); if (null != componentName && requestParams.containsKey(componentName)) { extraParams.put(componentName, requestParams.get(componentName)); } 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.LOG_OUTPUT)) { extraParams.put(KeyNames.LOG_OUTPUT, requestParams.get(KeyNames.LOG_OUTPUT)); } 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)); } RequestOperationLevel operationLevel = actionExecutionContext.getOperationLevel(); if (operationLevel != null) { String clusterName = operationLevel.getClusterName(); String serviceName = operationLevel.getServiceName(); if (isTopologyRefreshRequired(actionName, clusterName, serviceName)) { extraParams.put(KeyNames.REFRESH_TOPOLOGY, "True"); } } addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams, commandDetail); } else { throw new AmbariException("Unsupported action " + actionName); } } }  void addServiceCheckAction(Stage stage, String hostname, String smokeTestRole,
      long nowTimestamp, String serviceName, String componentName,
      Map<String, String> actionParameters, boolean retryAllowed, boolean autoSkipFailure); void validateAction(ExecuteActionRequest actionRequest); void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext,
      Stage stage, Map<String, String> requestParams); String getRepoInfo(Cluster cluster, Host host); String getRepoInfo(Cluster cluster, String hostOSType, String hostOSFamily, String hostName); ExecuteCommandJson getCommandJson(ActionExecutionContext actionExecContext,
      Cluster cluster, StackId stackId); boolean isTopologyRefreshRequired(String actionName, String clusterName, String serviceName); }
AmbariCustomCommandExecutionHelper { public void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext, Stage stage, Map<String, String> requestParams) throws AmbariException { List<RequestResourceFilter> resourceFilters = actionExecutionContext.getResourceFilters(); for (RequestResourceFilter resourceFilter : resourceFilters) { LOG.debug("Received a command execution request" + ", clusterName=" + actionExecutionContext.getClusterName() + ", serviceName=" + resourceFilter.getServiceName() + ", request=" + actionExecutionContext.toString()); String actionName = actionExecutionContext.getActionName(); if (actionName.contains(SERVICE_CHECK_COMMAND_NAME)) { findHostAndAddServiceCheckAction(actionExecutionContext, resourceFilter, stage); } else if (actionName.equals(DECOMMISSION_COMMAND_NAME)) { addDecommissionAction(actionExecutionContext, resourceFilter, stage); } else if (isValidCustomCommand(actionExecutionContext, resourceFilter)) { String commandDetail = getReadableCustomCommandDetail(actionExecutionContext, resourceFilter); Map<String, String> extraParams = new HashMap<>(); String componentName = (null == resourceFilter.getComponentName()) ? null : resourceFilter.getComponentName().toLowerCase(); if (null != componentName && requestParams.containsKey(componentName)) { extraParams.put(componentName, requestParams.get(componentName)); } 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.LOG_OUTPUT)) { extraParams.put(KeyNames.LOG_OUTPUT, requestParams.get(KeyNames.LOG_OUTPUT)); } 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)); } RequestOperationLevel operationLevel = actionExecutionContext.getOperationLevel(); if (operationLevel != null) { String clusterName = operationLevel.getClusterName(); String serviceName = operationLevel.getServiceName(); if (isTopologyRefreshRequired(actionName, clusterName, serviceName)) { extraParams.put(KeyNames.REFRESH_TOPOLOGY, "True"); } } addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams, commandDetail); } else { throw new AmbariException("Unsupported action " + actionName); } } }  void addServiceCheckAction(Stage stage, String hostname, String smokeTestRole,
      long nowTimestamp, String serviceName, String componentName,
      Map<String, String> actionParameters, boolean retryAllowed, boolean autoSkipFailure); void validateAction(ExecuteActionRequest actionRequest); void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext,
      Stage stage, Map<String, String> requestParams); String getRepoInfo(Cluster cluster, Host host); String getRepoInfo(Cluster cluster, String hostOSType, String hostOSFamily, String hostName); ExecuteCommandJson getCommandJson(ActionExecutionContext actionExecContext,
      Cluster cluster, StackId stackId); boolean isTopologyRefreshRequired(String actionName, String clusterName, String serviceName); static final Map<String, String> masterToSlaveMappingForDecom; final static String DECOM_INCLUDED_HOSTS; final static String DECOM_EXCLUDED_HOSTS; final static String DECOM_SLAVE_COMPONENT; final static String HBASE_MARK_DRAINING_ONLY; final static String UPDATE_EXCLUDE_FILE_ONLY; final static int MIN_STRICT_SERVICE_CHECK_TIMEOUT; static final String DECOMMISSION_COMMAND_NAME; }