use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionGcpWithGcpEncryptionResourcesPresent.
@Test
public void testConversionGcpWithGcpEncryptionResourcesPresent() {
Network network = new Network();
network.setAttributes(new Json(NETWORK_ATTRIBUTES));
dbStack.setNetwork(network);
dbStack.setCloudPlatform("GCP");
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("GCP");
environmentResponse.setGcp(GcpEnvironmentParameters.builder().withResourceEncryptionParameters(GcpResourceEncryptionParameters.builder().withEncryptionKey("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);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack 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);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack 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();
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class AbstractRedbeamsTerminationAction method createFlowContext.
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) {
Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId());
CloudContext cloudContext = null;
CloudCredential cloudCredential = null;
DatabaseStack databaseStack = null;
DBStack dbStack = null;
if (optionalDBStack.isPresent()) {
dbStack = optionalDBStack.get();
MDCBuilder.buildMdcContext(dbStack);
Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
String userName = dbStack.getOwnerCrn().getUserId();
String accountId = dbStack.getOwnerCrn().getAccountId();
cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withUserName(userName).withLocation(location).withAccountId(accountId).build();
try {
Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
cloudCredential = credentialConverter.convert(credential);
} catch (Exception ex) {
LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId());
}
databaseStack = databaseStackConverter.convert(dbStack);
} else {
LOGGER.warn("DBStack for {} id is not found in the database, it seems to be only possible if the redbeams process was killed during the execution" + " of the termination finished action", payload.getResourceId());
}
return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class AbstractRedbeamsStartAction method createFlowContext.
@Override
protected RedbeamsStartContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStartState, RedbeamsStartEvent> stateContext, P payload) {
DBStack dbStack = dbStackService.getById(payload.getResourceId());
MDCBuilder.buildMdcContext(dbStack);
Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
String userName = dbStack.getOwnerCrn().getUserId();
String accountId = dbStack.getOwnerCrn().getAccountId();
CloudContext cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withLocation(location).withUserName(userName).withAccountId(accountId).build();
Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
CloudCredential cloudCredential = credentialConverter.convert(credential);
DatabaseStack databaseStack = databaseStackConverter.convert(dbStack);
return new RedbeamsStartContext(flowParameters, cloudContext, cloudCredential, databaseStack);
}
Aggregations