use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method getResourceArnByLogicalId.
public String getResourceArnByLogicalId(AuthenticatedContext ac, String logicalId, String region) {
String cFStackName = getCfStackName(ac);
AmazonCloudFormationClient amazonCfClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeStackResourceResult result = amazonCfClient.describeStackResource(new DescribeStackResourceRequest().withStackName(cFStackName).withLogicalResourceId(logicalId));
return result.getStackResourceDetail().getPhysicalResourceId();
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method updateCloudformationWithLoadBalancers.
public List<CloudResourceStatus> updateCloudformationWithLoadBalancers(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier, ModelContext modelContext) {
List<CloudResourceStatus> statuses = new ArrayList<>();
List<CloudLoadBalancer> cloudLoadBalancers = stack.getLoadBalancers();
String cFStackName = cfStackUtil.getCfStackName(ac);
if (!cloudLoadBalancers.isEmpty()) {
LOGGER.debug("Creating load balancers of types " + cloudLoadBalancers.stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::name).collect(Collectors.joining(",")));
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfRetryClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(credentialView, regionName);
List<CloudResource> instances = cfStackUtil.getInstanceCloudResources(ac, cfRetryClient, amazonASClient, stack.getGroups());
Network network = stack.getNetwork();
AwsNetworkView awsNetworkView = new AwsNetworkView(network);
if (modelContext == null) {
LOGGER.debug("Creating default model context");
modelContext = awsModelService.buildDefaultModelContext(ac, stack, resourceNotifier);
}
Map<String, List<String>> instanceIdsByGroupName = instances.stream().collect(Collectors.groupingBy(CloudResource::getGroup, mapping(CloudResource::getInstanceId, toList())));
List<AwsLoadBalancer> awsLoadBalancers = loadBalancerCommonService.getAwsLoadBalancers(cloudLoadBalancers, instanceIdsByGroupName, awsNetworkView);
modelContext.withLoadBalancers(awsLoadBalancers);
LOGGER.debug("Starting CloudFormation update to create load balancer and target groups.");
ListStackResourcesResult result;
if (checkForLoadBalancerAndTargetGroupResources(cfRetryClient, cFStackName, awsLoadBalancers)) {
LOGGER.debug("Load balancer and target group resources already exist, skipping creation");
result = cfRetryClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
} else {
result = updateCloudFormationStack(ac, stack, modelContext);
}
setLoadBalancerMetadata(awsLoadBalancers, result);
LOGGER.debug("Starting CloudFormation update to create listeners.");
if (checkForListenerResources(cfRetryClient, cFStackName, awsLoadBalancers)) {
LOGGER.debug("Listener resources already exist, skipping creation");
result = cfRetryClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
} else {
result = updateCloudFormationStack(ac, stack, modelContext);
}
ListStackResourcesResult finalResult = result;
awsLoadBalancers.forEach(lb -> statuses.add(createLoadBalancerStatus(ac, lb, finalResult)));
} else {
LOGGER.debug("No load balancers in stack");
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsRdsTerminateService method initiateCFTemplateDeletion.
private void initiateCFTemplateDeletion(AuthenticatedContext ac, String cFStackName, AwsCredentialView credentialView, String regionName) {
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
boolean exists = retryService.testWith2SecDelayMax15Times(() -> cfStackUtil.isCfStackExists(cfClient, cFStackName));
if (exists) {
DeleteStackRequest deleteStackRequest = awsStackRequestHelper.createDeleteStackRequest(cFStackName);
cfClient.deleteStack(deleteStackRequest);
LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId());
Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = cfClient.waiters().stackDeleteComplete();
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest).withPollingStrategy(getBackoffCancellablePollingStrategy(stackCancellationCheck));
stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsMetadataCollector method collectInstancesForGroup.
public List<Instance> collectInstancesForGroup(AuthenticatedContext ac, AmazonAutoScalingClient amazonASClient, AmazonEc2Client amazonEC2Client, AmazonCloudFormationClient amazonCFClient, String group) {
LOGGER.debug("Collect aws instances for group: {}", group);
String asGroupName = cloudFormationStackUtil.getAutoscalingGroupName(ac, amazonCFClient, group);
List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(amazonASClient, asGroupName);
DescribeInstancesRequest instancesRequest = cloudFormationStackUtil.createDescribeInstancesRequest(instanceIds);
DescribeInstancesResult instancesResult = amazonEC2Client.describeInstances(instancesRequest);
return instancesResult.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsStackValidator method validateStackNameAvailability.
private void validateStackNameAvailability(AuthenticatedContext ac) {
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
String cFStackName = cfStackUtil.getCfStackName(ac);
try {
LOGGER.debug("Checking stack name availability. [{}]", cFStackName);
cfClient.describeStacks(new DescribeStacksRequest().withStackName(cFStackName));
throw new CloudConnectorException(String.format("Stack already exists with the given name: %s", cFStackName));
} catch (AmazonServiceException e) {
if (e.getErrorMessage().contains(cFStackName + " does not exist")) {
LOGGER.info("Stack name is available, CF stack not found by name {}", cFStackName);
} else {
LOGGER.warn("Exception while checking stack name availability.", e);
}
}
}
Aggregations