changeset 581:618d4bc8e7a1

ReporterDestination introduced
author Devel 1
date Mon, 02 Oct 2017 09:41:54 +0200
parents a521874e90ea
children 41c917297b0e
files stress-tester/src/main/java/com/passus/st/Main.java stress-tester/src/main/java/com/passus/st/PcapReporter.java stress-tester/src/main/java/com/passus/st/client/http/ReporterDestination.java stress-tester/src/main/java/com/passus/st/client/http/ReporterFileDestination.java stress-tester/src/main/java/com/passus/st/client/http/ReporterRemoteDestination.java stress-tester/src/main/java/com/passus/st/client/http/ReporterWrapper.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java
diffstat 7 files changed, 200 insertions(+), 149 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/Main.java	Fri Sep 29 16:35:53 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/Main.java	Mon Oct 02 09:41:54 2017 +0200
@@ -13,8 +13,9 @@
 import com.passus.st.client.MemoryEventsCache;
 import com.passus.st.client.http.DumperHttpClientListener;
 import com.passus.st.client.http.HttpClient;
-import com.passus.st.client.http.ReporterWrapper;
+import com.passus.st.client.http.ReporterRemoteDestination;
 import com.passus.st.client.http.HttpSourceNameAwareClientWorkerDispatcher;
+import com.passus.st.client.http.ReporterDestination;
 import com.passus.st.client.http.SummaryHttpClientListener;
 import com.passus.st.client.http.WriterHttpClientListener;
 import com.passus.st.client.http.filter.HttpFiltersConfigurator;
@@ -51,6 +52,9 @@
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.io.IOUtils;
+import static com.passus.st.utils.CliUtils.option;
+import static com.passus.st.utils.CliUtils.option;
+import static com.passus.st.utils.CliUtils.option;
 
 /**
  *
@@ -307,8 +311,8 @@
                 }
                 reporterClient.start();
 
-                ReporterWrapper reporterWrapper = new ReporterWrapper(reporterClient);
-                Registry.getInstance().add("reporterWrapper", reporterWrapper);
+                ReporterRemoteDestination reporterWrapper = new ReporterRemoteDestination(reporterClient);
+                Registry.getInstance().add(ReporterDestination.SERVICE_NAME, reporterWrapper);
                 client.addListener(reporterWrapper);
                 collector.addHandler(reporterWrapper);
             }
--- a/stress-tester/src/main/java/com/passus/st/PcapReporter.java	Fri Sep 29 16:35:53 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/PcapReporter.java	Mon Oct 02 09:41:54 2017 +0200
@@ -23,7 +23,7 @@
 import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.client.http.HttpScopes;
 import com.passus.st.client.http.HttpSessionPayloadEvent;
-import com.passus.st.client.http.ReporterWrapper;
+import com.passus.st.client.http.ReporterRemoteDestination;
 import com.passus.st.emitter.SessionInfo;
 import com.passus.st.metric.FileMetricsCollectionAppender;
 import com.passus.st.metric.ScheduledMetricsCollector;
@@ -43,6 +43,12 @@
 import org.apache.commons.cli.ParseException;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import static com.passus.st.Main.printMetrics;
+import static com.passus.st.utils.CliUtils.option;
+import static com.passus.st.Main.printMetrics;
+import static com.passus.st.utils.CliUtils.option;
+import static com.passus.st.Main.printMetrics;
+import static com.passus.st.utils.CliUtils.option;
 
 /**
  *
@@ -169,13 +175,13 @@
         private final HttpRequestEncoder reqEncoder = new HttpRequestEncoder();
         private final HttpResponseEncoder respEncoder = new HttpResponseEncoder();
 
-        private final ReporterWrapper reporter;
+        private final ReporterRemoteDestination reporter;
         private final boolean partialSession;
         private volatile int count;
         private volatile boolean finished;
 
         public LocalHandler(SocketReporterClient reporterClient, boolean partialSession) {
-            reporter = new ReporterWrapper(reporterClient);
+            reporter = new ReporterRemoteDestination(reporterClient);
             this.partialSession = partialSession;
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/ReporterDestination.java	Mon Oct 02 09:41:54 2017 +0200
@@ -0,0 +1,27 @@
+package com.passus.st.client.http;
+
+import com.passus.data.ByteString;
+import com.passus.net.http.HttpHeaders;
+import com.passus.st.client.http.filter.HttpSequenceListener;
+import com.passus.st.metric.MetricsCollectionHandler;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public interface ReporterDestination extends HttpClientListener, HttpSequenceListener, MetricsCollectionHandler {
+
+    public static final String SERVICE_NAME = "ReporterDestination";
+
+    public static final Set<ByteString> ALLOWED_REQ_HEADERS = new HashSet<>(Arrays.asList(
+            HttpHeaders.USER_AGENT, HttpHeaders.CONTENT_TYPE
+    ));
+
+    public static final Set<ByteString> ALLOWED_RESP_HEADERS = new HashSet<>(Arrays.asList(
+            HttpHeaders.CONTENT_TYPE
+    ));
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/ReporterFileDestination.java	Mon Oct 02 09:41:54 2017 +0200
@@ -0,0 +1,24 @@
+package com.passus.st.client.http;
+
+import com.passus.commons.metric.MapMetric;
+import com.passus.commons.metric.MetricsCollection;
+import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpResponse;
+
+
+public class ReporterFileDestination implements ReporterDestination {
+
+    @Override
+    public void responseReceived(HttpRequest request, HttpResponse response, HttpFlowContext context) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public void sequenceDetected(MapMetric sequence) {
+    }
+
+    @Override
+    public void handle(MetricsCollection mc) {
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/ReporterRemoteDestination.java	Mon Oct 02 09:41:54 2017 +0200
@@ -0,0 +1,129 @@
+package com.passus.st.client.http;
+
+import com.passus.commons.metric.MapMetric;
+import com.passus.commons.metric.MetricsCollection;
+import com.passus.data.ByteString;
+import com.passus.net.SocketAddress;
+import com.passus.net.http.HttpHeaders;
+import com.passus.net.http.HttpMessage;
+import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpResponse;
+import com.passus.st.ParametersBag;
+import static com.passus.st.client.http.HttpConsts.PARAM_USERNAME;
+import static com.passus.st.client.http.HttpConsts.TAG_CONTENT_SIZE;
+import static com.passus.st.client.http.HttpConsts.TAG_HEADER_SIZE;
+import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID;
+import static com.passus.st.client.http.HttpConsts.TAG_TIME_END;
+import static com.passus.st.client.http.HttpConsts.TAG_TIME_START;
+import com.passus.st.emitter.SessionInfo;
+import com.passus.st.reporter.ReporterClient;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ * @author Mirosław Hawrot
+ */
+public class ReporterRemoteDestination implements ReporterDestination {
+
+    private final ReporterClient reporterClient;
+
+    public ReporterRemoteDestination(ReporterClient reporterClient) {
+        this.reporterClient = reporterClient;
+    }
+
+    private void populateHeaders(Map<CharSequence, CharSequence> dst, Set<ByteString> allowedHeaders, HttpMessage message) {
+        HttpHeaders headers = message.getHeaders();
+        for (ByteString name : allowedHeaders) {
+            ByteString value = headers.get(name);
+            if (value != null) {
+                dst.put(name, value);
+            }
+        }
+    }
+
+    private void populateMisc(Map<CharSequence, CharSequence> misc, HttpFlowContext context, HttpRequest request) {
+        ParametersBag params = context.scopes().getSession(request, false);
+        String username = params == null ? null : (String) params.get(PARAM_USERNAME);
+
+        String sessionId = (String) request.getTag(TAG_SESSION_ID);
+        if (username != null || sessionId != null) {
+            if (username != null) {
+                misc.put("username", username);
+            }
+
+            if (sessionId != null) {
+                misc.put("sessionId", sessionId);
+            }
+        }
+    }
+
+    @Override
+    public void responseReceived(HttpRequest request, HttpResponse response, HttpFlowContext context) {
+        if (request == null && response == null) {
+            return;
+        }
+
+        SessionInfo session = context.sessionInfo();
+
+        HttpRequestResponseMetric metric = new HttpRequestResponseMetric();
+
+        if (context.channelContext != null) {
+            SocketAddress localAddress = context.channelContext.getLocalAddress();
+            SocketAddress remoteAddress = context.channelContext.getRemoteAddress();
+            metric.setClientIp(localAddress.getIp().toString());
+            metric.setClientPort(localAddress.getPort());
+            metric.setServerIp(remoteAddress.getIp().toString());
+            metric.setServerPort(remoteAddress.getPort());
+        } else {
+            metric.setClientIp(session.getSrcIp().toString());
+            metric.setClientPort(session.getSrcPort());
+            metric.setServerIp(session.getDstIp().toString());
+            metric.setServerPort(session.getDstPort());
+        }
+        metric.setOrigClientIp(session.getSrcIp().toString());
+        metric.setOrigClientPort(session.getSrcPort());
+        metric.setOrigServerIp(session.getDstIp().toString());
+        metric.setOrigServerPort(session.getDstPort());
+
+        if (request != null) {
+            metric.setReqId(request.getId());
+            populateHeaders(metric.getReqHdrs(), ALLOWED_REQ_HEADERS, request);
+            populateMisc(metric.getMisc(), context, request);
+
+            metric.setReqHdrSize((Long) request.getTag(TAG_HEADER_SIZE));
+            metric.setReqCntSize((Long) request.getTag(TAG_CONTENT_SIZE));
+            metric.setReqStart((Long) request.getTag(TAG_TIME_START));
+            metric.setReqStop((Long) request.getTag(TAG_TIME_END));
+
+            metric.setMethod(request.getMethod().toString());
+            metric.setUrl(request.getUrl().toString());
+            metric.setReqVersion(request.getVersion().toString());
+        }
+
+        if (response != null) {
+            populateHeaders(metric.getRespHdrs(), ALLOWED_RESP_HEADERS, response);
+
+            metric.setRespHdrSize((Long) response.getTag(TAG_HEADER_SIZE));
+            metric.setRespCntSize((Long) response.getTag(TAG_CONTENT_SIZE));
+            metric.setRespStart((Long) response.getTag(TAG_TIME_START));
+            metric.setRespStop((Long) response.getTag(TAG_TIME_END));
+
+            metric.setCode(response.getStatus().getCode());
+            metric.setReason(response.getStatus().getReasonPhrase().toString());
+            metric.setRespVersion(response.getVersion().toString());
+        }
+
+        reporterClient.send(metric);
+    }
+
+    @Override
+    public void handle(MetricsCollection mc) {
+        reporterClient.send(mc);
+    }
+
+    @Override
+    public void sequenceDetected(MapMetric sequence) {
+        reporterClient.send(sequence);
+    }
+}
--- a/stress-tester/src/main/java/com/passus/st/client/http/ReporterWrapper.java	Fri Sep 29 16:35:53 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,141 +0,0 @@
-package com.passus.st.client.http;
-
-import com.passus.commons.metric.MapMetric;
-import com.passus.commons.metric.MetricsCollection;
-import com.passus.data.ByteString;
-import com.passus.net.SocketAddress;
-import com.passus.net.http.HttpHeaders;
-import com.passus.net.http.HttpMessage;
-import com.passus.net.http.HttpRequest;
-import com.passus.net.http.HttpResponse;
-import com.passus.st.ParametersBag;
-import static com.passus.st.client.http.HttpConsts.PARAM_USERNAME;
-import static com.passus.st.client.http.HttpConsts.TAG_CONTENT_SIZE;
-import static com.passus.st.client.http.HttpConsts.TAG_HEADER_SIZE;
-import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID;
-import static com.passus.st.client.http.HttpConsts.TAG_TIME_END;
-import static com.passus.st.client.http.HttpConsts.TAG_TIME_START;
-import com.passus.st.client.http.filter.HttpSequenceListener;
-import com.passus.st.emitter.SessionInfo;
-import com.passus.st.metric.MetricsCollectionHandler;
-import com.passus.st.reporter.ReporterClient;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- *
- * @author Mirosław Hawrot
- */
-public class ReporterWrapper implements HttpClientListener, MetricsCollectionHandler, HttpSequenceListener {
-
-    private static final Set<ByteString> ALLOWED_REQ_HEADERS = new HashSet<>();
-    private static final Set<ByteString> ALLOWED_RESP_HEADERS = new HashSet<>();
-
-    private final ReporterClient reporterClient;
-
-    public ReporterWrapper(ReporterClient reporterClient) {
-        this.reporterClient = reporterClient;
-    }
-
-    static {
-        ALLOWED_REQ_HEADERS.add(HttpHeaders.USER_AGENT);
-        ALLOWED_REQ_HEADERS.add(HttpHeaders.CONTENT_TYPE);
-        ALLOWED_RESP_HEADERS.add(HttpHeaders.CONTENT_TYPE);
-    }
-
-    private void populateHeaders(Map<CharSequence, CharSequence> dst, Set<ByteString> allowedHeaders, HttpMessage message) {
-        HttpHeaders headers = message.getHeaders();
-        for (ByteString name : allowedHeaders) {
-            ByteString value = headers.get(name);
-            if (value != null) {
-                dst.put(name, value);
-            }
-        }
-    }
-
-    private void populateMisc(Map<CharSequence, CharSequence> misc, HttpFlowContext context, HttpRequest request) {
-        ParametersBag params = context.scopes().getSession(request, false);
-        String username = params == null ? null : (String) params.get(PARAM_USERNAME);
-
-        String sessionId = (String) request.getTag(TAG_SESSION_ID);
-        if (username != null || sessionId != null) {
-            if (username != null) {
-                misc.put("username", username);
-            }
-
-            if (sessionId != null) {
-                misc.put("sessionId", sessionId);
-            }
-        }
-    }
-
-    @Override
-    public void responseReceived(HttpRequest request, HttpResponse response, HttpFlowContext context) {
-        if (request == null && response == null) {
-            return;
-        }
-
-        SessionInfo session = context.sessionInfo();
-
-        HttpRequestResponseMetric metric = new HttpRequestResponseMetric();
-
-        if (context.channelContext != null) {
-            SocketAddress localAddress = context.channelContext.getLocalAddress();
-            SocketAddress remoteAddress = context.channelContext.getRemoteAddress();
-            metric.setClientIp(localAddress.getIp().toString());
-            metric.setClientPort(localAddress.getPort());
-            metric.setServerIp(remoteAddress.getIp().toString());
-            metric.setServerPort(remoteAddress.getPort());
-        } else {
-            metric.setClientIp(session.getSrcIp().toString());
-            metric.setClientPort(session.getSrcPort());
-            metric.setServerIp(session.getDstIp().toString());
-            metric.setServerPort(session.getDstPort());
-        }
-        metric.setOrigClientIp(session.getSrcIp().toString());
-        metric.setOrigClientPort(session.getSrcPort());
-        metric.setOrigServerIp(session.getDstIp().toString());
-        metric.setOrigServerPort(session.getDstPort());
-
-        if (request != null) {
-            metric.setReqId(request.getId());
-            populateHeaders(metric.getReqHdrs(), ALLOWED_REQ_HEADERS, request);
-            populateMisc(metric.getMisc(), context, request);
-
-            metric.setReqHdrSize((Long) request.getTag(TAG_HEADER_SIZE));
-            metric.setReqCntSize((Long) request.getTag(TAG_CONTENT_SIZE));
-            metric.setReqStart((Long) request.getTag(TAG_TIME_START));
-            metric.setReqStop((Long) request.getTag(TAG_TIME_END));
-
-            metric.setMethod(request.getMethod().toString());
-            metric.setUrl(request.getUrl().toString());
-            metric.setReqVersion(request.getVersion().toString());
-        }
-
-        if (response != null) {
-            populateHeaders(metric.getRespHdrs(), ALLOWED_RESP_HEADERS, response);
-
-            metric.setRespHdrSize((Long) response.getTag(TAG_HEADER_SIZE));
-            metric.setRespCntSize((Long) response.getTag(TAG_CONTENT_SIZE));
-            metric.setRespStart((Long) response.getTag(TAG_TIME_START));
-            metric.setRespStop((Long) response.getTag(TAG_TIME_END));
-
-            metric.setCode(response.getStatus().getCode());
-            metric.setReason(response.getStatus().getReasonPhrase().toString());
-            metric.setRespVersion(response.getVersion().toString());
-        }
-
-        reporterClient.send(metric);
-    }
-
-    @Override
-    public void handle(MetricsCollection mc) {
-        reporterClient.send(mc);
-    }
-
-    @Override
-    public void sequenceDetected(MapMetric sequence) {
-        reporterClient.send(sequence);
-    }
-}
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java	Fri Sep 29 16:35:53 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java	Mon Oct 02 09:41:54 2017 +0200
@@ -25,7 +25,8 @@
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpResponse;
 import com.passus.st.client.http.HttpFlowContext;
-import com.passus.st.client.http.ReporterWrapper;
+import com.passus.st.client.http.ReporterDestination;
+import com.passus.st.client.http.ReporterRemoteDestination;
 import com.passus.st.plugin.PluginConstants;
 import java.io.Serializable;
 import java.text.ParseException;
@@ -378,7 +379,8 @@
 
         values = (Map<String, ValueExtractor>) config.get("values", Collections.EMPTY_MAP);
 
-        ReporterWrapper reporterWrapper = Registry.getInstance().get("reporterWrapper", ReporterWrapper.class);
+        ReporterRemoteDestination reporterWrapper = Registry.getInstance().get(
+                ReporterDestination.SERVICE_NAME, ReporterRemoteDestination.class);
         if (reporterWrapper != null) {
             listener = reporterWrapper;
         }