use of com.amazonaws.services.autoscaling.model.CreateAutoScalingGroupRequest 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);
}
Aggregations