Search in sources :

Example 1 with LaunchTemplateSpecification

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;
}
Also used : LaunchTemplateSpecification(com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification)

Example 2 with 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;
}
Also used : LaunchTemplateSpecification(com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification) UpdateAutoScalingGroupResult(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupResult) UpdateAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest)

Example 3 with LaunchTemplateSpecification

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);
        }
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) LaunchTemplateSpecification(com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) CreateLaunchTemplateVersionResult(com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Map(java.util.Map)

Aggregations

LaunchTemplateSpecification (com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification)3 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 UpdateAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest)1 UpdateAutoScalingGroupResult (com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupResult)1 CreateLaunchTemplateVersionResult (com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult)1 AmazonAutoScalingClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient)1 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)1 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 Map (java.util.Map)1