use of com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification in project cloudbreak by hortonworks.
the class AwsLaunchTemplateUpdateService method getLaunchTemplateSpecification.
private LaunchTemplateSpecification getLaunchTemplateSpecification(AutoScalingGroup autoScalingGroup) {
LaunchTemplateSpecification launchTemplateSpecification = autoScalingGroup.getLaunchTemplate() == null ? autoScalingGroup.getMixedInstancesPolicy().getLaunchTemplate().getLaunchTemplateSpecification() : autoScalingGroup.getLaunchTemplate();
LOGGER.debug("Current launch template specification {} for autoScaling group {}", launchTemplateSpecification, autoScalingGroup);
return launchTemplateSpecification;
}
use of com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification in project cloudbreak by hortonworks.
the class AwsLaunchTemplateUpdateService method updateAutoScalingGroup.
private UpdateAutoScalingGroupResult updateAutoScalingGroup(Map<LaunchTemplateField, String> updatableFields, AmazonAutoScalingClient autoScalingClient, AutoScalingGroup autoScalingGroup, LaunchTemplateSpecification launchTemplateSpecification, CreateLaunchTemplateVersionResult createLaunchTemplateVersionResult) {
LaunchTemplateSpecification newLaunchTemplateSpecification = new LaunchTemplateSpecification().withLaunchTemplateId(launchTemplateSpecification.getLaunchTemplateId()).withVersion(createLaunchTemplateVersionResult.getLaunchTemplateVersion().getVersionNumber().toString());
UpdateAutoScalingGroupResult updateAutoScalingGroupResult = autoScalingClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(autoScalingGroup.getAutoScalingGroupName()).withLaunchTemplate(newLaunchTemplateSpecification));
LOGGER.info("Create new LauncTemplateVersion {} with new fields {} and attached it to the {} autoscaling group.", newLaunchTemplateSpecification, updatableFields, autoScalingGroup.getAutoScalingGroupName());
return updateAutoScalingGroupResult;
}
use of com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification 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);
}
}
}
Aggregations