use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class StopStartUpscaleActions method cmCommissionAction.
@Bean(name = "STOPSTART_UPSCALE_HOSTS_COMMISSION_STATE")
public Action<?, ?> cmCommissionAction() {
return new AbstractStopStartUpscaleActions<>(StopStartUpscaleStartInstancesResult.class) {
@Override
protected void doExecute(StopStartUpscaleContext context, StopStartUpscaleStartInstancesResult payload, Map<Object, Object> variables) throws Exception {
// Update instance metadata for successful nodes before handling / logging info about failures.
List<CloudVmInstanceStatus> cloudVmInstanceStatusList = payload.getAffectedInstanceStatuses();
Set<String> cloudInstanceIdsStarted = cloudVmInstanceStatusList.stream().filter(x -> x.getStatus() == InstanceStatus.STARTED).map(x -> x.getCloudInstance().getInstanceId()).collect(Collectors.toUnmodifiableSet());
List<InstanceMetaData> startedInstancesMetaData = cloudInstanceIdToInstanceMetaDataConverter.getNotDeletedAndNotZombieInstances(context.getStack(), context.getHostGroupName(), cloudInstanceIdsStarted);
clusterUpscaleFlowService.instancesStarted(context.getStack().getId(), startedInstancesMetaData);
handleInstanceUnsuccessfulStart(context, cloudVmInstanceStatusList);
// This list is currently empty. It could be populated later in another flow-step by querying CM to get service health.
// Meant to be a mechanism which detects cloud instances which are RUNNING, but not being utilized (likely due to previous failures)
List<CloudInstance> instancesWithServicesNotRunning = payload.getStartInstanceRequest().getStartedInstancesWithServicesNotRunning();
List<InstanceMetaData> metaDataWithServicesNotRunning = cloudInstanceIdToInstanceMetaDataConverter.getNotDeletedAndNotZombieInstances(context.getStack(), context.getHostGroupName(), instancesWithServicesNotRunning.stream().map(i -> i.getInstanceId()).collect(Collectors.toUnmodifiableSet()));
LOGGER.info("StartedInstancesCount={}, StartedInstancesMetadataCount={}," + " instancesWithServicesNotRunningCount={}, instancesWithServicesNotRunningMetadataCount={}", cloudInstanceIdsStarted.size(), startedInstancesMetaData.size(), instancesWithServicesNotRunning.size(), metaDataWithServicesNotRunning.size());
int toCommissionNodeCount = metaDataWithServicesNotRunning.size() + startedInstancesMetaData.size();
if (toCommissionNodeCount < context.getAdjustment()) {
LOGGER.warn("Not enough nodes found to commission. DesiredCount={}, availableCount={}", context.getAdjustment(), toCommissionNodeCount);
clusterUpscaleFlowService.warnNotEnoughInstances(context.getStack().getId(), context.getHostGroupName(), context.getAdjustment(), toCommissionNodeCount);
}
clusterUpscaleFlowService.upscaleCommissioningNodes(context.getStack().getId(), context.getHostGroupName(), startedInstancesMetaData, metaDataWithServicesNotRunning);
StopStartUpscaleCommissionViaCMRequest commissionRequest = new StopStartUpscaleCommissionViaCMRequest(context.getStack().getId(), context.getHostGroupName(), startedInstancesMetaData, metaDataWithServicesNotRunning);
sendEvent(context, commissionRequest);
}
private void handleInstanceUnsuccessfulStart(StopStartUpscaleContext context, List<CloudVmInstanceStatus> cloudVmInstanceStatusList) {
try {
List<CloudVmInstanceStatus> instancesNotInDesiredState = cloudVmInstanceStatusList.stream().filter(i -> i.getStatus() != InstanceStatus.STARTED).collect(Collectors.toList());
if (instancesNotInDesiredState.size() > 0) {
// Not updating the status of these instances in the DB. Instead letting the regular syncer threads take care of this.
// This is in case there is additional logic in the syncers while processing Instance state changes.
LOGGER.warn("Some instances could not be started: count={}, instances={}", instancesNotInDesiredState.size(), instancesNotInDesiredState);
clusterUpscaleFlowService.logInstancesFailedToStart(context.getStack().getId(), instancesNotInDesiredState);
// TODO CB-15132: Eventually, we may want to take some corrective action.
}
} catch (Exception e) {
LOGGER.warn("Failed while attempting to log info about instances which did not start. Ignoring, and letting flow proceed", e);
}
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class FillInMemoryStateStoreRestartAction method restart.
@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
Payload stackPayload = (Payload) payload;
Stack stack = stackService.getByIdWithListsInTransaction(stackPayload.getResourceId());
restart(flowParameters, flowChainId, event, payload, stack);
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class InitializeMDCContextRestartAction method restart.
@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
Payload stackPayload = (Payload) payload;
Stack stack = stackService.getById(stackPayload.getResourceId());
MDCBuilder.buildMdcContext(stack);
super.restart(flowParameters, flowChainId, event, payload);
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class StackStartActions method stackStartAction.
@Bean(name = "START_STATE")
public Action<?, ?> stackStartAction() {
return new AbstractStackStartAction<>(StackEvent.class) {
@Override
protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
stackStartStopService.startStackStart(context);
sendEvent(context);
}
@Override
protected Selectable createRequest(StackStartStopContext context) {
Stack stack = context.getStack();
LOGGER.debug("Assembling start request for stack: {}", stack);
List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(stack.getNotDeletedAndNotZombieInstanceMetaDataList(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudResource> resources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
cloudInstances.forEach(instance -> context.getStack().getParameters().forEach(instance::putParameter));
return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), resources, cloudInstances);
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class StackStopActions method stackStopAction.
@Bean(name = "STOP_STATE")
public Action<?, ?> stackStopAction() {
return new AbstractStackStopAction<>(StackEvent.class) {
@Override
protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
stackStartStopService.startStackStop(context);
sendEvent(context);
}
@Override
protected Selectable createRequest(StackStartStopContext context) {
Stack stack = context.getStack();
List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(context.getInstanceMetaData(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudResource> cloudResources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
cloudInstances.forEach(instance -> stack.getParameters().forEach(instance::putParameter));
return new StopInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
}
};
}
Aggregations