Search in sources :

Example 56 with FlowParameters

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

the class ExternalDatabaseStartActions method externalDatabaseStartFailureAction.

@Bean(name = "EXTERNAL_DATABASE_START_FAILED_STATE")
public Action<?, ?> externalDatabaseStartFailureAction() {
    return new AbstractExternalDatabaseStartAction<>(StartExternalDatabaseFailed.class) {

        @Override
        protected void doExecute(ExternalDatabaseContext context, StartExternalDatabaseFailed payload, Map<Object, Object> variables) {
            stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FAILED, payload.getException().getMessage());
            getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_START_FAILED, context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(ExternalDatabaseContext context) {
            return new StackEvent(ExternalDatabaseStartEvent.EXTERNAL_DATABASE_START_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
        }

        @Override
        protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStartState, ExternalDatabaseStartEvent> stateContext, StartExternalDatabaseFailed payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            super.beforeReturnFlowContext(flowParameters, stateContext, payload);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractExternalDatabaseStartAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.start.action.AbstractExternalDatabaseStartAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StateContext(org.springframework.statemachine.StateContext) ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) StartExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseFailed) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 57 with FlowParameters

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

the class ExternalDatabaseCreationActions method externalDatabaseCreationFailureAction.

@Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE")
public Action<?, ?> externalDatabaseCreationFailureAction() {
    return new AbstractExternalDatabaseCreationAction<>(CreateExternalDatabaseFailed.class) {

        @Override
        protected void doExecute(ExternalDatabaseContext context, CreateExternalDatabaseFailed payload, Map<Object, Object> variables) {
            stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, payload.getException().getMessage());
            getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(ExternalDatabaseContext context) {
            return new StackEvent(ExternalDatabaseCreationEvent.EXTERNAL_DATABASE_CREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
        }

        @Override
        protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, CreateExternalDatabaseFailed payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            super.beforeReturnFlowContext(flowParameters, stateContext, payload);
        }
    };
}
Also used : CreateExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseFailed) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StateContext(org.springframework.statemachine.StateContext) AbstractExternalDatabaseCreationAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.provision.action.AbstractExternalDatabaseCreationAction) ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 58 with FlowParameters

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

the class CertRenewalActions method startCertRenewAction.

@Bean(name = "START_CERT_RENEWAL_STATE")
public Action<?, ?> startCertRenewAction() {
    return new AbstractSdxAction<>(SdxStartCertRenewalEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxStartCertRenewalEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Start cert renewal.");
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            if (payload.isInternal()) {
                certRenewalService.renewInternalCertificate(sdxCluster);
            } else {
                certRenewalService.renewCertificate(sdxCluster, payload.getUserId());
            }
            SdxEvent sdxEvent = new SdxEvent(SdxCertRenewalEvent.CERT_RENEWAL_STARTED_EVENT.event(), payload.getResourceId(), payload.getUserId());
            sendEvent(context, sdxEvent);
        }

        @Override
        protected Object getFailurePayload(SdxStartCertRenewalEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRenewalFailedEvent(payload, ex.getMessage());
        }
    };
}
Also used : SdxStartCertRenewalEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent) 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) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 59 with FlowParameters

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

the class CertRenewalActions method certRenewInProgressAction.

@Bean(name = "CERT_RENEWAL_IN_PROGRESS_STATE")
public Action<?, ?> certRenewInProgressAction() {
    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 {
            LOGGER.info("Cert renewal is in progress. Start waiting to finish.");
            sendEvent(context, new SdxCertRenewalWaitEvent(context));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRenewalFailedEvent(payload, ex.getMessage());
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) SdxCertRenewalWaitEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalWaitEvent) StateContext(org.springframework.statemachine.StateContext) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 60 with FlowParameters

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

the class SdxCmSyncActions method cmSyncFailedAction.

@Bean(name = "SDX_CM_SYNC_FAILED_STATE")
public Action<?, ?> cmSyncFailedAction() {
    return new AbstractSdxAction<>(SdxCmSyncFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxCmSyncFailedEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Sdx cm sync failure, error: ", payload.getException());
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, SDX_CM_SYNC_FAILED_HANDLED_EVENT.event(), payload);
        }

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