summaryrefslogtreecommitdiffstats
path: root/vespa-http-client
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-03-24 14:24:13 +0100
committerGitHub <noreply@github.com>2020-03-24 14:24:13 +0100
commit560c59fa920be8f236ae820e28eefbda85634d48 (patch)
tree78269a064f59aff3b2772534da227d0ad1dc32a9 /vespa-http-client
parent0b3704a8e43472b66f0a79ae251ccfc6bcecbfe5 (diff)
parentdbcbcb0ca1c1b5b3aaea6e5ee55c7abf98569536 (diff)
Merge pull request #12664 from vespa-engine/bratseth/dont-use-phrase-segmentation-flag
Bratseth/dont use phrase segmentation flag
Diffstat (limited to 'vespa-http-client')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java11
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java22
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/Runner.java47
3 files changed, 39 insertions, 41 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java
index cff9e2fefb0..83113722814 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java
@@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit;
* @author dybis
*/
@Command(name = "vespa-http-client",
- description = "This is a tool for feeding xml or json data to a Vespa application.")
+ description = "This is a tool for feeding xml or json data to a Vespa application.")
public class CommandLineArguments {
/**
@@ -44,7 +44,7 @@ public class CommandLineArguments {
* @return null on failure or if help option is set to true.
*/
static CommandLineArguments build(String[] args) {
- final CommandLineArguments cmdArgs;
+ CommandLineArguments cmdArgs;
try {
cmdArgs = SingleCommand.singleCommand(CommandLineArguments.class).parse(args);
} catch (Exception e) {
@@ -115,7 +115,7 @@ public class CommandLineArguments {
return true;
default:
System.err.println("Not valid value for priority. Allowed values are HIGHEST, VERY_HIGH, HIGH_[1-3], " +
- "NORMAL_[1-6], LOW_[1-3], VERY_LOW, and LOWEST.");
+ "NORMAL_[1-6], LOW_[1-3], VERY_LOW, and LOWEST.");
return false;
}
}
@@ -254,7 +254,7 @@ public class CommandLineArguments {
public boolean getAddRootElementToXml() { return addRootElementToXml; }
SessionParams createSessionParams(boolean useJson) {
- final int minThrottleValue = useDynamicThrottlingArg ? 10 : 0;
+ int minThrottleValue = useDynamicThrottlingArg ? 10 : 0;
Path privateKeyPath = Optional.ofNullable(this.privateKeyPath).map(Paths::get).orElse(null);
Path certificatePath = Optional.ofNullable(this.certificatePath).map(Paths::get).orElse(null);
Path caCertificatesPath = Optional.ofNullable(this.caCertificatesPath).map(Paths::get).orElse(null);
@@ -307,8 +307,7 @@ public class CommandLineArguments {
else {
Iterable<String> hosts = Splitter.on(',').trimResults().split(hostArg);
for (String host : hosts) {
- builder.addCluster(new Cluster.Builder()
- .addEndpoint(Endpoint.create(host, portArg, useTls))
+ builder.addCluster(new Cluster.Builder().addEndpoint(Endpoint.create(host, portArg, useTls))
.build());
}
}
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java
index 36cdf18e102..5bf48019785 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/FormatInputStream.java
@@ -31,14 +31,14 @@ public class FormatInputStream {
* IllegalArgumentException if unable to determine data format.
*
* @param stream InputStream of the data if present
- * @param inputFile Path to file to use as input
- * @param addRootElementToXml To add vespafeed root element around the input data stream
- * @throws IOException on errors.
+ * @param inputFile path to file to use as input
+ * @param addRootElementToXml to add vespafeed root element around the input data stream
+ * @throws IOException on errors
*/
public FormatInputStream(InputStream stream, Optional<String> inputFile, boolean addRootElementToXml)
throws IOException {
- final DataFormatDetector dataFormatDetector = new DataFormatDetector(new JsonFactory(), new XmlFactory());
- final DataFormatMatcher formatMatcher;
+ DataFormatDetector dataFormatDetector = new DataFormatDetector(new JsonFactory(), new XmlFactory());
+ DataFormatMatcher formatMatcher;
if (inputFile.isPresent()) {
try (FileInputStream fileInputStream = new FileInputStream(inputFile.get())) {
@@ -47,9 +47,8 @@ public class FormatInputStream {
inputStream = new FileInputStream(inputFile.get());
} else {
- if (stream.available() == 0) {
+ if (stream.available() == 0)
System.out.println("No data in stream yet and no file specified, waiting for data.");
- }
inputStream = stream.markSupported() ? stream : new BufferedInputStream(stream);
inputStream.mark(DataFormatDetector.DEFAULT_MAX_INPUT_LOOKAHEAD);
@@ -63,8 +62,8 @@ public class FormatInputStream {
return;
}
- if (formatMatcher.getMatchStrength() == MatchStrength.INCONCLUSIVE ||
- formatMatcher.getMatchStrength() == MatchStrength.NO_MATCH) {
+ if (formatMatcher.getMatchStrength() == MatchStrength.INCONCLUSIVE
+ || formatMatcher.getMatchStrength() == MatchStrength.NO_MATCH) {
throw new IllegalArgumentException("Could not detect input format");
}
@@ -72,11 +71,9 @@ public class FormatInputStream {
case "json":
format = Format.JSON;
break;
-
case "xml":
format = Format.XML;
break;
-
default:
throw new IllegalArgumentException("Unknown data format");
}
@@ -84,8 +81,7 @@ public class FormatInputStream {
private static InputStream addVespafeedTag(InputStream inputStream) {
return new SequenceInputStream(Collections.enumeration(Arrays.asList(
- new ByteArrayInputStream("<vespafeed>".getBytes()),
- inputStream,
+ new ByteArrayInputStream("<vespafeed>".getBytes()), inputStream,
new ByteArrayInputStream("</vespafeed>".getBytes())))
);
}
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/Runner.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/Runner.java
index 59953fbe002..7c034cab75f 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/Runner.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/Runner.java
@@ -29,12 +29,15 @@ public class Runner {
* @param verbose if true will print some information to stderr
* @return send time in ms, not including validating
*/
- public static long send(
- FeedClient feedClient, InputStream inputStream, boolean isJson, AtomicInteger numSent, boolean verbose) {
+ public static long send(FeedClient feedClient,
+ InputStream inputStream,
+ boolean isJson,
+ AtomicInteger numSent,
+ boolean verbose) {
- if (verbose) {
+ if (verbose)
System.err.println("Now sending data.");
- }
+
long sendStartTime = System.currentTimeMillis();
if (isJson) {
JsonReader.read(inputStream, feedClient, numSent);
@@ -48,47 +51,47 @@ public class Runner {
long sendTotalTime = System.currentTimeMillis() - sendStartTime;
- if (verbose) {
+ if (verbose)
System.err.println("Waiting for all results, sent " + numSent.get() + " docs.");
- }
+
feedClient.close();
- if (verbose) {
+ if (verbose)
System.err.println("Session closed.");
- }
return sendTotalTime;
}
public static void main(String[] args) throws IOException {
CommandLineArguments commandLineArgs = CommandLineArguments.build(args);
- if (commandLineArgs == null) {
+ if (commandLineArgs == null)
System.exit(1);
- }
- FormatInputStream formatInputStream = new FormatInputStream(
- System.in,
- Optional.ofNullable(commandLineArgs.getFile()),
- commandLineArgs.getAddRootElementToXml());
+ FormatInputStream formatInputStream = new FormatInputStream(System.in,
+ Optional.ofNullable(commandLineArgs.getFile()),
+ commandLineArgs.getAddRootElementToXml());
- int intervalOfLogging = commandLineArgs.getVerbose()
+ int intervalOfLogging =
+ commandLineArgs.getVerbose()
? commandLineArgs.getWhenVerboseEnabledPrintMessageForEveryXDocuments()
: Integer.MAX_VALUE;
AtomicInteger numSent = new AtomicInteger(0);
SimpleLoggerResultCallback callback = new SimpleLoggerResultCallback(numSent, intervalOfLogging);
- FeedClient feedClient = FeedClientFactory.create(
- commandLineArgs.createSessionParams(formatInputStream.getFormat()== FormatInputStream.Format.JSON), callback);
+ FeedClient feedClient = FeedClientFactory.create(commandLineArgs.createSessionParams(formatInputStream.getFormat()== FormatInputStream.Format.JSON),
+ callback);
- long sendTotalTimeMs = send(
- feedClient, formatInputStream.getInputStream(),
- formatInputStream.getFormat() == FormatInputStream.Format.JSON, numSent, commandLineArgs.getVerbose());
+ long sendTotalTimeMs = send(feedClient,
+ formatInputStream.getInputStream(),
+ formatInputStream.getFormat() == FormatInputStream.Format.JSON,
+ numSent,
+ commandLineArgs.getVerbose());
if (commandLineArgs.getVerbose()) {
System.err.println(feedClient.getStatsAsJson());
double transferTimeSec = ((double) sendTotalTimeMs) / 1000.0;
- if (transferTimeSec > 0) {
+ if (transferTimeSec > 0)
System.err.printf("Docs/sec %.3f%n", numSent.get() / transferTimeSec);
- }
+
if (commandLineArgs.getFile() != null) {
double fileSizeMb = ((double) new File(commandLineArgs.getFile()).length()) / 1024.0 / 1024.0;
System.err.println("Sent " + fileSizeMb + " MB in " + transferTimeSec + " seconds.");