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;
}
}
}
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;
}
Aggregations