use of com.sequenceiq.redbeams.domain.stack.Network 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");
}
use of com.sequenceiq.redbeams.domain.stack.Network in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionAzureWithAzureEncryptionResourcesPresent.
@Test
public void testConversionAzureWithAzureEncryptionResourcesPresent() {
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().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(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(ENCRYPTION_KEY_URL).toString()).isEqualTo(KEY_URL);
assertThat(parameters.get(ENCRYPTION_KEY_RESOURCE_GROUP_NAME).toString()).isEqualTo(RESOURCE_GROUP);
assertThat(parameters.size()).isEqualTo(4);
}
use of com.sequenceiq.redbeams.domain.stack.Network in project cloudbreak by hortonworks.
the class AllocateDatabaseServerV4RequestToDBStackConverter method buildNetwork.
private Network buildNetwork(NetworkV4StackRequest source, DetailedEnvironmentResponse environmentResponse, CloudPlatform cloudPlatform, DBStack dbStack) {
Network network = new Network();
network.setName(generateNetworkName());
Map<String, Object> parameters = source != null ? providerParameterCalculator.get(source).asMap() : getSubnetsFromEnvironment(environmentResponse, cloudPlatform, dbStack);
networkParameterAdder.addParameters(parameters, environmentResponse, cloudPlatform, dbStack);
if (parameters != null) {
try {
network.setAttributes(new Json(parameters));
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid network parameters", e);
}
}
return network;
}
Aggregations