Search in sources :

Example 41 with FlowParameters

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

the class SdxCreateActions method rdsCreation.

@Bean(name = "SDX_CREATION_WAIT_RDS_STATE")
public Action<?, ?> rdsCreation() {
    return new AbstractSdxAction<>(StorageValidationSuccessEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, StorageValidationSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            RdsWaitRequest req = new RdsWaitRequest(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(StorageValidationSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StorageValidationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StorageValidationSuccessEvent) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) RdsWaitRequest(com.sequenceiq.datalake.flow.create.event.RdsWaitRequest) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 42 with FlowParameters

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

the class SdxCreateActions method envWaitInProgress.

@Bean(name = "SDX_CREATION_WAIT_ENV_STATE")
public Action<?, ?> envWaitInProgress() {
    return new AbstractSdxAction<>(RdsWaitSuccessEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, RdsWaitSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            EnvWaitRequest req = EnvWaitRequest.from(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(RdsWaitSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) RdsWaitSuccessEvent(com.sequenceiq.datalake.flow.create.event.RdsWaitSuccessEvent) StateContext(org.springframework.statemachine.StateContext) EnvWaitRequest(com.sequenceiq.datalake.flow.create.event.EnvWaitRequest) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 43 with FlowParameters

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

the class SdxCreateActions method failedAction.

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

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

        @Override
        protected void doExecute(SdxContext context, SdxCreateFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            String statusReason = "Datalake creation failed";
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
            if (StringUtils.hasText(errorMessage)) {
                statusReason = statusReason + ". " + errorMessage;
            } else if (exception.getMessage() != null) {
                statusReason = statusReason + ". " + exception.getMessage();
            }
            LOGGER.error(statusReason, exception);
            try {
                SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.PROVISIONING_FAILED, statusReason, payload.getResourceId());
                metricService.incrementMetricCounter(MetricType.SDX_CREATION_FAILED, sdxCluster);
                eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_CREATION_FAILED);
            } catch (NotFoundException notFoundException) {
                LOGGER.info("Can not set status to SDX_CREATION_FAILED because data lake was not found");
            } catch (DatalakeStatusUpdateException datalakeStatusUpdateException) {
                LOGGER.info("Status update for data lake failed (possible reason: ongoing parallel deletion flow): {}", exception.getMessage());
            }
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, SDX_CREATE_FAILED_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxCreateFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 44 with FlowParameters

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

the class SdxCreateActions method sdxValidation.

@Bean(name = "SDX_CREATION_VALIDATION_STATE")
public Action<?, ?> sdxValidation() {
    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 {
            setCorrectSdxIdIfNecessary(context, payload);
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_PROVISION_STARTED);
            SdxValidationRequest req = new SdxValidationRequest(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) SdxValidationRequest(com.sequenceiq.datalake.flow.create.event.SdxValidationRequest) StateContext(org.springframework.statemachine.StateContext) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 45 with FlowParameters

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

the class SdxCreateActions method finishedAction.

@Bean(name = "SDX_CREATION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractSdxAction<>(StackCreationSuccessEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, StackCreationSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, "Datalake is running", payload.getResourceId());
            metricService.incrementMetricCounter(MetricType.SDX_CREATION_FINISHED, sdxCluster);
            jobService.schedule(context.getSdxId(), SdxClusterJobAdapter.class);
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_PROVISION_FINISHED);
            sendEvent(context, SDX_CREATE_FINALIZED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(StackCreationSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
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) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) 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