use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AllocateDatabaseServerV4RequestToDBStackConverterTest method conversionTestWhenOptionalElementsAreProvided.
@Test
void conversionTestWhenOptionalElementsAreProvided() throws IOException {
setupAllocateRequest(true);
when(databaseServerSslCertificateConfig.getNumberOfCertsByCloudPlatformAndRegion(AWS_CLOUD_PLATFORM.name(), REGION)).thenReturn(SINGLE_CERT);
when(databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndVersion(AWS_CLOUD_PLATFORM.name(), REGION, VERSION_3)).thenReturn(sslCertificateEntryV3);
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withCloudPlatform(AWS_CLOUD_PLATFORM.name()).withCrn(ENVIRONMENT_CRN).withLocation(LocationResponse.LocationResponseBuilder.aLocationResponse().withName(REGION).build()).withName(ENVIRONMENT_NAME).withTag(new TagResponse()).build();
when(environmentService.getByCrn(ENVIRONMENT_CRN)).thenReturn(environment);
DBStack dbStack = underTest.convert(allocateRequest, OWNER_CRN);
assertEquals(allocateRequest.getName(), dbStack.getName());
assertEquals(allocateRequest.getEnvironmentCrn(), dbStack.getEnvironmentId());
assertEquals(REGION, dbStack.getRegion());
assertEquals(AWS_CLOUD_PLATFORM.name(), dbStack.getCloudPlatform());
assertEquals(AWS_CLOUD_PLATFORM.name(), dbStack.getPlatformVariant());
assertEquals(1, dbStack.getParameters().size());
assertEquals("value", dbStack.getParameters().get("key"));
assertEquals(Crn.safeFromString(OWNER_CRN), dbStack.getOwnerCrn());
assertEquals(USER_EMAIL, dbStack.getUserName());
assertEquals(Status.REQUESTED, dbStack.getStatus());
assertEquals(DetailedDBStackStatus.PROVISION_REQUESTED, dbStack.getDbStackStatus().getDetailedDBStackStatus());
assertEquals(NOW.toEpochMilli(), dbStack.getDbStackStatus().getCreated().longValue());
assertEquals("n-uuid", dbStack.getNetwork().getName());
assertEquals(1, dbStack.getNetwork().getAttributes().getMap().size());
assertEquals("netvalue", dbStack.getNetwork().getAttributes().getMap().get("netkey"));
assertEquals("dbsvr-uuid", dbStack.getDatabaseServer().getName());
assertEquals(databaseServerRequest.getInstanceType(), dbStack.getDatabaseServer().getInstanceType());
assertEquals(DatabaseVendor.fromValue(databaseServerRequest.getDatabaseVendor()), dbStack.getDatabaseServer().getDatabaseVendor());
assertEquals("org.postgresql.Driver", dbStack.getDatabaseServer().getConnectionDriver());
assertEquals(databaseServerRequest.getStorageSize(), dbStack.getDatabaseServer().getStorageSize());
assertEquals(databaseServerRequest.getRootUserName(), dbStack.getDatabaseServer().getRootUserName());
assertEquals(databaseServerRequest.getRootUserPassword(), dbStack.getDatabaseServer().getRootPassword());
assertEquals(2, dbStack.getDatabaseServer().getAttributes().getMap().size());
assertEquals("dbvalue", dbStack.getDatabaseServer().getAttributes().getMap().get("dbkey"));
assertEquals(REDBEAMS_DB_MAJOR_VERSION, dbStack.getDatabaseServer().getAttributes().getMap().get("engineVersion"));
assertEquals(securityGroupRequest.getSecurityGroupIds(), dbStack.getDatabaseServer().getSecurityGroup().getSecurityGroupIds());
assertEquals(dbStack.getTags().get(StackTags.class).getUserDefinedTags().get("DistroXKey1"), "DistroXValue1");
verifySsl(dbStack, Set.of(CERT_PEM_V3), CLOUD_PROVIDER_IDENTIFIER_V3);
verify(databaseServerSslCertificateConfig, never()).getCertsByCloudPlatformAndRegionAndVersions(anyString(), anyString(), any());
verify(providerParameterCalculator).get(allocateRequest);
verify(providerParameterCalculator).get(networkRequest);
verify(subnetListerService, never()).listSubnets(any(), any());
verify(subnetChooserService, never()).chooseSubnets(anyList(), any(), any());
verify(networkParameterAdder, never()).addSubnetIds(any(), any(), any(), any());
verify(userGeneratorService, never()).generateUserName();
verify(passwordGeneratorService, never()).generatePassword(any());
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AllocateDatabaseServerV4RequestToDBStackConverterTest method conversionTestWhenSslEnabledAndTwoCertsReturnedInternal.
private void conversionTestWhenSslEnabledAndTwoCertsReturnedInternal(String cloudPlatform, int numOfCerts) {
when(databaseServerSslCertificateConfig.getNumberOfCertsByCloudPlatformAndRegion(cloudPlatform, REGION)).thenReturn(numOfCerts);
when(databaseServerSslCertificateConfig.getCertsByCloudPlatformAndRegionAndVersions(cloudPlatform, REGION, VERSION_2, VERSION_3)).thenReturn(Set.of(sslCertificateEntryV2, sslCertificateEntryV3));
DBStack dbStack = underTest.convert(allocateRequest, OWNER_CRN);
verifySsl(dbStack, Set.of(CERT_PEM_V2, CERT_PEM_V3), CLOUD_PROVIDER_IDENTIFIER_V3);
verify(databaseServerSslCertificateConfig, never()).getCertByCloudPlatformAndRegionAndVersion(anyString(), anyString(), anyInt());
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeNone.
@Test
void testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeNone() {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
DBStack dbStack = new DBStack();
dbStack.setSslConfig(new SslConfig());
initDBStackStatus(dbStack);
server.setDbStack(dbStack);
DatabaseServerV4Response response = converter.convert(server);
assertThat(response).isNotNull();
SslConfigV4Response sslConfigV4Response = response.getSslConfig();
assertThat(sslConfigV4Response).isNotNull();
assertThat(sslConfigV4Response.getSslMode()).isEqualTo(SslMode.DISABLED);
assertThat(sslConfigV4Response.getSslCertificateType()).isEqualTo(SslCertificateType.NONE);
assertThat(response.getStatus()).isEqualTo(dbStack.getStatus());
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentButSslConfigAbsent.
@Test
void testConversionOfSslConfigWhenDbStackPresentButSslConfigAbsent() {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
DBStack dbStack = new DBStack();
initDBStackStatus(dbStack);
server.setDbStack(dbStack);
DatabaseServerV4Response response = converter.convert(server);
assertThat(response).isNotNull();
assertThat(response.getSslConfig()).isNotNull();
assertThat(response.getSslConfig().getSslMode()).isEqualTo(SslMode.DISABLED);
assertThat(response.getStatus()).isEqualTo(dbStack.getStatus());
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversion.
@Test
public void testConversion() {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setId(1L);
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setName(RESOURCE_ID);
server.setDescription("mine not yours");
server.setHost(HOST);
server.setPort(PORT);
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
initializeSecrets(server);
server.setCreationDate(System.currentTimeMillis());
server.setEnvironmentId(ENVIRONMENT_ID);
server.setClusterCrn("myclustercrn");
server.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
DBStack dbStack = new DBStack();
initDBStackStatus(dbStack);
server.setDbStack(dbStack);
when(stringToSecretResponseConverter.convert(anyString())).thenReturn(new SecretResponse());
DatabaseServerV4Response response = converter.convert(server);
verify(stringToSecretResponseConverter, times(2)).convert(anyString());
assertThat(response).isNotNull();
assertThat(response.getId()).isEqualTo(server.getId());
assertThat(response.getCrn()).isEqualTo(server.getResourceCrn().toString());
assertThat(response.getName()).isEqualTo(server.getName());
assertThat(response.getDescription()).isEqualTo(server.getDescription());
assertThat(response.getHost()).isEqualTo(server.getHost());
assertThat(response.getPort()).isEqualTo(server.getPort());
assertThat(response.getDatabaseVendor()).isEqualTo(server.getDatabaseVendor().databaseType());
assertThat(response.getDatabaseVendorDisplayName()).isEqualTo(server.getDatabaseVendor().displayName());
assertThat(response.getConnectionUserName()).isNotNull();
assertThat(response.getConnectionPassword()).isNotNull();
assertThat(response.getCreationDate()).isEqualTo(server.getCreationDate());
assertThat(response.getEnvironmentCrn()).isEqualTo(server.getEnvironmentId());
assertThat(response.getClusterCrn()).isEqualTo(server.getClusterCrn());
assertThat(response.getResourceStatus()).isEqualTo(server.getResourceStatus());
assertThat(response.getStatus()).isEqualTo(dbStack.getStatus());
assertThat(response.getStatusReason()).isEqualTo(dbStack.getStatusReason());
}
Aggregations