Search in sources :

Example 76 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project aws-athena-query-federation by awslabs.

the class Ec2TableProvider method readWithConstraint.

/**
 * Calls DescribeInstances on the AWS EC2 Client returning all instances that match the supplied predicate and attempting
 * to push down certain predicates (namely queries for specific ec2 instance) to EC2.
 *
 * @See TableProvider
 */
@Override
public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker) {
    boolean done = false;
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    ValueSet idConstraint = recordsRequest.getConstraints().getSummary().get("instance_id");
    if (idConstraint != null && idConstraint.isSingleValue()) {
        request.setInstanceIds(Collections.singletonList(idConstraint.getSingleValue().toString()));
    }
    while (!done) {
        DescribeInstancesResult response = ec2.describeInstances(request);
        for (Reservation reservation : response.getReservations()) {
            for (Instance instance : reservation.getInstances()) {
                instanceToRow(instance, spiller);
            }
        }
        request.setNextToken(response.getNextToken());
        if (response.getNextToken() == null || !queryStatusChecker.isQueryRunning()) {
            done = true;
        }
    }
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) ValueSet(com.amazonaws.athena.connector.lambda.domain.predicate.ValueSet)

Example 77 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project onebusaway-application-modules by camsys.

the class BundleServerServiceImpl method getInstance.

private Instance getInstance(String instanceId) {
    try {
        DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
        List<String> list = new ArrayList<String>();
        list.add(instanceId);
        describeInstancesRequest.setInstanceIds(list);
        // this call can timeout and throw AmazonClientException if AWS is having
        // a bad day
        DescribeInstancesResult result = _ec2.describeInstances(describeInstancesRequest);
        if (!result.getReservations().isEmpty()) {
            if (!result.getReservations().get(0).getInstances().isEmpty()) {
                Instance i = result.getReservations().get(0).getInstances().get(0);
                return i;
            }
        }
    } catch (Exception e) {
        _log.error("Call to AWS threw exception", e);
    }
    return null;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)74 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)49 Reservation (com.amazonaws.services.ec2.model.Reservation)47 Instance (com.amazonaws.services.ec2.model.Instance)42 ArrayList (java.util.ArrayList)40 Filter (com.amazonaws.services.ec2.model.Filter)29 List (java.util.List)28 Map (java.util.Map)18 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)17 Collectors (java.util.stream.Collectors)17 Tag (com.amazonaws.services.ec2.model.Tag)13 Inject (javax.inject.Inject)13 Set (java.util.Set)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 TerminateInstancesRequest (com.amazonaws.services.ec2.model.TerminateInstancesRequest)11 TerminateInstancesResult (com.amazonaws.services.ec2.model.TerminateInstancesResult)11 Collection (java.util.Collection)11 DescribeVolumesResult (com.amazonaws.services.ec2.model.DescribeVolumesResult)10 StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)10