X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnettyutil%2Fhandler%2Fssh%2Fclient%2FSshHandler.java;fp=opendaylight%2Fnetconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnettyutil%2Fhandler%2Fssh%2FSshHandler.java;h=c710a010e226a43e90b937b8faa1ae2cf13017de;hp=1427c6f3a7e7c3b509a1889421c11910eff3f01c;hb=c0664e68c1408f269a5782f2dba4b1e9044164f6;hpb=ace21ede4027c481d820b40da25b74c73642e5da diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/SshHandler.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshHandler.java similarity index 83% rename from opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/SshHandler.java rename to opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshHandler.java index 1427c6f3a7..c710a010e2 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/SshHandler.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshHandler.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.nettyutil.handler.ssh; +package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelFuture; @@ -14,26 +14,30 @@ import io.netty.channel.ChannelFutureListener; 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.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshClient; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.Invoker; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshClientAdapter; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket.VirtualSocket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Netty SSH handler class. Acts as interface between Netty and SSH library. All standard Netty message handling * stops at instance of this class. All downstream events are handed of to wrapped {@link org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshClientAdapter}; */ public class SshHandler extends ChannelOutboundHandlerAdapter { + private static final Logger logger = LoggerFactory.getLogger(SshHandler.class); private static final String SOCKET = "socket"; private final VirtualSocket virtualSocket = new VirtualSocket(); private final SshClientAdapter sshClientAdapter; + + public static SshHandler createForNetconfSubsystem(AuthenticationHandler authenticationHandler) throws IOException { + return new SshHandler(authenticationHandler, Invoker.netconfSubsystem()); + } + + public SshHandler(AuthenticationHandler authenticationHandler, Invoker invoker) throws IOException { SshClient sshClient = new SshClient(virtualSocket, authenticationHandler); this.sshClientAdapter = new SshClientAdapter(sshClient, invoker); @@ -67,7 +71,11 @@ public class SshHandler extends ChannelOutboundHandlerAdapter { promise.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) { - sshClientAdapter.start(ctx); + if (channelFuture.isSuccess()) { + sshClientAdapter.start(ctx, channelFuture); + } else { + logger.debug("Failed to connect to remote host"); + } }} ); }