use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project SimianArmy by Netflix.
the class AWSClient method describeLaunchConfigurations.
/**
* Describe a set of specific launch configurations.
*
* @param names the launch configuration names
* @return the launch configurations
*/
public List<LaunchConfiguration> describeLaunchConfigurations(String... names) {
if (names == null || names.length == 0) {
LOGGER.info(String.format("Getting all launch configurations in region %s.", region));
} else {
LOGGER.info(String.format("Getting launch configurations for %d names in region %s.", names.length, region));
}
List<LaunchConfiguration> lcs = new LinkedList<LaunchConfiguration>();
AmazonAutoScalingClient asgClient = asgClient();
DescribeLaunchConfigurationsRequest request = new DescribeLaunchConfigurationsRequest().withLaunchConfigurationNames(names);
DescribeLaunchConfigurationsResult result = asgClient.describeLaunchConfigurations(request);
lcs.addAll(result.getLaunchConfigurations());
while (result.getNextToken() != null) {
request.setNextToken(result.getNextToken());
result = asgClient.describeLaunchConfigurations(request);
lcs.addAll(result.getLaunchConfigurations());
}
LOGGER.info(String.format("Got %d launch configurations in region %s.", lcs.size(), region));
return lcs;
}
use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project SimianArmy by Netflix.
the class AWSClient method describeAutoScalingGroups.
/**
* Describe a set of specific auto scaling groups.
*
* @param names the ASG names
* @return the auto scaling groups
*/
public List<AutoScalingGroup> describeAutoScalingGroups(String... names) {
if (names == null || names.length == 0) {
LOGGER.info(String.format("Getting all auto-scaling groups in region %s.", region));
} else {
LOGGER.info(String.format("Getting auto-scaling groups for %d names in region %s.", names.length, region));
}
List<AutoScalingGroup> asgs = new LinkedList<AutoScalingGroup>();
AmazonAutoScalingClient asgClient = asgClient();
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
if (names != null) {
request.setAutoScalingGroupNames(Arrays.asList(names));
}
DescribeAutoScalingGroupsResult result = asgClient.describeAutoScalingGroups(request);
asgs.addAll(result.getAutoScalingGroups());
while (result.getNextToken() != null) {
request.setNextToken(result.getNextToken());
result = asgClient.describeAutoScalingGroups(request);
asgs.addAll(result.getAutoScalingGroups());
}
LOGGER.info(String.format("Got %d auto-scaling groups in region %s.", asgs.size(), region));
return asgs;
}
use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project SimianArmy by Netflix.
the class AWSClient method describeAutoScalingInstances.
/**
* Describe a set of specific auto-scaling instances.
*
* @param instanceIds the instance ids
* @return the instances
*/
public List<AutoScalingInstanceDetails> describeAutoScalingInstances(String... instanceIds) {
if (instanceIds == null || instanceIds.length == 0) {
LOGGER.info(String.format("Getting all auto-scaling instances in region %s.", region));
} else {
LOGGER.info(String.format("Getting auto-scaling instances for %d ids in region %s.", instanceIds.length, region));
}
List<AutoScalingInstanceDetails> instances = new LinkedList<AutoScalingInstanceDetails>();
AmazonAutoScalingClient asgClient = asgClient();
DescribeAutoScalingInstancesRequest request = new DescribeAutoScalingInstancesRequest();
if (instanceIds != null) {
request.setInstanceIds(Arrays.asList(instanceIds));
}
DescribeAutoScalingInstancesResult result = asgClient.describeAutoScalingInstances(request);
instances.addAll(result.getAutoScalingInstances());
while (result.getNextToken() != null) {
request = request.withNextToken(result.getNextToken());
result = asgClient.describeAutoScalingInstances(request);
instances.addAll(result.getAutoScalingInstances());
}
LOGGER.info(String.format("Got %d auto-scaling instances.", instances.size()));
return instances;
}
use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsResourceConnector method resumeAutoScaling.
private void resumeAutoScaling(AuthenticatedContext ac, CloudStack stack) {
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
for (Group group : stack.getGroups()) {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, group.getName(), ac.getCloudContext().getLocation().getRegion().value());
amazonASClient.resumeProcesses(new ResumeProcessesRequest().withAutoScalingGroupName(asGroupName).withScalingProcesses(SUSPENDED_PROCESSES));
}
}
use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsResourceConnector method downscale.
@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, Object resourcesToRemove) {
Collection<String> instanceIds = new ArrayList<>();
for (CloudInstance vm : vms) {
instanceIds.add(vm.getInstanceId());
}
String asGroupName = cfStackUtil.getAutoscalingGroupName(auth, vms.get(0).getTemplate().getGroupName(), auth.getCloudContext().getLocation().getRegion().value());
DetachInstancesRequest detachInstancesRequest = new DetachInstancesRequest().withAutoScalingGroupName(asGroupName).withInstanceIds(instanceIds).withShouldDecrementDesiredCapacity(true);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(auth.getCloudCredential()), auth.getCloudContext().getLocation().getRegion().value());
try {
amazonASClient.detachInstances(detachInstancesRequest);
} catch (AmazonServiceException e) {
if (!"ValidationError".equals(e.getErrorCode()) || !e.getErrorMessage().contains("not part of Auto Scaling") || instanceIds.stream().anyMatch(id -> !e.getErrorMessage().contains(id))) {
throw e;
}
LOGGER.info(e.getErrorMessage());
}
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(auth.getCloudCredential()), auth.getCloudContext().getLocation().getRegion().value());
try {
amazonEC2Client.terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceIds));
} catch (AmazonServiceException e) {
if (!"InvalidInstanceID.NotFound".equals(e.getErrorCode())) {
throw e;
}
LOGGER.info(e.getErrorMessage());
}
LOGGER.info("Terminated instances in stack '{}': '{}'", auth.getCloudContext().getId(), instanceIds);
return check(auth, resources);
}
Aggregations