Search in sources :

Example 36 with DBStack

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());
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with DBStack

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());
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack)

Example 38 with DBStack

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());
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with DBStack

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());
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with DBStack

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());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) 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