Search in sources :

Example 1 with StopExternalDatabaseFailed

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

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

the class ExternalDatabaseStopActionsTest method externalDatabaseCreationFailureAction.

@Test
void externalDatabaseCreationFailureAction() {
    RuntimeException expectedException = new RuntimeException(MESSAGE);
    StopExternalDatabaseFailed stopExternalDatabaseFailedPayload = new StopExternalDatabaseFailed(STACK_ID, EXTERNAL_DATABASE_STOP_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(stopExternalDatabaseFailedPayload);
    Action<?, ?> action = configureAction(underTest::externalDatabaseStopFailureAction);
    action.execute(stateContext);
    verify(stackUpdaterService).updateStatus(STACK_ID, DetailedStackStatus.EXTERNAL_DATABASE_STOP_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FAILED, MESSAGE);
    verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
    verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
    verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_STOP_FAILED, STACK);
    verify(flow).setFlowFailed(exceptionCaptor.capture());
    assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_STOP_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 : StopExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Test(org.junit.jupiter.api.Test)

Example 3 with StopExternalDatabaseFailed

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

the class StopExternalDatabaseHandlerTest method acceptCatchErrors.

@ParameterizedTest
@ValueSource(classes = { UserBreakException.class, PollerStoppedException.class, PollerException.class, Exception.class })
@MockitoSettings(strictness = Strictness.LENIENT)
void acceptCatchErrors(Class<? extends Exception> exceptionClass) {
    doAnswer(a -> {
        throw exceptionClass.getDeclaredConstructor().newInstance();
    }).when(stopService).stopDatabase(any(), any(DatabaseAvailabilityType.class), any());
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("AWS");
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    when(externalDatabaseConfig.isExternalDatabasePauseSupportedFor(any())).thenReturn(true);
    Stack stack = buildStack(DatabaseAvailabilityType.HA);
    stack.setType(StackType.WORKLOAD);
    stack.getCluster().setDatabaseServerCrn(DATABASE_CRN);
    when(stackService.getById(anyLong())).thenReturn(stack);
    StopExternalDatabaseRequest request = new StopExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn");
    Event<StopExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
    underTest.accept(event);
    verify(stopService).stopDatabase(eq(stack.getCluster()), eq(DatabaseAvailabilityType.HA), eq(environment));
    verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED), eq("External database stop in progress"));
    verify(stackUpdaterService, never()).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED), anyString());
    ArgumentCaptor<Event<StopExternalDatabaseFailed>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(eq("StopExternalDatabaseFailed"), eventCaptor.capture());
    Event<StopExternalDatabaseFailed> value = eventCaptor.getValue();
    assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
    assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
Also used : StopExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) StopExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings)

Aggregations

StopExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed)3 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)2 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)1 ExternalDatabaseContext (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext)1 AbstractExternalDatabaseStopAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.stop.action.AbstractExternalDatabaseStopAction)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 StopExternalDatabaseRequest (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)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 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 MockitoSettings (org.mockito.junit.jupiter.MockitoSettings)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1 Event (reactor.bus.Event)1