diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2019-08-22 12:58:54 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2019-08-22 12:58:54 +0200 |
commit | 483aeab1a54bde8a24f428b937f700da35564047 (patch) | |
tree | 38b96f2bbe1d5d28160cf2a4f1ffb971f865a3c2 /vespa-maven-plugin | |
parent | c0444cf8384a34981530d06743af26f163248744 (diff) |
Factor out getting the zone of a deployment given optional region and environment
Diffstat (limited to 'vespa-maven-plugin')
-rw-r--r-- | vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java | 13 | ||||
-rw-r--r-- | vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java | 8 |
2 files changed, 14 insertions, 7 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 e2bbbb86706..6b7af01a3ea 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 @@ -2,6 +2,8 @@ package ai.vespa.hosted.plugin; import ai.vespa.hosted.api.ControllerHttpClient; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.zone.ZoneId; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; @@ -68,6 +70,17 @@ public abstract class AbstractVespaMojo extends AbstractMojo { : ControllerHttpClient.withKeyAndCertificate(URI.create(endpoint), Paths.get(privateKeyFile), Paths.get(certificateFile)); } + protected ZoneId zoneOf(String environment, String region) { + if (region == null) + return controller.defaultZone(environment != null ? Environment.from(environment) + : Environment.dev); + + if (environment == null) + throw new IllegalArgumentException("Environment must be specified if region is specified"); + + return ZoneId.from(environment, region); + } + protected String projectPathOf(String first, String... rest) { return project.getBasedir().toPath().resolve(Path.of(first, rest)).toString(); } 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 d62ccb1bba4..d6d98b945c9 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 @@ -4,7 +4,6 @@ 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.Environment; import com.yahoo.config.provision.zone.ZoneId; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -42,12 +41,7 @@ public class DeployMojo extends AbstractVespaMojo { projectPathOf("target", "application.zip")))); if (vespaVersion != null) deployment = deployment.atVersion(vespaVersion); - ZoneId zone = region == null - ? controller.defaultZone(environment == null - ? Environment.dev - : Environment.from(environment)) - : ZoneId.from(environment, region); - + ZoneId zone = zoneOf(environment, region); DeploymentResult result = controller.deploy(deployment, id, zone); getLog().info(result.message()); |