use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class EnvDeleteActionsTest method setUp.
@BeforeEach
void setUp() {
FlowParameters flowParameters = new FlowParameters(FLOW_ID, FLOW_TRIGGER_USER_CRN, null);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name())).thenReturn(flowParameters);
actionPayload = new EnvDeleteEvent(ACTION_PAYLOAD_SELECTOR, ENVIRONMENT_ID, ENVIRONMENT_NAME, ENVIRONMENT_CRN, true);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(actionPayload);
when(stateContext.getExtendedState()).thenReturn(extendedState);
when(extendedState.getVariables()).thenReturn(new HashMap<>());
when(stateContext.getStateMachine()).thenReturn(stateMachine);
when(stateMachine.getState()).thenReturn(state);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
when(spanBuilder.start()).thenReturn(span);
when(tracer.activateSpan(span)).thenReturn(scope);
when(span.context()).thenReturn(spanContext);
when(flowEvent.name()).thenReturn("eventName");
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class UpgradeCcmActionsTest method setUp.
@BeforeEach
void setUp() {
FlowParameters flowParameters = new FlowParameters(FLOW_ID, FLOW_TRIGGER_USER_CRN, null);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name())).thenReturn(flowParameters);
actionPayload = new UpgradeCcmEvent(ACTION_PAYLOAD_SELECTOR, ENVIRONMENT_ID, ENVIRONMENT_NAME, ENVIRONMENT_CRN);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(actionPayload);
when(stateContext.getExtendedState()).thenReturn(extendedState);
when(extendedState.getVariables()).thenReturn(new HashMap<>());
when(stateContext.getStateMachine()).thenReturn(stateMachine);
when(stateMachine.getState()).thenReturn(state);
lenient().when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
when(spanBuilder.start()).thenReturn(span);
when(tracer.activateSpan(span)).thenReturn(scope);
when(span.context()).thenReturn(spanContext);
when(flowEvent.name()).thenReturn("eventName");
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class SleepFlow method sleepFailed.
@Bean("SLEEP_FAILED_STATE")
public Action<?, ?> sleepFailed() {
return new AbstractAction<>(SleepFailedEvent.class) {
@Override
protected CommonContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SleepFailedEvent payload) {
return new CommonContext(flowParameters);
}
@Override
protected void doExecute(CommonContext context, SleepFailedEvent payload, Map<Object, Object> variables) throws Exception {
LOGGER.info("Sleep fail handled!");
Flow flow = getFlow(context.getFlowId());
flow.setFlowFailed(new Exception(payload.getReason()));
sendEvent(context, SleepEvent.SLEEP_FAIL_HANDLED_EVENT.selector(), payload);
}
@Override
protected Object getFailurePayload(SleepFailedEvent payload, Optional<CommonContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class RedbeamsProvisionActions method provisionFailed.
@Bean(name = "REDBEAMS_PROVISION_FAILED_STATE")
public Action<?, ?> provisionFailed() {
return new AbstractRedbeamsProvisionAction<>(RedbeamsFailureEvent.class) {
// A lot here - some of this could go into some sort of failure handler class
// compare to core StackCreationService::handleStackCreationFailure
@Override
protected void prepareExecution(RedbeamsFailureEvent payload, Map<Object, Object> variables) {
Exception failureException = payload.getException();
LOGGER.info("Error during database stack creation flow:", failureException);
if (failureException instanceof CancellationException || ExceptionUtils.getRootCause(failureException) instanceof CancellationException) {
LOGGER.debug("The flow has been cancelled");
} else {
// StackCreationActions / StackCreationService only update status if stack isn't mid-deletion
String errorReason = failureException == null ? "Unknown error" : failureException.getMessage();
Optional<DBStack> dbStack = dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.PROVISION_FAILED, errorReason);
metricService.incrementMetricCounter(MetricType.DB_PROVISION_FAILED, dbStack);
}
}
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsProvisionState, RedbeamsProvisionEvent> stateContext, RedbeamsFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected Selectable createRequest(RedbeamsContext context) {
return new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_FAILURE_HANDLED_EVENT.event(), 0L);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ExternalDatabaseCreationActionsTest method setup.
@BeforeEach
void setup() {
STACK.setId(STACK_ID);
FlowParameters flowParameters = new FlowParameters(FLOW_ID, FLOW_TRIGGER_USER_CRN, null);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name())).thenReturn(flowParameters);
when(stateContext.getExtendedState()).thenReturn(extendedState);
when(extendedState.getVariables()).thenReturn(new HashMap<>());
when(stateContext.getStateMachine()).thenReturn(stateMachine);
when(stateMachine.getState()).thenReturn(state);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
when(spanBuilder.start()).thenReturn(span);
when(tracer.activateSpan(span)).thenReturn(scope);
when(span.context()).thenReturn(spanContext);
when(flowEvent.name()).thenReturn("eventName");
}
Aggregations