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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations