Search in sources :

Example 16 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

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

Example 17 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class SdxDetachActions method sdxAttachNewClusterFailedAction.

@Bean(name = "SDX_ATTACH_NEW_CLUSTER_FAILED_STATE")
public Action<?, ?> sdxAttachNewClusterFailedAction() {
    return new AbstractSdxAction<>(SdxDetachFailedEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxDetachFailedEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxDetachFailedEvent payload, Map<Object, Object> variables) throws Exception {
            SdxCluster clusterToReattach = (SdxCluster) variables.get(DETACHED_SDX);
            clusterToReattach = sdxAttachService.reattachDetachedSdxCluster(clusterToReattach);
            LOGGER.info("Successfully restored detached SDX with ID {}.", clusterToReattach.getId());
            sendEvent(context, SDX_DETACH_FAILED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxDetachFailedEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to recover from detach of SDX with ID {}.", payload.getResourceId());
            return payload;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxDetachFailedEvent(com.sequenceiq.datalake.flow.detach.event.SdxDetachFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 18 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class SdxDetachActions method sdxDetachCluster.

@Bean(name = "SDX_DETACH_CLUSTER_STATE")
public Action<?, ?> sdxDetachCluster() {
    return new AbstractSdxAction<>(SdxStartDetachEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxStartDetachEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxStartDetachEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Detaching of SDX with ID {} in progress.", payload.getResourceId());
            SdxCluster detached = sdxDetachService.detachCluster(payload.getResourceId(), payload.isDetachDuringRecovery());
            variables.put(RESIZED_SDX, payload.getSdxCluster());
            variables.put(DETACHED_SDX, detached);
            variables.put(IS_DETACH_DURING_RECOVERY, payload.isDetachDuringRecovery());
            eventSenderService.sendEventAndNotification(detached, context.getFlowTriggerUserCrn(), ResourceEvent.SDX_DETACH_STARTED, List.of(detached.getClusterName()));
            sendEvent(context, SDX_DETACH_CLUSTER_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxStartDetachEvent payload, Optional<SdxContext> flowContext, Exception e) {
            return SdxDetachFailedEvent.from(payload, e);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxStartDetachEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 19 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class SdxDetachActions method sdxAttachNewCluster.

@Bean(name = "SDX_ATTACH_NEW_CLUSTER_STATE")
public Action<?, ?> sdxAttachNewCluster() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
            SdxCluster detachedCluster = (SdxCluster) variables.get(DETACHED_SDX);
            sdxDetachService.markAsDetached(detachedCluster.getId());
            eventSenderService.notifyEvent(detachedCluster, context, ResourceEvent.SDX_DETACH_FINISHED);
            LOGGER.info("Detaching of SDX with ID {} finished.", detachedCluster.getId());
            if (!((boolean) variables.get(IS_DETACH_DURING_RECOVERY))) {
                SdxCluster resizedCluster = (SdxCluster) variables.get(RESIZED_SDX);
                LOGGER.info("Attaching of SDX cluster with ID {} in progress.", resizedCluster.getId());
                MDCBuilder.buildMdcContext(resizedCluster);
                resizedCluster = sdxAttachService.saveSdxAndAssignResourceOwnerRole(resizedCluster);
                sdxAttachService.markAsAttached(resizedCluster);
                LOGGER.info("Attaching of SDX cluster with ID {} is complete.", resizedCluster.getId());
                context.setSdxId(resizedCluster.getId());
            }
            sendEvent(context, SDX_ATTACH_NEW_CLUSTER_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to attach new cluster during detach.", e);
            return SdxDetachFailedEvent.from(payload, e);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 20 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class StartDatahubActions method failedAction.

@Bean(name = "START_DATAHUB_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractSdxAction<>(StartDatahubFailedEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, StartDatahubFailedEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, StartDatahubFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            DatalakeStatusEnum failedStatus = DatalakeStatusEnum.START_FAILED;
            LOGGER.info("Update SDX status to {} for resource: {}", failedStatus, payload.getResourceId(), exception);
            String statusReason = "Datahub start failed";
            if (exception.getMessage() != null) {
                statusReason = exception.getMessage();
            }
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sdxStatusService.setStatusForDatalakeAndNotify(failedStatus, statusReason, payload.getResourceId());
            sendEvent(context, START_DATAHUB_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(StartDatahubFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : DatalakeStatusEnum(com.sequenceiq.datalake.entity.DatalakeStatusEnum) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) StartDatahubFailedEvent(com.sequenceiq.datalake.flow.datahub.event.StartDatahubFailedEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) 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