@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof TerminateInstancesRequest == false) return false; TerminateInstancesRequest other = (TerminateInstancesRequest) obj; if (other.getInstanceIds() == null ^ this.getInstanceIds() == null) return false; if (other.getInstanceIds() != null && other.getInstanceIds().equals(this.getInstanceIds()) == false) return false; return true; }
// Terminates an instances and returns a list of terminated instance ids. public static List<String> terminateInstances(AmazonEC2 ec2, Collection<String> ids) { for (String id : ids) { logger.info("Terminating instance id: " + id); } TerminateInstancesRequest request = new TerminateInstancesRequest(); request.setInstanceIds(ids); ArrayList<String> terminated = new ArrayList<String>(); for (InstanceStateChange state : ec2.terminateInstances(request).getTerminatingInstances()) { terminated.add(state.getInstanceId()); } return terminated; }
public Request<TerminateInstancesRequest> marshall( TerminateInstancesRequest terminateInstancesRequest) { if (terminateInstancesRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<TerminateInstancesRequest> request = new DefaultRequest<TerminateInstancesRequest>(terminateInstancesRequest, "AmazonEC2"); request.addParameter("Action", "TerminateInstances"); request.addParameter("Version", "2012-03-01"); java.util.List<String> instanceIdsList = terminateInstancesRequest.getInstanceIds(); int instanceIdsListIndex = 1; for (String instanceIdsListValue : instanceIdsList) { if (instanceIdsListValue != null) { request.addParameter( "InstanceId." + instanceIdsListIndex, StringUtils.fromString(instanceIdsListValue)); } instanceIdsListIndex++; } return request; }
public void terminateEC2(String... ec2id) { TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(); amazonClient.terminateInstances(terminateInstancesRequest.withInstanceIds(ec2id)); }