Example usage for com.amazonaws.services.ec2.model StartInstancesRequest getInstanceIds

List of usage examples for com.amazonaws.services.ec2.model StartInstancesRequest getInstanceIds

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model StartInstancesRequest getInstanceIds.

Prototype


public java.util.List<String> getInstanceIds() 

Source Link

Document

The IDs of the instances.

Usage

From source file:de.fischer.thotti.ec2.clients.EC2Starter.java

License:Apache License

private void executeRequest(EC2RequestData<StartInstancesRequest> 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 w  w  .ja  v  a2 s .  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<StartInstancesRequest> runRequests = regionRequests.getRequests();

        for (StartInstancesRequest request : runRequests) {
            if (logger.isInfoEnabled()) {
                List<String> idList = request.getInstanceIds();

                for (String id : idList) {
                    logger.info(
                            "Going to start instance {} in " + "region {} ({}). Internal request ID is #{}.",
                            new Object[] { id, regionName, requestID });
                }
            }

            StartInstancesResult result = null;

            try {
                result = getClient().startInstances(request);
            } catch (AmazonServiceException ase) {
                handleAmazonServiceException(ase);
            } catch (AmazonClientException ace) {
                handleAmazonClientException(ace);
            }

            // @todo here we should check, if Amazon started all requested instances, Oliver Fischer, 15. June 2011
            if (logger.isInfoEnabled()) {
                for (InstanceStateChange stateChange : result.getStartingInstances()) {
                    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 StartInstancesResult startInstances(StartInstancesRequest request) {

    if (request.getInstanceIds() == null || request.getInstanceIds().isEmpty())
        throw new IllegalArgumentException("Instance ID not specified.");

    return awsHttpClient.startInstances(request);
}