use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsLaunchConfigurationImageUpdateService method updateImage.
public void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource) {
AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential());
String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName();
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName);
Map<AutoScalingGroup, String> scalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource);
List<LaunchConfiguration> oldLaunchConfigurations = launchConfigurationHandler.getLaunchConfigurations(autoScalingClient, scalingGroups.keySet());
for (LaunchConfiguration oldLaunchConfiguration : oldLaunchConfigurations) {
changeImageInAutoscalingGroup(authenticatedContext, stack, autoScalingClient, scalingGroups, oldLaunchConfiguration);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsLaunchTemplateUpdateService method updateFields.
public void updateFields(AuthenticatedContext authenticatedContext, String stackName, Map<LaunchTemplateField, String> updatableFields, boolean dryRun) {
AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential());
String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName();
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName);
AmazonEc2Client ec2Client = awsClient.createEc2Client(credentialView, regionName);
Map<AutoScalingGroup, String> autoScalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, stackName);
autoScalingGroups = filterGroupsForDryRun(autoScalingGroups, dryRun);
LOGGER.debug("Modifying the {} fields for the [{}] autoscaling groups' launchtemplates [dryrun: {}]", updatableFields, autoScalingGroups.values(), dryRun);
for (Map.Entry<AutoScalingGroup, String> asgEntry : autoScalingGroups.entrySet()) {
AutoScalingGroup autoScalingGroup = asgEntry.getKey();
LOGGER.debug("Creating new launchtemplate version for [{}] autoscale group...", autoScalingGroup.getAutoScalingGroupName());
LaunchTemplateSpecification launchTemplateSpecification = getLaunchTemplateSpecification(autoScalingGroup);
CreateLaunchTemplateVersionResult createLaunchTemplateVersionResult = getCreateLaunchTemplateVersionRequest(ec2Client, updatableFields, launchTemplateSpecification);
modifyLaunchTemplate(ec2Client, launchTemplateSpecification, createLaunchTemplateVersionResult, !dryRun);
if (dryRun) {
LOGGER.debug("Autoscale group update will be skipped because of dryrun, which just test the permissions for modifiying the launch template.");
} else {
updateAutoScalingGroup(updatableFields, autoScalingClient, autoScalingGroup, launchTemplateSpecification, createLaunchTemplateVersionResult);
}
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsLoadBalancerMetadataCollector method getParameters.
public Map<String, Object> getParameters(AuthenticatedContext ac, LoadBalancer loadBalancer, AwsLoadBalancerScheme scheme) {
String region = ac.getCloudContext().getLocation().getRegion().value();
String cFStackName = cloudFormationStackUtil.getCfStackName(ac);
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
AmazonCloudFormationClient cfRetryClient = awsClient.createCloudFormationClient(credentialView, region);
ListStackResourcesResult result = cfRetryClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
Map<String, Object> parameters = parseTargetGroupCloudParams(scheme, result.getStackResourceSummaries());
parameters.put(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, loadBalancer.getLoadBalancerArn());
return parameters;
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsMetadataCollector method collectCloudVmMetaDataStatuses.
private List<CloudVmMetaDataStatus> collectCloudVmMetaDataStatuses(AuthenticatedContext ac, List<CloudInstance> vms, List<CloudResource> resources, List<String> knownInstanceIdList) {
LOGGER.debug("Collect Cloud VM metadata statuses");
List<CloudVmMetaDataStatus> collectedCloudVmMetaDataStatuses = new ArrayList<>();
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient amazonCFClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), region);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), region);
AmazonEc2Client amazonEC2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();
Multimap<String, CloudInstance> instanceGroupMap = getInstanceGroupMap(vms);
Set<String> subnetIds = new HashSet<>();
Multimap<String, Instance> instancesOnAWSForGroup = ArrayListMultimap.create();
for (String group : instanceGroupMap.keySet()) {
List<Instance> instancesForGroup = collectInstancesForGroup(ac, amazonASClient, amazonEC2Client, amazonCFClient, group);
LOGGER.info("Collected instances for group: {}", instancesForGroup.stream().map(Instance::getInstanceId).collect(Collectors.joining(",")));
instancesOnAWSForGroup.putAll(group, instancesForGroup);
subnetIds.addAll(getSubnetIdsForInstances(instancesForGroup));
}
LOGGER.info("Collected subnet IDs: {}", subnetIds);
Map<String, String> subnetIdToAvailabilityZoneMap = buildSubnetIdToAvailabilityZoneMap(subnetIds, amazonEC2Client);
LOGGER.info("Subnet id to availability zone map: {}", subnetIdToAvailabilityZoneMap);
Multimap<String, Instance> unknownInstancesForGroup = getUnknownInstancesForGroup(knownInstanceIdList, instancesOnAWSForGroup);
for (CloudInstance vm : vms) {
if (vm.getInstanceId() == null) {
addFromUnknownMap(vm, resources, unknownInstancesForGroup, collectedCloudVmMetaDataStatuses, subnetIdToAvailabilityZoneMap);
} else {
addKnownInstance(vm, instancesOnAWSForGroup, collectedCloudVmMetaDataStatuses, subnetIdToAvailabilityZoneMap);
}
}
LOGGER.info("Collected cloud VM metadata and statuses: {}", collectedCloudVmMetaDataStatuses);
return collectedCloudVmMetaDataStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient in project cloudbreak by hortonworks.
the class AwsNetworkConnector method deleteNetworkWithSubnets.
@Override
public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) {
if (!networkDeletionRequest.isExisting()) {
AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential());
String regionName = networkDeletionRequest.getRegion();
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
String stackName = networkDeletionRequest.getStackName();
boolean exists = retryService.testWith2SecDelayMax15Times(() -> cfStackUtil.isCfStackExists(cfClient, stackName));
if (exists) {
DeleteStackRequest deleteStackRequest = new DeleteStackRequest();
deleteStackRequest.setStackName(stackName);
cfClient.deleteStack(deleteStackRequest);
Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete();
LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", stackName);
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName);
run(deletionWaiter, describeStacksRequest, null, String.format("Network delete failed (cloudformation: %s)", stackName), () -> awsCloudFormationErrorMessageProvider.getErrorReason(credentialView, regionName, stackName, ResourceStatus.DELETE_FAILED));
}
}
}
Aggregations