Mercurial > stress-tester
changeset 1182:37b399460a0c
Converter - "save-response" option
author | Devel 2 |
---|---|
date | Wed, 17 Jun 2020 12:15:05 +0200 |
parents | 34e3e448755c |
children | 934772a77136 |
files | stress-tester/src/main/java/com/passus/st/converter/Converter.java stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java |
diffstat | 2 files changed, 35 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/converter/Converter.java Wed Jun 17 11:24:07 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/converter/Converter.java Wed Jun 17 12:15:05 2020 +0200 @@ -7,9 +7,7 @@ import com.passus.st.CliHelper; import com.passus.st.CliOptions; import com.passus.st.config.JobConfigurator; -import com.passus.st.reader.nc.NcHttpWriteMode; import com.passus.st.source.NcEventDestination; -import com.passus.st.source.PcapSessionEventSource; import org.apache.commons.cli.*; import java.io.File; @@ -23,26 +21,6 @@ private final CliHelper cliHelper = new CliHelper(); - private static final String WRITE_MODES = "skip|headers-only|full-message"; - - private static NcHttpWriteMode resolveWriteMode(String raw, NcHttpWriteMode defaultValue) { - if (raw == null) { - return defaultValue; - } - - raw = raw.toLowerCase(); - switch (raw) { - case "skip": - return NcHttpWriteMode.SKIP; - case "headers-only": - return NcHttpWriteMode.HEADERS_ONLY; - case "full-message": - return NcHttpWriteMode.FULL_MESSAGE; - default: - throw new IllegalArgumentException("Invalid write mode '" + raw + "'."); - } - } - private boolean askOverwriteIfExists(String output) { File f = new File(output); if (f.exists()) { @@ -56,7 +34,7 @@ static void printHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("[options] <output nc>", "description", options, ""); + formatter.printHelp("[options] <config file> <output nc>", "description", options, ""); } private Options createOptions() { @@ -70,8 +48,8 @@ .build() ); - options.addOption(option("c", "config-file").desc("Configuration file.") - .hasArg().argName("file") + options.addOption(option("sr", "save-response").desc("Save only requests (default false).") + .hasArg().argName("") .build() ); @@ -99,31 +77,27 @@ try { CommandLine cl = new DefaultParser().parse(options, args); String[] clArgs = cl.getArgs(); - if (clArgs.length != 1) { - System.err.println("Output file required."); + if (clArgs.length != 2) { + System.err.println("Configuration and output file required."); printHelp(options); return; } - String output = clArgs[0]; + String configFile = clArgs[0]; + String output = clArgs[1]; System.out.println("Converting to " + output); cliHelper.configureLogger(cl); - boolean overwrite = processOverwriteOption(cl, output); - ConfigurationContext context = ConfigurationContext.create(); Errors errors = new Errors(); - JobConfigurator jobConfigurator = null; - Configuration config = null; - if (cl.hasOption("c")) { - String configFile = cl.getOptionValue("c"); - ConverterConfiguratorPluginFactory pluginFactory = new ConverterConfiguratorPluginFactory(); - config = cliHelper.readConfiguration(configFile); - jobConfigurator = cliHelper.processJobConfiguration(config, context, errors, pluginFactory); - } + ConverterConfiguratorPluginFactory pluginFactory = new ConverterConfiguratorPluginFactory(); + Configuration config = cliHelper.readConfiguration(configFile); + JobConfigurator jobConfigurator = cliHelper.processJobConfiguration(config, context, errors, pluginFactory); + boolean overwrite = processOverwriteOption(cl, output); NcEventDestination dst = new NcEventDestination(output); dst.setAllowOverwrite(overwrite); + dst.setWriteResponse(cl.hasOption("sr")); ConverterJob converterJob = ConverterJob.create(context, dst); converterJob.start();
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java Wed Jun 17 11:24:07 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java Wed Jun 17 12:15:05 2020 +0200 @@ -3,8 +3,6 @@ import com.passus.commons.service.ServiceException; import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; -import com.passus.net.http.HttpRequestEncoder; -import com.passus.net.http.HttpResponseEncoder; import com.passus.st.client.DataEvents.DataEnd; import com.passus.st.client.Event; import com.passus.st.client.SessionPayloadEvent; @@ -15,6 +13,8 @@ import java.io.IOException; import static com.passus.st.Protocols.*; +import static com.passus.st.source.NcPayloadWriter.FLAG_WRITE_REQUEST; +import static com.passus.st.source.NcPayloadWriter.FLAG_WRITE_RESPONSE; /** * @author Mirosław Hawrot @@ -27,10 +27,6 @@ private NcDataBlockWriter writer; - private final HttpRequestEncoder requestEncoder = HttpRequestEncoder.getInstance(); - - private final HttpResponseEncoder responseEncoder = HttpResponseEncoder.getInstance(); - private final NcHttpPayloadWriter httpWriter = new NcHttpPayloadWriter(); private final NcDnsPayloadWriter dnsWriter = new NcDnsPayloadWriter(); @@ -43,6 +39,8 @@ private boolean allowOverwrite; + private boolean writeResponse = true; + public NcEventDestination() { } @@ -62,6 +60,14 @@ this.ncFile = ncFile; } + public boolean isWriteResponse() { + return writeResponse; + } + + public void setWriteResponse(boolean writeResponse) { + this.writeResponse = writeResponse; + } + @Override public boolean isStarted() { return started; @@ -82,6 +88,17 @@ } try { + int writerFlags = FLAG_WRITE_REQUEST | FLAG_WRITE_RESPONSE; + if (!writeResponse) { + writerFlags = FLAG_WRITE_REQUEST; + } + + httpWriter.setFlags(writerFlags); + dnsWriter.setFlags(writerFlags); + netflowWriter.setFlags(writerFlags); + pgSqlWriter.setFlags(writerFlags); + mySqlWriter.setFlags(writerFlags); + writer = new NcDataBlockWriter(ncFile); writer.setAllowOverwrite(allowOverwrite); writer.open();