use of com.amazonaws.services.cloudformation.model.ResourceStatus.CREATE_FAILED 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);
}
Aggregations