Search in sources :

Example 1 with RebootInstancesRequest

use of com.amazonaws.services.ec2.model.RebootInstancesRequest in project aws-doc-sdk-examples by awsdocs.

the class RebootInstance method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply an instance id\n" + "Ex: RebootInstnace <instance_id>\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String instance_id = args[0];
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    RebootInstancesRequest request = new RebootInstancesRequest().withInstanceIds(instance_id);
    RebootInstancesResult response = ec2.rebootInstances(request);
    System.out.printf("Successfully rebooted instance %s", instance_id);
}
Also used : RebootInstancesRequest(com.amazonaws.services.ec2.model.RebootInstancesRequest) RebootInstancesResult(com.amazonaws.services.ec2.model.RebootInstancesResult) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2)

Example 2 with RebootInstancesRequest

use of com.amazonaws.services.ec2.model.RebootInstancesRequest in project camel by apache.

the class EC2Producer method rebootInstances.

private void rebootInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    RebootInstancesRequest request = new RebootInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } else {
        throw new IllegalArgumentException("Instances Ids must be specified");
    }
    try {
        LOG.trace("Rebooting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
        ec2Client.rebootInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Reboot Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
}
Also used : RebootInstancesRequest(com.amazonaws.services.ec2.model.RebootInstancesRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection)

Aggregations

RebootInstancesRequest (com.amazonaws.services.ec2.model.RebootInstancesRequest)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 RebootInstancesResult (com.amazonaws.services.ec2.model.RebootInstancesResult)1 Collection (java.util.Collection)1