From: Marian Dubai Date: Fri, 14 Nov 2014 14:52:51 +0000 (+0100) Subject: Fix checkstyle warnings in netconf-netty-util X-Git-Tag: release/lithium~832 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=d5fcdd3416922d61f0bdebbe57e351456e3a3750 Fix checkstyle warnings in netconf-netty-util Change-Id: I123c7cbff15c1267a1bdb537e100c1bf2f9894d7 Signed-off-by: Marian Dubai --- diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java index e0799d3a2a..4eaeee9d78 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java @@ -26,7 +26,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class AbstractNetconfSession> extends AbstractProtocolSession implements NetconfSession, NetconfExiSession { - private static final Logger logger = LoggerFactory.getLogger(AbstractNetconfSession.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSession.class); private final L sessionListener; private final long sessionId; private boolean up = false; @@ -39,7 +39,7 @@ public abstract class AbstractNetconfSession, L extends NetconfSessionListener> -extends AbstractSessionNegotiator { + extends AbstractSessionNegotiator { - private static final Logger logger = LoggerFactory.getLogger(AbstractNetconfSessionNegotiator.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSessionNegotiator.class); public static final String NAME_OF_EXCEPTION_HANDLER = "lastExceptionHandler"; @@ -85,7 +85,7 @@ extends AbstractSessionNegotiator { @Override public void operationComplete(Future future) { Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); - logger.debug("Ssl handshake complete"); + LOG.debug("Ssl handshake complete"); start(); } }); @@ -105,7 +105,7 @@ extends AbstractSessionNegotiator { private void start() { final NetconfMessage helloMessage = this.sessionPreferences.getHelloMessage(); - logger.debug("Session negotiation started with hello message {} on channel {}", XmlUtil.toString(helloMessage.getDocument()), channel); + LOG.debug("Session negotiation started with hello message {} on channel {}", XmlUtil.toString(helloMessage.getDocument()), channel); channel.pipeline().addLast(NAME_OF_EXCEPTION_HANDLER, new ExceptionHandlingInboundChannelHandler()); @@ -121,7 +121,7 @@ extends AbstractSessionNegotiator { synchronized (this) { if (state != State.ESTABLISHED) { - logger.debug("Connection timeout after {}, session is in state {}", timeout, state); + LOG.debug("Connection timeout after {}, session is in state {}", timeout, state); // Do not fail negotiation if promise is done or canceled // It would result in setting result of the promise second time and that throws exception @@ -133,9 +133,9 @@ extends AbstractSessionNegotiator { @Override public void operationComplete(ChannelFuture future) throws Exception { if(future.isSuccess()) { - logger.debug("Channel {} closed: success", future.channel()); + LOG.debug("Channel {} closed: success", future.channel()); } else { - logger.warn("Channel {} closed: fail", future.channel()); + LOG.warn("Channel {} closed: fail", future.channel()); } } }); @@ -223,7 +223,7 @@ extends AbstractSessionNegotiator { protected abstract S getSession(L sessionListener, Channel channel, NetconfHelloMessage message) throws NetconfDocumentedException; private synchronized void changeState(final State newState) { - logger.debug("Changing state from : {} to : {} for channel: {}", state, newState, channel); + LOG.debug("Changing state from : {} to : {} for channel: {}", state, newState, channel); Preconditions.checkState(isStateChangePermitted(state, newState), "Cannot change state from %s to %s for chanel %s", state, newState, channel); this.state = newState; @@ -249,7 +249,7 @@ extends AbstractSessionNegotiator { if (state == State.OPEN_WAIT && newState == State.FAILED) { return true; } - logger.debug("Transition from {} to {} is not allowed", state, newState); + LOG.debug("Transition from {} to {} is not allowed", state, newState); return false; } @@ -259,7 +259,7 @@ extends AbstractSessionNegotiator { private final class ExceptionHandlingInboundChannelHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - logger.warn("An exception occurred during negotiation with {}", channel.remoteAddress(), cause); + LOG.warn("An exception occurred during negotiation with {}", channel.remoteAddress(), cause); cancelTimeout(); negotiationFailed(cause); changeState(State.FAILED); diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ChunkedFramingMechanismEncoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ChunkedFramingMechanismEncoder.java index a66e45882f..c4cddb802e 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ChunkedFramingMechanismEncoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ChunkedFramingMechanismEncoder.java @@ -8,16 +8,14 @@ package org.opendaylight.controller.netconf.nettyutil.handler; +import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; - import org.opendaylight.controller.netconf.util.messages.NetconfMessageConstants; import org.opendaylight.controller.netconf.util.messages.NetconfMessageHeader; -import com.google.common.base.Preconditions; - public class ChunkedFramingMechanismEncoder extends MessageToByteEncoder { public static final int DEFAULT_CHUNK_SIZE = 8192; public static final int MIN_CHUNK_SIZE = 128; diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/EOMFramingMechanismEncoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/EOMFramingMechanismEncoder.java index 92d8f12c1a..514b2e129e 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/EOMFramingMechanismEncoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/EOMFramingMechanismEncoder.java @@ -11,7 +11,6 @@ package org.opendaylight.controller.netconf.nettyutil.handler; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; - import org.opendaylight.controller.netconf.util.messages.NetconfMessageConstants; public class EOMFramingMechanismEncoder extends MessageToByteEncoder { diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java index 35f7679496..30589daa22 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java @@ -8,23 +8,22 @@ package org.opendaylight.controller.netconf.nettyutil.handler; +import io.netty.buffer.ByteBuf; +import io.netty.handler.codec.MessageToByteEncoder; import org.opendaylight.controller.netconf.util.messages.FramingMechanism; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.MessageToByteEncoder; - public final class FramingMechanismHandlerFactory { - private static final Logger logger = LoggerFactory.getLogger(FramingMechanismHandlerFactory.class); + private static final Logger LOG = LoggerFactory.getLogger(FramingMechanismHandlerFactory.class); private FramingMechanismHandlerFactory() { // not called - private constructor for utility class } public static MessageToByteEncoder createHandler(FramingMechanism framingMechanism) { - logger.debug("{} framing mechanism was selected.", framingMechanism); + LOG.debug("{} framing mechanism was selected.", framingMechanism); if (framingMechanism == FramingMechanism.EOM) { return new EOMFramingMechanismEncoder(); } else { diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfChunkAggregator.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfChunkAggregator.java index e2a745f3fb..6a7b752023 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfChunkAggregator.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfChunkAggregator.java @@ -8,19 +8,17 @@ package org.opendaylight.controller.netconf.nettyutil.handler; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.netty.buffer.ByteBuf; import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NetconfChunkAggregator extends ByteToMessageDecoder { - private final static Logger logger = LoggerFactory.getLogger(NetconfChunkAggregator.class); + private final static Logger LOG = LoggerFactory.getLogger(NetconfChunkAggregator.class); private static final String GOT_PARAM_WHILE_WAITING_FOR_PARAM = "Got byte {} while waiting for {}"; private static final String GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM = "Got byte {} while waiting for {}-{}"; public static final int DEFAULT_MAXIMUM_CHUNK_SIZE = 16 * 1024 * 1024; @@ -44,21 +42,21 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder { private void checkNewLine(byte b,String errorMessage){ if (b != '\n') { - logger.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM, b, (byte)'\n'); + LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM, b, (byte)'\n'); throw new IllegalStateException(errorMessage); } } private void checkHash(byte b,String errorMessage){ if (b != '#') { - logger.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM, b, (byte)'#'); + LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM, b, (byte)'#'); throw new IllegalStateException(errorMessage); } } private void checkChunkSize(){ if (chunkSize > maxChunkSize) { - logger.debug("Parsed chunk size {}, maximum allowed is {}", chunkSize, maxChunkSize); + LOG.debug("Parsed chunk size {}, maximum allowed is {}", chunkSize, maxChunkSize); throw new IllegalStateException("Maximum chunk size exceeded"); } @@ -101,7 +99,7 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder { } if (b < '0' || b > '9') { - logger.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte)'0', (byte)'9'); + LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte)'0', (byte)'9'); throw new IllegalStateException("Invalid chunk size encountered"); } @@ -118,7 +116,7 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder { * comes through. */ if (in.readableBytes() < chunkSize) { - logger.debug("Buffer has {} bytes, need {} to complete chunk", in.readableBytes(), chunkSize); + LOG.debug("Buffer has {} bytes, need {} to complete chunk", in.readableBytes(), chunkSize); in.discardReadBytes(); return; } @@ -175,7 +173,7 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder { } else if (b == '#') { state = State.FOOTER_FOUR; } else { - logger.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte) '#', (byte) '1', (byte) '9'); + LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte) '#', (byte) '1', (byte) '9'); throw new IllegalStateException("Malformed chunk footer encountered (byte 2)"); } } @@ -193,7 +191,7 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder { private static int processHeaderLengthFirst(byte b) { if (!isHeaderLengthFirst(b)) { - logger.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte)'1', (byte)'9'); + LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte)'1', (byte)'9'); throw new IllegalStateException("Invalid chunk size encountered (byte 0)"); } diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java index 57134af3c7..db3dcafbde 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java @@ -7,14 +7,18 @@ */ package org.opendaylight.controller.netconf.nettyutil.handler; +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufUtil; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; import java.io.InputStream; import java.util.List; - import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; - import org.opendaylight.controller.netconf.api.NetconfMessage; import org.openexi.sax.EXIReader; import org.slf4j.Logger; @@ -22,14 +26,6 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; -import com.google.common.base.Preconditions; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufUtil; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder { private static final Logger LOG = LoggerFactory.getLogger(NetconfEXIToMessageDecoder.class); @@ -60,7 +56,7 @@ public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder { final EXIReader r = codec.getReader(); final SAXTransformerFactory transformerFactory - = (SAXTransformerFactory) TransformerFactory.newInstance(); + = (SAXTransformerFactory) TransformerFactory.newInstance(); final TransformerHandler handler = transformerFactory.newTransformerHandler(); r.setContentHandler(handler); diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfHelloMessageToXMLEncoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfHelloMessageToXMLEncoder.java index f39e2c425d..8af5cf3ff4 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfHelloMessageToXMLEncoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfHelloMessageToXMLEncoder.java @@ -7,22 +7,18 @@ */ package org.opendaylight.controller.netconf.nettyutil.handler; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Charsets; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; - import java.io.IOException; - import javax.xml.transform.TransformerException; - import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; - /** * Customized NetconfMessageToXMLEncoder that serializes additional header with * session metadata along with diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToXMLEncoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToXMLEncoder.java index d810a870ff..8ce9411cbd 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToXMLEncoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToXMLEncoder.java @@ -7,32 +7,28 @@ */ package org.opendaylight.controller.netconf.nettyutil.handler; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; - import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; - import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; - import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Comment; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; - public class NetconfMessageToXMLEncoder extends MessageToByteEncoder { private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageToXMLEncoder.class); private static final TransformerFactory FACTORY = TransformerFactory.newInstance(); diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoder.java index efe4861577..197ae5f424 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoder.java @@ -7,19 +7,20 @@ */ package org.opendaylight.controller.netconf.nettyutil.handler; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Charsets; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.List; - import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; @@ -28,10 +29,6 @@ import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; import org.xml.sax.SAXException; /** diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParameters.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParameters.java index ccd7dead9f..8590068774 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParameters.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParameters.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.netconf.nettyutil.handler.exi; +import com.google.common.base.Preconditions; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.openexi.proc.common.AlignmentType; import org.openexi.proc.common.EXIOptions; @@ -14,8 +15,6 @@ import org.openexi.proc.common.EXIOptionsException; import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import com.google.common.base.Preconditions; - public final class EXIParameters { private static final String EXI_PARAMETER_ALIGNMENT = "alignment"; static final String EXI_PARAMETER_BYTE_ALIGNED = "byte-aligned"; diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java index fa7d0900ed..14d753f1f8 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java @@ -8,9 +8,13 @@ package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOutboundHandlerAdapter; +import io.netty.channel.ChannelPromise; import java.io.IOException; import java.net.SocketAddress; - import org.apache.sshd.ClientChannel; import org.apache.sshd.ClientSession; import org.apache.sshd.SshClient; @@ -23,19 +27,12 @@ import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication. import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelOutboundHandlerAdapter; -import io.netty.channel.ChannelPromise; - /** * Netty SSH handler class. Acts as interface between Netty and SSH library. */ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { - private static final Logger logger = LoggerFactory.getLogger(AsyncSshHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(AsyncSshHandler.class); public static final String SUBSYSTEM = "netconf"; public static final SshClient DEFAULT_CLIENT = SshClient.setUpDefaultClient(); @@ -77,7 +74,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { } private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) { - logger.debug("Starting SSH to {} on channel: {}", address, ctx.channel()); + LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel()); final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address); sshConnectionFuture.addListener(new SshFutureListener() { @@ -94,7 +91,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { private synchronized void handleSshSessionCreated(final ConnectFuture future, final ChannelHandlerContext ctx) { try { - logger.trace("SSH session created on channel: {}", ctx.channel()); + LOG.trace("SSH session created on channel: {}", ctx.channel()); session = future.getSession(); final AuthFuture authenticateFuture = authenticationHandler.authenticate(session); @@ -115,7 +112,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { private synchronized void handleSshAuthenticated(final ClientSession session, final ChannelHandlerContext ctx) { try { - logger.debug("SSH session authenticated on channel: {}, server version: {}", ctx.channel(), session.getServerVersion()); + LOG.debug("SSH session authenticated on channel: {}, server version: {}", ctx.channel(), session.getServerVersion()); channel = session.createSubsystemChannel(SUBSYSTEM); channel.setStreaming(ClientChannel.Streaming.Async); @@ -137,7 +134,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { } private synchronized void handleSshChanelOpened(final ChannelHandlerContext ctx) { - logger.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel()); + LOG.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel()); connectPromise.setSuccess(); connectPromise = null; @@ -164,7 +161,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { } private synchronized void handleSshSetupFailure(final ChannelHandlerContext ctx, final Throwable e) { - logger.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), e); + LOG.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), e); connectPromise.setFailure(e); connectPromise = null; throw new IllegalStateException("Unable to setup SSH connection on channel: " + ctx.channel(), e); @@ -211,7 +208,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { channel = null; promise.setSuccess(); - logger.debug("SSH session closed on channel: {}", ctx.channel()); + LOG.debug("SSH session closed on channel: {}", ctx.channel()); ctx.fireChannelInactive(); } diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerReader.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerReader.java index ada15583cd..ca212e7c47 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerReader.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerReader.java @@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory; */ public final class AsyncSshHandlerReader implements SshFutureListener, AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(AsyncSshHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(AsyncSshHandlerReader.class); private static final int BUFFER_SIZE = 8192; @@ -49,9 +49,9 @@ public final class AsyncSshHandlerReader implements SshFutureListener 0) { final ByteBuf msg = Unpooled.wrappedBuffer(buf.array(), 0, future.getRead()); - if(logger.isTraceEnabled()) { - logger.trace("Reading message on channel: {}, message: {}", channelId, AsyncSshHandlerWriter.byteBufToString(msg)); + if(LOG.isTraceEnabled()) { + LOG.trace("Reading message on channel: {}, message: {}", channelId, AsyncSshHandlerWriter.byteBufToString(msg)); } readHandler.onMessageRead(msg); diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java index 8e639bd47c..1e976ce6a1 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; */ public final class AsyncSshHandlerWriter implements AutoCloseable { - private static final Logger logger = LoggerFactory + private static final Logger LOG = LoggerFactory .getLogger(AsyncSshHandlerWriter.class); // public static final int MAX_PENDING_WRITES = 1000; @@ -68,34 +68,34 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { private void writeWithPendingDetection(final ChannelHandlerContext ctx, final ChannelPromise promise, final ByteBuf byteBufMsg) { try { - if (logger.isTraceEnabled()) { - logger.trace("Writing request on channel: {}, message: {}", ctx.channel(), byteBufToString(byteBufMsg)); + if (LOG.isTraceEnabled()) { + LOG.trace("Writing request on channel: {}, message: {}", ctx.channel(), byteBufToString(byteBufMsg)); } asyncIn.write(toBuffer(byteBufMsg)).addListener(new SshFutureListener() { - @Override - public void operationComplete(final IoWriteFuture future) { - if (logger.isTraceEnabled()) { - logger.trace("Ssh write request finished on channel: {} with result: {}: and ex:{}, message: {}", + @Override + public void operationComplete(final IoWriteFuture future) { + if (LOG.isTraceEnabled()) { + LOG.trace("Ssh write request finished on channel: {} with result: {}: and ex:{}, message: {}", ctx.channel(), future.isWritten(), future.getException(), byteBufToString(byteBufMsg)); - } - - // Notify success or failure - if (future.isWritten()) { - promise.setSuccess(); - } else { - logger.warn("Ssh write request failed on channel: {} for message: {}", ctx.channel(), byteBufToString(byteBufMsg), future.getException()); - promise.setFailure(future.getException()); - } - - // Not needed anymore, release - byteBufMsg.release(); - - // Check pending queue and schedule next - // At this time we are guaranteed that we are not in pending state anymore so the next request should succeed - writePendingIfAny(); - } - }); + } + + // Notify success or failure + if (future.isWritten()) { + promise.setSuccess(); + } else { + LOG.warn("Ssh write request failed on channel: {} for message: {}", ctx.channel(), byteBufToString(byteBufMsg), future.getException()); + promise.setFailure(future.getException()); + } + + // Not needed anymore, release + byteBufMsg.release(); + + // Check pending queue and schedule next + // At this time we are guaranteed that we are not in pending state anymore so the next request should succeed + writePendingIfAny(); + } + }); } catch (final WritePendingException e) { queueRequest(ctx, byteBufMsg, promise); } @@ -109,8 +109,8 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { // In case of pending, reschedule next message from queue final PendingWriteRequest pendingWrite = pending.poll(); final ByteBuf msg = pendingWrite.msg; - if (logger.isTraceEnabled()) { - logger.trace("Writing pending request on channel: {}, message: {}", pendingWrite.ctx.channel(), byteBufToString(msg)); + if (LOG.isTraceEnabled()) { + LOG.trace("Writing pending request on channel: {}, message: {}", pendingWrite.ctx.channel(), byteBufToString(msg)); } writeWithPendingDetection(pendingWrite.ctx, pendingWrite.promise, msg); @@ -125,13 +125,13 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { private void queueRequest(final ChannelHandlerContext ctx, final ByteBuf msg, final ChannelPromise promise) { // try { - logger.debug("Write pending on channel: {}, queueing, current queue size: {}", ctx.channel(), pending.size()); - if (logger.isTraceEnabled()) { - logger.trace("Queueing request due to pending: {}", byteBufToString(msg)); + LOG.debug("Write pending on channel: {}, queueing, current queue size: {}", ctx.channel(), pending.size()); + if (LOG.isTraceEnabled()) { + LOG.trace("Queueing request due to pending: {}", byteBufToString(msg)); } new PendingWriteRequest(ctx, msg, promise).pend(pending); // } catch (final Exception ex) { -// logger.warn("Unable to queue write request on channel: {}. Setting fail for the request: {}", ctx.channel(), ex, byteBufToString(msg)); +// LOG.warn("Unable to queue write request on channel: {}. Setting fail for the request: {}", ctx.channel(), ex, byteBufToString(msg)); // msg.release(); // promise.setFailure(ex); // } diff --git a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIHandlersTest.java b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIHandlersTest.java index 8bc0fb8e82..4f804abfe8 100644 --- a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIHandlersTest.java +++ b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXIHandlersTest.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.netconf.nettyutil.handler; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; + import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; diff --git a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParametersTest.java b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParametersTest.java index 15ba3b41f8..70186f39a4 100644 --- a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParametersTest.java +++ b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/EXIParametersTest.java @@ -51,8 +51,8 @@ public class EXIParametersTest { fullOptions.setPreservePIs(true); return Arrays.asList(new Object[][]{ - {noChangeXml, new EXIOptions()}, - {fullOptionsXml, fullOptions}, + {noChangeXml, new EXIOptions()}, + {fullOptionsXml, fullOptions}, }); } diff --git a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/NetconfStartExiMessageTest.java b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/NetconfStartExiMessageTest.java index 47abe96687..9d831729fc 100644 --- a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/NetconfStartExiMessageTest.java +++ b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/exi/NetconfStartExiMessageTest.java @@ -53,8 +53,8 @@ public class NetconfStartExiMessageTest { fullOptions.setPreservePIs(true); return Arrays.asList(new Object[][]{ - {noChangeXml, new EXIOptions()}, - {fullOptionsXml, fullOptions}, + {noChangeXml, new EXIOptions()}, + {fullOptionsXml, fullOptions}, }); } diff --git a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java index b4c9e1e950..73f2287c8b 100644 --- a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java +++ b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; + import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture;