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

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

Introduction

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

Prototype


public void setInstanceIds(java.util.Collection<String> instanceIds) 

Source Link

Document

The IDs of the instances.

Usage

From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.ec2.redmine.RedmineEC2DeploymentWrapper.java

License:Open Source License

@Override
public void undeployResource(String resourceID) throws Exception {
    //Reading the credentials
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties"));
    String accessKey = properties.getProperty("accessKey");
    String secretKey = properties.getProperty("secretKey-NULL");
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonEC2Client client = new AmazonEC2Client(credentials);

    StopInstancesRequest request = new StopInstancesRequest();
    List<String> idList = new ArrayList<String>();
    idList.add(resourceID);/*  w  ww  .  j a  v a2  s. co  m*/
    request.setInstanceIds(idList);

    StopInstancesResult result = client.stopInstances(request);
}

From source file:com.carrotgarden.maven.aws.ecc.CarrotElasticCompute.java

License:BSD License

/**
 * http://shlomoswidler.com/2009/07/ec2-instance-life-cycle.html
 *//*from www.ja v  a 2  s  .co m*/
public void instanceStop(final String instanceId) throws Exception {

    final Instance instance = findInstance(instanceId);

    final InstanceStateName state = stateFrom(instance);

    logger.info("stop: current state=" + state);

    switch (state) {
    case Pending:
        waitForIstanceState(instanceId, InstanceStateName.Running);
    case Running:
        break;
    case Stopping:
        waitForIstanceState(instanceId, InstanceStateName.Stopped);
    case Stopped:
    case Terminated:
    case ShuttingDown:
        return;
    default:
        throw new IllegalStateException("start: unknown state");
    }

    final StopInstancesRequest request = new StopInstancesRequest();
    request.setInstanceIds(wrapList(instanceId));

    final StopInstancesResult result = amazonClient.stopInstances(request);

    waitForIstanceState(instanceId, InstanceStateName.Stopped);

}

From source file:com.ipcglobal.awscdh.config.ManageEc2.java

License:Apache License

/**
 * Stop all EC2 instances./*from  w  w w .j  a  v a2 s.c o  m*/
 *
 * @param instances the instances
 * @throws Exception the exception
 */
public void stopAllInstances(List<Instance> instances) throws Exception {
    List<String> instanceIds = new ArrayList<String>();
    for (Instance instance : instances)
        instanceIds.add(instance.getInstanceId());

    log.info("Initiating Stop for " + instanceIds.size() + " instances");
    StopInstancesRequest stopInstancesRequest = new StopInstancesRequest();
    stopInstancesRequest.setInstanceIds(instanceIds);
    StopInstancesResult stopInstancesResult = ec2Client.stopInstances(stopInstancesRequest);
    log.info("stopInstancesResult: " + stopInstancesResult);

    log.info("Sleeping for 1 minute after Stop initiated");
    Thread.sleep(1 * 60000L);

    long before = System.currentTimeMillis();
    log.info("Verifying Instances Stopped - Begin");
    verifyInstancesStopped(instances);
    log.info("Verifying Instances Stopped - Complete, elapsed="
            + Utils.convertMSecsToHMmSs(System.currentTimeMillis() - before));
}

From source file:com.stfciz.aws.ec2.data.EC2InstancesManager.java

/**
 *
 * @param instanceIds// ww  w  .ja va  2 s  . c o m
 */
public void stopInstance(String[] instanceIds) {
    StopInstancesRequest request = new StopInstancesRequest();
    request.setInstanceIds(Arrays.asList(instanceIds));
    this.amazonEC2Client.stopInstances(request);
}

From source file:com.yosanai.java.aws.console.DefaultAWSConnectionProvider.java

License:Open Source License

@Override
public void stopInstances(String... instanceIds) throws Exception {
    List<String> instanceIdsFiltered = getInstances(STATE_RUNNING, true, instanceIds);
    if (!instanceIdsFiltered.isEmpty()) {
        StopInstancesRequest stopInstancesRequest = new StopInstancesRequest();
        stopInstancesRequest.setInstanceIds(instanceIdsFiltered);
        getConnection().stopInstances(stopInstancesRequest);
    }/* w w  w.  j  av a  2 s .com*/
}

From source file:jp.aws.test.ec2.EC2Instance.java

License:Apache License

/**
 * ??/*  w ww.j ava2  s  .c  o m*/
 *
 * @throws Exception
 */
public void stop(String instanceId) {
    ArrayList<String> instanceIds = new ArrayList<String>();
    instanceIds.add(instanceId);

    StopInstancesRequest stopInstancesRequest = new StopInstancesRequest();
    stopInstancesRequest.setInstanceIds(instanceIds);
    clientManager.ec2().stopInstances(stopInstancesRequest);
}

From source file:org.gridgain.grid.util.ec2.GridEc2Helper.java

License:GNU General Public License

/**
 * @param instIds Instances' IDs.//from   w w w  . j a va  2  s  .  c  o m
 * @return List of stopped instances' IDs.
 * @throws GridException Thrown in case of any exception.
 */
public List<String> stopInstances(Collection<String> instIds) throws GridException {
    StopInstancesRequest req = new StopInstancesRequest();

    req.setInstanceIds(instIds);

    StopInstancesResult res;

    try {
        res = ec2.stopInstances(req);
    } catch (AmazonClientException ex) {
        throw new GridException("Failed to perform EC2 stop instances request: " + ex.getMessage(), ex);
    }

    List<String> stopIds = new ArrayList<String>();

    if (res.getStoppingInstances() != null)
        for (InstanceStateChange isc : res.getStoppingInstances())
            stopIds.add(isc.getInstanceId());

    return stopIds;
}