use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class GcpDatabaseServerLaunchService method getDatabaseInstance.
private DatabaseInstance getDatabaseInstance(DatabaseStack stack, String deploymentName, Compute compute, String projectId) throws java.io.IOException {
DatabaseServer databaseServer = stack.getDatabaseServer();
GcpDatabaseServerView databaseServerView = new GcpDatabaseServerView(databaseServer);
GcpDatabaseNetworkView databaseNetworkView = new GcpDatabaseNetworkView(stack.getNetwork());
Subnetwork subnetworkForRedbeams;
if (Strings.isNullOrEmpty(databaseNetworkView.getSharedProjectId())) {
subnetworkForRedbeams = compute.subnetworks().get(projectId, databaseServerView.getLocation(), databaseNetworkView.getSubnetId()).execute();
} else {
subnetworkForRedbeams = compute.subnetworks().get(databaseNetworkView.getSharedProjectId(), databaseServerView.getLocation(), databaseNetworkView.getSubnetId()).execute();
}
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setCurrentDiskSize(databaseServerView.getAllocatedStorageInMb());
databaseInstance.setName(deploymentName);
databaseInstance.setInstanceType("CLOUD_SQL_INSTANCE");
databaseInstance.setBackendType("SECOND_GEN");
databaseInstance.setRegion(databaseServerView.getLocation());
databaseInstance.setRootPassword(databaseServerView.getAdminPassword());
databaseInstance.setConnectionName(databaseServerView.getAdminLoginName());
databaseInstance.setGceZone(databaseNetworkView.getAvailabilityZone());
databaseInstance.setDatabaseVersion(databaseServerView.getDatabaseVersion());
databaseInstance.setSettings(getSettings(stack, databaseServerView, subnetworkForRedbeams));
String keyName = databaseServer.getStringParameter(VOLUME_ENCRYPTION_KEY_ID);
if (keyName != null && !keyName.isEmpty()) {
DiskEncryptionConfiguration diskEncryptionConfiguration = new DiskEncryptionConfiguration();
diskEncryptionConfiguration.setKmsKeyName(keyName);
databaseInstance.setDiskEncryptionConfiguration(diskEncryptionConfiguration);
}
return databaseInstance;
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class AwsStackRequestHelper method getStackParameters.
@VisibleForTesting
Collection<Parameter> getStackParameters(AuthenticatedContext ac, DatabaseStack stack, boolean deleteProtection) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
DatabaseServer databaseServer = stack.getDatabaseServer();
AwsRdsInstanceView awsRdsInstanceView = new AwsRdsInstanceView(databaseServer);
AwsRdsDbSubnetGroupView awsRdsDbSubnetGroupView = new AwsRdsDbSubnetGroupView(databaseServer);
AwsRdsVpcSecurityGroupView awsRdsVpcSecurityGroupView = new AwsRdsVpcSecurityGroupView(databaseServer);
AwsRdsDbParameterGroupView awsRdsDbParameterGroupView = new AwsRdsDbParameterGroupView(databaseServer);
List<Parameter> parameters = new ArrayList<>(asList(new Parameter().withParameterKey("DBInstanceClassParameter").withParameterValue(awsRdsInstanceView.getDBInstanceClass()), new Parameter().withParameterKey("DBInstanceIdentifierParameter").withParameterValue(awsRdsInstanceView.getDBInstanceIdentifier()), new Parameter().withParameterKey("DBSubnetGroupNameParameter").withParameterValue(awsRdsDbSubnetGroupView.getDBSubnetGroupName()), new Parameter().withParameterKey("DBSubnetGroupSubnetIdsParameter").withParameterValue(String.join(",", awsNetworkView.getSubnetList())), new Parameter().withParameterKey("EngineParameter").withParameterValue(awsRdsInstanceView.getEngine()), new Parameter().withParameterKey("MasterUsernameParameter").withParameterValue(awsRdsInstanceView.getMasterUsername()), new Parameter().withParameterKey("MasterUserPasswordParameter").withParameterValue(awsRdsInstanceView.getMasterUserPassword()), new Parameter().withParameterKey("DeletionProtectionParameter").withParameterValue(deleteProtection ? "true" : "false")));
addParameterIfNotNull(parameters, "AllocatedStorageParameter", awsRdsInstanceView.getAllocatedStorage());
addParameterIfNotNull(parameters, "BackupRetentionPeriodParameter", awsRdsInstanceView.getBackupRetentionPeriod());
addParameterIfNotNull(parameters, "EngineVersionParameter", awsRdsInstanceView.getEngineVersion());
addParameterIfNotNull(parameters, "MultiAZParameter", awsRdsInstanceView.getMultiAZ());
addParameterIfNotNull(parameters, "StorageTypeParameter", awsRdsInstanceView.getStorageType());
addParameterIfNotNull(parameters, "PortParameter", databaseServer.getPort());
boolean useSslEnforcement = databaseServer.isUseSslEnforcement();
addParameterIfNotNull(parameters, "DBParameterGroupNameParameter", useSslEnforcement ? awsRdsDbParameterGroupView.getDBParameterGroupName() : null);
addParameterIfNotNull(parameters, "DBParameterGroupFamilyParameter", useSslEnforcement ? awsRdsDbParameterGroupView.getDBParameterGroupFamily() : null);
addParameterIfNotNull(parameters, "SslCertificateIdentifierParameter", useSslEnforcement && awsRdsInstanceView.isSslCertificateIdentifierDefined() ? awsRdsInstanceView.getSslCertificateIdentifier() : null);
if (awsRdsInstanceView.getVPCSecurityGroups().isEmpty()) {
// VPC-id and VPC cidr should be filled in
parameters.addAll(asList(new Parameter().withParameterKey("VPCIdParameter").withParameterValue(String.valueOf(awsNetworkView.getExistingVpc())), new Parameter().withParameterKey("DBSecurityGroupNameParameter").withParameterValue(awsRdsVpcSecurityGroupView.getDBSecurityGroupName())));
} else {
parameters.add(new Parameter().withParameterKey("VPCSecurityGroupsParameter").withParameterValue(String.join(",", awsRdsInstanceView.getVPCSecurityGroups())));
}
return parameters;
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class AwsRdsLaunchService method launch.
public List<CloudResourceStatus> launch(AuthenticatedContext ac, DatabaseStack stack, PersistenceNotifier resourceNotifier) {
String cFStackName = cfStackUtil.getCfStackName(ac);
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
DatabaseServer databaseServer = stack.getDatabaseServer();
boolean useSslEnforcement = databaseServer.isUseSslEnforcement();
try {
cfClient.describeStacks(describeStacksRequest);
LOGGER.debug("Stack already exists: {}", cFStackName);
} catch (AmazonServiceException exception) {
// all subnets desired for DB subnet group are in the stack
boolean existingSubnet = awsNetworkView.isExistingSubnet();
LOGGER.warn("API call failed with this error:", exception);
if (!existingSubnet) {
throw new CloudConnectorException("Can only create RDS instance with existing subnets", exception);
}
CloudResource cloudFormationStack = new Builder().type(ResourceType.CLOUDFORMATION_STACK).name(cFStackName).availabilityZone(ac.getCloudContext().getLocation().getAvailabilityZone().value()).build();
resourceNotifier.notifyAllocation(cloudFormationStack, ac.getCloudContext());
RDSModelContext rdsModelContext = new RDSModelContext().withTemplate(stack.getTemplate()).withNetworkCidrs(awsNetworkView.getExistingVpcCidrs()).withHasPort(databaseServer.getPort() != null).withUseSslEnforcement(useSslEnforcement).withSslCertificateIdentifierDefined(new AwsRdsInstanceView(databaseServer).isSslCertificateIdentifierDefined()).withHasSecurityGroup(!databaseServer.getSecurity().getCloudSecurityIds().isEmpty()).withIsKmsCustom(stack.getDatabaseServer().getParameters().containsKey("key")).withGetKmsKey(getKmsKey(stack));
String cfTemplate = cloudFormationTemplateBuilder.build(rdsModelContext);
LOGGER.debug("CloudFormationTemplate: {}", cfTemplate);
cfClient.createStack(awsStackRequestHelper.createCreateStackRequest(ac, stack, cFStackName, cfTemplate));
}
LOGGER.debug("CloudFormation stack creation request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId());
Waiter<DescribeStacksRequest> creationWaiter = cfClient.waiters().stackCreateComplete();
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(creationWaiter, describeStacksRequest, stackCancellationCheck, String.format("RDS CloudFormation stack %s creation failed", cFStackName), () -> awsCloudFormationErrorMessageProvider.getErrorReason(ac, cFStackName, CREATE_FAILED));
List<CloudResource> databaseResources = getCreatedOutputs(ac, stack, cFStackName, cfClient, resourceNotifier, useSslEnforcement);
databaseResources.forEach(dbr -> resourceNotifier.notifyAllocation(dbr, ac.getCloudContext()));
// FIXME: For now, just return everything wrapped in a status object
return databaseResources.stream().map(resource -> new CloudResourceStatus(resource, ResourceStatus.CREATED)).collect(Collectors.toList());
// FIXME check does nothing?!
// return awsResourceConnector.check(ac, databaseResources);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class AzureTemplateBuilderDbTest method buildTestWhenDataEncryptionParametersPresentAndKeyVersionError.
@Test
void buildTestWhenDataEncryptionParametersPresentAndKeyVersionError() {
Template template = Optional.ofNullable(factoryBean.getObject()).map(config -> {
try {
return config.getTemplate("templates/arm-dbstack.ftl", "UTF-8");
} catch (IOException e) {
throw new IllegalStateException(e);
}
}).orElseThrow();
Subnet subnet = new Subnet(SUBNET_CIDR);
Network network = new Network(subnet, List.of(NETWORK_CIDR), OutboundInternetTraffic.ENABLED);
network.putParameter("subnets", FULL_SUBNET_ID);
Map<String, Object> params = new HashMap<String, Object>();
params.put("dbVersion", "10");
params.put(KEY_URL, "https://dummyVault.vault.azure.net/keys/dummyKey");
params.put(KEY_VAULT_RESOURCE_GROUP_NAME, "dummyResourceGroup");
DatabaseServer databaseServer = DatabaseServer.builder().serverId(SERVER_ID).rootUserName(ROOT_USER_NAME).rootPassword(ROOT_PASSWORD).location(REGION).params(params).build();
DatabaseStack databaseStack = new DatabaseStack(network, databaseServer, Collections.emptyMap(), template.toString());
assertThrows(IllegalArgumentException.class, () -> underTest.build(cloudContext, databaseStack));
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class AzureTemplateBuilderDbTest method createDatabaseStack.
private DatabaseStack createDatabaseStack(boolean useSslEnforcement, String template) {
Subnet subnet = new Subnet(SUBNET_CIDR);
Network network = new Network(subnet, List.of(NETWORK_CIDR), OutboundInternetTraffic.ENABLED);
network.putParameter("subnets", FULL_SUBNET_ID);
DatabaseServer databaseServer = DatabaseServer.builder().useSslEnforcement(useSslEnforcement).serverId(SERVER_ID).rootUserName(ROOT_USER_NAME).rootPassword(ROOT_PASSWORD).location(REGION).params(Map.of("dbVersion", "10")).build();
return new DatabaseStack(network, databaseServer, Collections.emptyMap(), template);
}
Aggregations