Search in sources :

Example 1 with AmazonAutoScaling

use of com.amazonaws.services.autoscaling.AmazonAutoScaling in project incubator-gobblin by apache.

the class AWSSdkClient method createLaunchConfig.

/**
 * Create a launch configuration that can be later used to create {@link AmazonAutoScaling} groups
 *
 * @param launchConfigName Desired launch config name
 * @param imageId AMI image id to use
 * @param instanceType EC2 instance type to use
 * @param keyName Key name
 * @param securityGroups Security groups to apply
 * @param kernelId Optional kernel id
 * @param ramdiskId Optional ram disk id
 * @param blockDeviceMapping Optional EBS device mapping
 * @param iamInstanceProfile Optional IAM instance profile
 * @param instanceMonitoring Optional instance monitoring
 * @param userData User data (eg. shell script to execute at instance boot under this launch config)
 */
public void createLaunchConfig(String launchConfigName, String imageId, String instanceType, String keyName, String securityGroups, Optional<String> kernelId, Optional<String> ramdiskId, Optional<BlockDeviceMapping> blockDeviceMapping, Optional<String> iamInstanceProfile, Optional<InstanceMonitoring> instanceMonitoring, String userData) {
    final AmazonAutoScaling autoScaling = getAmazonAutoScalingClient();
    CreateLaunchConfigurationRequest createLaunchConfigurationRequest = new CreateLaunchConfigurationRequest().withLaunchConfigurationName(launchConfigName).withImageId(imageId).withInstanceType(instanceType).withSecurityGroups(SPLITTER.splitToList(securityGroups)).withKeyName(keyName).withUserData(userData);
    if (kernelId.isPresent()) {
        createLaunchConfigurationRequest = createLaunchConfigurationRequest.withKernelId(kernelId.get());
    }
    if (ramdiskId.isPresent()) {
        createLaunchConfigurationRequest = createLaunchConfigurationRequest.withRamdiskId(ramdiskId.get());
    }
    if (blockDeviceMapping.isPresent()) {
        createLaunchConfigurationRequest = createLaunchConfigurationRequest.withBlockDeviceMappings(blockDeviceMapping.get());
    }
    if (iamInstanceProfile.isPresent()) {
        createLaunchConfigurationRequest = createLaunchConfigurationRequest.withIamInstanceProfile(iamInstanceProfile.get());
    }
    if (instanceMonitoring.isPresent()) {
        createLaunchConfigurationRequest = createLaunchConfigurationRequest.withInstanceMonitoring(instanceMonitoring.get());
    }
    autoScaling.createLaunchConfiguration(createLaunchConfigurationRequest);
    LOGGER.info("Created Launch Configuration: " + launchConfigName);
}
Also used : AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) CreateLaunchConfigurationRequest(com.amazonaws.services.autoscaling.model.CreateLaunchConfigurationRequest)

Example 2 with AmazonAutoScaling

use of com.amazonaws.services.autoscaling.AmazonAutoScaling in project incubator-gobblin by apache.

the class AWSSdkClient method deleteAutoScalingGroup.

/**
 * Delete an auto scaling group by its name
 *
 * @param autoScalingGroupName Name of auto scaling group to delete
 * @param shouldForceDelete If the AutoScalingGroup should be deleted without waiting for instances to terminate
 */
public void deleteAutoScalingGroup(String autoScalingGroupName, boolean shouldForceDelete) {
    final AmazonAutoScaling autoScaling = getAmazonAutoScalingClient();
    final DeleteAutoScalingGroupRequest deleteLaunchConfigurationRequest = new DeleteAutoScalingGroupRequest().withAutoScalingGroupName(autoScalingGroupName).withForceDelete(shouldForceDelete);
    autoScaling.deleteAutoScalingGroup(deleteLaunchConfigurationRequest);
    LOGGER.info("Deleted AutoScalingGroup: " + autoScalingGroupName);
}
Also used : DeleteAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.DeleteAutoScalingGroupRequest) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling)

Example 3 with AmazonAutoScaling

use of com.amazonaws.services.autoscaling.AmazonAutoScaling in project incubator-gobblin by apache.

the class AWSSdkClient method getAutoScalingGroupsWithTag.

/**
 * Get list of {@link AutoScalingGroup}s for a given tag
 *
 * @param tag Tag to filter the auto scaling groups
 * @return List of {@link AutoScalingGroup}s qualifying the filter tag
 */
public List<AutoScalingGroup> getAutoScalingGroupsWithTag(Tag tag) {
    final AmazonAutoScaling autoScaling = getAmazonAutoScalingClient();
    final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest();
    final List<AutoScalingGroup> allAutoScalingGroups = autoScaling.describeAutoScalingGroups(describeAutoScalingGroupsRequest).getAutoScalingGroups();
    final List<AutoScalingGroup> filteredAutoScalingGroups = Lists.newArrayList();
    for (AutoScalingGroup autoScalingGroup : allAutoScalingGroups) {
        for (TagDescription tagDescription : autoScalingGroup.getTags()) {
            if (tagDescription.getKey().equalsIgnoreCase(tag.getKey()) && tagDescription.getValue().equalsIgnoreCase(tag.getValue())) {
                filteredAutoScalingGroups.add(autoScalingGroup);
            }
        }
    }
    return filteredAutoScalingGroups;
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling)

Example 4 with AmazonAutoScaling

use of com.amazonaws.services.autoscaling.AmazonAutoScaling in project incubator-gobblin by apache.

the class AWSSdkClient method deleteLaunchConfiguration.

/**
 * Delete a launch configuration by its name
 *
 * @param launchConfigName Name of launch config to delete
 */
public void deleteLaunchConfiguration(String launchConfigName) {
    final AmazonAutoScaling autoScaling = getAmazonAutoScalingClient();
    final DeleteLaunchConfigurationRequest deleteLaunchConfigurationRequest = new DeleteLaunchConfigurationRequest().withLaunchConfigurationName(launchConfigName);
    autoScaling.deleteLaunchConfiguration(deleteLaunchConfigurationRequest);
    LOGGER.info("Deleted Launch Configuration: " + launchConfigName);
}
Also used : AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) DeleteLaunchConfigurationRequest(com.amazonaws.services.autoscaling.model.DeleteLaunchConfigurationRequest)

Example 5 with AmazonAutoScaling

use of com.amazonaws.services.autoscaling.AmazonAutoScaling in project incubator-gobblin by apache.

the class AWSSdkClient method createAutoScalingGroup.

/**
 * Create and launch an {@link AmazonAutoScaling} group
 *
 * @param groupName Auto scaling group name
 * @param launchConfig Launch configuration string
 * @param minSize Minimum number of instances to maintain in auto scaling group
 * @param maxSize Maximum number of instances to scale up-to for load
 * @param desiredCapacity Desired number of instances to maintain in auto scaling group
 * @param availabilityZones Optional availability zones to make use of
 * @param cooldown Optional cooldown period before any scaling event (default is 300 secs)
 * @param healthCheckGracePeriod Optional grace period till which no health check is performed after bootup (default is 300 secs)
 * @param healthCheckType Optional health check type (default is EC2 instance check)
 * @param loadBalancer Optional load balancer to use
 * @param terminationPolicy Optional termination policies
 * @param tags Optional tags to set on auto scaling group (they are set to propagate to EC2 instances implicitly)
 */
public void createAutoScalingGroup(String groupName, String launchConfig, Integer minSize, Integer maxSize, Integer desiredCapacity, Optional<String> availabilityZones, Optional<Integer> cooldown, Optional<Integer> healthCheckGracePeriod, Optional<String> healthCheckType, Optional<String> loadBalancer, Optional<String> terminationPolicy, List<Tag> tags) {
    AmazonAutoScaling autoScaling = getAmazonAutoScalingClient();
    // Propagate ASG tags to EC2 instances launched under the ASG by default
    // (we want to ensure this, hence not configurable)
    final List<Tag> tagsWithPropagationSet = Lists.newArrayList();
    for (Tag tag : tags) {
        tagsWithPropagationSet.add(tag.withPropagateAtLaunch(true));
    }
    CreateAutoScalingGroupRequest createAutoScalingGroupRequest = new CreateAutoScalingGroupRequest().withAutoScalingGroupName(groupName).withLaunchConfigurationName(launchConfig).withMinSize(minSize).withMaxSize(maxSize).withDesiredCapacity(desiredCapacity).withTags(tagsWithPropagationSet);
    if (availabilityZones.isPresent()) {
        createAutoScalingGroupRequest = createAutoScalingGroupRequest.withAvailabilityZones(SPLITTER.splitToList(availabilityZones.get()));
    }
    if (cooldown.isPresent()) {
        createAutoScalingGroupRequest = createAutoScalingGroupRequest.withDefaultCooldown(cooldown.get());
    }
    if (healthCheckGracePeriod.isPresent()) {
        createAutoScalingGroupRequest = createAutoScalingGroupRequest.withHealthCheckGracePeriod(healthCheckGracePeriod.get());
    }
    if (healthCheckType.isPresent()) {
        createAutoScalingGroupRequest = createAutoScalingGroupRequest.withHealthCheckType(healthCheckType.get());
    }
    if (loadBalancer.isPresent()) {
        createAutoScalingGroupRequest = createAutoScalingGroupRequest.withLoadBalancerNames(SPLITTER.splitToList(loadBalancer.get()));
    }
    if (terminationPolicy.isPresent()) {
        createAutoScalingGroupRequest = createAutoScalingGroupRequest.withTerminationPolicies(SPLITTER.splitToList(terminationPolicy.get()));
    }
    autoScaling.createAutoScalingGroup(createAutoScalingGroupRequest);
    LOGGER.info("Created AutoScalingGroup: " + groupName);
}
Also used : CreateAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.CreateAutoScalingGroupRequest) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) Tag(com.amazonaws.services.autoscaling.model.Tag)

Aggregations

AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)6 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)1 CreateAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.CreateAutoScalingGroupRequest)1 CreateLaunchConfigurationRequest (com.amazonaws.services.autoscaling.model.CreateLaunchConfigurationRequest)1 DeleteAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.DeleteAutoScalingGroupRequest)1 DeleteLaunchConfigurationRequest (com.amazonaws.services.autoscaling.model.DeleteLaunchConfigurationRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 Tag (com.amazonaws.services.autoscaling.model.Tag)1 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1