import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandlerWriter;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfClientSessionImpl;
-import org.opendaylight.netconf.nettyutil.handler.ssh.client.NettyPipelineAwareChannelSubsystem;
+import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture;
import org.opendaylight.netconf.shaded.sshd.client.future.OpenFuture;
LOG.info("Activating Netconf channel for {} with {}", getRemoteAddress(), listener);
final Promise<NetconfClientSession> activationPromise = newSessionPromise();
factory.getChannelInitializer(listener).initialize(nettyChannel, activationPromise);
- ((NettyPipelineAwareChannelSubsystem)netconfChannel).onClose(nettyChannel::doNettyDisconnect);
+ ((ChannelSubsystem) netconfChannel).onClose(nettyChannel::doNettyDisconnect);
factory.getNettyGroup().register(nettyChannel).awaitUninterruptibly(500);
return activationPromise;
}
SshWriteAsyncHandlerAdapter(final ClientChannel sshChannel) {
this.sshChannel = sshChannel;
- this.sshWriteAsyncHandler = new AsyncSshHandlerWriter(sshChannel.getAsyncIn());
+ sshWriteAsyncHandler = new AsyncSshHandlerWriter(sshChannel.getAsyncIn());
}
@Override
import org.opendaylight.netconf.client.NetconfClientSessionListener;
import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfClientSessionImpl;
-import org.opendaylight.netconf.nettyutil.handler.ssh.client.NettyPipelineAwareChannelSubsystem;
+import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
import org.opendaylight.netconf.shaded.sshd.client.future.OpenFuture;
import org.opendaylight.netconf.shaded.sshd.common.AttributeRepository.AttributeKey;
public void creatingAChannelSuccessfullyShouldResultInAnAttachedListener() throws Exception {
// given
final var mockFuture = mock(OpenFuture.class);
- final var mockChannelSubsystem = mock(NettyPipelineAwareChannelSubsystem.class);
+ final var mockChannelSubsystem = mock(ChannelSubsystem.class);
doReturn(mockFuture).when(mockChannelSubsystem).open();
doReturn(mockChannelSubsystem).when(mockSession).createSubsystemChannel(anyString(),
any(DefaultChannelPipeline.class));
import org.checkerframework.checker.lock.qual.Holding;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
+import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture;
import org.opendaylight.netconf.shaded.sshd.client.future.ConnectFuture;
private ChannelPromise connectPromise;
private AsyncSshHandlerWriter sshWriteAsyncHandler;
- private NettyAwareChannelSubsystem channel;
+ private ChannelSubsystem channel;
private ClientSession session;
private FutureListener<Object> negotiationFutureListener;
}
if (channel != null) {
- //TODO: see if calling just close() is sufficient
- //channel.close(false);
- channel.close();
+ channel.close(false);
channel = null;
}
promise.setSuccess();
*/
package org.opendaylight.netconf.nettyutil.handler.ssh.client;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
}
@Override
- public NettyAwareChannelSubsystem createSubsystemChannel(final String subsystem, final ChannelHandlerContext ctx)
+ public ChannelSubsystem createSubsystemChannel(final String subsystem, final ChannelHandlerContext ctx)
throws IOException {
- return registerSubsystem(new NettyAwareChannelSubsystem(subsystem, ctx));
+ requireNonNull(ctx);
+ return registerSubsystem(new NettyChannelSubsystem(subsystem) {
+ @Override
+ ChannelHandlerContext context() {
+ return ctx;
+ }
+ });
}
@Override
- public NettyPipelineAwareChannelSubsystem createSubsystemChannel(final String subsystem,
+ public ChannelSubsystem createSubsystemChannel(final String subsystem,
final ChannelPipeline pipeline) throws IOException {
- return registerSubsystem(new NettyPipelineAwareChannelSubsystem(subsystem, pipeline));
+ requireNonNull(pipeline);
+ return registerSubsystem(new NettyChannelSubsystem(subsystem) {
+ @Override
+ ChannelHandlerContext context() {
+ return pipeline.firstContext();
+ }
+ });
}
- private <T extends ChannelSubsystem> T registerSubsystem(final T subsystem) throws IOException {
+ private ChannelSubsystem registerSubsystem(final ChannelSubsystem subsystem) throws IOException {
final var service = getConnectionService();
final var id = service.registerChannel(subsystem);
if (log.isDebugEnabled()) {
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.nettyutil.handler.ssh.client;
-
-import static java.util.Objects.requireNonNull;
-
-import io.netty.channel.ChannelHandlerContext;
-
-/**
- * An {@link AbstractNettyChannelSubsystem} for subsystem which routes incoming data to a particular
- * {@link ChannelHandlerContext}.
- */
-// Non-final for testing
-public non-sealed class NettyAwareChannelSubsystem extends AbstractNettyChannelSubsystem {
- private final ChannelHandlerContext ctx;
-
- NettyAwareChannelSubsystem(final String subsystem, final ChannelHandlerContext ctx) {
- super(subsystem);
- this.ctx = requireNonNull(ctx);
- }
-
- @Override
- final ChannelHandlerContext context() {
- return ctx;
- }
-}
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import java.io.IOException;
+import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
/**
*
* @param subsystem The subsystem name
* @param ctx Context to which to route data to
- * @return The created {@link NettyAwareChannelSubsystem}
+ * @return The created {@link ChannelSubsystem}
* @throws IOException If failed to create the requested channel
*/
- NettyAwareChannelSubsystem createSubsystemChannel(String subsystem, ChannelHandlerContext ctx) throws IOException;
+ ChannelSubsystem createSubsystemChannel(String subsystem, ChannelHandlerContext ctx) throws IOException;
/**
* Allocate a channel to the specified subsystem. Incoming data on the channel will be routed to the
*
* @param subsystem The subsystem name
* @param pipeline ChannelPipeline to which to route data to
- * @return The created {@link NettyPipelineAwareChannelSubsystem}
+ * @return The created {@link ChannelSubsystem}
* @throws IOException If failed to create the requested channel
*/
- NettyPipelineAwareChannelSubsystem createSubsystemChannel(String subsystem, ChannelPipeline pipeline)
- throws IOException;
+ ChannelSubsystem createSubsystemChannel(String subsystem, ChannelPipeline pipeline) throws IOException;
}
import org.slf4j.LoggerFactory;
/**
- * Abstract base class for {@link NettyAwareChannelSubsystem} and {@link NettyPipelineAwareChannelSubsystem}.
+ * Abstract base class for {@link ChannelSubsystem}s backed by a Netty {@link ChannelHandlerContext}.
*/
-abstract sealed class AbstractNettyChannelSubsystem extends ChannelSubsystem
- permits NettyAwareChannelSubsystem, NettyPipelineAwareChannelSubsystem {
- private static final Logger LOG = LoggerFactory.getLogger(AbstractNettyChannelSubsystem.class);
+abstract class NettyChannelSubsystem extends ChannelSubsystem {
+ private static final Logger LOG = LoggerFactory.getLogger(NettyChannelSubsystem.class);
- AbstractNettyChannelSubsystem(final String subsystem) {
+ NettyChannelSubsystem(final String subsystem) {
super(subsystem);
}
+++ /dev/null
-/*
- * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.nettyutil.handler.ssh.client;
-
-import static java.util.Objects.requireNonNull;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPipeline;
-
-/**
- * A {@link AbstractNettyChannelSubsystem} for subsystem which routes incoming data to a particular
- * {@link ChannelPipeline}.
- */
-// Non-final for testing
-public non-sealed class NettyPipelineAwareChannelSubsystem extends AbstractNettyChannelSubsystem {
- private final ChannelPipeline pipeline;
-
- NettyPipelineAwareChannelSubsystem(final String subsystem, final ChannelPipeline pipeline) {
- super(subsystem);
- this.pipeline = requireNonNull(pipeline);
- }
-
- @Override
- final ChannelHandlerContext context() {
- return pipeline.firstContext();
- }
-}
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
+import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture;
import org.opendaylight.netconf.shaded.sshd.client.future.ConnectFuture;
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);
}
}, MoreExecutors.directExecutor());
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);
final IoOutputStream asyncIn = getMockedIoOutputStream();
final IoWriteFuture ioWriteFuture = asyncIn.writeBuffer(new ByteArrayBuffer());
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);
final IoOutputStream asyncIn = getMockedIoOutputStream();
final IoWriteFuture ioWriteFuture = asyncIn.writeBuffer(new ByteArrayBuffer());
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);
return connectFuture;
}
- private static NettyAwareClientSession getMockedSshSession(final NettyAwareChannelSubsystem subsystemChannel)
+ private static NettyAwareClientSession getMockedSshSession(final ChannelSubsystem subsystemChannel)
throws IOException {
final NettyAwareClientSession sshSession = mock(NettyAwareClientSession.class);
doReturn(false).when(sshSession).isClosed();
doReturn(false).when(sshSession).isClosing();
final CloseFuture closeFuture = mock(CloseFuture.class);
- Futures.addCallback(stubAddListener(closeFuture), new SuccessFutureListener<CloseFuture>() {
+ Futures.addCallback(stubAddListener(closeFuture), new SuccessFutureListener<>() {
@Override
public void onSuccess(final SshFutureListener<CloseFuture> result) {
doReturn(true).when(closeFuture).isClosed();
return sshSession;
}
- private NettyAwareChannelSubsystem getMockedSubsystemChannel(final IoInputStream asyncOut,
+ private ChannelSubsystem getMockedSubsystemChannel(final IoInputStream asyncOut,
final IoOutputStream asyncIn) throws IOException {
- final NettyAwareChannelSubsystem subsystemChannel = mock(NettyAwareChannelSubsystem.class);
+ final ChannelSubsystem subsystemChannel = mock(ChannelSubsystem.class);
doNothing().when(subsystemChannel).setStreaming(any(ClientChannel.Streaming.class));
final OpenFuture openFuture = mock(OpenFuture.class);
doReturn(openFuture).when(subsystemChannel).open();
doReturn(asyncIn).when(subsystemChannel).getAsyncIn();
doNothing().when(subsystemChannel).onClose(any());
- doNothing().when(subsystemChannel).close();
+ doReturn(null).when(subsystemChannel).close(false);
return subsystemChannel;
}
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
+ final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ConnectFuture connectFuture = getSuccessConnectFuture(sshSession);