Mercurial > stress-tester
changeset 902:f8b01b4c713f
lookups in cli
author | Devel 1 |
---|---|
date | Wed, 18 Apr 2018 09:02:17 +0200 |
parents | a609224a38df |
children | 8b26804049d4 |
files | stress-tester/src/main/java/com/passus/st/CliHelper.java stress-tester/src/main/java/com/passus/st/CliOptions.java stress-tester/src/main/java/com/passus/st/ConverterMain.java stress-tester/src/main/java/com/passus/st/Main.java stress-tester/src/main/java/com/passus/st/Main2.java |
diffstat | 5 files changed, 47 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/CliHelper.java Thu Apr 12 10:24:14 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/CliHelper.java Wed Apr 18 09:02:17 2018 +0200 @@ -9,6 +9,8 @@ import static com.passus.config.validation.ErrorsUtils.objectErrorToString; import com.passus.config.validation.ObjectError; import com.passus.filter.ValueExtractor; +import com.passus.lookup.Lookup; +import com.passus.lookup.LookupList; import com.passus.net.PortRangeSet; import com.passus.st.client.http.HttpClient; import com.passus.st.client.http.filter.HttpFilter; @@ -18,6 +20,7 @@ import com.passus.st.emitter.PassThroughSessionMapper; import com.passus.st.emitter.RuleBasedSessionMapper; import com.passus.st.emitter.SessionMapper; +import com.passus.st.lookup.LookupsDomainConfigurator; import com.passus.st.reader.nc.NcHeader; import com.passus.st.reader.pcap.PcapFileHeader; import com.passus.st.source.EventSource; @@ -157,6 +160,23 @@ return client; } + public void fillLookupList(CommandLine cl) throws Exception { + LookupList.getInstance().addAll(readLookups(cl)); + } + + public List<Lookup> readLookups(CommandLine cl) throws Exception { + if (cl.hasOption("lf")) { + File file = new File(cl.getOptionValue("lf")); + Errors errors = new Errors(); + ConfigurationContext context = new ConfigurationContextImpl(); + List<Lookup> lookups = LookupsDomainConfigurator.getLookups(file, errors, context); + handleErrors(errors, file); + return lookups; + } + + return Collections.EMPTY_LIST; + } + @SuppressWarnings("unchecked") public List<HttpFilter> readHttpFilters(CommandLine cl) throws Exception { if (cl.hasOption("ff")) { @@ -164,13 +184,7 @@ Errors errors = new Errors(); ConfigurationContext context = new ConfigurationContextImpl(); List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(file, errors, context); - if (errors.getErrorCount() != 0) { - printError("Error in file '" + file.getAbsolutePath() + "'.", false); - for (ObjectError error : errors.getAllErrors()) { - printError("\t" + objectErrorToString(error), false); - } - System.exit(1); - } + handleErrors(errors, file); return filters; } @@ -205,4 +219,14 @@ } return Collections.emptyMap(); } + + private void handleErrors(Errors errors, File file) { + if (errors.getErrorCount() != 0) { + printError("Error in file '" + file.getAbsolutePath() + "'.", false); + for (ObjectError error : errors.getAllErrors()) { + printError("\t" + objectErrorToString(error), false); + } + System.exit(1); + } + } }
--- a/stress-tester/src/main/java/com/passus/st/CliOptions.java Thu Apr 12 10:24:14 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/CliOptions.java Wed Apr 18 09:02:17 2018 +0200 @@ -59,6 +59,13 @@ ); } + public CliOptions addLookupsFileOptions() { + return addOption(option("lf", "lookupsFile").desc("Lookups file.") + .hasArg().argName("file") + .build() + ); + } + public CliOptions addHttpFiltersFileOption() { return addOption(option("ff", "filtersFile").desc("Filters file.") .hasArg().argName("file")
--- a/stress-tester/src/main/java/com/passus/st/ConverterMain.java Thu Apr 12 10:24:14 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/ConverterMain.java Wed Apr 18 09:02:17 2018 +0200 @@ -62,6 +62,7 @@ options.addLogLevelOption(); options.addAllowPartialSessionOption(); + options.addLookupsFileOptions(); options.addHttpFiltersFileOption(); options.addVarsFileOption(); options.addHttpPortsOption(); @@ -130,6 +131,8 @@ ConverterHttpClient client = new ConverterHttpClient(dst); + cliHelper.fillLookupList(cl); + List<HttpFilter> httpFilters = cliHelper.readHttpFilters(cl); if (httpFilters != null) { httpFilters.forEach(client::addFilter);
--- a/stress-tester/src/main/java/com/passus/st/Main.java Thu Apr 12 10:24:14 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main.java Wed Apr 18 09:02:17 2018 +0200 @@ -84,6 +84,7 @@ options.addMapperRuleOption(); options.addAllowPartialSessionOption(); options.addHttpClientOptions(); + options.addLookupsFileOptions(); options.addOption(option("pr", "parallelReplays").desc("Number of parallel replays. Works only for one pcap file.") .hasArg().argName("replays") @@ -241,6 +242,8 @@ collector.addHandler(reporterDestination); } + cliHelper.fillLookupList(cl); + List<HttpFilter> httpFilters = cliHelper.readHttpClientFilters(cl); if (httpFilters != null) { httpFilters.forEach(client::addFilter);
--- a/stress-tester/src/main/java/com/passus/st/Main2.java Thu Apr 12 10:24:14 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main2.java Wed Apr 18 09:02:17 2018 +0200 @@ -101,6 +101,7 @@ options.addMapperRuleOption(); options.addAllowPartialSessionOption(); options.addHttpClientOptions(); + options.addLookupsFileOptions(); options.addOption(option("pr", "parallelReplays").desc("Number of parallel replays. Works only for one pcap file.") .hasArg().argName("replays") @@ -247,6 +248,8 @@ collector.addHandler(reporterDestination); } + cliHelper.fillLookupList(cl); + List<HttpFilter> httpFilters = cliHelper.readHttpClientFilters(cl); if (httpFilters != null) { httpFilters.forEach(client::addFilter);