use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class UpgradeCcmActionsTest method setUp.
@BeforeEach
void setUp() {
sdxCluster = new SdxCluster();
sdxCluster.setId(SDX_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);
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 EnvironmentStatusUpdateServiceTest method testUpdateEnvironmentStatusAndNotify.
@Test
public void testUpdateEnvironmentStatusAndNotify() {
CommonContext commonContext = new CommonContext(new FlowParameters("flowId", "userCrn", null));
EnvironmentDto environmentDto = EnvironmentDto.builder().withId(1L).withEnvironmentStatus(EnvironmentStatus.STOP_DATAHUB_FAILED).build();
Environment environment = new Environment();
when(environmentService.findEnvironmentById(environmentDto.getResourceId())).thenReturn(Optional.of(environment));
when(environmentService.save(environment)).thenReturn(environment);
when(environmentService.getEnvironmentDto(environment)).thenReturn(environmentDto);
EnvironmentDto actual = underTest.updateEnvironmentStatusAndNotify(commonContext, environmentDto, EnvironmentStatus.STOP_DATAHUB_FAILED, ResourceEvent.ENVIRONMENT_VALIDATION_FAILED, EnvStartState.ENV_START_FINISHED_STATE);
Assertions.assertEquals(EnvironmentStatus.STOP_DATAHUB_FAILED, actual.getStatus());
verify(eventSenderService).sendEventAndNotification(environmentDto, "userCrn", ResourceEvent.ENVIRONMENT_VALIDATION_FAILED);
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class EnvCreationActionsTest 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 EnvCreationEvent(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);
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 ClusterStopActions method clusterStopFailedAction.
@Bean(name = "CLUSTER_STOP_FAILED_STATE")
public Action<?, ?> clusterStopFailedAction() {
return new AbstractStackFailureAction<ClusterStopState, ClusterStopEvent>() {
@Override
protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) {
clusterStopService.handleClusterStopFailure(context.getStackView(), payload.getException().getMessage());
getMetricService().incrementMetricCounter(MetricType.CLUSTER_STOP_FAILED, context.getStackView(), payload.getException());
sendEvent(context);
}
@Override
protected Selectable createRequest(StackFailureContext context) {
return new StackEvent(ClusterStopEvent.FINALIZED_EVENT.event(), context.getStackView().getId());
}
@Override
protected StackFailureContext createFlowContext(FlowParameters flowParameters, StateContext<ClusterStopState, ClusterStopEvent> stateContext, StackFailureEvent payload) {
StackView stack = stackService.getViewByIdWithoutAuth(payload.getResourceId());
MDCBuilder.buildMdcContext(stack);
return new StackFailureContext(flowParameters, stack);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class EnvClustersDeleteActions method failedAction.
@Bean(name = "ENV_CLUSTERS_DELETE_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractEnvClustersDeleteAction<>(EnvClusterDeleteFailedEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvClusterDeleteFailedEvent payload, Map<Object, Object> variables) {
LOGGER.warn("Failed to delete environment", payload.getException());
Exception e = payload.getException();
environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
environment.setStatusReason(payload.getMessage() == null ? e.getMessage() : payload.getMessage());
environment.setStatus(EnvironmentStatus.DELETE_FAILED);
Environment result = environmentService.save(environment);
EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
metricService.incrementMetricCounter(MetricType.ENV_CLUSTERS_DELETION_FAILED, environmentDto, payload.getException());
eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ResourceEvent.ENVIRONMENT_DELETION_FAILED);
}, () -> LOGGER.error("Cannot set delete failed to env because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", payload.getResourceId()));
LOGGER.info("Flow entered into ENV_CLUSTERS_DELETE_FAILED_STATE");
sendEvent(context, HANDLED_FAILED_ENV_CLUSTERS_DELETE_EVENT.event(), payload);
}
@Override
protected CommonContext createFlowContext(FlowParameters flowParameters, StateContext<EnvClustersDeleteState, EnvClustersDeleteStateSelectors> stateContext, EnvClusterDeleteFailedEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return new CommonContext(flowParameters);
}
};
}
Aggregations