import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.netconf.api.TransportConstants;
import org.opendaylight.netconf.client.NetconfClientSession;
import org.opendaylight.netconf.client.NetconfClientSessionListener;
import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
import org.opendaylight.netconf.shaded.sshd.common.future.SshFutureListener;
import org.opendaylight.netconf.shaded.sshd.common.session.Session;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev230430.connection.parameters.Protocol.Name;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.Protocol.Name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Non-final for testing
class CallHomeSessionContext implements CallHomeProtocolSessionContext {
+
private static final Logger LOG = LoggerFactory.getLogger(CallHomeSessionContext.class);
+ private static final String NETCONF = "netconf";
@VisibleForTesting
static final Session.AttributeKey<CallHomeSessionContext> SESSION_KEY = new Session.AttributeKey<>();
LOG.debug("Opening NETCONF Subsystem on {}", sshSession);
try {
final MinaSshNettyChannel nettyChannel = newMinaSshNettyChannel();
- final ClientChannel netconfChannel = ((NetconfClientSessionImpl) sshSession).createSubsystemChannel(
- TransportConstants.SSH_SUBSYSTEM, nettyChannel.pipeline());
+ final ClientChannel netconfChannel =
+ ((NetconfClientSessionImpl) sshSession).createSubsystemChannel(NETCONF, nettyChannel.pipeline());
netconfChannel.setStreaming(ClientChannel.Streaming.Async);
netconfChannel.open().addListener(newSshFutureListener(netconfChannel, nettyChannel));
} catch (IOException e) {
sshSession.close(false);
}
- private synchronized Promise<NetconfClientSession> doActivate(final ClientChannel netconfChannel,
+ private synchronized ListenableFuture<NetconfClientSession> doActivate(final ClientChannel netconfChannel,
final NetconfClientSessionListener listener, final MinaSshNettyChannel nettyChannel) {
if (activated) {
- return newSessionPromise().setFailure(new IllegalStateException("Session already activated."));
+ return Futures.immediateFailedFuture(new IllegalStateException("Session already activated."));
}
activated = true;
nettyChannel.pipeline().addFirst(new SshWriteAsyncHandlerAdapter(netconfChannel));
factory.getChannelInitializer(listener).initialize(nettyChannel, activationPromise);
((ChannelSubsystem) netconfChannel).onClose(nettyChannel::doNettyDisconnect);
factory.getNettyGroup().register(nettyChannel).awaitUninterruptibly(500);
- return activationPromise;
+ final SettableFuture<NetconfClientSession> future = SettableFuture.create();
+ activationPromise.addListener(ignored -> {
+ final var cause = activationPromise.cause();
+ if (cause != null) {
+ future.setException(cause);
+ } else {
+ future.set(activationPromise.getNow());
+ }
+ });
+ return future;
}
@Deprecated(since = "7.0.0", forRemoval = true)
- protected MinaSshNettyChannel newMinaSshNettyChannel() {
+ @VisibleForTesting
+ MinaSshNettyChannel newMinaSshNettyChannel() {
return new MinaSshNettyChannel(this, sshSession);
}