Search in sources :

Example 31 with Flow

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

the class RedbeamsTerminationActions method failedAction.

@Bean(name = "REDBEAMS_TERMINATION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractRedbeamsTerminationAction<>(RedbeamsFailureEvent.class, false) {

        // A lot here - some of this could go into some sort of failure handler class
        // compare to core StackCreationService::handleStackCreationFailure
        @Override
        protected void doExecute(RedbeamsContext context, RedbeamsFailureEvent payload, Map<Object, Object> variables) {
            Exception failureException = payload.getException();
            LOGGER.info("Error during database stack termination flow:", failureException);
            if (failureException instanceof CancellationException || ExceptionUtils.getRootCause(failureException) instanceof CancellationException) {
                LOGGER.debug("The flow has been cancelled");
            } else {
                // StackCreationActions / StackCreationService only update status if stack isn't mid-deletion
                String errorReason = failureException == null ? "Unknown error" : failureException.getMessage();
                Optional<DBStack> dbStack = dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.DELETE_FAILED, errorReason);
                metricService.incrementMetricCounter(MetricType.DB_TERMINATION_FAILED, dbStack);
            }
            sendEvent(context, REDBEAMS_TERMINATION_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, RedbeamsFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected Object getFailurePayload(RedbeamsFailureEvent payload, Optional<RedbeamsContext> flowContext, Exception ex) {
            return payload;
        }
    };
}
Also used : Optional(java.util.Optional) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) StateContext(org.springframework.statemachine.StateContext) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Flow(com.sequenceiq.flow.core.Flow) AbstractRedbeamsTerminationAction(com.sequenceiq.redbeams.flow.redbeams.termination.AbstractRedbeamsTerminationAction) RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) RedbeamsContext(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 32 with Flow

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

the class ChangePrimaryGatewayActions method failureAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_FAIL_STATE")
public Action<?, ?> failureAction() {
    return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewayFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected ChangePrimaryGatewayContext createFlowContext(FlowParameters flowParameters, StateContext<ChangePrimaryGatewayState, ChangePrimaryGatewayFlowEvent> stateContext, ChangePrimaryGatewayFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewayFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Change primary gateway failed with payload: " + payload);
            Stack stack = context.getStack();
            String environmentCrn = stack.getEnvironmentCrn();
            SuccessDetails successDetails = new SuccessDetails(environmentCrn);
            successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
            String message = "Change primary gateway failed during " + payload.getFailedPhase();
            FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
            if (payload.getFailureDetails() != null) {
                failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
            }
            String errorReason = getErrorReason(payload.getException());
            stackUpdater.updateStackStatus(context.getStack().getId(), DetailedStackStatus.REPAIR_FAILED, errorReason);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            LOGGER.info("Enabling the status checker for stack ID {} after failing repairing", stack.getId());
            enableStatusChecker(stack, "Failed to repair FreeIPA");
            enableNodeStatusChecker(stack, "Failed to repair FreeIPA");
            sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<ChangePrimaryGatewayFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter());
            payloadConverters.add(new HealthCheckFailedToChangePrimaryGatewayFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) HealthCheckFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.HealthCheckFailedToChangePrimaryGatewayFailureEventConverter) StateContext(org.springframework.statemachine.StateContext) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.freeipa.entity.Stack) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) ArrayList(java.util.ArrayList) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 33 with Flow

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

the class StartDatabaseServerFailedAction method createFlowContext.

@Override
protected RedbeamsStartContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStartState, RedbeamsStartEvent> stateContext, RedbeamsFailureEvent payload) {
    Flow flow = getFlow(flowParameters.getFlowId());
    flow.setFlowFailed(payload.getException());
    return super.createFlowContext(flowParameters, stateContext, payload);
}
Also used : Flow(com.sequenceiq.flow.core.Flow)

Example 34 with Flow

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

the class StopDatabaseServerFailedAction method createFlowContext.

@Override
protected RedbeamsStopContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStopState, RedbeamsStopEvent> stateContext, RedbeamsFailureEvent payload) {
    Flow flow = getFlow(flowParameters.getFlowId());
    flow.setFlowFailed(payload.getException());
    return super.createFlowContext(flowParameters, stateContext, payload);
}
Also used : Flow(com.sequenceiq.flow.core.Flow)

Example 35 with Flow

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

the class StackProvisionActions method stackCreationFailureAction.

@Bean(name = "STACK_CREATION_FAILED_STATE")
public Action<?, ?> stackCreationFailureAction() {
    return new AbstractStackFailureAction<StackProvisionState, StackProvisionEvent>() {

        @Override
        protected StackFailureContext createFlowContext(FlowParameters flowParameters, StateContext<StackProvisionState, StackProvisionEvent> stateContext, StackFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            Stack stack = stackService.getStackById(payload.getResourceId());
            MDCBuilder.buildMdcContext(stack);
            flow.setFlowFailed(payload.getException());
            return new StackFailureContext(flowParameters, stack);
        }

        @Override
        protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) {
            stackProvisionService.handleStackCreationFailure(context.getStack(), payload.getException());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackFailureContext context) {
            return new StackEvent(StackProvisionEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractStackFailureAction(com.sequenceiq.freeipa.flow.stack.AbstractStackFailureAction) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) StateContext(org.springframework.statemachine.StateContext) StackFailureContext(com.sequenceiq.freeipa.flow.stack.StackFailureContext) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

Flow (com.sequenceiq.flow.core.Flow)37 Map (java.util.Map)30 Bean (org.springframework.context.annotation.Bean)30 FlowParameters (com.sequenceiq.flow.core.FlowParameters)28 StateContext (org.springframework.statemachine.StateContext)28 Optional (java.util.Optional)12 SdxContext (com.sequenceiq.datalake.flow.SdxContext)8 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)8 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)7 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 ExternalDatabaseContext (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext)4 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 List (java.util.List)4 AbstractStackFailureAction (com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction)3 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)3 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)2