Search in sources :

Example 1 with ExternalDatabaseContext

use of com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext in project cloudbreak by hortonworks.

the class ExternalDatabaseStopActions method externalDatabaseStopFailureAction.

@Bean(name = "EXTERNAL_DATABASE_STOP_FAILED_STATE")
public Action<?, ?> externalDatabaseStopFailureAction() {
    return new AbstractExternalDatabaseStopAction<>(StopExternalDatabaseFailed.class) {

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

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

        @Override
        protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStopState, ExternalDatabaseStopEvent> stateContext, StopExternalDatabaseFailed payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            super.beforeReturnFlowContext(flowParameters, stateContext, payload);
        }
    };
}
Also used : AbstractExternalDatabaseStopAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.stop.action.AbstractExternalDatabaseStopAction) StopExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StateContext(org.springframework.statemachine.StateContext) 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 2 with ExternalDatabaseContext

use of com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext in project cloudbreak by hortonworks.

the class AbstractExternalDatabaseStopAction method createFlowContext.

@Override
protected ExternalDatabaseContext createFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStopState, ExternalDatabaseStopEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithClusterInTransaction(payload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    beforeReturnFlowContext(flowParameters, stateContext, payload);
    return new ExternalDatabaseContext(flowParameters, stack);
}
Also used : ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 3 with ExternalDatabaseContext

use of com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext in project cloudbreak by hortonworks.

the class ExternalDatabaseTerminationActions method externalDatabaseTerminationFailureAction.

@Bean(name = "EXTERNAL_DATABASE_TERMINATION_FAILED_STATE")
public Action<?, ?> externalDatabaseTerminationFailureAction() {
    return new AbstractExternalDatabaseTerminationAction<>(TerminateExternalDatabaseFailed.class) {

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

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

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

Example 4 with ExternalDatabaseContext

use of com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext in project cloudbreak by hortonworks.

the class ExternalDatabaseTerminationActions method externalDatabaseTermination.

@Bean(name = "WAIT_FOR_EXTERNAL_DATABASE_TERMINATION_STATE")
public Action<?, ?> externalDatabaseTermination() {
    return new AbstractExternalDatabaseTerminationAction<>(TerminationEvent.class) {

        @Override
        protected void doExecute(ExternalDatabaseContext context, TerminationEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            TerminateExternalDatabaseRequest request = new TerminateExternalDatabaseRequest(stack.getId(), "TerminateExternalDatabaseRequest", stack.getName(), stack.getResourceCrn(), payload.getTerminationType().isForced());
            sendEvent(context, request);
        }
    };
}
Also used : ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) AbstractExternalDatabaseTerminationAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.action.AbstractExternalDatabaseTerminationAction) ExternalDatabaseTerminationEvent(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.config.ExternalDatabaseTerminationEvent) TerminationEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationEvent) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TerminateExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseRequest) Bean(org.springframework.context.annotation.Bean)

Example 5 with ExternalDatabaseContext

use of com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext in project cloudbreak by hortonworks.

the class AbstractExternalDatabaseStartAction method createFlowContext.

@Override
protected ExternalDatabaseContext createFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStartState, ExternalDatabaseStartEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithClusterInTransaction(payload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    beforeReturnFlowContext(flowParameters, stateContext, payload);
    return new ExternalDatabaseContext(flowParameters, stack);
}
Also used : ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

ExternalDatabaseContext (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)9 Map (java.util.Map)5 Bean (org.springframework.context.annotation.Bean)5 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 Flow (com.sequenceiq.flow.core.Flow)4 FlowParameters (com.sequenceiq.flow.core.FlowParameters)4 Test (org.junit.jupiter.api.Test)4 StateContext (org.springframework.statemachine.StateContext)4 AbstractExternalDatabaseTerminationAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.action.AbstractExternalDatabaseTerminationAction)2 AbstractExternalDatabaseCreationAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.provision.action.AbstractExternalDatabaseCreationAction)1 AbstractExternalDatabaseStartAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.start.action.AbstractExternalDatabaseStartAction)1 AbstractExternalDatabaseStopAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.stop.action.AbstractExternalDatabaseStopAction)1 ExternalDatabaseTerminationEvent (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.config.ExternalDatabaseTerminationEvent)1 CreateExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseFailed)1 StartExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseFailed)1 StopExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed)1 TerminateExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseFailed)1 TerminateExternalDatabaseRequest (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseRequest)1 TerminationEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationEvent)1