use of build.buildfarm.v1test.GetHostsResult 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 build.buildfarm.v1test.GetHostsResult in project bazel-buildfarm by bazelbuild.
the class AdminService method getHosts.
@Override
public void getHosts(GetHostsRequest request, StreamObserver<GetHostsResult> responseObserver) {
try {
GetHostsResult result = null;
if (adminController != null) {
result = adminController.getHosts(request.getFilter(), request.getAgeInMinutes(), request.getStatus());
}
responseObserver.onNext(result);
responseObserver.onCompleted();
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not get hosts.", e);
responseObserver.onError(io.grpc.Status.fromThrowable(e).asException());
}
}
Aggregations