diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-05-20 15:08:10 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-05-20 15:14:15 +0200 |
commit | 6d45672aadcfedcbf705df33d1bf51ef113e4d69 (patch) | |
tree | c8b9224868b54d55d95ffcf3a99e1d574f3e5904 /vespa-feed-client | |
parent | b6581058576a41de9152e37b4a2e4564b2e71506 (diff) |
com.yahoo -> ai
Diffstat (limited to 'vespa-feed-client')
-rw-r--r-- | vespa-feed-client/pom.xml | 8 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/CliArguments.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/CliArguments.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/CliClient.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/CliClient.java) | 8 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/DocumentId.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/DocumentId.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClient.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedClient.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedClientBuilder.java) | 3 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedException.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedException.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java) | 13 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java) | 6 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/JsonStreamFeeder.java | 100 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/OperationParameters.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/OperationParameters.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/RequestStrategy.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/RequestStrategy.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/Result.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/Result.java) | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/SslContextBuilder.java (renamed from vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/SslContextBuilder.java) | 2 | ||||
-rwxr-xr-x | vespa-feed-client/src/main/sh/vespa-version-generator.sh | 2 | ||||
-rw-r--r-- | vespa-feed-client/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java (renamed from vespa-feed-client/src/test/java/com/yahoo/vespa/feed/client/CliArgumentsTest.java) | 13 | ||||
-rw-r--r-- | vespa-feed-client/src/test/java/ai/vespa/feed/client/HttpRequestStrategyTest.java | 38 |
17 files changed, 171 insertions, 36 deletions
diff --git a/vespa-feed-client/pom.xml b/vespa-feed-client/pom.xml index cb1e015118e..4a44f1c0240 100644 --- a/vespa-feed-client/pom.xml +++ b/vespa-feed-client/pom.xml @@ -48,6 +48,12 @@ <scope>compile</scope> </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <scope>compile</scope> + </dependency> + <!-- test scope --> <dependency> <groupId>org.junit.jupiter</groupId> @@ -89,7 +95,7 @@ <executable>src/main/sh/vespa-version-generator.sh</executable> <arguments> <argument>${project.basedir}/../dist/vtag.map</argument> - <argument>${project.build.directory}/generated-sources/vespa-version/com/yahoo/vespa/feed/client/Vespa.java</argument> + <argument>${project.build.directory}/generated-sources/vespa-version/ai/vespa/feed/client/Vespa.java</argument> </arguments> <sourceRoot>${project.build.directory}/generated-sources/vespa-version</sourceRoot> </configuration> diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/CliArguments.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/CliArguments.java index e276d34129f..e0ceb9b22ce 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/CliArguments.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/CliArguments.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/CliClient.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/CliClient.java index 5a4a4ead631..83a0c650318 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/CliClient.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/CliClient.java @@ -1,7 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; - -import com.yahoo.vespa.feed.client.CliArguments.CliArgumentsException; +package ai.vespa.feed.client; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; @@ -46,12 +44,12 @@ class CliClient { } FeedClient feedClient = createFeedClient(cliArgs); return 0; - } catch (CliArgumentsException | IOException e) { + } catch (CliArguments.CliArgumentsException | IOException e) { return handleException(e); } } - private static FeedClient createFeedClient(CliArguments cliArgs) throws CliArgumentsException, IOException { + private static FeedClient createFeedClient(CliArguments cliArgs) throws CliArguments.CliArgumentsException, IOException { FeedClientBuilder builder = FeedClientBuilder.create(cliArgs.endpoint()); cliArgs.connections().ifPresent(builder::setMaxConnections); cliArgs.maxStreamsPerConnection().ifPresent(builder::setMaxConnections); diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/DocumentId.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/DocumentId.java index e00cedb293b..21513a5dac2 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/DocumentId.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/DocumentId.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import java.util.Objects; import java.util.Optional; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedClient.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClient.java index b32c4531fb4..1b616a70da9 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedClient.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClient.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import java.io.Closeable; import java.util.concurrent.CompletableFuture; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedClientBuilder.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java index 491260178e9..95a49abcc25 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedClientBuilder.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java @@ -1,12 +1,11 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import java.net.URI; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.function.Supplier; import static java.util.Objects.requireNonNull; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedException.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedException.java index d3de5e0cbe1..eb31d1aa808 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/FeedException.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedException.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; /** * @author bjorncs diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java index 58b9eef832b..fc1637fe17f 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; @@ -31,9 +31,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; -import static com.yahoo.vespa.feed.client.Result.Type.conditionNotMet; -import static com.yahoo.vespa.feed.client.Result.Type.failure; -import static com.yahoo.vespa.feed.client.Result.Type.success; import static java.util.Objects.requireNonNull; /** @@ -140,7 +137,7 @@ class HttpFeedClient implements FeedClient { try { close(); } catch (IOException exception) { throw new UncheckedIOException(exception); } } - return new Result(failure, documentId, thrown.getMessage(), null); + return new Result(Result.Type.failure, documentId, thrown.getMessage(), null); } return toResult(response, documentId); }); @@ -149,9 +146,9 @@ class HttpFeedClient implements FeedClient { static Result toResult(SimpleHttpResponse response, DocumentId documentId) { Result.Type type; switch (response.getCode()) { - case 200: type = success; break; - case 412: type = conditionNotMet; break; - default: type = failure; + case 200: type = Result.Type.success; break; + case 412: type = Result.Type.conditionNotMet; break; + default: type = Result.Type.failure; } Map<String, String> responseJson = null; // TODO: parse JSON. return new Result(type, documentId, response.getBodyText(), "trace"); diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java index db6bc8d21fe..0512d6a64c9 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import org.apache.hc.client5.http.HttpRequestRetryStrategy; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; @@ -18,8 +18,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; -import static com.yahoo.vespa.feed.client.FeedClient.OperationType.remove; - /** * Controls request execution and retries: * <ul> @@ -69,7 +67,7 @@ class HttpRequestStrategy implements RequestStrategy<SimpleHttpResponse>, HttpRe switch (request.getMethod().toUpperCase()) { case "POST": return wrapped.retry(FeedClient.OperationType.put); case "PUT": return wrapped.retry(FeedClient.OperationType.update); - case "DELETE": return wrapped.retry(remove); + case "DELETE": return wrapped.retry(FeedClient.OperationType.remove); default: throw new IllegalStateException("Unexpected HTTP method: " + request.getMethod()); } } diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/JsonStreamFeeder.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/JsonStreamFeeder.java new file mode 100644 index 00000000000..7ece0d4ef73 --- /dev/null +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/JsonStreamFeeder.java @@ -0,0 +1,100 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.feed.client; + +import com.fasterxml.jackson.core.JsonParser; + +import java.io.InputStream; +import java.time.Duration; + +import static java.util.Objects.requireNonNull; + +/** + * @author jonmv + */ +public class JsonStreamFeeder { + + private final FeedClient client; + private final OperationParameters protoParameters; + + private JsonStreamFeeder(FeedClient client, OperationParameters protoParameters) { + this.client = client; + this.protoParameters = protoParameters; + } + + public static Builder builder(FeedClient client) { return new Builder(client); } + + /** Feeds a stream containing a JSON array of feed operations on the form + * <pre> + * [ + * { + * "id": "id:ns:type::boo", + * "fields": { ... document fields ... } + * }, + * { + * "put": "id:ns:type::foo", + * "fields": { ... document fields ... } + * }, + * { + * "update": "id:ns:type:n=4:bar", + * "create": true, + * "fields": { ... partial update fields ... } + * }, + * { + * "remove": "id:ns:type:g=foo:bar", + * "condition": "type.baz = \"bax\"" + * }, + * ... + * ] + * </pre> + * Note that {@code "id"} is an alias for the document put operation. + */ + public void feed(InputStream jsonStream) { + + } + + + static class Tokenizer { + + private final InputStream in; + private final JsonParser json; + + public Tokenizer(InputStream in, JsonParser json) { + this.in = in; + this.json = json; + } + + } + + + + public static class Builder { + + final FeedClient client; + OperationParameters parameters; + + private Builder(FeedClient client) { + this.client = requireNonNull(client); + } + + public Builder withTimeout(Duration timeout) { + parameters = parameters.timeout(timeout); + return this; + } + + public Builder withRoute(String route) { + parameters = parameters.route(route); + return this; + } + + public Builder withTracelevel(int tracelevel) { + parameters = parameters.tracelevel(tracelevel); + return this; + } + + public JsonStreamFeeder build() { + return new JsonStreamFeeder(client, parameters); + } + + } + +} diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/OperationParameters.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/OperationParameters.java index 8423e6a9e1b..78450caf204 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/OperationParameters.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/OperationParameters.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import java.time.Duration; import java.util.Optional; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/RequestStrategy.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/RequestStrategy.java index 194815aadf8..e5eb956114e 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/RequestStrategy.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/RequestStrategy.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/Result.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/Result.java index 23abff3f8e7..31a6cf6e893 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/Result.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/Result.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import java.util.Optional; diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/SslContextBuilder.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/SslContextBuilder.java index 326ead6d005..1a5f27c5d66 100644 --- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/SslContextBuilder.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/SslContextBuilder.java @@ -1,5 +1,5 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; diff --git a/vespa-feed-client/src/main/sh/vespa-version-generator.sh b/vespa-feed-client/src/main/sh/vespa-version-generator.sh index d8f5878e2c5..7203212297a 100755 --- a/vespa-feed-client/src/main/sh/vespa-version-generator.sh +++ b/vespa-feed-client/src/main/sh/vespa-version-generator.sh @@ -16,7 +16,7 @@ mkdir -p $destinationDir versionNumber=$(cat $source | grep V_TAG_COMPONENT | awk '{print $2}' ) cat > $destination <<- END -package com.yahoo.vespa.feed.client; +package ai.vespa.feed.client; class Vespa { static final String VERSION = "$versionNumber"; diff --git a/vespa-feed-client/src/test/java/com/yahoo/vespa/feed/client/CliArgumentsTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java index 1a4f963975e..b8dda66bf96 100644 --- a/vespa-feed-client/src/test/java/com/yahoo/vespa/feed/client/CliArgumentsTest.java +++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java @@ -1,6 +1,5 @@ -package com.yahoo.vespa.feed.client;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.feed.client;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -import com.yahoo.vespa.feed.client.CliArguments.CliArgumentsException; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -17,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.*; class CliArgumentsTest { @Test - void parses_parameters_correctly() throws CliArgumentsException { + void parses_parameters_correctly() throws CliArguments.CliArgumentsException { CliArguments args = CliArguments.fromRawArgs(new String[]{ "--endpoint=https://vespa.ai:4443/", "--file=feed.json", "--connections=10", "--max-streams-per-connection=128", "--certificate=cert.pem", "--private-key=key.pem", @@ -34,16 +33,16 @@ class CliArgumentsTest { } @Test - void fails_on_missing_parameters() throws CliArgumentsException { + void fails_on_missing_parameters() throws CliArguments.CliArgumentsException { CliArguments cliArguments = CliArguments.fromRawArgs(new String[0]); - CliArgumentsException exception = assertThrows(CliArgumentsException.class, cliArguments::endpoint); + CliArguments.CliArgumentsException exception = assertThrows(CliArguments.CliArgumentsException.class, cliArguments::endpoint); assertEquals("Endpoint must be specified", exception.getMessage()); - exception = assertThrows(CliArgumentsException.class, cliArguments::inputFile); + exception = assertThrows(CliArguments.CliArgumentsException.class, cliArguments::inputFile); assertEquals("Feed file must be specified", exception.getMessage()); } @Test - void generated_help_page_contains_expected_description() throws CliArgumentsException, IOException { + void generated_help_page_contains_expected_description() throws CliArguments.CliArgumentsException, IOException { CliArguments args = CliArguments.fromRawArgs(new String[]{"--help"}); assertTrue(args.helpSpecified()); diff --git a/vespa-feed-client/src/test/java/ai/vespa/feed/client/HttpRequestStrategyTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/HttpRequestStrategyTest.java new file mode 100644 index 00000000000..a643783bd46 --- /dev/null +++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/HttpRequestStrategyTest.java @@ -0,0 +1,38 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.feed.client; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.time.Duration; +import java.time.Instant; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +class HttpRequestStrategyTest { + + @Test + void test() throws InterruptedException { + AtomicLong c = new AtomicLong(); + class Counter { + long d; + synchronized long next() { return ++d; } + } + Counter d = new Counter(); + int n = 2; + ExecutorService executor = Executors.newFixedThreadPool(n); + Instant now = Instant.now(); + for (int i = 0; i < n; i++) { + executor.submit(() -> { + //while (c.incrementAndGet() < 1e8); + //while (d.next() < 1e8); + }); + } + executor.shutdown(); + executor.awaitTermination(1, TimeUnit.DAYS); + Assertions.fail("ms: " + Duration.between(now, Instant.now()).toMillis()); + }; + +} |