use of com.amazonaws.services.ec2.model.Reservation in project GNS by MobilityFirst.
the class AWSEC2 method describeInstances.
/**
* Describe Current Instances
*
* @param ec2
*/
public static void describeInstances(AmazonEC2 ec2) {
StringBuilder output = new StringBuilder();
String prefix = currentTab + "Current Instances: ";
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
Set<Instance> instances = new HashSet<Instance>();
// add all instances to a Set.
for (Reservation reservation : reservations) {
instances.addAll(reservation.getInstances());
}
prefix = prefix.concat(" [" + instances.size() + " total] ");
for (Instance ins : instances) {
// instance state
output.append(prefix);
prefix = ", ";
output.append(ins.getPublicDnsName());
output.append(" (");
output.append(ins.getInstanceId());
output.append(") ");
output.append(ins.getState().getName());
}
System.out.println(output);
}
use of com.amazonaws.services.ec2.model.Reservation in project GNS by MobilityFirst.
the class AWSEC2 method findInstance.
/**
* Find an instance
*
* @param ec2
* @param createdInstanceId
* @return the name of the instance or null
*/
public static Instance findInstance(AmazonEC2 ec2, String createdInstanceId) {
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
Set<Instance> instances = new HashSet<>();
// add all instances to a Set.
for (Reservation reservation : reservations) {
instances.addAll(reservation.getInstances());
}
for (Instance instance : instances) {
if (createdInstanceId.equals(instance.getInstanceId())) {
return instance;
}
}
return null;
}
use of com.amazonaws.services.ec2.model.Reservation in project aws-doc-sdk-examples by awsdocs.
the class DescribeInstances method main.
public static void main(String[] args) {
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
boolean done = false;
while (!done) {
DescribeInstancesRequest request = new DescribeInstancesRequest();
DescribeInstancesResult response = ec2.describeInstances(request);
for (Reservation reservation : response.getReservations()) {
for (Instance instance : reservation.getInstances()) {
System.out.printf("Found reservation with id %s, " + "AMI %s, " + "type %s, " + "state %s " + "and monitoring state %s", instance.getInstanceId(), instance.getImageId(), instance.getInstanceType(), instance.getState().getName(), instance.getMonitoring().getState());
}
}
request.setNextToken(response.getNextToken());
if (response.getNextToken() == null) {
done = true;
}
}
}
use of com.amazonaws.services.ec2.model.Reservation in project druid by druid-io.
the class EC2AutoScaler method idToIpLookup.
@Override
public List<String> idToIpLookup(List<String> nodeIds) {
final List<String> retVal = FluentIterable.from(Lists.partition(nodeIds, 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("instance-id", 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.getPrivateIpAddress();
}
}).toList();
log.debug("Performing lookup: %s --> %s", nodeIds, retVal);
return retVal;
}
use of com.amazonaws.services.ec2.model.Reservation 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;
}
Aggregations