Search in sources :

Example 36 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack 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 37 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverterTest method testConversionEmpty.

@Test
public void testConversionEmpty() {
    dbStack.setNetwork(null);
    dbStack.setDatabaseServer(null);
    dbStack.setTags(null);
    dbStack.setParameters(null);
    dbStack.setTemplate(null);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    assertThat(convertedStack.getNetwork()).isNull();
    assertThat(convertedStack.getDatabaseServer()).isNull();
    assertThat(convertedStack.getTemplate()).isNull();
    assertThat(convertedStack.getTags().size()).isEqualTo(0);
}
Also used : DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) Test(org.junit.jupiter.api.Test)

Example 38 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack 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)

Example 39 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverterTest method testConversionWithNullSslConfig.

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

Example 40 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverterTest method testConversionWithSslCertificateNone.

@Test
void testConversionWithSslCertificateNone() {
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    dbStack.setDatabaseServer(server);
    dbStack.setSslConfig(new SslConfig());
    DatabaseStack convertedStack = underTest.convert(dbStack);
    assertThat(convertedStack.getDatabaseServer().isUseSslEnforcement()).isFalse();
}
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)

Aggregations

DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)48 Test (org.junit.jupiter.api.Test)34 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)24 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)24 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)22 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)16 InstancesListResponse (com.google.api.services.sqladmin.model.InstancesListResponse)13 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)12 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)12 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)11 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)9 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 Json (com.sequenceiq.cloudbreak.common.json.Json)8 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Network (com.sequenceiq.redbeams.domain.stack.Network)7