Search in sources :

Example 1 with StartExternalDatabaseResult

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

the class StartExternalDatabaseHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StartExternalDatabaseRequest> event) {
    LOGGER.debug("In StartExternalDatabaseHandler.doAccept");
    StartExternalDatabaseRequest request = event.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Selectable result;
    try {
        if (StackType.WORKLOAD != stack.getType()) {
            LOGGER.debug("External database start in Cloudbreak service is required for WORKLOAD stacks only.");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Start is not possible.", stack.getName());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
            LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED, "External database start in progress");
            startService.startDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED, "External database start finished");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.error("Database 'start' polling exited before timeout. Cause: ", e);
        result = startFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.error(String.format("Database 'start' poller stopped for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.error(String.format("Database 'start' polling failed for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    }
    return result;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 2 with StartExternalDatabaseResult

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

the class StartExternalDatabaseHandlerTest method acceptHappyPath.

@Test
void acceptHappyPath() {
    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).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED), eq("External database start finished"));
    ArgumentCaptor<Event<StartExternalDatabaseResult>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(eq("StartExternalDatabaseResult"), eventCaptor.capture());
    Event<StartExternalDatabaseResult> value = eventCaptor.getValue();
    assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
    assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
Also used : StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with StartExternalDatabaseResult

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

the class ExternalDatabaseStartActionsTest method externalDatabaseStartFinishedAction.

@Test
void externalDatabaseStartFinishedAction() {
    StartExternalDatabaseResult startExternalDatabaseResultPayload = new StartExternalDatabaseResult(STACK_ID, EXTERNAL_DATABASE_STARTED_EVENT.event(), STACK_NAME, STACK_CRN);
    when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(startExternalDatabaseResultPayload);
    Action<?, ?> action = configureAction(underTest::externalDatabaseStartFinishedAction);
    action.execute(stateContext);
    verifyNoMoreInteractions(stackUpdaterService);
    verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
    verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
    verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_START_SUCCESSFUL, STACK);
    assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_START_FINALIZED_EVENT");
    Object capturedPayload = payloadArgumentCaptor.getValue();
    assertThat(capturedPayload).isInstanceOf(StackEvent.class);
    StackEvent stackEvent = (StackEvent) capturedPayload;
    assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID);
}
Also used : StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) Test(org.junit.jupiter.api.Test)

Aggregations

StartExternalDatabaseResult (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 StartExternalDatabaseRequest (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 Test (org.junit.jupiter.api.Test)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Event (reactor.bus.Event)1