Search in sources :

Example 86 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.

the class InstanceInVPC method checkInstancesInVPC.

private Set<String> checkInstancesInVPC(String region, Collection<String> instances) {
    Set<String> failedInstances = Sets.newHashSet();
    for (String instanceId : instances) {
        for (Instance awsInstance : getAWSInstances(region, instanceId)) {
            if (awsInstance.getVpcId() == null) {
                LOGGER.info(String.format("Instance %s is not in a virtual private cloud", instanceId));
                failedInstances.add(instanceId);
            }
        }
    }
    return failedInstances;
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance)

Example 87 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.

the class InstanceTooOld method getInstanceLaunchTimes.

/**
 * Gets the launch time (in milliseconds) for a list of instance ids of the same region. The default
 * implementation is using an AWS client. The method can be overridden in subclasses to get the instance
 * launch times differently.
 * @param region
 *      the region of the instances
 * @param instanceIds
 *      the instance ids, all instances should be in the same region.
 * @return
 *      the map from instance id to the launch time in milliseconds
 */
protected Map<String, Long> getInstanceLaunchTimes(String region, String... instanceIds) {
    Map<String, Long> result = Maps.newHashMap();
    if (instanceIds == null || instanceIds.length == 0) {
        return result;
    }
    AWSClient awsClient = new AWSClient(region, awsCredentialsProvider);
    for (Instance instance : awsClient.describeInstances(instanceIds)) {
        if (instance.getLaunchTime() != null) {
            result.put(instance.getInstanceId(), instance.getLaunchTime().getTime());
        } else {
            LOGGER.warn(String.format("No launch time found for instance %s", instance.getInstanceId()));
        }
    }
    return result;
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) AWSClient(com.netflix.simianarmy.client.aws.AWSClient)

Example 88 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class RebootInstance method rebootEC2Instance.

// snippet-start:[ec2.java2.reboot_instance.main]
public static void rebootEC2Instance(Ec2Client ec2, String instanceId) {
    try {
        RebootInstancesRequest request = RebootInstancesRequest.builder().instanceIds(instanceId).build();
        ec2.rebootInstances(request);
        System.out.printf("Successfully rebooted instance %s", instanceId);
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : RebootInstancesRequest(software.amazon.awssdk.services.ec2.model.RebootInstancesRequest) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception)

Example 89 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class StartStopInstance method startInstance.

// snippet-start:[ec2.java2.start_stop_instance.start]
public static void startInstance(Ec2Client ec2, String instanceId) {
    StartInstancesRequest request = StartInstancesRequest.builder().instanceIds(instanceId).build();
    ec2.startInstances(request);
    System.out.printf("Successfully started instance %s", instanceId);
}
Also used : StartInstancesRequest(software.amazon.awssdk.services.ec2.model.StartInstancesRequest)

Example 90 with Instance

use of software.amazon.awssdk.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.

the class StartStopInstance method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "   <instanceId>\n\n" + "Where:\n" + "   instanceId - an instance id value that you can obtain from the AWS Console. \n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String instanceId = args[0];
    boolean start;
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    if (args[1].equals("start")) {
        start = true;
    } else {
        start = false;
    }
    if (start) {
        startInstance(ec2, instanceId);
    } else {
        stopInstance(ec2, instanceId);
    }
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)86 ArrayList (java.util.ArrayList)43 Reservation (com.amazonaws.services.ec2.model.Reservation)39 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)31 List (java.util.List)23 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)22 HashMap (java.util.HashMap)22 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)18 Operation (com.vmware.xenon.common.Operation)18 Tag (com.amazonaws.services.ec2.model.Tag)17 Map (java.util.Map)17 Test (org.junit.Test)16 Filter (com.amazonaws.services.ec2.model.Filter)14 HashSet (java.util.HashSet)13 Volume (com.amazonaws.services.ec2.model.Volume)12 Utils (com.vmware.xenon.common.Utils)12 TimeUnit (java.util.concurrent.TimeUnit)12 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)11 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)11 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)10