Search in sources :

Example 1 with TerminateExternalDatabaseFailed

use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseFailed 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 2 with TerminateExternalDatabaseFailed

use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseFailed in project cloudbreak by hortonworks.

the class ExternalDatabaseTerminationActionsTest method externalDatabaseCreationFailureAction.

@Test
void externalDatabaseCreationFailureAction() {
    RuntimeException expectedException = new RuntimeException(MESSAGE);
    TerminateExternalDatabaseFailed terminateExternalDatabaseFailedPayload = new TerminateExternalDatabaseFailed(STACK_ID, EXTERNAL_DATABASE_CREATION_FAILED_EVENT.event(), STACK_NAME, null, expectedException);
    when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK);
    when(runningFlows.get(anyString())).thenReturn(flow);
    when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(terminateExternalDatabaseFailedPayload);
    Action<?, ?> action = configureAction(underTest::externalDatabaseTerminationFailureAction);
    action.execute(stateContext);
    verify(stackUpdaterService).updateStatus(STACK_ID, DetailedStackStatus.DELETE_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FAILED, MESSAGE);
    verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
    verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
    verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_TERMINATION_FAILED, STACK);
    verify(flow).setFlowFailed(exceptionCaptor.capture());
    assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_TERMINATION_FAILURE_HANDLED_EVENT");
    Object capturedPayload = payloadArgumentCaptor.getValue();
    assertThat(capturedPayload).isInstanceOf(StackEvent.class);
    StackEvent stackEvent = (StackEvent) capturedPayload;
    assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID);
    Exception exception = exceptionCaptor.getValue();
    assertThat(exception).isEqualTo(expectedException);
}
Also used : StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) TerminateExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseFailed) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)2 TerminateExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseFailed)2 ExternalDatabaseContext (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext)1 AbstractExternalDatabaseTerminationAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.action.AbstractExternalDatabaseTerminationAction)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1