Search in sources :

Example 1 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class StartDatabaseServerFailedActionTest method shouldCreateRequest.

@Test
public void shouldCreateRequest() {
    RedbeamsEvent request = (RedbeamsEvent) victim.createRequest(null);
    assertEquals(RedbeamsStartEvent.REDBEAMS_START_FAILURE_HANDLED_EVENT.event(), request.selector());
}
Also used : RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) Test(org.junit.jupiter.api.Test)

Example 2 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class StopDatabaseServerActionTest method shouldUpdateStatusOnPrepare.

@Test
public void shouldUpdateStatusOnPrepare() {
    RedbeamsEvent event = new RedbeamsEvent(RESOURCE_ID);
    victim.prepareExecution(event, null);
    verify(dbStackStatusUpdater).updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOP_IN_PROGRESS);
}
Also used : RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) Test(org.junit.jupiter.api.Test)

Example 3 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsCreationServiceTest method testLaunchDatabaseServer.

@Test
public void testLaunchDatabaseServer() throws Exception {
    when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(connector);
    when(connector.resources().getDBStackTemplate()).thenReturn(TEMPLATE);
    Crn crn = Crn.fromString("crn:cdp:iam:us-west-1:1234:database:2312312");
    when(dbStackService.findByNameAndEnvironmentCrn(DB_STACK_NAME, ENVIRONMENT_CRN)).thenReturn(Optional.empty());
    when(dbStackService.save(dbStack)).thenReturn(dbStack);
    when(databaseServerConfigService.findByEnvironmentCrnAndClusterCrn(ENVIRONMENT_CRN, CLUSTER_CRN)).thenReturn(Optional.empty());
    DBStack launchedStack = underTest.launchDatabaseServer(dbStack, CLUSTER_CRN);
    assertThat(launchedStack).isEqualTo(dbStack);
    verify(dbStackService).save(dbStack);
    assertThat(dbStack.getResourceCrn()).isEqualTo(crn.toString());
    assertThat(dbStack.getTemplate()).isEqualTo(TEMPLATE);
    ArgumentCaptor<DatabaseServerConfig> databaseServerConfigCaptor = ArgumentCaptor.forClass(DatabaseServerConfig.class);
    verify(databaseServerConfigService).create(databaseServerConfigCaptor.capture(), eq(RedbeamsCreationService.DEFAULT_WORKSPACE), eq(false));
    DatabaseServerConfig databaseServerConfig = databaseServerConfigCaptor.getValue();
    assertThat(databaseServerConfig.getResourceStatus()).isEqualTo(ResourceStatus.SERVICE_MANAGED);
    assertThat(databaseServerConfig.getAccountId()).isEqualTo(ACCOUNT_ID);
    assertThat(databaseServerConfig.getName()).isEqualTo(DB_STACK_NAME);
    assertThat(databaseServerConfig.getDescription()).isEqualTo(DB_STACK_DESCRIPTION);
    assertThat(databaseServerConfig.getEnvironmentId()).isEqualTo(ENVIRONMENT_CRN);
    assertThat(databaseServerConfig.getConnectionDriver()).isEqualTo(CONNECTION_DRIVER);
    assertThat(databaseServerConfig.getConnectionUserName()).isEqualTo(ROOT_USER_NAME);
    assertThat(databaseServerConfig.getConnectionPassword()).isEqualTo(ROOT_PASSWORD);
    assertThat(databaseServerConfig.getDatabaseVendor()).isEqualTo(DatabaseVendor.POSTGRES);
    assertThat(databaseServerConfig.getHost()).isNull();
    assertThat(databaseServerConfig.getPort()).isNull();
    assertThat(databaseServerConfig.getResourceCrn()).isEqualTo(crn);
    assertThat(databaseServerConfig.getDbStack().isPresent()).isTrue();
    assertThat(databaseServerConfig.getDbStack().get()).isEqualTo(dbStack);
    ArgumentCaptor<RedbeamsEvent> eventCaptor = ArgumentCaptor.forClass(RedbeamsEvent.class);
    verify(flowManager).notify(eq(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector()), eventCaptor.capture());
    RedbeamsEvent provisionEvent = eventCaptor.getValue();
    assertThat(provisionEvent.selector()).isEqualTo(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector());
    assertThat(provisionEvent.getResourceId()).isEqualTo(dbStack.getId());
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Test(org.junit.jupiter.api.Test)

Example 4 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsTerminationServiceTest method verifyTermination.

private void verifyTermination(long id) {
    verify(dbStackStatusUpdater).updateStatus(id, DetailedDBStackStatus.DELETE_REQUESTED);
    ArgumentCaptor<RedbeamsEvent> eventCaptor = ArgumentCaptor.forClass(RedbeamsEvent.class);
    InOrder inOrder = Mockito.inOrder(cancelService, flowManager);
    inOrder.verify(cancelService).cancelRunningFlows(id);
    inOrder.verify(flowManager).notify(eq(RedbeamsTerminationEvent.REDBEAMS_TERMINATION_EVENT.selector()), eventCaptor.capture());
    RedbeamsEvent event = eventCaptor.getValue();
    assertEquals(id, event.getResourceId().longValue());
    assertTrue(event.isForced());
}
Also used : InOrder(org.mockito.InOrder) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Example 5 with RedbeamsEvent

use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.

the class RedbeamsCreationService method launchDatabaseServer.

public DBStack launchDatabaseServer(DBStack dbStack, String clusterCrn) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Create called with: {}", dbStack);
    }
    if (dbStackService.findByNameAndEnvironmentCrn(dbStack.getName(), dbStack.getEnvironmentId()).isPresent()) {
        throw new BadRequestException("A stack for this database server already exists in the environment");
    }
    Optional<DatabaseServerConfig> optionalDBServerConfig = databaseServerConfigService.findByEnvironmentCrnAndClusterCrn(dbStack.getEnvironmentId(), clusterCrn);
    DBStack savedDbStack;
    boolean startFlow = false;
    if (optionalDBServerConfig.isEmpty()) {
        LOGGER.debug("DataBaseServerConfig is not available by cluster crn '{}'", clusterCrn);
        savedDbStack = saveDbStackAndRegisterDatabaseServerConfig(dbStack, clusterCrn);
        startFlow = true;
    } else {
        DatabaseServerConfig dbServerConfig = optionalDBServerConfig.get();
        if (dbServerConfig.getDbStack().isEmpty()) {
            LOGGER.debug("DBStack is not available in DatabaseServerConfig '{}'", dbServerConfig.getResourceCrn());
            savedDbStack = saveDbStackInDatabaseServerConfig(dbServerConfig, dbStack);
            startFlow = true;
        } else {
            savedDbStack = dbServerConfig.getDbStack().get();
        }
    }
    if (startFlow) {
        flowManager.notify(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), savedDbStack.getId()));
    }
    return savedDbStack;
}
Also used : DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Aggregations

RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)17 Test (org.junit.jupiter.api.Test)8 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)6 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)2 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)2 RedbeamsContext (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext)2 Event (reactor.bus.Event)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)1 AbstractRedbeamsProvisionAction (com.sequenceiq.redbeams.flow.redbeams.provision.AbstractRedbeamsProvisionAction)1 RedbeamsStartContext (com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext)1 StartDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerFailed)1 StartDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest)1