Search in sources :

Example 1 with GetHostsResult

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();
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) GetHostsResult(build.buildfarm.v1test.GetHostsResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) Host(build.buildfarm.v1test.Host) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 2 with GetHostsResult

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());
    }
}
Also used : GetHostsResult(build.buildfarm.v1test.GetHostsResult)

Aggregations

GetHostsResult (build.buildfarm.v1test.GetHostsResult)2 Host (build.buildfarm.v1test.Host)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 Instance (com.amazonaws.services.ec2.model.Instance)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 ArrayList (java.util.ArrayList)1