Example usage for com.amazonaws.services.ec2 AmazonEC2 stopInstances

List of usage examples for com.amazonaws.services.ec2 AmazonEC2 stopInstances

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2 AmazonEC2 stopInstances.

Prototype

StopInstancesResult stopInstances(StopInstancesRequest stopInstancesRequest);

Source Link

Document

Stops an Amazon EBS-backed instance.

Usage

From source file:aws.example.ec2.StartStopInstance.java

License:Open Source License

public static void stopInstance(String instance_id) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DryRunSupportedRequest<StopInstancesRequest> dry_request = () -> {
        StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);

        return request.getDryRunRequest();
    };//from   www  .  java 2s .c o  m

    DryRunResult dry_response = ec2.dryRun(dry_request);

    if (!dry_response.isSuccessful()) {
        System.out.printf("Failed dry run to stop instance %s", instance_id);
        throw dry_response.getDryRunResponse();
    }

    StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);

    ec2.stopInstances(request);

    System.out.printf("Successfully stop instance %s", instance_id);
}

From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java

License:Apache License

public void stopInstances(List<String> instanceIds, AmazonEC2 ec2Client)
        throws RemoteException, InterruptedException {
    StopInstancesRequest stopRequest = new StopInstancesRequest(instanceIds);
    ec2Client.stopInstances(stopRequest);
    for (String instanceId : instanceIds) {
        waitForState(instanceId, "stopped", 8, ec2Client);
    }/* w w w. j  a v  a2s .c  o  m*/
}

From source file:ec2.StartStopInstance.java

License:Open Source License

public static void stopInstance(String instanceId) {

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DryRunSupportedRequest<StopInstancesRequest> stopInstanceDryRun = () -> {
        StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instanceId);

        return request.getDryRunRequest();
    };/*w  w  w  .  j  av a2  s.  c o  m*/

    DryRunResult dryRunResponse = ec2.dryRun(stopInstanceDryRun);

    if (!dryRunResponse.isSuccessful()) {
        System.out.printf("Failed dry run to stop instance %s", instanceId);
        throw dryRunResponse.getDryRunResponse();
    }

    StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instanceId);

    ec2.stopInstances(request);

    System.out.printf("Successfully stop instance %s", instanceId);
}

From source file:edu.umass.cs.aws.support.AWSEC2.java

License:Apache License

/**
 * Stop an instance/*from   w ww  .  jav a2  s  .c o m*/
 *
 * @param ec2
 * @param createdInstanceId
 */
public static void stopInstance(AmazonEC2 ec2, String createdInstanceId) {
    System.out.println("Stopping Instance:" + createdInstanceId);
    List<String> instanceIds = new LinkedList<>();
    instanceIds.add(createdInstanceId);

    StopInstancesRequest stopIR = new StopInstancesRequest(instanceIds);
    ec2.stopInstances(stopIR);
}

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

License:Open Source License

void stop() {
    try {// ww  w. java  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;/*from   w w  w.j av  a  2  s . com*/
    }

    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.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.j  a  v a2s.  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);
}