Search in sources :

Example 86 with FlowParameters

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");
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 87 with FlowParameters

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);
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 88 with FlowParameters

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");
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 89 with FlowParameters

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);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StateContext(org.springframework.statemachine.StateContext) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 90 with FlowParameters

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);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) StateContext(org.springframework.statemachine.StateContext) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Aggregations

FlowParameters (com.sequenceiq.flow.core.FlowParameters)103 Map (java.util.Map)84 StateContext (org.springframework.statemachine.StateContext)84 Bean (org.springframework.context.annotation.Bean)81 Optional (java.util.Optional)67 SdxContext (com.sequenceiq.datalake.flow.SdxContext)56 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)52 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)31 Flow (com.sequenceiq.flow.core.Flow)28 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)16 Stack (com.sequenceiq.freeipa.entity.Stack)12 List (java.util.List)11 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 PollerStoppedException (com.dyngr.exception.PollerStoppedException)7 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)7 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)7 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)7