Search in sources :

Example 1 with StartExternalDatabaseFailed

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

the class ExternalDatabaseStartActions method externalDatabaseStartFailureAction.

@Bean(name = "EXTERNAL_DATABASE_START_FAILED_STATE")
public Action<?, ?> externalDatabaseStartFailureAction() {
    return new AbstractExternalDatabaseStartAction<>(StartExternalDatabaseFailed.class) {

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

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

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

Example 2 with StartExternalDatabaseFailed

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

the class StartExternalDatabaseHandlerTest 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(startService).startDatabase(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);
    StartExternalDatabaseRequest request = new StartExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn");
    Event<StartExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
    underTest.accept(event);
    verify(startService).startDatabase(eq(stack.getCluster()), eq(DatabaseAvailabilityType.HA), eq(environment));
    verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED), eq("External database start in progress"));
    verify(stackUpdaterService, never()).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED), anyString());
    ArgumentCaptor<Event<StartExternalDatabaseFailed>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(eq("StartExternalDatabaseFailed"), eventCaptor.capture());
    Event<StartExternalDatabaseFailed> value = eventCaptor.getValue();
    assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
    assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) StartExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseFailed) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) 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)

Example 3 with StartExternalDatabaseFailed

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

the class ExternalDatabaseStartActionsTest method externalDatabaseCreationFailureAction.

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

Aggregations

StartExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseFailed)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 AbstractExternalDatabaseStartAction (com.sequenceiq.cloudbreak.core.flow2.externaldatabase.start.action.AbstractExternalDatabaseStartAction)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 StartExternalDatabaseRequest (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest)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