Further rework of base schemas
[netconf.git] / netconf / callhome-provider / src / main / java / org / opendaylight / netconf / callhome / mount / CallHomeMountDispatcher.java
index b8c2ba80905b31af884ecffede57efe211604e4d..407fa8e60ee87ab37e7a5d25e067d28eb3f16506 100644 (file)
@@ -5,9 +5,10 @@
  * 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.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;
@@ -15,8 +16,8 @@ import java.net.InetSocketAddress;
 import org.opendaylight.aaa.encrypt.AAAEncryptionService;
 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
 import org.opendaylight.controller.config.threadpool.ThreadPool;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.callhome.mount.CallHomeMountSessionContext.CloseCallback;
 import org.opendaylight.netconf.callhome.protocol.CallHomeChannelActivator;
 import org.opendaylight.netconf.callhome.protocol.CallHomeNetconfSubsystemListener;
@@ -25,7 +26,9 @@ 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.topology.api.SchemaRepositoryProvider;
+import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
+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 +42,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;
@@ -47,24 +50,37 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
 
     protected CallHomeTopology topology;
 
-    private final CloseCallback onCloseHandler = new CloseCallback() {
-        @Override
-        public void onClosed(final CallHomeMountSessionContext deviceContext) {
-            LOG.info("Removing {} from Netconf Topology.", deviceContext.getId());
-            topology.disconnectNode(deviceContext.getId());
-        }
+    private final CloseCallback onCloseHandler = deviceContext -> {
+        LOG.info("Removing {} from Netconf Topology.", deviceContext.getId());
+        topology.disconnectNode(deviceContext.getId());
     };
 
+    private final DeviceActionFactory deviceActionFactory;
+    private final BaseNetconfSchemas baseSchemas;
+
+    public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
+                                   final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
+                                   final SchemaResourceManager schemaRepositoryProvider,
+                                   final BaseNetconfSchemas baseSchemas, final DataBroker dataBroker,
+                                   final DOMMountPointService mountService,
+                                   final AAAEncryptionService encryptionService) {
+        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 AAAEncryptionService encryptionService) {
+            final SchemaResourceManager schemaRepositoryProvider, final BaseNetconfSchemas baseSchemas,
+            final DataBroker dataBroker, final DOMMountPointService mountService,
+            final AAAEncryptionService encryptionService, final DeviceActionFactory deviceActionFactory) {
         this.topologyId = topologyId;
         this.eventExecutor = eventExecutor;
         this.keepaliveExecutor = keepaliveExecutor;
         this.processingExecutor = processingExecutor;
         this.schemaRepositoryProvider = schemaRepositoryProvider;
+        this.deviceActionFactory = deviceActionFactory;
         this.sessionManager = new CallHomeMountSessionManager();
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.dataBroker = dataBroker;
         this.mountService = mountService;
         this.encryptionService = encryptionService;
@@ -92,18 +108,21 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
 
     void createTopology() {
         this.topology = new CallHomeTopology(topologyId, this, eventExecutor, keepaliveExecutor, processingExecutor,
-                schemaRepositoryProvider, dataBroker, mountService, encryptionService);
+                schemaRepositoryProvider, dataBroker, mountService, encryptionService, baseSchemas,
+                deviceActionFactory);
     }
 
     @Override
     public void onNetconfSubsystemOpened(final CallHomeProtocolSessionContext session,
-            final CallHomeChannelActivator activator) {
+                                         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() {