use of com.amazonaws.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(Lists.<String>newArrayList());
}
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;
}
use of com.amazonaws.services.ec2.model.TerminateInstancesRequest in project camel by apache.
the class EC2Producer method terminateInstances.
private void terminateInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
TerminateInstancesRequest request = new TerminateInstancesRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
} else {
throw new IllegalArgumentException("Instances Ids must be specified");
}
TerminateInstancesResult result;
try {
result = ec2Client.terminateInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Terminate Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Terminating instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.model.TerminateInstancesRequest in project camel by apache.
the class AmazonEC2ClientMock method terminateInstances.
@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) {
TerminateInstancesResult result = new TerminateInstancesResult();
if (terminateInstancesRequest.getInstanceIds().contains("test-1")) {
Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
InstanceStateChange sc = new InstanceStateChange();
InstanceState previousState = new InstanceState();
previousState.setCode(80);
previousState.setName(InstanceStateName.Running);
InstanceState newState = new InstanceState();
newState.setCode(16);
newState.setName(InstanceStateName.Terminated);
sc.setPreviousState(previousState);
sc.setCurrentState(newState);
sc.setInstanceId("test-1");
coll.add(sc);
result.setTerminatingInstances(coll);
} else {
throw new AmazonServiceException("The image-id doesn't exists");
}
return result;
}
use of com.amazonaws.services.ec2.model.TerminateInstancesRequest in project GNS by MobilityFirst.
the class AWSEC2 method terminateInstance.
/**
* Terminate an instance
*
* @param ec2
* @param createdInstanceId
*/
public static void terminateInstance(AmazonEC2 ec2, String createdInstanceId) {
System.out.println("Terminating Instance:" + createdInstanceId);
List<String> instanceIds = new LinkedList<>();
instanceIds.add(createdInstanceId);
TerminateInstancesRequest tir = new TerminateInstancesRequest(instanceIds);
ec2.terminateInstances(tir);
}
Aggregations