From 1bf286b9b95ea1f3705436ca551a29fa4ecb6fc3 Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Tue, 3 Mar 2020 15:33:27 +0100 Subject: Allow aggregating deployment log in client --- .../src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java | 7 ++++--- hosted-api/src/main/java/ai/vespa/hosted/api/DeploymentLog.java | 9 +++++++++ 2 files changed, 13 insertions(+), 3 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 376719aed1d..79c11cf86de 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 @@ -156,11 +156,12 @@ public abstract class ControllerHttpClient { public DeploymentLog followDeploymentUntilDone(ApplicationId id, ZoneId zone, long run, Consumer out) { long last = -1; - DeploymentLog log; + DeploymentLog log = null; while (true) { - log = deploymentLog(id, zone, run, last); - for (DeploymentLog.Entry entry : log.entries()) + DeploymentLog update = deploymentLog(id, zone, run, last); + for (DeploymentLog.Entry entry : update.entries()) out.accept(entry); + log = (log == null ? update : log.updatedWith(update)); last = log.last().orElse(last); if ( ! log.isActive()) diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/DeploymentLog.java b/hosted-api/src/main/java/ai/vespa/hosted/api/DeploymentLog.java index 177c72107e0..9eae9a33cff 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/DeploymentLog.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/DeploymentLog.java @@ -4,6 +4,7 @@ package ai.vespa.hosted.api; import java.time.Instant; import java.util.List; import java.util.OptionalLong; +import java.util.stream.Stream; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.toUnmodifiableList; @@ -27,6 +28,14 @@ public class DeploymentLog { this.last = last; } + /** Returns this log updated with the content of the other. */ + public DeploymentLog updatedWith(DeploymentLog other) { + return new DeploymentLog(Stream.concat(entries.stream(), other.entries.stream()).collect(toUnmodifiableList()), + other.active, + other.status, + other.last); + } + public List entries() { return entries; } -- cgit v1.2.3