List of usage examples for com.amazonaws.services.autoscaling.model UpdateAutoScalingGroupRequest setDesiredCapacity
public void setDesiredCapacity(Integer desiredCapacity)
The number of EC2 instances that should be running in the Auto Scaling group.
From source file:com.netflix.dynomitemanager.sidecore.aws.AWSMembership.java
License:Apache License
@Override public void expandRacMembership(int count) { AmazonAutoScaling client = null;/*www.j a v a2s. co m*/ try { client = getAutoScalingClient(); DescribeAutoScalingGroupsRequest asgReq = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(config.getASGName()); DescribeAutoScalingGroupsResult res = client.describeAutoScalingGroups(asgReq); AutoScalingGroup asg = res.getAutoScalingGroups().get(0); UpdateAutoScalingGroupRequest ureq = new UpdateAutoScalingGroupRequest(); ureq.setAutoScalingGroupName(asg.getAutoScalingGroupName()); ureq.setMinSize(asg.getMinSize() + 1); ureq.setMaxSize(asg.getMinSize() + 1); ureq.setDesiredCapacity(asg.getMinSize() + 1); client.updateAutoScalingGroup(ureq); } finally { if (client != null) client.shutdown(); } }
From source file:com.pinterest.arcee.autoscaling.AwsAutoScaleGroupManager.java
License:Apache License
@Override public void increaseASGDesiredCapacityBySize(String groupName, int instanceCnt) throws Exception { DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest(); request.setAutoScalingGroupNames(Arrays.asList(groupName)); DescribeAutoScalingGroupsResult result = aasClient.describeAutoScalingGroups(request); List<AutoScalingGroup> groups = result.getAutoScalingGroups(); if (groups.isEmpty()) { return;/* www . j a v a 2 s .c o m*/ } AutoScalingGroup group = groups.get(0); int curCapacity = group.getDesiredCapacity(); UpdateAutoScalingGroupRequest updateRequest = new UpdateAutoScalingGroupRequest(); updateRequest.setAutoScalingGroupName(groupName); updateRequest.setDesiredCapacity(curCapacity + instanceCnt); updateRequest.setMaxSize(Math.max(group.getMaxSize(), curCapacity + instanceCnt)); aasClient.updateAutoScalingGroup(updateRequest); }
From source file:com.pinterest.arcee.autoscaling.AwsAutoScalingManager.java
License:Apache License
private void changeGroupCapacity(String groupName, int size, boolean increment) throws Exception { AutoScalingGroup group = getAutoScalingGroup(groupName); if (group == null) { return;//from w ww .jav a 2 s .c om } int currCapacity = group.getDesiredCapacity(); int currMinSize = group.getMinSize(); int currMaxSize = group.getMaxSize(); if (increment) { currCapacity += size; if (currMaxSize == currMinSize) { currMinSize = currCapacity; currMaxSize = currCapacity; } else { currMaxSize = Math.max(currMaxSize, currCapacity); } } else { currCapacity = Math.max(currCapacity - size, 0); if (currMaxSize == currMinSize) { currMinSize = currCapacity; currMaxSize = currCapacity; } else { currMinSize = Math.min(currMinSize, currCapacity); } } UpdateAutoScalingGroupRequest updateRequest = new UpdateAutoScalingGroupRequest(); updateRequest.setAutoScalingGroupName(groupName); updateRequest.setDesiredCapacity(currCapacity); updateRequest.setMaxSize(currMaxSize); updateRequest.setMinSize(currMinSize); aasClient.updateAutoScalingGroup(updateRequest); }
From source file:com.pinterest.clusterservice.cm.AwsVmManager.java
License:Apache License
@Override public void launchHosts(String clusterName, int num) throws Exception { AutoScalingGroup group = getAutoScalingGroup(clusterName); if (group == null) { LOG.error(String.format("Failed to launch hosts: auto scaling group %s does not exist", clusterName)); throw new Exception( String.format("Failed to launch hosts: auto scaling group %s does not exist", clusterName)); }/* w w w. j a v a 2s.c o m*/ try { UpdateAutoScalingGroupRequest updateRequest = new UpdateAutoScalingGroupRequest(); updateRequest.setAutoScalingGroupName(clusterName); updateRequest.setDesiredCapacity(group.getDesiredCapacity() + num); updateRequest.setMaxSize(Math.max(group.getDesiredCapacity(), group.getDesiredCapacity() + num)); aasClient.updateAutoScalingGroup(updateRequest); } catch (AmazonClientException e) { LOG.error(String.format("Failed to launch %d hosts to auto scaling group %s: %s", num, clusterName, e.getMessage())); throw new Exception(String.format("Failed to launch %d hosts to auto scaling group %s: %s", num, clusterName, e.getMessage())); } }