aboutsummaryrefslogtreecommitdiffstats
path: root/hosted-api
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-10-13 07:19:51 +0200
committerHarald Musum <musum@yahooinc.com>2021-10-13 07:19:51 +0200
commit9fc0828a88678540ed847a1412cdae3940f39c31 (patch)
treed2c016fb8d694077e9e5a6b47742a57268052e58 /hosted-api
parent9512873b312a5348e29662c1bcd0e07a385c44e1 (diff)
Add method for getting instance info
Note: Only a small part of response included in InstanceInfo
Diffstat (limited to 'hosted-api')
-rw-r--r--hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java37
1 files changed, 37 insertions, 0 deletions
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<DeploymentLog.Entry> 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<byte[]> response, ApplicationId applicationId) {
+ Set<ZoneId> 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<ZoneId> zones;
+
+ InstanceInfo(ApplicationId applicationId, Set<ZoneId> zones) {
+ this.applicationId = applicationId;
+ this.zones = zones;
+ }
+
+ public ApplicationId applicationId() {
+ return applicationId;
+ }
+
+ public Set<ZoneId> zones() {
+ return zones;
+ }
+
+ }
+
}