Use a local for nodeId
[netconf.git] / netconf / callhome-provider / src / main / java / org / opendaylight / netconf / callhome / mount / CallHomeMountDispatcher.java
index e8e1925962d037907daff5a2ece2941aed183940..80c8f1353d377e85e88fc0f8dc866da60d2541c6 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.callhome.mount;
 
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.FailedFuture;
 import io.netty.util.concurrent.Future;
@@ -24,8 +26,10 @@ import org.opendaylight.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.netconf.client.NetconfClientSession;
 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
+import org.opendaylight.netconf.nettyutil.ReconnectFuture;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
-import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider;
+import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.slf4j.Logger;
@@ -39,7 +43,7 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
     private final EventExecutor eventExecutor;
     private final ScheduledThreadPool keepaliveExecutor;
     private final ThreadPool processingExecutor;
-    private final SchemaRepositoryProvider schemaRepositoryProvider;
+    private final SchemaResourceManager schemaRepositoryProvider;
     private final CallHomeMountSessionManager sessionManager;
     private final DataBroker dataBroker;
     private final DOMMountPointService mountService;
@@ -48,25 +52,28 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
     protected CallHomeTopology topology;
 
     private final CloseCallback onCloseHandler = deviceContext -> {
-        LOG.info("Removing {} from Netconf Topology.", deviceContext.getId());
-        topology.disconnectNode(deviceContext.getId());
+        final var nodeId = deviceContext.getId();
+        LOG.info("Removing {} from Netconf Topology.", nodeId);
+        topology.disconnectNode(nodeId);
     };
 
     private final DeviceActionFactory deviceActionFactory;
+    private final BaseNetconfSchemas baseSchemas;
 
     public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
                                    final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
-                                   final SchemaRepositoryProvider schemaRepositoryProvider, final DataBroker dataBroker,
+                                   final SchemaResourceManager schemaRepositoryProvider,
+                                   final BaseNetconfSchemas baseSchemas, final DataBroker dataBroker,
                                    final DOMMountPointService mountService,
                                    final AAAEncryptionService encryptionService) {
-        this(topologyId, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, dataBroker,
-                mountService, encryptionService, null);
+        this(topologyId, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, baseSchemas,
+            dataBroker, mountService, encryptionService, null);
     }
 
     public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
             final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
-            final SchemaRepositoryProvider schemaRepositoryProvider, final DataBroker dataBroker,
-            final DOMMountPointService mountService,
+            final SchemaResourceManager schemaRepositoryProvider, final BaseNetconfSchemas baseSchemas,
+            final DataBroker dataBroker, final DOMMountPointService mountService,
             final AAAEncryptionService encryptionService, final DeviceActionFactory deviceActionFactory) {
         this.topologyId = topologyId;
         this.eventExecutor = eventExecutor;
@@ -75,6 +82,7 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
         this.schemaRepositoryProvider = schemaRepositoryProvider;
         this.deviceActionFactory = deviceActionFactory;
         this.sessionManager = new CallHomeMountSessionManager();
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.dataBroker = dataBroker;
         this.mountService = mountService;
         this.encryptionService = encryptionService;
@@ -86,23 +94,22 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
     }
 
     @Override
-    public Future<Void> createReconnectingClient(final NetconfReconnectingClientConfiguration clientConfiguration) {
-        return activateChannel(clientConfiguration);
+    public ReconnectFuture createReconnectingClient(final NetconfReconnectingClientConfiguration clientConfiguration) {
+        return new SingleReconnectFuture(eventExecutor, activateChannel(clientConfiguration));
     }
 
-    private <V> Future<V> activateChannel(final NetconfClientConfiguration conf) {
+    private Future<NetconfClientSession> activateChannel(final NetconfClientConfiguration conf) {
         final InetSocketAddress remoteAddr = conf.getAddress();
         final CallHomeMountSessionContext context = getSessionManager().getByAddress(remoteAddr);
         LOG.info("Activating NETCONF channel for ip {} device context {}", remoteAddr, context);
-        if (context == null) {
-            return new FailedFuture<>(eventExecutor, new NullPointerException());
-        }
-        return context.activateNetconfChannel(conf.getSessionListener());
+        return context == null ? new FailedFuture<>(eventExecutor, new NullPointerException())
+            : context.activateNetconfChannel(conf.getSessionListener());
     }
 
     void createTopology() {
         this.topology = new CallHomeTopology(topologyId, this, eventExecutor, keepaliveExecutor, processingExecutor,
-                schemaRepositoryProvider, dataBroker, mountService, encryptionService, deviceActionFactory);
+                schemaRepositoryProvider, dataBroker, mountService, encryptionService, baseSchemas,
+                deviceActionFactory);
     }
 
     @Override
@@ -110,10 +117,12 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
                                          final CallHomeChannelActivator activator) {
         final CallHomeMountSessionContext deviceContext =
                 getSessionManager().createSession(session, activator, onCloseHandler);
-        final NodeId nodeId = deviceContext.getId();
-        final Node configNode = deviceContext.getConfigNode();
-        LOG.info("Provisioning fake config {}", configNode);
-        topology.connectNode(nodeId, configNode);
+        if (deviceContext != null) {
+            final NodeId nodeId = deviceContext.getId();
+            final Node configNode = deviceContext.getConfigNode();
+            LOG.info("Provisioning fake config {}", configNode);
+            topology.connectNode(nodeId, configNode);
+        }
     }
 
     public CallHomeMountSessionManager getSessionManager() {