String clusterName = stage.getClusterName();
Cluster cluster = clusters.getCluster(clusterName);
StackId stackId = cluster.getDesiredStackVersion();
AmbariMetaInfo ambariMetaInfo = managementController.getAmbariMetaInfo();
ServiceInfo serviceInfo = ambariMetaInfo.getServiceInfo
(stackId.getStackName(), stackId.getStackVersion(), serviceName);
StackInfo stackInfo = ambariMetaInfo.getStackInfo
(stackId.getStackName(), stackId.getStackVersion());
long nowTimestamp = System.currentTimeMillis();
for (String hostName : hosts) {
Host host = clusters.getHost(hostName);
stage.addHostRoleExecutionCommand(hostName, Role.valueOf(componentName),
RoleCommand.CUSTOM_COMMAND,
new ServiceComponentHostOpInProgressEvent(componentName,
hostName, nowTimestamp), cluster.getClusterName(), serviceName);
Map<String, Map<String, String>> configurations =
new TreeMap<String, Map<String, String>>();
Map<String, Map<String, String>> configTags =
managementController.findConfigurationTagsWithOverrides(cluster, hostName);
HostRoleCommand cmd = stage.getHostRoleCommand(hostName, componentName);
if (cmd != null) {
cmd.setCommandDetail(commandDetail);
cmd.setCustomCommandName(commandName);
}
ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostName,
componentName).getExecutionCommand();
execCmd.setConfigurations(configurations);
execCmd.setConfigurationTags(configTags);
execCmd.setClusterHostInfo(
StageUtils.getClusterHostInfo(clusters.getHostsForCluster(clusterName), cluster));
hostLevelParams.put(CUSTOM_COMMAND, commandName);
// Set parameters required for re-installing clients on restart
hostLevelParams.put(REPO_INFO, getRepoInfo
(cluster, host));
execCmd.setHostLevelParams(hostLevelParams);
Map<String, String> commandParams = new TreeMap<String, String>();
commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
if (additionalCommandParams != null) {
for (String key : additionalCommandParams.keySet()) {
commandParams.put(key, additionalCommandParams.get(key));
}
}
String commandTimeout = configs.getDefaultAgentTaskTimeout();
ComponentInfo componentInfo = ambariMetaInfo.getComponent(
stackId.getStackName(), stackId.getStackVersion(),
serviceName, componentName);
if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
// Service check command is not custom command
CommandScriptDefinition script = componentInfo.getCommandScript();
if (script != null) {
commandParams.put(SCRIPT, script.getScript());
commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
if (script.getTimeout() > 0) {
commandTimeout = String.valueOf(script.getTimeout());
}
} else {
String message = String.format("Component %s has not command script " +
"defined. It is not possible to send command for " +
"this service", componentName);
throw new AmbariException(message);
}
// We don't need package/repo information to perform service check
}
commandParams.put(COMMAND_TIMEOUT, commandTimeout);
commandParams.put(SERVICE_PACKAGE_FOLDER,
serviceInfo.getServicePackageFolder());
commandParams.put(HOOKS_FOLDER, stackInfo.getStackHooksFolder());
execCmd.setCommandParams(commandParams);
Map<String, String> roleParams = execCmd.getRoleParams();