use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project airavata by apache.
the class AmazonUtil method terminateInstances.
/**
* Terminate instances
*
* @param instanceIds
*/
public static void terminateInstances(String... instanceIds) {
// terminate
TerminateInstancesRequest request = new TerminateInstancesRequest();
getEC2Client().terminateInstances(request.withInstanceIds(instanceIds));
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project airavata by apache.
the class AmazonUtil method terminateInstances.
/**
* Terminate instances
*
* @param instanceIds
*/
public static void terminateInstances(List<String> instanceIds) {
// terminate
TerminateInstancesRequest request = new TerminateInstancesRequest(instanceIds);
getEC2Client().terminateInstances(request);
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest 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);
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project druid by druid-io.
the class EC2AutoScaler method terminateWithIds.
@Override
public AutoScalingData terminateWithIds(List<String> ids) {
if (ids.isEmpty()) {
return new AutoScalingData(new ArrayList<>());
}
try {
log.info("Terminating instances[%s]", ids);
amazonEC2Client.terminateInstances(new TerminateInstancesRequest(ids));
return new AutoScalingData(ids);
} catch (Exception e) {
log.error(e, "Unable to terminate any instances.");
}
return null;
}
Aggregations