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

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

Introduction

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

Prototype


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

Source Link

Document

The IDs of the instances.

Usage

From source file:com.liferay.amazontools.AMIBuilder.java

License:Open Source License

protected void terminateInstance(String instanceId) {
    TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest();

    List<String> instanceIds = terminateInstancesRequest.getInstanceIds();

    instanceIds.add(instanceId);/*from w  ww  . j  a  v a  2s .  c om*/

    TerminateInstancesResult terminateInstancesResult = amazonEC2Client
            .terminateInstances(terminateInstancesRequest);

    List<InstanceStateChange> instanceStateChanges = terminateInstancesResult.getTerminatingInstances();

    if (!instanceStateChanges.isEmpty()) {
        System.out.println("Terminated instance " + instanceId);
    } else {
        System.out.println("Unable to terminate instance " + instanceId);
    }
}

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

License:Apache License

private void executeRequest(EC2RequestData<TerminateInstancesRequest> 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 va  2  s .com*/

    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<TerminateInstancesRequest> runRequests = regionRequests.getRequests();

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

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

            TerminateInstancesResult result = null;

            try {
                result = getClient().terminateInstances(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.getTerminatingInstances()) {

                    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:jp.primecloud.auto.aws.typica.EucaEc2Client.java

License:Open Source License

@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) {
    try {/*from   ww w.jav a2 s .c o  m*/
        List<TerminatingInstanceDescription> descriptions = jec2
                .terminateInstances(terminateInstancesRequest.getInstanceIds());
        List<InstanceStateChange> terminatingInstances = new InstanceStateChangeTerminateConverter()
                .convert(descriptions);
        return new TerminateInstancesResult().withTerminatingInstances(terminatingInstances);
    } catch (EC2Exception e) {
        throw new AmazonClientException(e);
    }
}

From source file:web.component.impl.aws.AWSEC2Impl.java

@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest request) {

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

    return awsHttpClient.terminateInstances(request);
}