From 69f547d7370020f3d7222c993e68ff178a8733a5 Mon Sep 17 00:00:00 2001 From: jonmv Date: Wed, 23 Aug 2023 14:23:13 +0200 Subject: Return build number with submit response --- .../ai/vespa/hosted/api/ControllerHttpClient.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'hosted-api') 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 87bf2057bc6..7768c1a1712 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 @@ -68,6 +68,8 @@ public abstract class ControllerHttpClient { private final HttpClient client; private final URI endpoint; + public record SubmitResult(String message, long id) { } + /** Creates an HTTP client against the given endpoint, using the given HTTP client builder to create a client. */ protected ControllerHttpClient(URI endpoint, SSLContext sslContext) { if (sslContext == null) { @@ -113,14 +115,14 @@ public abstract class ControllerHttpClient { } /** Sends the given submission to the remote controller and returns the version of the accepted package, or throws if this fails. */ - public String submit(Submission submission, TenantName tenant, ApplicationName application) { - return toMessage(send(request(HttpRequest.newBuilder(applicationPath(tenant, application).resolve("submit")) - .timeout(Duration.ofMinutes(30)), - POST, - new MultiPartStreamer().addJson("submitOptions", metaToJson(submission)) - .addFile("applicationZip", submission.applicationZip()) - .addFile("applicationTestZip", submission.applicationTestZip())), - 1)); + public SubmitResult submit(Submission submission, TenantName tenant, ApplicationName application) { + return toSubmitResult(send(request(HttpRequest.newBuilder(applicationPath(tenant, application).resolve("submit")) + .timeout(Duration.ofMinutes(30)), + POST, + new MultiPartStreamer().addJson("submitOptions", metaToJson(submission)) + .addFile("applicationZip", submission.applicationZip()) + .addFile("applicationTestZip", submission.applicationTestZip())), + 1)); } /** Sends the given deployment to the given application in the given zone, or throws if this fails. */ @@ -462,6 +464,12 @@ public abstract class ControllerHttpClient { return toInspector(response).field("message").asString(); } + private static SubmitResult toSubmitResult(HttpResponse response) { + Inspector rootObject = toInspector(response); + return new SubmitResult(rootObject.field("message").asString(), + rootObject.field("build").asLong()); + } + private static DeploymentResult toDeploymentResult(HttpResponse response) { Inspector rootObject = toInspector(response); return new DeploymentResult(rootObject.field("message").asString(), -- cgit v1.2.3