Rename AsyncSshHandler.handleSshSetupFailure() 20/102720/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 09:02:06 +0000 (11:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 11:57:25 +0000 (13:57 +0200)
Rename this method to onOpenFailure() and move it to a more appropriate
place.

JIRA: NETCONF-905
Change-Id: I9ab3b6d4e7701fe3ee432ee0965322426dda0bec
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java

index 0934720948cb33085b5e29862741de40bb4b3459..c8312e9419af95fe90a91c8130f35c74319a0ff1 100644 (file)
@@ -103,17 +103,6 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
                 negotiationFuture);
     }
 
-    private synchronized void handleSshSetupFailure(final ChannelHandlerContext ctx, final Throwable error) {
-        LOG.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), error);
-
-        // If the promise is not yet done, we have failed with initial connect and set connectPromise to failure
-        if (!connectPromise.isDone()) {
-            connectPromise.setFailure(error);
-        }
-
-        disconnect(ctx, ctx.newPromise());
-    }
-
     @Override
     public synchronized void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
         sshWriteAsyncHandler.write(ctx, msg, promise);
@@ -146,7 +135,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
     private void onConnectComplete(final ConnectFuture future, final ChannelHandlerContext ctx) {
         final var cause = future.getException();
         if (cause != null) {
-            handleSshSetupFailure(ctx, cause);
+            onOpenFailure(ctx, cause);
             return;
         }
 
@@ -164,7 +153,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
         try {
             authFuture = authenticationHandler.authenticate(clientSession);
         } catch (final IOException e) {
-            handleSshSetupFailure(ctx, e);
+            onOpenFailure(ctx, e);
             return;
         }
 
@@ -175,7 +164,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
             final ChannelHandlerContext ctx) {
         final var cause = future.getException();
         if (cause != null) {
-            handleSshSetupFailure(ctx, new AuthenticationFailedException("Authentication failed", cause));
+            onOpenFailure(ctx, new AuthenticationFailedException("Authentication failed", cause));
             return;
         }
 
@@ -193,7 +182,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
             channel.setStreaming(ClientChannel.Streaming.Async);
             openFuture = channel.open();
         } catch (final IOException e) {
-            handleSshSetupFailure(ctx, e);
+            onOpenFailure(ctx, e);
             return;
         }
 
@@ -203,7 +192,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
     private void onOpenComplete(final OpenFuture future, final ChannelHandlerContext ctx) {
         final var cause = future.getException();
         if (cause != null) {
-            handleSshSetupFailure(ctx, cause);
+            onOpenFailure(ctx, cause);
             return;
         }
 
@@ -222,6 +211,17 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
         channel.onClose(() -> disconnect(ctx, ctx.newPromise()));
     }
 
+    private synchronized void onOpenFailure(final ChannelHandlerContext ctx, final Throwable cause) {
+        LOG.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), cause);
+
+        // If the promise is not yet done, we have failed with initial connect and set connectPromise to failure
+        if (!connectPromise.isDone()) {
+            connectPromise.setFailure(cause);
+        }
+
+        disconnect(ctx, ctx.newPromise());
+    }
+
     @Override
     public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) {
         disconnect(ctx, promise);