Example usage for com.amazonaws.services.ec2.model StopInstancesRequest StopInstancesRequest

List of usage examples for com.amazonaws.services.ec2.model StopInstancesRequest StopInstancesRequest

Introduction

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

Prototype

public StopInstancesRequest(java.util.List<String> instanceIds) 

Source Link

Document

Constructs a new StopInstancesRequest object.

Usage

From source file:hudson.plugins.ec2.EC2AbstractSlave.java

License:Open Source License

void stop() {
    try {//from   www .j a  v  a 2 s.c  om
        AmazonEC2 ec2 = getCloud().connect();
        StopInstancesRequest request = new StopInstancesRequest(Collections.singletonList(getInstanceId()));
        LOGGER.fine("Sending stop request for " + getInstanceId());
        ec2.stopInstances(request);
        LOGGER.info("EC2 instance stop request sent for " + getInstanceId());
        toComputer().disconnect(null);
    } catch (AmazonClientException e) {
        Instance i = getInstance(getInstanceId(), getCloud());
        LOGGER.log(Level.WARNING,
                "Failed to stop EC2 instance: " + getInstanceId() + " info: " + ((i != null) ? i : ""), e);
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2StopInstanceTask.java

License:Apache License

@TaskAction
public void stopInstance() {
    // to enable conventionMappings feature
    List<String> instanceIds = getInstanceIds();

    if (instanceIds.isEmpty()) {
        return;/*www.j  a  va  2 s .c om*/
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    stopInstancesResult = ec2.stopInstances(new StopInstancesRequest(instanceIds));
    getLogger().info("Stop EC2 instance {} requested", instanceIds);
}

From source file:org.elasticdroid.model.ControlInstancesModel.java

License:Open Source License

/**
 * Method that does the actual work of starting or stopping the instances
 * //from   www  .ja  v  a 2  s . c o m
 * This method uses the stop boolean to identify whether the instances should be stopped 
 * (stop = true) or started (stop = false).
 * 
 * @return Returns one of the following:
 * <ul>
 *    <li>newInstanceStates: Returns a list of stateCodes and state names for all of the instances
 *    </li>
 *    <li> AmazonServiceException</li>
 *    <li> AmazonClientException</li>
 * </ul>
 * 
 */
public Object controlInstances(List<String> instances) {

    for (String instance : instances) {
        Log.v(TAG, "Starting instance: " + instance);
    }

    //create credentials using the BasicAWSCredentials class
    BasicAWSCredentials credentials = new BasicAWSCredentials(connectionData.get("accessKey"),
            connectionData.get("secretAccessKey"));
    //create Amazon EC2 Client object, and set tye end point to the region. params[3]
    //contains endpoint
    AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
    //override the default connection endpoint if provided.
    if (connectionData.get("endpoint") != null) {
        amazonEC2Client.setEndpoint(connectionData.get("endpoint"));
    }

    //if you want to start an instance
    if (operationType == ControlType.START_INSTANCE) {
        StartInstancesRequest request = new StartInstancesRequest(instances);
        StartInstancesResult result = null;
        try {
            result = amazonEC2Client.startInstances(request);
        } catch (AmazonServiceException amazonServiceException) {
            return amazonServiceException;
        } catch (AmazonClientException amazonClientException) {
            return amazonClientException;
        }
        //redundant check.
        if (result != null) {
            return result.getStartingInstances();
        }
    }
    //stop = true, start the instance.
    else {
        StopInstancesRequest request = new StopInstancesRequest(instances);
        StopInstancesResult result = null;

        try {
            result = amazonEC2Client.stopInstances(request);
        } catch (AmazonServiceException amazonServiceException) {
            return amazonServiceException;
        } catch (AmazonClientException amazonClientException) {
            return amazonClientException;
        }

        if (result != null) {
            return result.getStoppingInstances();
        }
    }

    return null;
}

From source file:org.onebusaway.admin.service.server.impl.BundleServerServiceImpl.java

License:Apache License

@Override
public String stop(String instanceId) {
    if (!_isAws) {
        return LOCAL_HOST;
    }// ww  w  .  java2  s.co m
    if (LOCAL_HOST.equalsIgnoreCase(instanceId)) {
        return instanceId;
    }

    List<String> instances = new ArrayList<String>();
    instances.add(instanceId);
    StopInstancesRequest stopInstancesRequest = new StopInstancesRequest(instances);
    StopInstancesResult stopInstancesResult = _ec2.stopInstances(stopInstancesRequest);
    InstanceStateChange change = null;
    if (!stopInstancesResult.getStoppingInstances().isEmpty()) {
        change = stopInstancesResult.getStoppingInstances().get(0);
        _log.info("from state=" + change.getPreviousState() + " to state=" + change.getCurrentState());
        return change.getInstanceId();
    }
    return null;
}

From source file:org.xmlsh.aws.gradle.ec2.AmazonEC2StopInstanceTask.java

License:BSD License

@TaskAction
public void stopInstance() {
    // to enable conventionMappings feature
    List<String> instanceIds = getInstanceIds();

    if (instanceIds.isEmpty())
        return;//from w  w  w  .jav  a 2 s. c  o m

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    stopInstancesResult = ec2.stopInstances(new StopInstancesRequest(instanceIds));
    getLogger().info("Stop EC2 instance {} requested", instanceIds);
}

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

@Override
public StopInstancesResult stopInstances(List<String> instanceIds) {
    return stopInstances(new StopInstancesRequest(instanceIds));
}