Added channel to logs in NETCONF negotiator 72/98272/3
authorJaroslav Tóth <jtoth@frinx.io>
Tue, 26 Oct 2021 18:27:25 +0000 (20:27 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 11 Nov 2021 12:20:07 +0000 (12:20 +0000)
- It simplifies debugging and investigation of deployment
  with a lot of NETCONF MPs.

JIRA: NETCONF-827
Change-Id: I221aab35e8d8d63481130678e1c755077125ad74
Signed-off-by: Jaroslav Tóth <jtoth@frinx.io>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java

index 1816fee0e041f119c0b545e37e4bf21055b2c585..46ae45589f2cd99a069d01128d4de0e88645a777 100644 (file)
@@ -73,7 +73,7 @@ public class NetconfClientSessionNegotiator extends
             try {
                 startNegotiation();
             } catch (final Exception e) {
-                LOG.warn("Unexpected negotiation failure", e);
+                LOG.warn("Unexpected negotiation failure on channel {}", channel, e);
                 negotiationFailed(e);
                 return;
             }
index 978bd381c2afe9e74dd05ccbc0f4b541b38b4828..171d8d2cdff1b69d6337dc7ff5f3e6aeddcc6ca1 100644 (file)
@@ -126,12 +126,14 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
                 synchronized (this) {
                     if (state != State.ESTABLISHED) {
 
-                        LOG.debug("Connection timeout after {}, session is in state {}", timeout, state);
+                        LOG.debug("Connection timeout after {}, session backed by channel {} is in state {}",
+                                timeout, channel, 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
                         if (!isPromiseFinished()) {
-                            LOG.warn("Netconf session was not established after {}", connectionTimeoutMillis);
+                            LOG.warn("Netconf session backed by channel {} was not established after {}",
+                                    channel, connectionTimeoutMillis);
                             changeState(State.FAILED);
 
                             channel.close().addListener((GenericFutureListener<ChannelFuture>) future -> {
@@ -235,7 +237,7 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
     private synchronized void changeState(final State newState) {
         LOG.debug("Changing state from : {} to : {} for channel: {}", state, newState, channel);
         checkState(isStateChangePermitted(state, newState),
-                "Cannot change state from %s to %s for chanel %s", state, newState, channel);
+                "Cannot change state from %s to %s for channel %s", state, newState, channel);
         this.state = newState;
     }
 
@@ -271,7 +273,8 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
     private final class ExceptionHandlingInboundChannelHandler extends ChannelInboundHandlerAdapter {
         @Override
         public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
-            LOG.warn("An exception occurred during negotiation with {}", channel.remoteAddress(), cause);
+            LOG.warn("An exception occurred during negotiation with {} on channel {}",
+                    channel.remoteAddress(), channel, cause);
             cancelTimeout();
             negotiationFailed(cause);
             changeState(State.FAILED);
@@ -299,10 +302,10 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
     protected final void sendMessage(final NetconfMessage msg) {
         this.channel.writeAndFlush(msg).addListener(f -> {
             if (!f.isSuccess()) {
-                LOG.info("Failed to send message {}", msg, f.cause());
+                LOG.info("Failed to send message {} on channel {}", msg, channel, f.cause());
                 negotiationFailed(f.cause());
             } else {
-                LOG.trace("Message {} sent to socket", msg);
+                LOG.trace("Message {} sent to socket on channel {}", msg, channel);
             }
         });
     }
@@ -314,7 +317,7 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
         try {
             startNegotiation();
         } catch (final Exception e) {
-            LOG.warn("Unexpected negotiation failure", e);
+            LOG.warn("Unexpected negotiation failure on channel {}", channel, e);
             negotiationFailed(e);
         }
     }
@@ -326,14 +329,14 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
         try {
             handleMessage((NetconfHelloMessage) msg);
         } catch (final Exception e) {
-            LOG.debug("Unexpected error while handling negotiation message {}", msg, e);
+            LOG.debug("Unexpected error while handling negotiation message {} on channel {}", msg, channel, e);
             negotiationFailed(e);
         }
     }
 
     @Override
     public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
-        LOG.info("Unexpected error during negotiation", cause);
+        LOG.info("Unexpected error during negotiation on channel {}", channel, cause);
         negotiationFailed(cause);
     }