diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-04-29 09:39:23 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-04-29 09:39:23 +0200 |
commit | 9b2cccc9a3c3c919ed56c0bd65ca652a797bd4a1 (patch) | |
tree | 8dcedb06b6f9dd3f6c3dd12009ff7c2592577abc | |
parent | 1749fc5eab95388e1944e42fd3110546d8c46ba3 (diff) |
Move API things to new module: hosted-api
-rw-r--r-- | hosted-api/OWNERS | 1 | ||||
-rw-r--r-- | hosted-api/README.md | 1 | ||||
-rw-r--r-- | hosted-api/pom.xml | 34 | ||||
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/Method.java (renamed from vespa-maven-plugin/src/main/java/ai/vespa/hosted/api/Method.java) | 0 | ||||
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java (renamed from vespa-maven-plugin/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java) | 14 | ||||
-rw-r--r-- | hosted-api/src/test/java/ai/vespa/hosted/api/MultiPartStreamerTest.java (renamed from vespa-maven-plugin/src/test/java/ai/vespa/hosted/api/MultiPartStreamerTest.java) | 5 | ||||
-rw-r--r-- | pom.xml | 1 | ||||
-rw-r--r-- | vespa-maven-plugin/pom.xml | 16 |
8 files changed, 51 insertions, 21 deletions
diff --git a/hosted-api/OWNERS b/hosted-api/OWNERS new file mode 100644 index 00000000000..d0a102ecbf4 --- /dev/null +++ b/hosted-api/OWNERS @@ -0,0 +1 @@ +jonmv diff --git a/hosted-api/README.md b/hosted-api/README.md new file mode 100644 index 00000000000..28eea5c3f3d --- /dev/null +++ b/hosted-api/README.md @@ -0,0 +1 @@ +# Hosted Vespa controller API miscellaneous
\ No newline at end of file diff --git a/hosted-api/pom.xml b/hosted-api/pom.xml new file mode 100644 index 00000000000..3ca8c3c5fd5 --- /dev/null +++ b/hosted-api/pom.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>vespa</artifactId> + <groupId>com.yahoo.vespa</groupId> + <version>7-SNAPSHOT</version> + </parent> + <artifactId>hosted-api</artifactId> + <description>Miscellaneous for tenant client -- hosted Vespa controller communication</description> + + <dependencies> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>config-provisioning</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>vespajlib</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/api/Method.java b/hosted-api/src/main/java/ai/vespa/hosted/api/Method.java index ff7c1e4270b..ff7c1e4270b 100644 --- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/api/Method.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/Method.java diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java b/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java index e42df52ca3f..7ed86210957 100644 --- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java @@ -65,16 +65,15 @@ public class MultiPartStreamer { } /** - * Returns a builder whose data is an aggregate stream of the current parts of this. + * Streams the aggregate of the current parts of this to the given request builder, and returns it. * Modifications to this streamer after a request builder has been obtained is not reflected in that builder. * This method can be used multiple times, to create new requests. * The request builder's method and content should not be set after it has been obtained. */ - public HttpRequest.Builder requestBuilder(Method method) { + public HttpRequest.Builder streamTo(HttpRequest.Builder request, Method method) { InputStream aggregate = data(); // Get the streams now, not when the aggregate is used. - return HttpRequest.newBuilder() - .setHeader("Content-Type", "multipart/form-data; boundary=" + boundary) - .method(method.name(), HttpRequest.BodyPublishers.ofInputStream(() -> aggregate)); + return request.setHeader("Content-Type", contentType()) + .method(method.name(), HttpRequest.BodyPublishers.ofInputStream(() -> aggregate)); } /** Returns an input stream which is an aggregate of all current parts in this, plus an end marker. */ @@ -93,6 +92,11 @@ public class MultiPartStreamer { return new BufferedInputStream(aggregate); } + /** Returns the value of the {@code "Content-Type"} header to use with this. */ + public String contentType() { + return "multipart/form-data; boundary=" + boundary + "; charset: utf-8"; + } + /** Returns the separator to put between one part and the next, when this is a string. */ private InputStream separator(String name, String contentType) { return asStream(disposition(name) + type(contentType)); diff --git a/vespa-maven-plugin/src/test/java/ai/vespa/hosted/api/MultiPartStreamerTest.java b/hosted-api/src/test/java/ai/vespa/hosted/api/MultiPartStreamerTest.java index 3abb04976c1..d94a5b3314c 100644 --- a/vespa-maven-plugin/src/test/java/ai/vespa/hosted/api/MultiPartStreamerTest.java +++ b/hosted-api/src/test/java/ai/vespa/hosted/api/MultiPartStreamerTest.java @@ -6,6 +6,7 @@ import org.junit.rules.TemporaryFolder; import java.io.IOException; import java.net.URI; +import java.net.http.HttpRequest; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -60,8 +61,8 @@ public class MultiPartStreamerTest { assertEquals(expected, new String(streamer.data().readAllBytes())); - assertEquals(List.of("multipart/form-data; boundary=My boundary"), - streamer.requestBuilder(Method.POST) + assertEquals(List.of("multipart/form-data; boundary=My boundary; charset: utf-8"), + streamer.streamTo(HttpRequest.newBuilder(), Method.POST) .uri(URI.create("https://uri/path")) .build().headers().allValues("Content-Type")); } @@ -138,5 +138,6 @@ <module>vsm</module> <module>yolean</module> <module>zkfacade</module> + <module>hosted-api</module> </modules> </project> diff --git a/vespa-maven-plugin/pom.xml b/vespa-maven-plugin/pom.xml index b9bff8ee342..4516c57f32a 100644 --- a/vespa-maven-plugin/pom.xml +++ b/vespa-maven-plugin/pom.xml @@ -4,17 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>ai.vespa.hosted</groupId> - <artifactId>vespa-maven-plugin</artifactId> <parent> <groupId>com.yahoo.vespa</groupId> <artifactId>parent</artifactId> <version>7-SNAPSHOT</version> <relativePath>../parent/pom.xml</relativePath> </parent> - <version>7-SNAPSHOT</version> - <packaging>maven-plugin</packaging> + <artifactId>vespa-maven-plugin</artifactId> <description>Maven Plugin for deploying a Vespa application package</description> + <packaging>maven-plugin</packaging> <prerequisites> <maven>3.5.0</maven> @@ -22,16 +20,6 @@ <dependencies> <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>config-provisioning</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>vespajlib</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> </dependency> |