List of usage examples for com.amazonaws.services.ec2.model StopInstancesRequest getInstanceIds
public java.util.List<String> getInstanceIds()
The IDs of the instances.
From source file:de.fischer.thotti.ec2.clients.EC2Stopper.java
License:Apache License
private void executeRequest(EC2RequestData<StopInstancesRequest> requestData) throws AWSCommunicationException { int requestID = 1; Map<String, SortedSet<Instance>> instances = new HashMap<String, SortedSet<Instance>>(); List<Region> awsRegions = getAWSRegions(); // @todo this should be a separate method for (Region region : awsRegions) { EC2RunnerContext context = new EC2RunnerContext(); context.regionName = region.getRegionName(); context.endPoint = region.getEndpoint(); getRegionContextCache().put(context.regionName, context); }/*from w ww . j a v a 2s. c o m*/ for (String regionName : requestData.getAllRegions()) { EC2RunnerContext ctx = getRegionContextCache().get(regionName); Comparator comparator = new EC2Executor.InstaceAvailabilityComparator(); SortedSet<Instance> describedInstances = new TreeSet<Instance>(comparator); setRegionContext(ctx); switchCommunicationEndPoint(); RegionRequests regionRequests = requestData.getRegion(regionName); List<StopInstancesRequest> runRequests = regionRequests.getRequests(); for (StopInstancesRequest request : runRequests) { if (logger.isInfoEnabled()) { List<String> idList = request.getInstanceIds(); for (String id : idList) { logger.info("Going to stop instance {} in " + "region {} ({}). Internal request ID is #{}.", new Object[] { id, regionName, requestID }); } } StopInstancesResult result = null; try { result = getClient().stopInstances(request); } catch (AmazonServiceException ase) { handleAmazonServiceException(ase); } catch (AmazonClientException ace) { handleAmazonClientException(ace); } // @todo here we should check, if Amazon terminated all requested instances, Oliver Fischer, 15. June 2011 if (logger.isInfoEnabled()) { for (InstanceStateChange stateChange : result.getStoppingInstances()) { logger.info("Amazon AWS changed state of instance {} from {} to {}", new Object[] { stateChange.getInstanceId(), stateChange.getPreviousState(), stateChange.getCurrentState() }); } requestID++; // For the next request instances.put(regionName, describedInstances); } } } }
From source file:web.component.impl.aws.AWSEC2Impl.java
@Override public StopInstancesResult stopInstances(StopInstancesRequest request) { if (request.getInstanceIds() == null || request.getInstanceIds().isEmpty()) throw new IllegalArgumentException("Instance ID not specified."); return awsHttpClient.stopInstances(request); }