diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-06-24 17:10:28 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-06-24 17:10:28 +0200 |
commit | 150aff6805eaa1b23a72bad7b01b89cee72ea6cf (patch) | |
tree | cfadc02f181f8665976a001591bd134caf5fef97 /vespa-feed-client | |
parent | 2f22aff9a94ce547809715e2d4ef72dc61a11426 (diff) |
Implement dryrun in FeedClient, use it from CLI and Hadoop feeder
Diffstat (limited to 'vespa-feed-client')
4 files changed, 50 insertions, 1 deletions
diff --git a/vespa-feed-client/abi-spec.json b/vespa-feed-client/abi-spec.json index 70cb4c3f09f..d794fcf851a 100644 --- a/vespa-feed-client/abi-spec.json +++ b/vespa-feed-client/abi-spec.json @@ -175,6 +175,7 @@ "public ai.vespa.feed.client.FeedClientBuilder setCertificate(java.nio.file.Path, java.nio.file.Path)", "public ai.vespa.feed.client.FeedClientBuilder setCertificate(java.util.Collection, java.security.PrivateKey)", "public ai.vespa.feed.client.FeedClientBuilder setCertificate(java.security.cert.X509Certificate, java.security.PrivateKey)", + "public ai.vespa.feed.client.FeedClientBuilder setDryrun(boolean)", "public ai.vespa.feed.client.FeedClientBuilder setCaCertificatesFile(java.nio.file.Path)", "public ai.vespa.feed.client.FeedClientBuilder setCaCertificates(java.util.Collection)", "public ai.vespa.feed.client.FeedClient build()" diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/DryrunCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/DryrunCluster.java new file mode 100644 index 00000000000..9e6ad0150c7 --- /dev/null +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/DryrunCluster.java @@ -0,0 +1,42 @@ +// 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 java.nio.charset.StandardCharsets; +import java.time.Duration; +import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Dryrun implementation that reports every request/operation as successful + * + * @author bjorncs + */ +class DryrunCluster implements Cluster { + + private final static Logger log = Logger.getLogger(DryrunCluster.class.getName()); + + static final Duration DELAY = Duration.ofMillis(1); + + @Override + public void dispatch(HttpRequest request, CompletableFuture<HttpResponse> vessel) { + long millis = DELAY.toMillis(); + log.log(Level.FINE, "Dryrun of request '{0}' with delay of {1}ms", new Object[]{request, millis}); + if (millis > 0) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + vessel.cancel(true); + Thread.currentThread().interrupt(); + return; + } + } + vessel.complete(new SimpleOkResponse()); + } + + private static class SimpleOkResponse implements HttpResponse { + @Override public int code() { return 200; } + @Override public byte[] body() { return "{\"message\":\"dummy dryrun message\"}".getBytes(StandardCharsets.UTF_8); } + } + +} diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java index 0f685ec5b7f..57aaf67c2d9 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java @@ -45,6 +45,7 @@ public class FeedClientBuilder { PrivateKey privateKey; Collection<X509Certificate> caCertificates; boolean benchmark; + boolean dryrun; /** Creates a builder for a single container endpoint **/ public static FeedClientBuilder create(URI endpoint) { return new FeedClientBuilder(Collections.singletonList(endpoint)); } @@ -158,6 +159,11 @@ public class FeedClientBuilder { return setCertificate(Collections.singletonList(certificate), privateKey); } + public FeedClientBuilder setDryrun(boolean enabled) { + this.dryrun = enabled; + return this; + } + /** * Overrides JVM default SSL truststore * @param caCertificatesFile Path to PEM encoded file containing trusted certificates diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java index 1987bae18f9..1b939a0361c 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java @@ -59,7 +59,7 @@ class HttpRequestStrategy implements RequestStrategy { }); HttpRequestStrategy(FeedClientBuilder builder) throws IOException { - this(builder, new ApacheCluster(builder)); + this(builder, builder.dryrun ? new DryrunCluster() : new ApacheCluster(builder)); } HttpRequestStrategy(FeedClientBuilder builder, Cluster cluster) { |