Search in sources :

Example 1 with SecurityGroup

use of com.sequenceiq.redbeams.domain.stack.SecurityGroup 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 2 with SecurityGroup

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

the class DBStackToDatabaseStackConverter method buildDatabaseServer.

private DatabaseServer buildDatabaseServer(DBStack dbStack) {
    com.sequenceiq.redbeams.domain.stack.DatabaseServer dbStackDatabaseServer = dbStack.getDatabaseServer();
    if (dbStackDatabaseServer == null) {
        return null;
    }
    Map<String, Object> params = buildParameters(dbStack);
    SecurityGroup securityGroup = dbStackDatabaseServer.getSecurityGroup();
    DatabaseServer.Builder builder = DatabaseServer.builder().serverId(dbStackDatabaseServer.getName()).flavor(dbStackDatabaseServer.getInstanceType()).engine(getDatabaseEngine(dbStackDatabaseServer)).connectionDriver(dbStackDatabaseServer.getConnectionDriver()).rootUserName(dbStackDatabaseServer.getRootUserName()).rootPassword(dbStackDatabaseServer.getRootPassword()).port(dbStackDatabaseServer.getPort()).useSslEnforcement(determineSslEnforcement(dbStack)).storageSize(dbStackDatabaseServer.getStorageSize()).security(securityGroup == null ? null : new Security(Collections.emptyList(), securityGroup.getSecurityGroupIds())).status(CREATE_REQUESTED).location(dbStack.getRegion()).highAvailability(dbStack.isHa()).params(params);
    return builder.build();
}
Also used : DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) SecurityGroup(com.sequenceiq.redbeams.domain.stack.SecurityGroup) Security(com.sequenceiq.cloudbreak.cloud.model.Security)

Aggregations

SecurityGroup (com.sequenceiq.redbeams.domain.stack.SecurityGroup)2 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)1 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)1 Security (com.sequenceiq.cloudbreak.cloud.model.Security)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)1 Network (com.sequenceiq.redbeams.domain.stack.Network)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1