diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-23 11:15:49 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-23 11:15:49 +0100 |
commit | 59f0e0e4c0e2dd8765da655f32cb918952b98a37 (patch) | |
tree | 68b60d2022c02e159f20f84a60df80301070a470 /vespa-http-client | |
parent | 12b6d7de3e6f468c6146cad364e7152d83be1ff1 (diff) |
Non-functional changes only
Diffstat (limited to 'vespa-http-client')
3 files changed, 34 insertions, 39 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 5adb312eceb..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 @@ -35,9 +35,9 @@ public class Runner { 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); @@ -51,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."); |