Search in sources :

Example 1 with StopExternalDatabaseRequest

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

the class StopExternalDatabaseHandlerTest 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);
    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).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FINISHED), eq("External database stop finished"));
    ArgumentCaptor<Event<StopExternalDatabaseResult>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(eq("StopExternalDatabaseResult"), eventCaptor.capture());
    Event<StopExternalDatabaseResult> 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) StopExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseResult) StopExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with StopExternalDatabaseRequest

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

the class StopExternalDatabaseHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StopExternalDatabaseRequest> event) {
    LOGGER.debug("In StopExternalDatabaseHandler.doAccept");
    StopExternalDatabaseRequest 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 stop in Cloudbreak service is required for WORKLOAD stacks only.");
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
        } else if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Stop is not possible.", stack.getName());
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_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 StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED, "External database stop in progress");
            stopService.stopDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FINISHED, "External database stop finished");
            result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.error("Database 'stop' polling exited before timeout. Cause: ", e);
        result = stopFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.error(String.format("Database 'stop' poller stopped for stack: %s", stack.getName()), e);
        result = stopFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.error(String.format("Database 'stop' polling failed for stack: %s", stack.getName()), e);
        result = stopFailedEvent(stack, e);
    }
    return result;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StopExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseResult) StopExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 3 with StopExternalDatabaseRequest

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

the class StopExternalDatabaseHandlerTest method acceptNonDatahub.

@Test
void acceptNonDatahub() {
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("AWS");
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    Stack stack = buildStack(DatabaseAvailabilityType.HA);
    stack.setType(StackType.DATALAKE);
    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, never()).stopDatabase(any(), any(), eq(environment));
    verify(stackUpdaterService, never()).updateStatus(any(), any(), any(), any());
    verify(eventBus).notify(eq("StopExternalDatabaseResult"), any(Event.class));
}
Also used : 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with StopExternalDatabaseRequest

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

the class StopExternalDatabaseHandlerTest method acceptNotSupportedCloudProvider.

@Test
void acceptNotSupportedCloudProvider() {
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("AWS");
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    when(externalDatabaseConfig.isExternalDatabasePauseSupportedFor(any())).thenReturn(false);
    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, never()).stopDatabase(any(), any(), eq(environment));
    verify(stackUpdaterService, never()).updateStatus(any(), any(), any(), any());
    verify(eventBus).notify(eq("StopExternalDatabaseResult"), any(Event.class));
}
Also used : 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with StopExternalDatabaseRequest

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

the class StopExternalDatabaseHandlerTest method acceptDbNone.

@Test
void acceptDbNone() {
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("AWS");
    when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
    Stack stack = buildStack(DatabaseAvailabilityType.NONE);
    stack.setType(StackType.WORKLOAD);
    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, never()).stopDatabase(any(), any(), eq(environment));
    verify(stackUpdaterService, never()).updateStatus(any(), any(), any(), any());
    verify(eventBus).notify(eq("StopExternalDatabaseResult"), any(Event.class));
}
Also used : 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 StopExternalDatabaseRequest (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest)6 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Event (reactor.bus.Event)5 Test (org.junit.jupiter.api.Test)4 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)2 StopExternalDatabaseResult (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseResult)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 StopExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 MockitoSettings (org.mockito.junit.jupiter.MockitoSettings)1