From 9fc0828a88678540ed847a1412cdae3940f39c31 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Wed, 13 Oct 2021 07:19:51 +0200 Subject: Add method for getting instance info Note: Only a small part of response included in InstanceInfo --- .../ai/vespa/hosted/api/ControllerHttpClient.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'hosted-api/src/main') diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java b/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java index 907d57fffe7..4a79857955a 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java @@ -200,6 +200,14 @@ public abstract class ControllerHttpClient { tenantName); } + /** Returns instance info for the given application id. */ + public InstanceInfo applicationInstance(ApplicationId applicationId) { + return toInstanceInfo(send(request(HttpRequest.newBuilder(instancePath(applicationId)) + .timeout(Duration.ofSeconds(20)), + GET)), + applicationId); + } + /** Follows the given deployment job until it is done, or this thread is interrupted, at which point the current status is returned. */ public DeploymentLog followDeploymentUntilDone(ApplicationId id, ZoneId zone, long run, Consumer out) { @@ -470,6 +478,15 @@ public abstract class ControllerHttpClient { return applicationIds; } + // Note: Much more data in response, only the interesting parts of response are included in InstanceInfo for now + private static InstanceInfo toInstanceInfo(HttpResponse response, ApplicationId applicationId) { + Set zones = new HashSet<>(); + toInspector(response).field("instances").traverse((ArrayTraverser) (___, entryObject) -> + zones.add(ZoneId.from(entryObject.field("environment").asString(), + entryObject.field("region").asString()))); + return new InstanceInfo(applicationId, zones); + } + private static Slime toSlime(byte[] data) { return SlimeUtils.jsonToSlime(data); } @@ -541,4 +558,24 @@ public abstract class ControllerHttpClient { } } + public static class InstanceInfo { + + private final ApplicationId applicationId; + private final Set zones; + + InstanceInfo(ApplicationId applicationId, Set zones) { + this.applicationId = applicationId; + this.zones = zones; + } + + public ApplicationId applicationId() { + return applicationId; + } + + public Set zones() { + return zones; + } + + } + } -- cgit v1.2.3