use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project cloudbreak by hortonworks.
the class TagsUtil method checkTagsAws.
protected static void checkTagsAws(Regions region, Collection<String> instanceIdList, Map<String, String> tagsToCheckMap) {
Map<String, String> extractedTagsToCheck = new HashMap<>();
List<Tag> extractedTags;
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
describeInstancesRequest.withInstanceIds(instanceIdList);
DescribeInstancesResult describeInstancesResultAll = ec2.describeInstances(describeInstancesRequest);
List<Reservation> reservationsAll = describeInstancesResultAll.getReservations();
for (Reservation reservation : reservationsAll) {
for (Instance instance : reservation.getInstances()) {
extractedTags = instance.getTags();
Assert.assertNotNull(extractedTags);
for (Tag tag : extractedTags) {
extractedTagsToCheck.put(tag.getKey(), tag.getValue());
}
checkTags(tagsToCheckMap, extractedTagsToCheck);
extractedTags.clear();
}
}
}
use of com.amazonaws.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;
}
use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project druid by druid-io.
the class EC2AutoScaler method ipToIdLookup.
@Override
public List<String> ipToIdLookup(List<String> ips) {
final List<String> retVal = FluentIterable.from(Lists.partition(ips, MAX_AWS_FILTER_VALUES)).transformAndConcat(new Function<List<String>, Iterable<Reservation>>() {
@Override
public Iterable<Reservation> apply(List<String> input) {
return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", input))).getReservations();
}
}).transformAndConcat(new Function<Reservation, Iterable<Instance>>() {
@Override
public Iterable<Instance> apply(Reservation reservation) {
return reservation.getInstances();
}
}).transform(new Function<Instance, String>() {
@Override
public String apply(Instance instance) {
return instance.getInstanceId();
}
}).toList();
log.debug("Performing lookup: %s --> %s", ips, retVal);
return retVal;
}
use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project druid by druid-io.
the class EC2AutoScaler method terminate.
@Override
public AutoScalingData terminate(List<String> ips) {
if (ips.isEmpty()) {
return new AutoScalingData(new ArrayList<>());
}
DescribeInstancesResult result = amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", ips)));
List<Instance> instances = new ArrayList<>();
for (Reservation reservation : result.getReservations()) {
instances.addAll(reservation.getInstances());
}
try {
return terminateWithIds(Lists.transform(instances, new Function<Instance, String>() {
@Override
public String apply(Instance input) {
return input.getInstanceId();
}
}));
} catch (Exception e) {
log.error(e, "Unable to terminate any instances.");
}
return null;
}
Aggregations