Search in sources :

Example 1 with RedbeamsFailureEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent in project cloudbreak by hortonworks.

the class StopDatabaseServerFailedActionTest method shouldUpdateStatusAndIncrementMetricOnPrepare.

@Test
public void shouldUpdateStatusAndIncrementMetricOnPrepare() {
    RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, exception);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOP_FAILED, null)).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_STOP_FAILED, dbStackOptional);
}
Also used : RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Example 2 with RedbeamsFailureEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent in project cloudbreak by hortonworks.

the class RedbeamsProvisionActions method provisionFailed.

@Bean(name = "REDBEAMS_PROVISION_FAILED_STATE")
public Action<?, ?> provisionFailed() {
    return new AbstractRedbeamsProvisionAction<>(RedbeamsFailureEvent.class) {

        // A lot here - some of this could go into some sort of failure handler class
        // compare to core StackCreationService::handleStackCreationFailure
        @Override
        protected void prepareExecution(RedbeamsFailureEvent payload, Map<Object, Object> variables) {
            Exception failureException = payload.getException();
            LOGGER.info("Error during database stack creation 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.PROVISION_FAILED, errorReason);
                metricService.incrementMetricCounter(MetricType.DB_PROVISION_FAILED, dbStack);
            }
        }

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

        @Override
        protected Selectable createRequest(RedbeamsContext context) {
            return new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_FAILURE_HANDLED_EVENT.event(), 0L);
        }
    };
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) StateContext(org.springframework.statemachine.StateContext) AbstractRedbeamsProvisionAction(com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Flow(com.sequenceiq.flow.core.Flow) RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) Map(java.util.Map) RedbeamsContext(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext) Bean(org.springframework.context.annotation.Bean)

Example 3 with RedbeamsFailureEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent 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 4 with RedbeamsFailureEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent in project cloudbreak by hortonworks.

the class StartDatabaseServerFailedActionTest method shouldUpdateStatusWithUknownErrorAndIncrementMetricOnPrepare.

@Test
public void shouldUpdateStatusWithUknownErrorAndIncrementMetricOnPrepare() {
    RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, null);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.START_FAILED, "Unknown error")).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_START_FAILED, dbStackOptional);
}
Also used : RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Example 5 with RedbeamsFailureEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent in project cloudbreak by hortonworks.

the class StartDatabaseServerFailedActionTest method shouldUpdateStatusAndIncrementMetricOnPrepare.

@Test
public void shouldUpdateStatusAndIncrementMetricOnPrepare() {
    RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, exception);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.START_FAILED, null)).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_START_FAILED, dbStackOptional);
}
Also used : RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Aggregations

DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)6 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)6 Test (org.junit.jupiter.api.Test)4 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)2 Flow (com.sequenceiq.flow.core.Flow)2 FlowParameters (com.sequenceiq.flow.core.FlowParameters)2 RedbeamsContext (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext)2 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 StateContext (org.springframework.statemachine.StateContext)2 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)1 AbstractRedbeamsProvisionAction (com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction)1 AbstractRedbeamsTerminationAction (com.sequenceiq.redbeams.flow.redbeams.termination.AbstractRedbeamsTerminationAction)1 Optional (java.util.Optional)1