diff options
3 files changed, 33 insertions, 15 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 9c563306cee..63de0fd8373 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 @@ -31,6 +31,7 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.OptionalLong; import java.util.concurrent.Callable; import java.util.function.Supplier; import java.util.stream.Stream; @@ -285,7 +286,8 @@ public abstract class ControllerHttpClient { })); return new DeploymentLog(entries, rootObject.field("active").asBool(), - rootObject.field("lastId").asLong()); + rootObject.field("lastId").valid() ? OptionalLong.of(rootObject.field("lastId").asLong()) + : OptionalLong.empty()); } private static Slime toSlime(byte[] data) { 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 07d93a3519b..f2da64e9403 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 @@ -2,6 +2,7 @@ package ai.vespa.hosted.api; import java.time.Instant; import java.util.List; +import java.util.OptionalLong; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.toUnmodifiableList; @@ -15,9 +16,9 @@ public class DeploymentLog { private final List<Entry> entries; private final boolean active; - private final long last; + private final OptionalLong last; - public DeploymentLog(List<Entry> entries, boolean active, long last) { + public DeploymentLog(List<Entry> entries, boolean active, OptionalLong last) { this.entries = entries.stream().sorted(comparing(Entry::at)).collect(toUnmodifiableList()); this.active = active; this.last = last; @@ -31,7 +32,7 @@ public class DeploymentLog { return active; } - public long last() { + public OptionalLong last() { return last; } diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java index 503dcdea629..63bb21430ad 100644 --- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java +++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java @@ -1,8 +1,10 @@ package ai.vespa.hosted.plugin; +import ai.vespa.hosted.api.ControllerHttpClient; import ai.vespa.hosted.api.Deployment; import ai.vespa.hosted.api.DeploymentLog; import ai.vespa.hosted.api.DeploymentResult; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.zone.ZoneId; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -62,18 +64,31 @@ public class DeployMojo extends AbstractVespaMojo { DeploymentResult result = controller.deploy(deployment, id, zone); System.out.println(result.message()); - if (follow) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss").withZone(ZoneOffset.UTC); - DeploymentLog log = controller.deploymentLog(id, zone, result.run()); - do { - for (DeploymentLog.Entry entry : log.entries()) - System.out.printf("[%10s%10s] %s\n", - entry.level().toUpperCase(), - formatter.format(entry.at()), - entry.message()); - log = controller.deploymentLog(id, zone, result.run(), log.last()); + if (follow) tailLogs(id, zone, result.run()); + } + + private void tailLogs(ApplicationId id, ZoneId zone, long run) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss").withZone(ZoneOffset.UTC); + long last = -1; + while (true) { + DeploymentLog log = controller.deploymentLog(id, zone, run, last); + for (DeploymentLog.Entry entry : log.entries()) + System.out.printf("%8s%11s %s\n", + "[" + entry.level().toUpperCase(), + formatter.format(entry.at()) + "]", + entry.message()); + last = log.last().orElse(last); + + if (!log.isActive()) + break; + + try { + Thread.sleep(1000); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + break; } - while (log.isActive()); } } |