use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project bazel-buildfarm by bazelbuild.
the class AwsAdmin method getInstanceId.
private Instance getInstanceId(String privateDnsName) {
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withFilters(new Filter().withName("private-dns-name").withValues(privateDnsName));
DescribeInstancesResult instancesResult = ec2.describeInstances(describeInstancesRequest);
for (Reservation r : instancesResult.getReservations()) {
for (Instance e : r.getInstances()) {
if (e.getPrivateDnsName() != null && e.getPrivateDnsName().equals(privateDnsName)) {
return e;
}
}
}
return null;
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project bazel-buildfarm by bazelbuild.
the class AwsAdmin method getHosts.
@Override
public GetHostsResult getHosts(String filter, int ageInMinutes, String status) {
GetHostsResult.Builder resultBuilder = GetHostsResult.newBuilder();
List<Host> hosts = new ArrayList<>();
DescribeInstancesResult instancesResult = ec2.describeInstances(new DescribeInstancesRequest().withFilters(new Filter().withName("tag-value").withValues(filter)));
long hostNum = 1L;
for (Reservation r : instancesResult.getReservations()) {
for (Instance e : r.getInstances()) {
long uptime = getHostUptimeInMinutes(e.getLaunchTime());
if (e.getPrivateIpAddress() != null && uptime > ageInMinutes && status.equalsIgnoreCase(e.getState().getName())) {
Host.Builder hostBuilder = Host.newBuilder();
hostBuilder.setHostNum(hostNum++);
hostBuilder.setDnsName(e.getPrivateDnsName());
hostBuilder.setHostId(e.getInstanceId());
hostBuilder.setIpAddress(e.getPrivateIpAddress());
hostBuilder.setLaunchTime(Timestamps.fromMillis(e.getLaunchTime().getTime()));
hostBuilder.setLifecycle(e.getInstanceLifecycle() != null ? e.getInstanceLifecycle() : "on demand");
hostBuilder.setNumCores(e.getCpuOptions().getCoreCount());
hostBuilder.setState(e.getState().getName());
hostBuilder.setType(e.getInstanceType());
hostBuilder.setUptimeMinutes(uptime);
hosts.add(hostBuilder.build());
}
}
}
resultBuilder.addAllHosts(hosts);
resultBuilder.setNumHosts(hosts.size());
logger.log(Level.FINE, String.format("Got %d hosts for filter: %s", hosts.size(), filter));
return resultBuilder.build();
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project bazel-buildfarm by bazelbuild.
the class AdminServiceImpl method getInstanceIdByPrivateDnsName.
@Override
public String getInstanceIdByPrivateDnsName(String dnsName) {
Filter filter = new Filter().withName("private-dns-name").withValues(dnsName);
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withFilters(filter);
DescribeInstancesResult instancesResult = ec2.describeInstances(describeInstancesRequest);
for (Reservation r : instancesResult.getReservations()) {
for (com.amazonaws.services.ec2.model.Instance e : r.getInstances()) {
if (e.getPrivateDnsName() != null && e.getPrivateDnsName().equals(dnsName)) {
return e.getInstanceId();
}
}
}
return null;
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project solarnetwork-central by SolarNetwork.
the class AwsVirtualMachineBiz method virtualMachinesForIds.
@Override
public Iterable<VirtualMachine> virtualMachinesForIds(Set<String> ids) {
AmazonEC2 client = getEc2Client();
DescribeInstancesRequest req = new DescribeInstancesRequest().withInstanceIds(ids);
DescribeInstancesResult res;
List<VirtualMachine> results = new ArrayList<>(ids.size());
do {
res = client.describeInstances(req);
for (Reservation reservation : res.getReservations()) {
for (Instance inst : reservation.getInstances()) {
results.add(new Ec2VirtualMachine(inst));
}
}
req.setNextToken(res.getNextToken());
} while (res.getNextToken() != null);
return results;
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project ignite-extensions by apache.
the class TcpDiscoveryElbIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
initClients();
List<String> instanceIds = new ArrayList<>();
DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName);
List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions();
for (LoadBalancerDescription desc : descs) {
for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId());
}
DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations();
List<InetSocketAddress> addrs = new ArrayList<>();
for (Reservation reservation : reservations) {
List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();
for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0));
}
return addrs;
}
Aggregations