Search in sources :

Example 6 with DatabaseServer

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

the class DBStackToDatabaseStackConverterTest method testConversionAwsWithAwsEncryptionResourcesPresent.

@Test
public void testConversionAwsWithAwsEncryptionResourcesPresent() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    dbStack.setCloudPlatform("AWS");
    dbStack.setParameters(new HashMap<>());
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCloudPlatform("AWS");
    environmentResponse.setAws(AwsEnvironmentParameters.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParameters.builder().withEncryptionKeyArn("value").build()).build());
    when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
    assertThat(parameters.get("key").toString()).isEqualTo("value");
    assertThat(parameters.size()).isEqualTo(3);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 7 with DatabaseServer

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

the class DBStackToDatabaseStackConverterTest method testConversionWithSslCertificateCloudProviderOwned.

@Test
void testConversionWithSslCertificateCloudProviderOwned() {
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    dbStack.setDatabaseServer(server);
    SslConfig sslConfig = new SslConfig();
    sslConfig.setSslCertificateType(SslCertificateType.CLOUD_PROVIDER_OWNED);
    dbStack.setSslConfig(sslConfig);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    assertThat(convertedStack.getDatabaseServer().isUseSslEnforcement()).isTrue();
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Test(org.junit.jupiter.api.Test)

Example 8 with DatabaseServer

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

the class RedbeamsCreationService method saveDbStack.

private DBStack saveDbStack(DBStack dbStack) {
    // possible future change is to use a flow here (GetPlatformTemplateRequest, modified for database server)
    // for now, just get it synchronously / within this thread, it ought to be quick
    CloudPlatformVariant platformVariant = new CloudPlatformVariant(dbStack.getCloudPlatform(), dbStack.getPlatformVariant());
    try {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(platformVariant);
        if (connector == null) {
            throw new RedbeamsException("Failed to find cloud connector for platform variant " + platformVariant);
        }
        String template = connector.resources().getDBStackTemplate();
        if (template == null) {
            throw new RedbeamsException("No database stack template is available for platform variant " + platformVariant);
        }
        dbStack.setTemplate(template);
    } catch (TemplatingNotSupportedException e) {
        throw new RedbeamsException("Failed to retrieve database stack template for cloud platform", e);
    }
    DatabaseServer databaseServer = dbStack.getDatabaseServer();
    if (databaseServer.getConnectionDriver() == null) {
        String connectionDriver = databaseServer.getDatabaseVendor().connectionDriver();
        databaseServer.setConnectionDriver(connectionDriver);
        LOGGER.info("Database server allocation request lacked a connection driver; defaulting to {}", connectionDriver);
    }
    return dbStackService.save(dbStack);
}
Also used : CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) TemplatingNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.TemplatingNotSupportedException) RedbeamsException(com.sequenceiq.redbeams.exception.RedbeamsException)

Example 9 with DatabaseServer

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

the class DBStackToDatabaseStackConverterTest method testConversionAzureWithSingleResourceGroups.

@Test
public void testConversionAzureWithSingleResourceGroups() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    dbStack.setCloudPlatform(CLOUD_PLATFORM);
    dbStack.setParameters(new HashMap<>());
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCloudPlatform(CLOUD_PLATFORM);
    environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName(RESOURCE_GROUP).build()).build());
    when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
    assertThat(parameters.get(RESOURCE_GROUP_NAME_PARAMETER).toString()).isEqualTo(RESOURCE_GROUP);
    assertThat(parameters.get(RESOURCE_GROUP_USAGE_PARAMETER).toString()).isEqualTo(ResourceGroupUsage.SINGLE.name());
    assertThat(parameters.size()).isEqualTo(4);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 10 with DatabaseServer

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

the class DBStackToDatabaseStackConverterTest method testConversionNormal.

@Test
public void testConversionNormal() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    DatabaseServer server = new DatabaseServer();
    server.setName("myserver");
    server.setInstanceType("db.m3.medium");
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setConnectionDriver("org.postgresql.Driver");
    server.setRootUserName("root");
    server.setRootPassword("cloudera");
    server.setStorageSize(50L);
    SecurityGroup securityGroup = new SecurityGroup();
    Set<String> securityGroupIds = new HashSet<>();
    securityGroupIds.add("sg-1234");
    securityGroup.setSecurityGroupIds(securityGroupIds);
    server.setSecurityGroup(securityGroup);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DatabaseStack convertedStack = underTest.convert(dbStack);
    assertThat(convertedStack.getNetwork().getParameters().size()).isEqualTo(1);
    assertThat(convertedStack.getNetwork().getParameters().get("foo")).isEqualTo("bar");
    assertThat(convertedStack.getDatabaseServer().getServerId()).isEqualTo("myserver");
    assertThat(convertedStack.getDatabaseServer().getFlavor()).isEqualTo("db.m3.medium");
    assertThat(convertedStack.getDatabaseServer().getEngine()).isEqualTo(DatabaseEngine.POSTGRESQL);
    assertThat(convertedStack.getDatabaseServer().getConnectionDriver()).isEqualTo("org.postgresql.Driver");
    assertThat(convertedStack.getDatabaseServer().getRootUserName()).isEqualTo("root");
    assertThat(convertedStack.getDatabaseServer().getRootPassword()).isEqualTo("cloudera");
    assertThat(convertedStack.getDatabaseServer().getStorageSize()).isEqualTo(50L);
    assertThat(convertedStack.getDatabaseServer().getSecurity().getCloudSecurityIds()).isEqualTo(List.of("sg-1234"));
    assertThat(convertedStack.getDatabaseServer().getStatus()).isEqualTo(CREATE_REQUESTED);
    assertThat(convertedStack.getDatabaseServer().getParameters().size()).isEqualTo(2);
    assertThat(convertedStack.getDatabaseServer().getParameters().get("this")).isEqualTo("that");
    assertThat(convertedStack.getTemplate()).isEqualTo("template");
    Map<String, String> tags = convertedStack.getTags();
    assertThat(tags.size()).isEqualTo(3);
    assertThat(tags.get("ukey1")).isEqualTo("uvalue1");
    assertThat(tags.get("dkey1")).isEqualTo("dvalue1");
    assertThat(tags.get("key1")).isEqualTo("value1");
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SecurityGroup(com.sequenceiq.redbeams.domain.stack.SecurityGroup) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)16 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)11 Test (org.junit.jupiter.api.Test)11 Json (com.sequenceiq.cloudbreak.common.json.Json)8 Network (com.sequenceiq.redbeams.domain.stack.Network)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)3 DatabaseVendor (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DatabaseVendor)1 TemplatingNotSupportedException (com.sequenceiq.cloudbreak.cloud.exception.TemplatingNotSupportedException)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)1 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 SecurityGroup (com.sequenceiq.redbeams.domain.stack.SecurityGroup)1 RedbeamsException (com.sequenceiq.redbeams.exception.RedbeamsException)1 HashSet (java.util.HashSet)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1