Search in sources :

Example 6 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class UpdateDatabaseServerRegistrationHandlerTest method doAcceptTestWhenFailureSslCertificateSyncError.

@Test
void doAcceptTestWhenFailureSslCertificateSyncError() throws Exception {
    DBStack dbStack = getDBStack();
    dbStack.setCloudPlatform(CloudPlatform.AZURE.toString());
    when(dbStackService.getById(anyLong())).thenReturn(dbStack);
    addDatabaseServerToDBStack(dbStack);
    setupMocksMinimal();
    when(userGeneratorService.updateUserName(ROOT_USER_NAME, Optional.of(CloudPlatform.AZURE), DB_HOST_NAME)).thenReturn(ROOT_USER_NAME + "@" + DB_SHORT_HOST_NAME);
    Exception e = new Exception();
    doThrow(e).when(databaseServerSslCertificateSyncService).syncSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
    Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
    verifyFailureEvent(e, selectable);
    verify(databaseServerConfigService).update(databaseServerConfigCaptor.capture());
    DatabaseServerConfig databaseServerConfig = databaseServerConfigCaptor.getValue();
    assertThat(databaseServerConfig.getHost()).isEqualTo(DB_HOST_NAME);
    assertThat(databaseServerConfig.getPort().intValue()).isEqualTo(PORT);
    assertThat(databaseServerConfig.getConnectionUserName()).isEqualTo(ROOT_USER_NAME + "@" + DB_SHORT_HOST_NAME);
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) Test(org.junit.jupiter.api.Test)

Example 7 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class UpdateDatabaseServerRegistrationHandlerTest method doAcceptTestWhenSuccess.

@Test
void doAcceptTestWhenSuccess() throws Exception {
    DBStack dbStack = getDBStack();
    dbStack.setCloudPlatform(CloudPlatform.AZURE.toString());
    when(dbStackService.getById(anyLong())).thenReturn(dbStack);
    addDatabaseServerToDBStack(dbStack);
    setupMocksMinimal();
    when(userGeneratorService.updateUserName(ROOT_USER_NAME, Optional.of(CloudPlatform.AZURE), DB_HOST_NAME)).thenReturn(ROOT_USER_NAME + "@" + DB_SHORT_HOST_NAME);
    Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
    assertThat(selectable).isInstanceOf(UpdateDatabaseServerRegistrationSuccess.class);
    UpdateDatabaseServerRegistrationSuccess updateDatabaseServerRegistrationSuccess = (UpdateDatabaseServerRegistrationSuccess) selectable;
    assertThat(updateDatabaseServerRegistrationSuccess.getResourceId()).isEqualTo(RESOURCE_ID);
    verify(databaseServerConfigService).update(databaseServerConfigCaptor.capture());
    DatabaseServerConfig databaseServerConfig = databaseServerConfigCaptor.getValue();
    assertThat(databaseServerConfig.getHost()).isEqualTo(DB_HOST_NAME);
    assertThat(databaseServerConfig.getPort().intValue()).isEqualTo(PORT);
    assertThat(databaseServerConfig.getConnectionUserName()).isEqualTo(ROOT_USER_NAME + "@" + DB_SHORT_HOST_NAME);
    verify(databaseServerSslCertificateSyncService).syncSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) UpdateDatabaseServerRegistrationSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationSuccess) Test(org.junit.jupiter.api.Test)

Example 8 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class StopDatabaseServerFailedActionTest method shouldUpdateStatusAndIncrementMetricOnPrepare.

@Test
public void shouldUpdateStatusAndIncrementMetricOnPrepare() {
    RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, exception);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOP_FAILED, null)).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_STOP_FAILED, dbStackOptional);
}
Also used : RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Example 9 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class StopDatabaseServerFinishedActionTest method shouldUpdateStatusOnPrepare.

@Test
public void shouldUpdateStatusOnPrepare() {
    StopDatabaseServerSuccess event = new StopDatabaseServerSuccess(RESOURCE_ID);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOPPED)).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_STOP_FINISHED, dbStackOptional);
}
Also used : StopDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerSuccess) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Example 10 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificateSyncServiceTest method syncSslCertificateIfNeededTestWhenFailureSslAwsCloudProviderOwnedMismatchingActiveSslRootCertificateInvalidCertificateEntryBlankPem.

@Test
void syncSslCertificateIfNeededTestWhenFailureSslAwsCloudProviderOwnedMismatchingActiveSslRootCertificateInvalidCertificateEntryBlankPem() throws Exception {
    DBStack dbStack = getDBStack(createSslConfig(SslCertificateType.CLOUD_PROVIDER_OWNED, CERT_ID_1));
    dbStack.setCloudPlatform(CloudPlatform.AWS.name());
    setupCloudConnectorMock();
    when(resourceConnector.getDatabaseServerActiveSslRootCertificate(authenticatedContext, databaseStack)).thenReturn(new CloudDatabaseServerSslCertificate(CloudDatabaseServerSslCertificateType.ROOT, CERT_ID_2));
    SslCertificateEntry cert = new SslCertificateEntry(CERT_VERSION, CERT_ID_2, "", x509Cert);
    when(databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndCloudProviderIdentifier(CloudPlatform.AWS.name(), REGION, CERT_ID_2)).thenReturn(cert);
    IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, () -> underTest.syncSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack));
    assertThat(illegalStateException).hasMessage(String.format("Blank PEM in SSL certificate with CloudProviderIdentifier \"%s\" for cloud platform \"%s\"", CERT_ID_2, CloudPlatform.AWS.name()));
    verify(dbStackService, never()).save(any(DBStack.class));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) SslCertificateEntry(com.sequenceiq.redbeams.configuration.SslCertificateEntry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)83 Test (org.junit.jupiter.api.Test)28 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 Test (org.junit.Test)13 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)7 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)7 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)6 Credential (com.sequenceiq.redbeams.dto.Credential)6 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)6 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)5 CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)5 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Location (com.sequenceiq.cloudbreak.cloud.model.Location)4