aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client-cli
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-05-27 14:23:05 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-05-27 14:28:38 +0200
commit42a887bd4c8235745aae49a7344cf30ce633d2a7 (patch)
tree84e0aba2a86bae94e0ce5a8577bcaa54eec2a816 /vespa-feed-client-cli
parent92bed65606488fb057a3ec81cd63b07c35843ff2 (diff)
Add parameter for route, timeout and trace level
Diffstat (limited to 'vespa-feed-client-cli')
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/CliArguments.java49
-rw-r--r--vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java7
-rw-r--r--vespa-feed-client-cli/src/test/resources/help.txt3
3 files changed, 56 insertions, 3 deletions
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/CliArguments.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/CliArguments.java
index 30dcf4cd877..8710f2feafa 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/CliArguments.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/CliArguments.java
@@ -16,10 +16,12 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
+import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
+import java.util.OptionalDouble;
import java.util.OptionalInt;
/**
@@ -42,6 +44,9 @@ class CliArguments {
private static final String HELP_OPTION = "help";
private static final String MAX_STREAMS_PER_CONNECTION = "max-streams-per-connection";
private static final String PRIVATE_KEY_OPTION = "private-key";
+ private static final String ROUTE_OPTION = "route";
+ private static final String TIMEOUT_OPTION = "timeout";
+ private static final String TRACE_OPTION = "trace";
private static final String VERSION_OPTION = "version";
private final CommandLine arguments;
@@ -116,12 +121,23 @@ class CliArguments {
boolean benchmarkModeEnabled() { return has(BENCHMARK_OPTION); }
+ Optional<String> route() { return stringValue(ROUTE_OPTION); }
+
+ OptionalInt traceLevel() throws CliArgumentsException { return intValue(TRACE_OPTION); }
+
+ Optional<Duration> timeout() throws CliArgumentsException {
+ OptionalDouble timeout = doubleValue(TIMEOUT_OPTION);
+ return timeout.isPresent()
+ ? Optional.of(Duration.ofMillis((long)(timeout.getAsDouble()*1000)))
+ : Optional.empty();
+ }
+
private OptionalInt intValue(String option) throws CliArgumentsException {
try {
Number number = (Number) arguments.getParsedOptionValue(option);
return number != null ? OptionalInt.of(number.intValue()) : OptionalInt.empty();
} catch (ParseException e) {
- throw new CliArgumentsException(String.format("Invalid value for '%s': %s", option, e.getMessage()), e);
+ throw newInvalidValueException(option, e);
}
}
@@ -131,12 +147,27 @@ class CliArguments {
if (certificateFile == null) return Optional.empty();
return Optional.of(certificateFile.toPath());
} catch (ParseException e) {
- throw new CliArgumentsException(String.format("Invalid value for '%s': %s", option, e.getMessage()), e);
+ throw newInvalidValueException(option, e);
+ }
+ }
+
+ private Optional<String> stringValue(String option) { return Optional.ofNullable(arguments.getOptionValue(option)); }
+
+ private OptionalDouble doubleValue(String option) throws CliArgumentsException {
+ try {
+ Number number = (Number) arguments.getParsedOptionValue(option);
+ return number != null ? OptionalDouble.of(number.doubleValue()) : OptionalDouble.empty();
+ } catch (ParseException e) {
+ throw newInvalidValueException(option, e);
}
}
private boolean has(String option) { return arguments.hasOption(option); }
+ private static CliArgumentsException newInvalidValueException(String option, ParseException cause) {
+ return new CliArgumentsException(String.format("Invalid value for '%s': %s", option, cause.getMessage()), cause);
+ }
+
private static Options createOptions() {
// TODO Add description to each option
return new Options()
@@ -190,6 +221,20 @@ class CliArguments {
.build())
.addOption(Option.builder()
.longOpt(BENCHMARK_OPTION)
+ .build())
+ .addOption(Option.builder()
+ .longOpt(ROUTE_OPTION)
+ .hasArg()
+ .build())
+ .addOption(Option.builder()
+ .longOpt(TIMEOUT_OPTION)
+ .hasArg()
+ .type(Number.class)
+ .build())
+ .addOption(Option.builder()
+ .longOpt(TRACE_OPTION)
+ .hasArg()
+ .type(Number.class)
.build());
}
diff --git a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java
index 33ee31ff0dc..9ccccfeba26 100644
--- a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java
+++ b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/CliArgumentsTest.java
@@ -7,6 +7,7 @@ import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.time.Duration;
import static org.junit.jupiter.api.Assertions.*;
@@ -21,7 +22,8 @@ class CliArgumentsTest {
"--endpoint=https://vespa.ai:4443/", "--file=feed.json", "--connections=10",
"--max-streams-per-connection=128", "--certificate=cert.pem", "--private-key=key.pem",
"--ca-certificates=ca-certs.pem", "--disable-ssl-hostname-verification",
- "--header=\"My-Header: my-value\"", "--header", "Another-Header: another-value", "--benchmark"});
+ "--header=\"My-Header: my-value\"", "--header", "Another-Header: another-value", "--benchmark",
+ "--route=myroute", "--timeout=0.125", "--trace=9"});
assertEquals(URI.create("https://vespa.ai:4443/"), args.endpoint());
assertEquals(Paths.get("feed.json"), args.inputFile());
assertEquals(10, args.connections().getAsInt());
@@ -36,6 +38,9 @@ class CliArgumentsTest {
assertEquals("my-value", args.headers().get("My-Header"));
assertEquals("another-value", args.headers().get("Another-Header"));
assertTrue(args.benchmarkModeEnabled());
+ assertEquals("myroute", args.route().get());
+ assertEquals(Duration.ofMillis(125), args.timeout().get());
+ assertEquals(9, args.traceLevel().getAsInt());
}
@Test
diff --git a/vespa-feed-client-cli/src/test/resources/help.txt b/vespa-feed-client-cli/src/test/resources/help.txt
index 9ad7642d4ec..a52842b32fd 100644
--- a/vespa-feed-client-cli/src/test/resources/help.txt
+++ b/vespa-feed-client-cli/src/test/resources/help.txt
@@ -11,4 +11,7 @@ Vespa feed client
--help
--max-streams-per-connection <arg>
--private-key <arg>
+ --route <arg>
+ --timeout <arg>
+ --trace <arg>
--version