smokeTestServices.add(serviceName);
continue;
}
for (String componentName :
changedComponentCount.get(serviceName).keySet()) {
ServiceComponent sc = cluster.getService(serviceName)
.getServiceComponent(componentName);
StackId stackId = sc.getDesiredStackVersion();
ComponentInfo compInfo = ambariMetaInfo.getComponentCategory(
stackId.getStackName(), stackId.getStackVersion(), serviceName,
componentName);
if (compInfo.isMaster()) {
smokeTestServices.add(serviceName);
}
// FIXME if master check if we need to run a smoke test for the master
}
}
if (!changedScHosts.isEmpty()
|| !smokeTestServices.isEmpty()) {
long nowTimestamp = System.currentTimeMillis();
requestId = Long.valueOf(actionManager.getNextRequestId());
// FIXME cannot work with a single stage
// multiple stages may be needed for reconfigure
long stageId = 0;
Stage stage = createNewStage(cluster, requestId.longValue());
stage.setStageId(stageId);
//HACK
String jobtrackerHost = this.getJobTrackerHost(cluster);
for (String compName : changedScHosts.keySet()) {
for (State newState : changedScHosts.get(compName).keySet()) {
for (ServiceComponentHost scHost :
changedScHosts.get(compName).get(newState)) {
RoleCommand roleCommand;
State oldSchState = scHost.getState();
ServiceComponentHostEvent event;
switch(newState) {
case INSTALLED:
if (oldSchState == State.INIT
|| oldSchState == State.UNINSTALLED
|| oldSchState == State.INSTALLED
|| oldSchState == State.INSTALLING
|| oldSchState == State.INSTALL_FAILED) {
roleCommand = RoleCommand.INSTALL;
event = new ServiceComponentHostInstallEvent(
scHost.getServiceComponentName(), scHost.getHostName(),
nowTimestamp,
scHost.getDesiredStackVersion().getStackId());
} else if (oldSchState == State.STARTED
|| oldSchState == State.START_FAILED
|| oldSchState == State.INSTALLED
|| oldSchState == State.STOP_FAILED) {
roleCommand = RoleCommand.STOP;
event = new ServiceComponentHostStopEvent(
scHost.getServiceComponentName(), scHost.getHostName(),
nowTimestamp);
} else {
throw new AmbariException("Invalid transition for"
+ " servicecomponenthost"
+ ", clusterName=" + cluster.getClusterName()
+ ", clusterId=" + cluster.getClusterId()
+ ", serviceName=" + scHost.getServiceName()
+ ", componentName=" + scHost.getServiceComponentName()
+ ", hostname=" + scHost.getHostName()
+ ", currentState=" + oldSchState
+ ", newDesiredState=" + newState);
}
break;
case STARTED:
StackId stackId = scHost.getDesiredStackVersion();
ComponentInfo compInfo = ambariMetaInfo.getComponentCategory(
stackId.getStackName(), stackId.getStackVersion(), scHost.getServiceName(),
scHost.getServiceComponentName());
if (oldSchState == State.INSTALLED
|| oldSchState == State.START_FAILED || oldSchState == State.STARTING) {
roleCommand = RoleCommand.START;
event = new ServiceComponentHostStartEvent(
scHost.getServiceComponentName(), scHost.getHostName(),
nowTimestamp, scHost.getDesiredConfigVersionsRecursive());
} else {
String error = "Invalid transition for"
+ " servicecomponenthost"
+ ", clusterName=" + cluster.getClusterName()
+ ", clusterId=" + cluster.getClusterId()
+ ", serviceName=" + scHost.getServiceName()
+ ", componentName=" + scHost.getServiceComponentName()
+ ", hostname=" + scHost.getHostName()
+ ", currentState=" + oldSchState
+ ", newDesiredState=" + newState;
if (compInfo.isMaster()) {
throw new AmbariException(error);
} else {
LOG.info("Ignoring: " + error);
continue;
}
}
break;
case UNINSTALLED:
if (oldSchState == State.INSTALLED
|| oldSchState == State.UNINSTALL_FAILED) {
roleCommand = RoleCommand.UNINSTALL;
event = new ServiceComponentHostStartEvent(
scHost.getServiceComponentName(), scHost.getHostName(),
nowTimestamp, scHost.getDesiredConfigVersionsRecursive());
} else {
throw new AmbariException("Invalid transition for"
+ " servicecomponenthost"
+ ", clusterName=" + cluster.getClusterName()
+ ", clusterId=" + cluster.getClusterId()
+ ", serviceName=" + scHost.getServiceName()
+ ", componentName=" + scHost.getServiceComponentName()
+ ", hostname=" + scHost.getHostName()
+ ", currentState=" + oldSchState
+ ", newDesiredState=" + newState);
}
break;
case INIT:
throw new AmbariException("Unsupported transition to INIT for"
+ " servicecomponenthost"
+ ", clusterName=" + cluster.getClusterName()
+ ", clusterId=" + cluster.getClusterId()
+ ", serviceName=" + scHost.getServiceName()
+ ", componentName=" + scHost.getServiceComponentName()
+ ", hostname=" + scHost.getHostName()
+ ", currentState=" + oldSchState
+ ", newDesiredState=" + newState);
default:
throw new AmbariException("Unsupported state change operation"
+ ", newState=" + newState.toString());
}
if (LOG.isDebugEnabled()) {
LOG.debug("Create a new host action"
+ ", requestId=" + requestId.longValue()
+ ", componentName=" + scHost.getServiceComponentName()
+ ", hostname=" + scHost.getHostName()
+ ", roleCommand=" + roleCommand.name());
}
Map<String, Config> configs = scHost.getDesiredConfigs();
// Clone configurations for the command
Map<String, Map<String, String>> configurations =
new TreeMap<String, Map<String, String>>();
for (Config config : configs.values()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cloning configs for execution command"
+ ", configType=" + config.getType()
+ ", configVersionTag=" + config.getVersionTag()
+ ", clusterName=" + scHost.getClusterName()
+ ", serviceName=" + scHost.getServiceName()
+ ", componentName=" + scHost.getServiceComponentName()
+ ", hostname=" + scHost.getHostName());
}
configurations.put(config.getType(),
config.getProperties());
}
// HACK HACK HACK
if ((!scHost.getHostName().equals(jobtrackerHost))
&& configurations.get("global") != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting rca_enabled to false for host "
+ scHost.getHostName());
}
configurations.get("global").put("rca_enabled", "false");
}
createHostAction(cluster, stage, scHost, configurations,
roleCommand, nowTimestamp, event);
}
}
}
for (String serviceName : smokeTestServices) {
Service s = cluster.getService(serviceName);
// find service component host
String clientHost = getClientHostForRunningAction(cluster, s);
String smokeTestRole =
actionMetadata.getServiceCheckAction(serviceName);
if (clientHost == null || smokeTestRole == null) {
LOG.info("Nothing to do for service check as could not find role or"
+ " or host to run check on"
+ ", clusterName=" + cluster.getClusterName()
+ ", serviceName=" + serviceName
+ ", clientHost=" + clientHost
+ ", serviceCheckRole=" + smokeTestRole);
continue;
}
stage.addHostRoleExecutionCommand(clientHost,
Role.valueOf(smokeTestRole),
RoleCommand.EXECUTE,
new ServiceComponentHostOpInProgressEvent(null, clientHost,
nowTimestamp), cluster.getClusterName(), serviceName);
Map<String, Map<String, String>> configurations =
new TreeMap<String, Map<String, String>>();
Map<String, Config> allConfigs = cluster.getService(serviceName).getDesiredConfigs();
if (allConfigs != null) {
for (Map.Entry<String, Config> entry: allConfigs.entrySet()) {
configurations.put(entry.getValue().getType(), entry.getValue().getProperties());
}
}
stage.getExecutionCommandWrapper(clientHost,
smokeTestRole).getExecutionCommand()
.setConfigurations(configurations);
// Generate cluster host info
stage.getExecutionCommandWrapper(clientHost, smokeTestRole)
.getExecutionCommand()
.setClusterHostInfo(StageUtils.getClusterHostInfo(cluster, hostsMap));
}
RoleGraph rg = new RoleGraph(rco);
rg.build(stage);
stages = rg.getStages();
if (LOG.isDebugEnabled()) {
LOG.debug("Triggering Action Manager"
+ ", clusterName=" + cluster.getClusterName()
+ ", requestId=" + requestId.longValue()
+ ", stagesCount=" + stages.size());
}
actionManager.sendActions(stages);
}
if (changedServices != null) {
for (Entry<State, List<Service>> entry : changedServices.entrySet()) {
State newState = entry.getKey();
for (Service s : entry.getValue()) {
if (s.isClientOnlyService()
&& newState == State.STARTED) {
continue;
}
s.setDesiredState(newState);
}
}
}
if (changedComps != null) {
for (Entry<State, List<ServiceComponent>> entry :
changedComps.entrySet()){
State newState = entry.getKey();
for (ServiceComponent sc : entry.getValue()) {
sc.setDesiredState(newState);
}
}
}
for (Map<State, List<ServiceComponentHost>> stateScHostMap :