diff options
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java | 26 | ||||
-rw-r--r-- | vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java | 20 |
2 files changed, 27 insertions, 19 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 f1486ae7117..6fba083e607 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 @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.List; import java.util.OptionalLong; import java.util.concurrent.Callable; +import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Stream; @@ -145,6 +146,31 @@ public abstract class ControllerHttpClient { GET))); } + /** 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) { + long last = -1; + DeploymentLog log; + while (true) { + log = deploymentLog(id, zone, run, last); + for (DeploymentLog.Entry entry : log.entries()) + out.accept(entry); + last = log.last().orElse(last); + + if ( ! log.isActive()) + break; + + try { + Thread.sleep(1000); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + break; + } + } + return log; + } + /** Returns the sorted list of log entries from the deployment job of the given ids. */ public DeploymentLog deploymentLog(ApplicationId id, ZoneId zone, long run) { return deploymentLog(id, zone, run, -1); 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 851b1fa214c..cc714f38290 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 @@ -60,25 +60,7 @@ public class DeployMojo extends AbstractVespaDeploymentMojo { } private void tailLogs(ApplicationId id, ZoneId zone, long run) throws MojoFailureException, MojoExecutionException { - long last = -1; - DeploymentLog log; - while (true) { - log = controller.deploymentLog(id, zone, run, last); - for (DeploymentLog.Entry entry : log.entries()) - print(entry); - last = log.last().orElse(last); - - if ( ! log.isActive()) - break; - - try { - Thread.sleep(1000); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } + DeploymentLog log = controller.followDeploymentUntilDone(id, zone, run, this::print); switch (log.status()) { case success: return; case error: throw new MojoExecutionException("Unexpected error during deployment; see log for details"); |