use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class SdxRepairActions method sdxRepairStarted.
@Bean(name = "SDX_REPAIR_START_STATE")
public Action<?, ?> sdxRepairStarted() {
return new AbstractSdxAction<>(SdxRepairStartEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxRepairStartEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxRepairStartEvent payload, Map<Object, Object> variables) throws Exception {
LOGGER.info("Start repair flow for Datalake: {}", payload.getResourceId());
SdxRepairStartRequest request = new SdxRepairStartRequest(payload.getResourceId(), payload.getUserId(), payload.getRepairSettings());
sendEvent(context, request.selector(), request);
}
@Override
protected Object getFailurePayload(SdxRepairStartEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return SdxRepairCouldNotStartEvent.from(payload, ex);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class DatalakeRestoreActionsTest method testGetNewSdxIdForResizeDoExecute.
@Test
public void testGetNewSdxIdForResizeDoExecute() throws Exception {
when(sdxBackupRestoreService.triggerDatalakeRestore(eq(NEW_SDX_ID), any(), any(), eq(USER_CRN))).thenReturn(new DatalakeRestoreStatusResponse(BACKUP_ID, RESTORE_ID, State.STARTED, Optional.empty()));
DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), NEW_SDX_ID, DATALAKE_NAME, USER_CRN, null, BACKUP_LOCATION, null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE);
AbstractAction action = (AbstractAction) underTest.triggerDatalakeRestore();
initActionPrivateFields(action);
AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
SdxContext context = SdxContext.from(new FlowParameters(FLOW_ID, FLOW_ID, null), event);
testSupport.doExecute(context, event, new HashMap());
ArgumentCaptor<DatalakeDatabaseRestoreStartEvent> captor = ArgumentCaptor.forClass(DatalakeDatabaseRestoreStartEvent.class);
verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
DatalakeDatabaseRestoreStartEvent captorValue = captor.getValue();
Assertions.assertEquals(NEW_SDX_ID, captorValue.getResourceId());
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class RebootActions method rebootFailureAction.
@Bean(name = "REBOOT_FAILED_STATE")
public Action<?, ?> rebootFailureAction() {
return new AbstractRebootAction<>(InstanceFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(RebootContext context, InstanceFailureEvent payload, Map<Object, Object> variables) {
addMdcOperationId(variables);
rebootService.handleInstanceRebootError(context);
String message = String.format("Rebooting failed for %s.", context.getInstanceIds());
LOGGER.error(message);
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
FailureDetails failureDetails = new FailureDetails(stack.getEnvironmentCrn(), message);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
sendEvent(context, new InstanceEvent(RebootEvent.REBOOT_FAIL_HANDLED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList()));
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, InstanceFailureEvent payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
return new RebootContext(flowParameters, stack, payload.getInstanceIds().stream().map(instanceId -> {
InstanceMetaData md = new InstanceMetaData();
md.setInstanceId(instanceId);
return md;
}).collect(Collectors.toList()), null, null);
}
@Override
protected Object getFailurePayload(InstanceFailureEvent payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<InstanceFailureEvent>> payloadConverters) {
payloadConverters.add(new RebootInstancesResultToCleanupFailureEventConverter());
payloadConverters.add(new WaitUntilAvailableFailedToInstanceFailureEventConverter());
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ImageChangeActionTest method testSameImage.
@Test
public void testSameImage() 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);
ImageSettingsRequest request = new ImageSettingsRequest();
when(imageService.getByStackId(1L)).thenReturn(imageEntity);
when(imageService.changeImage(stack, request)).thenReturn(imageEntity);
when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of());
Map<Object, Object> variables = new HashMap<>();
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_CHANGE_NOT_REQUIRED_EVENT.event(), event.selector());
assertEquals(1L, event.getResourceId());
assertEquals(request, event.getRequest());
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ImageChangeActionTest method testStoreRevision.
@Test
public void testStoreRevision() 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(1, 2, 3));
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));
assertEquals(3, variables.get(ORIGINAL_IMAGE_REVISION));
assertEquals(2L, variables.get(IMAGE_ENTITY_ID));
assertFalse(variables.containsKey(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