use of com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesRequest in project cloudbreak by hortonworks.
the class RebootActions method rebootAction.
@Bean(name = "REBOOT_STATE")
public Action<?, ?> rebootAction() {
return new AbstractRebootAction<>(RebootInstanceEvent.class) {
@Override
protected void doExecute(RebootContext context, RebootInstanceEvent payload, Map<Object, Object> variables) {
setOperationId(variables, payload.getOperationId());
LOGGER.info("Starting reboot for {}", context.getInstanceIds());
rebootService.startInstanceReboot(context);
sendEvent(context);
}
@Override
protected Object getFailurePayload(RebootInstanceEvent payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected Selectable createRequest(RebootContext context) {
List<CloudInstance> cloudInstances = context.getInstanceMetaDataList().stream().map(instanceMetaData -> instanceMetaDataToCloudInstanceConverter.convert(instanceMetaData)).collect(Collectors.toList());
List<CloudResource> cloudResources = getCloudResources(context.getStack().getId());
return new RebootInstancesRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, RebootInstanceEvent payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
CloudContext cloudContext = getCloudContext(stack);
Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
return new RebootContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
};
}
Aggregations