diff options
Diffstat (limited to 'vespa-maven-plugin')
-rw-r--r-- | vespa-maven-plugin/pom.xml | 25 | ||||
-rw-r--r-- | vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/SubmitMojo.java | 103 |
2 files changed, 128 insertions, 0 deletions
diff --git a/vespa-maven-plugin/pom.xml b/vespa-maven-plugin/pom.xml index 4516c57f32a..57ce1ccadf8 100644 --- a/vespa-maven-plugin/pom.xml +++ b/vespa-maven-plugin/pom.xml @@ -20,6 +20,31 @@ <dependencies> <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>hosted-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>config-provisioning</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>security-utils</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>vespajlib</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>commons-cli</groupId> + <artifactId>commons-cli</artifactId> + </dependency> + <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> </dependency> diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/SubmitMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/SubmitMojo.java new file mode 100644 index 00000000000..88302c8cec6 --- /dev/null +++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/SubmitMojo.java @@ -0,0 +1,103 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.hosted.plugin; + +import ai.vespa.hosted.api.ControllerHttpClient; +import ai.vespa.hosted.api.Submission; +import com.yahoo.config.provision.ApplicationId; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * Submits a Vespa application package and corresponding test jars to the hosted Vespa API. + * + * @author jonmv + */ +@Mojo(name = "submit") +public class SubmitMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject project; + + @Parameter(property = "endpoint", defaultValue = "https://api.vespa.corp.yahoo.com:4443") // TODO jvenstad: Change default + private String endpointUri; + + @Parameter(property = "tenant") + private String tenant; + + @Parameter(property = "application") + private String application; + + @Parameter(property = "instance") + private String instance; + + @Parameter(property = "applicationZip") + private String applicationZip; + + @Parameter(property = "applicationTestZip") + private String applicationTestZip; + + @Parameter(property = "privateKeyFile", required = true) + private String privateKeyFile; + + @Parameter(property = "authorEmail", required = true) + private String authorEmail; + + @Parameter(property = "repository", defaultValue = "unknown") + private String repository; + + @Parameter(property = "branch", defaultValue = "unknown") + private String branch; + + @Parameter(property = "commit", defaultValue = "unknown") + private String commit; + + @Override + public void execute() { + try { + setup(); + ControllerHttpClient controller = new ControllerHttpClient(URI.create(endpointUri), + Files.readString(Paths.get(privateKeyFile), UTF_8), + ApplicationId.from(tenant, application, instance)); + + Submission submission = new Submission(repository, branch, commit, authorEmail, + Paths.get(applicationZip), Paths.get(applicationTestZip)); + + System.out.println(controller.submit(submission)); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private void setup() { + tenant = firstNonBlank(tenant, project.getProperties().getProperty("tenant")); + application = firstNonBlank(application, project.getProperties().getProperty("application")); + instance = firstNonBlank(instance, project.getProperties().getProperty("instance")); + applicationZip = firstNonBlank(applicationZip, projectPathOf("target", "application.zip")); + applicationTestZip = firstNonBlank(applicationTestZip, projectPathOf("target", "application-test.zip")); + } + + private String projectPathOf(String first, String... rest) { + return project.getBasedir().toPath().resolve(Path.of(first, rest)).toString(); + } + + /** Returns the first of the given strings which is non-null and non-blank. */ + private static String firstNonBlank(String... values) { + for (String value : values) + if (value != null && ! value.isBlank()) + return value; + throw new IllegalArgumentException("No valid value given"); + } + +} |