diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2019-09-12 12:59:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-12 12:59:54 +0200 |
commit | 4c4072e53213f75c739bbfc152e884cab94bdf3c (patch) | |
tree | 2c50bf414541b679c664a4ef10f466d01593d5e3 /vespa-maven-plugin | |
parent | cc8a4ee468a4a403d1be54260259b060851b35e6 (diff) | |
parent | 10cc1a0232d7f09116fb9eeaaa646c67ce3c29d5 (diff) |
Merge pull request #10590 from vespa-engine/jvenstad/reflect-deployment-status-in-plugin-exit
Reflect deployment job status when plugin exists
Diffstat (limited to 'vespa-maven-plugin')
-rw-r--r-- | vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java | 6 | ||||
-rw-r--r-- | vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java | 20 |
2 files changed, 22 insertions, 4 deletions
diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java index e59b94ead4a..bf8f6f83f53 100644 --- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java +++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java @@ -4,6 +4,7 @@ import ai.vespa.hosted.api.ControllerHttpClient; import com.yahoo.config.provision.ApplicationId; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -44,11 +45,14 @@ public abstract class AbstractVespaMojo extends AbstractMojo { protected ControllerHttpClient controller; @Override - public final void execute() throws MojoExecutionException { + public final void execute() throws MojoExecutionException, MojoFailureException { try { setup(); doExecute(); } + catch (MojoFailureException | MojoExecutionException e) { + throw e; + } catch (Exception e) { throw new MojoExecutionException("Execution failed for application '" + id + "':", e); } 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 9ef31cafb1b..7deffd37a79 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 @@ -5,6 +5,8 @@ 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.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -30,7 +32,7 @@ public class DeployMojo extends AbstractVespaDeploymentMojo { private boolean follow; @Override - protected void doExecute() { + protected void doExecute() throws MojoFailureException, MojoExecutionException { Deployment deployment = Deployment.ofPackage(Paths.get(firstNonBlank(applicationZip, projectPathOf("target", "application.zip")))); if (vespaVersion != null) deployment = deployment.atVersion(vespaVersion); @@ -42,10 +44,11 @@ public class DeployMojo extends AbstractVespaDeploymentMojo { if (follow) tailLogs(id, zone, result.run()); } - private void tailLogs(ApplicationId id, ZoneId zone, long run) { + private void tailLogs(ApplicationId id, ZoneId zone, long run) throws MojoFailureException, MojoExecutionException { long last = -1; + DeploymentLog log; while (true) { - DeploymentLog log = controller.deploymentLog(id, zone, run, last); + log = controller.deploymentLog(id, zone, run, last); for (DeploymentLog.Entry entry : log.entries()) print(entry); last = log.last().orElse(last); @@ -61,6 +64,17 @@ public class DeployMojo extends AbstractVespaDeploymentMojo { break; } } + switch (log.status()) { + case success: return; + case error: throw new MojoExecutionException("Unexpected error during deployment; see log for details"); + case aborted: throw new MojoFailureException("Deployment was aborted, probably by a newer deployment"); + case outOfCapacity: throw new MojoFailureException("No capacity left in zone; please contact the Vespa team"); + case deploymentFailed: throw new MojoFailureException("Deployment failed; see log for details"); + case installationFailed: throw new MojoFailureException("Installation failed; see Vespa log for details"); + case running: throw new MojoFailureException("Deployment not completed"); + case testFailure: throw new IllegalStateException("Unexpected status; tests are not run for manual deployments"); + default: throw new IllegalArgumentException("Unexpected status '" + log.status() + "'"); + } } private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss").withZone(ZoneOffset.UTC); |