use of com.sequenceiq.flow.core.FlowParameters 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);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class RebootActions method rebootFinishedAction.
@Bean(name = "REBOOT_FINISHED_STATE")
public Action<?, ?> rebootFinishedAction() {
return new AbstractRebootAction<>(HealthCheckSuccess.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(RebootContext context, HealthCheckSuccess payload, Map<Object, Object> variables) {
addMdcOperationId(variables);
rebootService.finishInstanceReboot(context);
LOGGER.info("Finished rebooting {}.", context.getInstanceIds());
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
successDetails.getAdditionalDetails().put("InstanceIds", context.getInstanceIdList());
operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
sendEvent(context);
}
@Override
protected Object getFailurePayload(HealthCheckSuccess payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected Selectable createRequest(RebootContext context) {
return new InstanceEvent(RebootEvent.REBOOT_FINALIZED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList());
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, HealthCheckSuccess payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
MDCBuilder.buildMdcContext(stack);
List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
return new RebootContext(flowParameters, stack, instances, null, null);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class RebootActions method rebootWaitUntilAvailableAction.
@Bean(name = "REBOOT_WAIT_UNTIL_AVAILABLE_STATE")
public Action<?, ?> rebootWaitUntilAvailableAction() {
return new AbstractRebootAction<>(RebootInstancesResult.class) {
@Override
protected void doExecute(RebootContext context, RebootInstancesResult payload, Map<Object, Object> variables) {
LOGGER.info("Starting reboot polling FreeIpa until it is available for {}", context.getInstanceIds());
rebootService.waitForAvailableStatus(context);
sendEvent(context);
}
@Override
protected Object getFailurePayload(RebootInstancesResult payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected Selectable createRequest(RebootContext context) {
return new HealthCheckRequest(context.getStack().getId(), true, context.getInstanceIdList());
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, RebootInstancesResult 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);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayActions method failureAction.
@Bean(name = "CHANGE_PRIMARY_GATEWAY_FAIL_STATE")
public Action<?, ?> failureAction() {
return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewayFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected ChangePrimaryGatewayContext createFlowContext(FlowParameters flowParameters, StateContext<ChangePrimaryGatewayState, ChangePrimaryGatewayFlowEvent> stateContext, ChangePrimaryGatewayFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewayFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Change primary gateway failed with payload: " + payload);
Stack stack = context.getStack();
String environmentCrn = stack.getEnvironmentCrn();
SuccessDetails successDetails = new SuccessDetails(environmentCrn);
successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
String message = "Change primary gateway failed during " + payload.getFailedPhase();
FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
if (payload.getFailureDetails() != null) {
failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
}
String errorReason = getErrorReason(payload.getException());
stackUpdater.updateStackStatus(context.getStack().getId(), DetailedStackStatus.REPAIR_FAILED, errorReason);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
LOGGER.info("Enabling the status checker for stack ID {} after failing repairing", stack.getId());
enableStatusChecker(stack, "Failed to repair FreeIPA");
enableNodeStatusChecker(stack, "Failed to repair FreeIPA");
sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<ChangePrimaryGatewayFailureEvent>> payloadConverters) {
payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter());
payloadConverters.add(new HealthCheckFailedToChangePrimaryGatewayFailureEventConverter());
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ImageChangeActionTest method testStoreImageEntity.
@Test
public void testStoreImageEntity() throws Exception {
StackContext stackContext = mock(StackContext.class);
Stack stack = new Stack();
when(stackContext.getStack()).thenReturn(stack);
when(stackContext.getFlowParameters()).thenReturn(new FlowParameters("flid", "userCrn", null));
ImageEntity imageEntity = new ImageEntity();
imageEntity.setId(2L);
when(imageService.getByStackId(1L)).thenReturn(imageEntity);
when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of());
Map<Object, Object> variables = new HashMap<>();
ImageSettingsRequest request = new ImageSettingsRequest();
underTest.doExecute(stackContext, new ImageChangeEvent(1L, request), variables);
assertEquals(Boolean.TRUE, variables.get(IMAGE_CHANGED_IN_DB));
assertFalse(variables.containsKey(ORIGINAL_IMAGE_REVISION));
assertFalse(variables.containsKey(IMAGE_ENTITY_ID));
assertEquals(imageEntity, variables.get(ORIGINAL_IMAGE));
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), captor.capture());
ImageChangeEvent event = (ImageChangeEvent) captor.getValue();
assertEquals(IMAGE_CHANGED_IN_DB_EVENT.event(), event.selector());
assertEquals(1L, event.getResourceId());
assertEquals(request, event.getRequest());
}
Aggregations