Add RemoteDeviceServices
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / NetconfDeviceSalProvider.java
index 05e75708a9dd9bb097b727134aa91c14345f5de9..9109ee4bcb5fba56fc0fd784130637c7e4b9e337 100644 (file)
@@ -12,9 +12,6 @@ import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.Transaction;
-import org.opendaylight.mdsal.binding.api.TransactionChain;
-import org.opendaylight.mdsal.binding.api.TransactionChainListener;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
@@ -25,6 +22,7 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -36,40 +34,20 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
 
     private final RemoteDeviceId id;
     private final MountInstance mountInstance;
-    private final DataBroker dataBroker;
 
     private volatile NetconfDeviceTopologyAdapter topologyDatastoreAdapter;
 
-    private TransactionChain txChain;
-
-    private final TransactionChainListener transactionChainListener =  new TransactionChainListener() {
-        @Override
-        public void onTransactionChainFailed(final TransactionChain chain, final Transaction transaction,
-                final Throwable cause) {
-            LOG.error("{}: TransactionChain({}) {} FAILED!", id, chain, transaction.getIdentifier(), cause);
-            chain.close();
-            resetTransactionChainForAdapaters();
-            throw new IllegalStateException(id + "  TransactionChain(" + chain + ") not committed correctly", cause);
-        }
-
-        @Override
-        public void onTransactionChainSuccessful(final TransactionChain chain) {
-            LOG.trace("{}: TransactionChain({}) SUCCESSFUL", id, chain);
-        }
-    };
-
     public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService) {
         this(deviceId, mountService, null);
     }
 
+    // FIXME: NETCONF-918: remove this method
     public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService,
             final DataBroker dataBroker) {
-        this.id = deviceId;
+        id = deviceId;
         mountInstance = new MountInstance(mountService, id);
-        this.dataBroker = dataBroker;
         if (dataBroker != null) {
-            txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
-            topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(id, txChain);
+            topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id);
         }
     }
 
@@ -86,21 +64,12 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         return local;
     }
 
-    private void resetTransactionChainForAdapaters() {
-        txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
-        topologyDatastoreAdapter.setTxChain(txChain);
-        LOG.trace("{}: Resetting TransactionChain {}", id, txChain);
-    }
-
     @Override
     public void close() {
         mountInstance.close();
         if (topologyDatastoreAdapter != null) {
             topologyDatastoreAdapter.close();
-        }
-        topologyDatastoreAdapter = null;
-        if (txChain != null) {
-            txChain.close();
+            topologyDatastoreAdapter = null;
         }
     }
 
@@ -117,9 +86,16 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
             this.id = requireNonNull(id);
         }
 
+        public void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
+                final RemoteDeviceServices services, final DOMDataBroker broker,
+                final NetconfDataTreeService dataTreeService) {
+            onTopologyDeviceConnected(initialCtx, services, new NetconfDeviceNotificationService(), broker,
+                dataTreeService);
+        }
+
         public synchronized void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
-                final DOMDataBroker broker, final NetconfDataTreeService netconfService, final DOMRpcService rpc,
-                final NetconfDeviceNotificationService newNotificationService, final DOMActionService deviceAction) {
+                final RemoteDeviceServices services, final NetconfDeviceNotificationService newNotificationService,
+                final DOMDataBroker broker, final NetconfDataTreeService dataTreeService) {
             requireNonNull(mountService, "Closed");
             checkState(topologyRegistration == null, "Already initialized");
 
@@ -130,15 +106,16 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
             if (broker != null) {
                 mountBuilder.addService(DOMDataBroker.class, broker);
             }
-            mountBuilder.addService(DOMRpcService.class, rpc);
-            mountBuilder.addService(DOMNotificationService.class, newNotificationService);
-            if (deviceAction != null) {
-                mountBuilder.addService(DOMActionService.class, deviceAction);
+            mountBuilder.addService(DOMRpcService.class, services.rpcs());
+            final var actions = services.actions();
+            if (actions != null) {
+                mountBuilder.addService(DOMActionService.class, actions);
             }
-            if (netconfService != null) {
-                mountBuilder.addService(NetconfDataTreeService.class, netconfService);
+            if (dataTreeService != null) {
+                mountBuilder.addService(NetconfDataTreeService.class, dataTreeService);
             }
-            this.notificationService = newNotificationService;
+            mountBuilder.addService(DOMNotificationService.class, newNotificationService);
+            notificationService = newNotificationService;
 
             topologyRegistration = mountBuilder.register();
             LOG.debug("{}: TOPOLOGY Mountpoint exposed into MD-SAL {}", id, topologyRegistration);