Mercurial > stress-tester
changeset 1061:b79ecce8df37
PgSqlFlowHandlerNetflowFlowHandler -> PgSqlFlowHandler
author | Devel 2 |
---|---|
date | Fri, 17 Apr 2020 11:13:20 +0200 |
parents | efe41a7d7272 |
children | 46ebffd7b305 |
files | stress-tester/src/main/java/com/passus/st/client/pgsql/PgSqlFlowHandler.java stress-tester/src/main/java/com/passus/st/client/pgsql/PgSqlFlowHandlerNetflowFlowHandler.java |
diffstat | 2 files changed, 102 insertions(+), 100 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/client/pgsql/PgSqlFlowHandler.java Fri Apr 17 11:13:20 2020 +0200 @@ -0,0 +1,102 @@ +package com.passus.st.client.pgsql; + +import com.passus.commons.Assert; +import com.passus.commons.time.TimeAware; +import com.passus.commons.time.TimeGenerator; +import com.passus.net.pgsql.PgSqlErrorResponseMessage; +import com.passus.net.pgsql.PgSqlMessage; +import com.passus.net.pgsql.PgSqlMessageType; +import com.passus.net.pgsql.PgSqlSimpleQueryMessage; +import com.passus.st.client.AbstractFlowHandler; +import com.passus.st.client.FlowContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import static com.passus.st.Protocols.NETFLOW; + +public class PgSqlFlowHandler extends AbstractFlowHandler<PgSqlMetric, PgSqlMessage, PgSqlMessage> implements TimeAware { + + private final Logger LOGGER = LogManager.getLogger(PgSqlFlowHandler.class); + + TimeGenerator timeGenerator = TimeGenerator.getDefaultGenerator(); + + public PgSqlFlowHandler() { + super(new PgSqlFlowHandlerDataEncoder(), new PgSqlFlowHandlerDataDecoder()); + } + + @Override + public int getProtocolId() { + return NETFLOW; + } + + @Override + protected PgSqlMetric createMetric() { + return new PgSqlMetric(); + } + + @Override + protected void onRequestSent0(PgSqlMessage req, FlowContext flowContext) { + if (collectMetrics) { + if (req.getType() == PgSqlMessageType.SIMPLE_QUERY) { + PgSqlSimpleQueryMessage simpleQueryMsg = (PgSqlSimpleQueryMessage) req; + synchronized (metric) { + metric.addQuery(simpleQueryMsg.getQuery()); + } + } + } + } + + private void disconnectAndBlock(FlowContext flowContext) { + try { + flowContext.block(); + flowContext.channelContext().close(); + } catch (Exception ignore) { + + } + } + + @Override + protected void onResponseReceived0(PgSqlMessage resp, FlowContext flowContext) { + if (resp.getType() == PgSqlMessageType.ERROR_RESPONSE) { + PgSqlErrorResponseMessage errorMsg = (PgSqlErrorResponseMessage) resp; + if (collectMetrics) { + synchronized (metric) { + metric.addErrorCode(errorMsg.getCode()); + } + } + + PgSqlMessage req = (PgSqlMessage) flowContext.sentRequest(); + if (req.getType() == PgSqlMessageType.STARTUP_MESSAGE) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("PgSql auth failed. Server message " + errorMsg); + } + + disconnectAndBlock(flowContext); + } else if (errorMsg.isConnectionExceptionClass()) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Fatal error. Server message " + errorMsg); + } + + disconnectAndBlock(flowContext); + } + } + } + + @Override + public TimeGenerator getTimeGenerator() { + return timeGenerator; + } + + @Override + public void setTimeGenerator(TimeGenerator timeGenerator) { + Assert.notNull(timeGenerator, "timeGenerator"); + this.timeGenerator = timeGenerator; + } + + @Override + public void init(FlowContext flowContext) { + flowContext.setBidirectional(true); + } + + +} \ No newline at end of file
--- a/stress-tester/src/main/java/com/passus/st/client/pgsql/PgSqlFlowHandlerNetflowFlowHandler.java Thu Apr 16 14:14:53 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -package com.passus.st.client.pgsql; - -import com.passus.commons.Assert; -import com.passus.commons.time.TimeAware; -import com.passus.commons.time.TimeGenerator; -import com.passus.net.pgsql.PgSqlErrorResponseMessage; -import com.passus.net.pgsql.PgSqlMessage; -import com.passus.net.pgsql.PgSqlMessageType; -import com.passus.net.pgsql.PgSqlSimpleQueryMessage; -import com.passus.st.client.AbstractFlowHandler; -import com.passus.st.client.FlowContext; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.IOException; - -import static com.passus.st.Protocols.NETFLOW; - -public class PgSqlFlowHandlerNetflowFlowHandler extends AbstractFlowHandler<PgSqlMetric, PgSqlMessage, PgSqlMessage> implements TimeAware { - - private final Logger LOGGER = LogManager.getLogger(PgSqlFlowHandlerNetflowFlowHandler.class); - - TimeGenerator timeGenerator = TimeGenerator.getDefaultGenerator(); - - public PgSqlFlowHandlerNetflowFlowHandler() { - super(new PgSqlFlowHandlerDataEncoder(), new PgSqlFlowHandlerDataDecoder()); - } - - @Override - public int getProtocolId() { - return NETFLOW; - } - - @Override - protected PgSqlMetric createMetric() { - return new PgSqlMetric(); - } - - @Override - protected void onRequestSent0(PgSqlMessage req, FlowContext flowContext) { - if (collectMetrics) { - if (req.getType() == PgSqlMessageType.SIMPLE_QUERY) { - PgSqlSimpleQueryMessage simpleQueryMsg = (PgSqlSimpleQueryMessage) req; - synchronized (metric) { - metric.addQuery(simpleQueryMsg.getQuery()); - } - } - } - } - - private void disconnectAndBlock(FlowContext flowContext) { - try { - flowContext.block(); - flowContext.channelContext().close(); - } catch (IOException ignore) { - - } finally { - - } - } - - @Override - protected void onResponseReceived0(PgSqlMessage resp, FlowContext flowContext) { - if (resp.getType() == PgSqlMessageType.ERROR_RESPONSE) { - PgSqlErrorResponseMessage errorMsg = (PgSqlErrorResponseMessage) resp; - PgSqlMessage req = (PgSqlMessage) flowContext.sentRequest(); - if (req.getType() == PgSqlMessageType.STARTUP_MESSAGE) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("PgSql auth failed. Server message " + errorMsg); - } - - disconnectAndBlock(flowContext); - } else if(errorMsg.isConnectionExceptionClass()) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Fatal error. Server message " + errorMsg); - } - - disconnectAndBlock(flowContext); - } - } - } - - @Override - public TimeGenerator getTimeGenerator() { - return timeGenerator; - } - - @Override - public void setTimeGenerator(TimeGenerator timeGenerator) { - Assert.notNull(timeGenerator, "timeGenerator"); - this.timeGenerator = timeGenerator; - } - - @Override - public void init(FlowContext flowContext) { - flowContext.setBidirectional(true); - } - - -} \ No newline at end of file