Rename MountInstance to NetconfDeviceMount 65/103865/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 1 Jan 2023 17:20:58 +0000 (18:20 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 1 Jan 2023 17:30:29 +0000 (18:30 +0100)
We have a rather useless indirection of components via
NetconfDeviceSalProvider. Eliminate it and promote the only part we care
about to a top-level construct.

Even this may prove unnecessary, as proper lifecycle would just track
the mount point within NetconfDeviceSalFacade. That requires more work
though, so we correctly integrate with netconf-topology-singleton, which
is doing its own thing.

JIRA: NETCONF-918
Change-Id: I014fe4953d4f832b8a9ad43cec95d3d961949716
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceMount.java [new file with mode: 0644]
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java [deleted file]
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java [deleted file]

index c3e801a785b8370d50f2e52f45b53aca78d3bf89..3ff56c9f8d0c7553ffc6376fb284e91aa4c2e575 100644 (file)
@@ -28,7 +28,7 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabi
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.AbstractNetconfDataTreeService;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceDataBroker;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData;
 import org.opendaylight.netconf.topology.spi.NetconfDeviceTopologyAdapter;
@@ -44,10 +44,10 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable {
 
     private final RemoteDeviceId id;
     private final Timeout actorResponseWaitTime;
-    private final NetconfDeviceSalProvider salProvider;
     private final ActorRef masterActorRef;
     private final ActorSystem actorSystem;
     private final NetconfDeviceTopologyAdapter datastoreAdapter;
+    private final NetconfDeviceMount mount;
     private final boolean lockDatastore;
 
     private NetconfDeviceSchema currentSchema = null;
@@ -64,7 +64,7 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable {
                     final DataBroker dataBroker,
                     final boolean lockDatastore) {
         this.id = id;
-        salProvider = new NetconfDeviceSalProvider(id, mountService);
+        mount = new NetconfDeviceMount(mountService, id);
         this.actorSystem = actorSystem;
         this.masterActorRef = masterActorRef;
         this.actorResponseWaitTime = actorResponseWaitTime;
@@ -105,25 +105,24 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable {
     public void onDeviceDisconnected() {
         LOG.info("Device {} disconnected - unregistering master mount point", id);
         datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty());
-        unregisterMasterMountPoint();
+        mount.onDeviceDisconnected();
     }
 
     @Override
     public void onDeviceFailed(final Throwable throwable) {
         datastoreAdapter.setDeviceAsFailed(throwable);
-        unregisterMasterMountPoint();
+        mount.onDeviceDisconnected();
     }
 
     @Override
     public void onNotification(final DOMNotification domNotification) {
-        salProvider.getMountInstance().publish(domNotification);
+        mount.publish(domNotification);
     }
 
     @Override
     public void close() {
         datastoreAdapter.close();
-        unregisterMasterMountPoint();
-        closeGracefully(salProvider);
+        mount.close();
     }
 
     private void registerMasterMountPoint() {
@@ -144,8 +143,8 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable {
             actorResponseWaitTime);
         final NetconfDataTreeService proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
             actorSystem.dispatcher(), actorResponseWaitTime);
-        salProvider.getMountInstance().onTopologyDeviceConnected(mountContext.getEffectiveModelContext(),
-            deviceServices, proxyDataBroker, proxyNetconfService);
+        mount.onDeviceConnected(mountContext.getEffectiveModelContext(), deviceServices,
+            proxyDataBroker, proxyNetconfService);
     }
 
     protected DOMDataBroker newDeviceDataBroker(final MountPointContext mountContext,
@@ -175,19 +174,4 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable {
         LOG.debug("{}: updateDeviceData with master address {}", id, masterAddress);
         datastoreAdapter.updateClusteredDeviceData(true, masterAddress, currentSchema.capabilities());
     }
-
-    private void unregisterMasterMountPoint() {
-        salProvider.getMountInstance().onTopologyDeviceDisconnected();
-    }
-
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    private void closeGracefully(final AutoCloseable resource) {
-        if (resource != null) {
-            try {
-                resource.close();
-            } catch (final Exception e) {
-                LOG.error("{}: Ignoring exception while closing {}", id, resource, e);
-            }
-        }
-    }
 }
index b7d44cb03cc71876ae46696d299f86166b70ee20..5c2b6bd57074d757bee8555041e4f2a373245f63 100644 (file)
@@ -12,58 +12,52 @@ import akka.actor.ActorSystem;
 import akka.util.Timeout;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class SlaveSalFacade {
-
     private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
 
+    private final AtomicBoolean registered = new AtomicBoolean(false);
     private final RemoteDeviceId id;
-    private final NetconfDeviceSalProvider salProvider;
+    private final NetconfDeviceMount mount;
     private final ActorSystem actorSystem;
     private final Timeout actorResponseWaitTime;
-    private final AtomicBoolean registered = new AtomicBoolean(false);
 
     public SlaveSalFacade(final RemoteDeviceId id,
                           final ActorSystem actorSystem,
                           final Timeout actorResponseWaitTime,
                           final DOMMountPointService mountPointService) {
         this.id = id;
-        salProvider = new NetconfDeviceSalProvider(id, mountPointService);
         this.actorSystem = actorSystem;
         this.actorResponseWaitTime = actorResponseWaitTime;
+        mount = new NetconfDeviceMount(mountPointService, id);
     }
 
     public void registerSlaveMountPoint(final EffectiveModelContext remoteSchemaContext, final ActorRef masterActorRef,
             final RemoteDeviceServices services) {
         if (!registered.compareAndSet(false, true)) {
+            LOG.info("Mount point {} already registered, skipping registation", id);
             return;
         }
 
-        final ProxyDOMDataBroker netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
+        final var netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
             actorSystem.dispatcher(), actorResponseWaitTime);
-        final NetconfDataTreeService proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
+        final var proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
             actorSystem.dispatcher(), actorResponseWaitTime);
 
-        salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, services, netconfDeviceDataBroker,
-            proxyNetconfService);
-
+        mount.onDeviceConnected(remoteSchemaContext, services, netconfDeviceDataBroker, proxyNetconfService);
         LOG.info("{}: Slave mount point registered.", id);
     }
 
     public void close() {
-        if (!registered.compareAndSet(true, false)) {
-            return;
+        if (registered.compareAndSet(true, false)) {
+            mount.onDeviceDisconnected();
+            LOG.info("{}: Slave mount point unregistered.", id);
         }
-
-        salProvider.getMountInstance().onTopologyDeviceDisconnected();
-
-        LOG.info("{}: Slave mount point unregistered.", id);
     }
 }
diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceMount.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceMount.java
new file mode 100644 (file)
index 0000000..33e999c
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2023 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.sal.connect.netconf.sal;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
+import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+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.NetconfRpcService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
+import org.opendaylight.netconf.sal.connect.api.SchemalessRpcService;
+import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Non-final for mocking
+public class NetconfDeviceMount implements AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceMount.class);
+
+    private final DOMMountPointService mountService;
+    private final RemoteDeviceId id;
+
+    private NetconfDeviceNotificationService notificationService;
+    private ObjectRegistration<DOMMountPoint> topologyRegistration;
+
+    public NetconfDeviceMount(final DOMMountPointService mountService, final RemoteDeviceId id) {
+        this.mountService = requireNonNull(mountService);
+        this.id = requireNonNull(id);
+    }
+
+    public void onDeviceConnected(final EffectiveModelContext initialCtx,
+            final RemoteDeviceServices services, final DOMDataBroker broker,
+            final NetconfDataTreeService dataTreeService) {
+        onDeviceConnected(initialCtx, services, new NetconfDeviceNotificationService(), broker,
+            dataTreeService);
+    }
+
+    public synchronized void onDeviceConnected(final EffectiveModelContext initialCtx,
+            final RemoteDeviceServices services, final NetconfDeviceNotificationService newNotificationService,
+            final DOMDataBroker broker, final NetconfDataTreeService dataTreeService) {
+        requireNonNull(mountService, "Closed");
+        checkState(topologyRegistration == null, "Already initialized");
+
+        final var mountBuilder = mountService.createMountPoint(id.getTopologyPath());
+        mountBuilder.addService(DOMSchemaService.class, FixedDOMSchemaService.of(() -> initialCtx));
+
+        final var rpcs = services.rpcs();
+        mountBuilder.addService(NetconfRpcService.class, rpcs);
+        if (rpcs instanceof Rpcs.Normalized normalized) {
+            mountBuilder.addService(DOMRpcService.class, normalized);
+        } else if (rpcs instanceof Rpcs.Schemaless schemaless) {
+            mountBuilder.addService(SchemalessRpcService.class, schemaless);
+        }
+        if (services.actions() instanceof Actions.Normalized normalized) {
+            mountBuilder.addService(DOMActionService.class, normalized);
+        }
+
+        if (broker != null) {
+            mountBuilder.addService(DOMDataBroker.class, broker);
+        }
+        if (dataTreeService != null) {
+            mountBuilder.addService(NetconfDataTreeService.class, dataTreeService);
+        }
+        mountBuilder.addService(DOMNotificationService.class, newNotificationService);
+        notificationService = newNotificationService;
+
+        topologyRegistration = mountBuilder.register();
+        LOG.debug("{}: Mountpoint exposed into MD-SAL {}", id, topologyRegistration);
+    }
+
+    public synchronized void onDeviceDisconnected() {
+        if (topologyRegistration == null) {
+            LOG.trace("{}: Not removing mountpoint from MD-SAL, mountpoint was not registered yet", id);
+            return;
+        }
+
+        try {
+            topologyRegistration.close();
+        } finally {
+            LOG.debug("{}: Mountpoint removed from MD-SAL {}", id, topologyRegistration);
+            topologyRegistration = null;
+        }
+    }
+
+    public synchronized void publish(final DOMNotification domNotification) {
+        checkNotNull(notificationService, "Device not set up yet, cannot handle notification %s", domNotification)
+            .publishNotification(domNotification);
+    }
+
+    @Override
+    public synchronized void close() {
+        onDeviceDisconnected();
+    }
+}
\ No newline at end of file
index d2fa6e573d5366908acaf3643e47f5915554a0ef..931ce6e941f3af04f78afbe23ea07dfb2f7e8515 100644 (file)
@@ -17,32 +17,27 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
 import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable {
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalFacade.class);
-
     private final RemoteDeviceId id;
-    private final NetconfDeviceSalProvider salProvider;
+    private final NetconfDeviceMount mount;
     private final boolean lockDatastore;
 
     public NetconfDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
             final boolean lockDatastore) {
-        this(id, new NetconfDeviceSalProvider(id, mountPointService), lockDatastore);
+        this(id, new NetconfDeviceMount(mountPointService, id), lockDatastore);
     }
 
     @VisibleForTesting
-    NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceSalProvider salProvider,
-            final boolean lockDatastore) {
+    NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceMount mount, final boolean lockDatastore) {
         this.id = requireNonNull(id);
-        this.salProvider = requireNonNull(salProvider);
+        this.mount = requireNonNull(mount);
         this.lockDatastore = lockDatastore;
     }
 
     @Override
     public synchronized void onNotification(final DOMNotification domNotification) {
-        salProvider.getMountInstance().publish(domNotification);
+        mount.publish(domNotification);
     }
 
     @Override
@@ -58,33 +53,21 @@ public class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseabl
         final var netconfDataBroker = new NetconfDeviceDataBroker(id, mountContext, deviceRpc, sessionPreferences,
             lockDatastore);
 
-        salProvider.getMountInstance().onTopologyDeviceConnected(modelContext, services, netconfDataBroker,
-            netconfDataTree);
+        mount.onDeviceConnected(modelContext, services, netconfDataBroker, netconfDataTree);
     }
 
     @Override
     public synchronized void onDeviceDisconnected() {
-        salProvider.getMountInstance().onTopologyDeviceDisconnected();
+        mount.onDeviceDisconnected();
     }
 
     @Override
     public synchronized void onDeviceFailed(final Throwable throwable) {
-        salProvider.getMountInstance().onTopologyDeviceDisconnected();
+        mount.onDeviceDisconnected();
     }
 
     @Override
     public synchronized void close() {
-        closeGracefully(salProvider);
-    }
-
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    private void closeGracefully(final AutoCloseable resource) {
-        if (resource != null) {
-            try {
-                resource.close();
-            } catch (final Exception e) {
-                LOG.warn("{}: Ignoring exception while closing {}", id, resource, e);
-            }
-        }
+        mount.close();
     }
 }
diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java
deleted file mode 100644 (file)
index ff4af46..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.sal.connect.netconf.sal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.Objects.requireNonNull;
-
-import org.opendaylight.mdsal.dom.api.DOMActionService;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-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.NetconfRpcService;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
-import org.opendaylight.netconf.sal.connect.api.SchemalessRpcService;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-// FIXME: remove this class and promote MountInstance to a top-level construct
-// Non-final for mocking
-public class NetconfDeviceSalProvider implements AutoCloseable {
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalProvider.class);
-
-    private final RemoteDeviceId id;
-    private final MountInstance mountInstance;
-
-    public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService) {
-        id = requireNonNull(deviceId);
-        mountInstance = new MountInstance(mountService, id);
-    }
-
-    public MountInstance getMountInstance() {
-        checkState(mountInstance != null, "%s: Mount instance was not initialized by sal. Cannot get mount instance",
-                id);
-        return mountInstance;
-    }
-
-    @Override
-    public void close() {
-        mountInstance.close();
-    }
-
-    public static class MountInstance implements AutoCloseable {
-
-        private final DOMMountPointService mountService;
-        private final RemoteDeviceId id;
-
-        private NetconfDeviceNotificationService notificationService;
-        private ObjectRegistration<DOMMountPoint> topologyRegistration;
-
-        MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) {
-            this.mountService = requireNonNull(mountService);
-            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 RemoteDeviceServices services, final NetconfDeviceNotificationService newNotificationService,
-                final DOMDataBroker broker, final NetconfDataTreeService dataTreeService) {
-            requireNonNull(mountService, "Closed");
-            checkState(topologyRegistration == null, "Already initialized");
-
-            final var mountBuilder = mountService.createMountPoint(id.getTopologyPath());
-            mountBuilder.addService(DOMSchemaService.class, FixedDOMSchemaService.of(() -> initialCtx));
-
-            final var rpcs = services.rpcs();
-            mountBuilder.addService(NetconfRpcService.class, rpcs);
-            if (rpcs instanceof Rpcs.Normalized normalized) {
-                mountBuilder.addService(DOMRpcService.class, normalized);
-            } else if (rpcs instanceof Rpcs.Schemaless schemaless) {
-                mountBuilder.addService(SchemalessRpcService.class, schemaless);
-            }
-            if (services.actions() instanceof Actions.Normalized normalized) {
-                mountBuilder.addService(DOMActionService.class, normalized);
-            }
-
-            if (broker != null) {
-                mountBuilder.addService(DOMDataBroker.class, broker);
-            }
-            if (dataTreeService != null) {
-                mountBuilder.addService(NetconfDataTreeService.class, dataTreeService);
-            }
-            mountBuilder.addService(DOMNotificationService.class, newNotificationService);
-            notificationService = newNotificationService;
-
-            topologyRegistration = mountBuilder.register();
-            LOG.debug("{}: TOPOLOGY Mountpoint exposed into MD-SAL {}", id, topologyRegistration);
-        }
-
-        @SuppressWarnings("checkstyle:IllegalCatch")
-        public synchronized void onTopologyDeviceDisconnected() {
-            if (topologyRegistration == null) {
-                LOG.trace("{}: Not removing TOPOLOGY mountpoint from MD-SAL, mountpoint was not registered yet", id);
-                return;
-            }
-
-            try {
-                topologyRegistration.close();
-            } catch (final Exception e) {
-                // Only log and ignore
-                LOG.warn("Unable to unregister mount instance for {}. Ignoring exception", id.getTopologyPath(), e);
-            } finally {
-                LOG.debug("{}: TOPOLOGY Mountpoint removed from MD-SAL {}", id, topologyRegistration);
-                topologyRegistration = null;
-            }
-        }
-
-        @Override
-        public synchronized void close() {
-            onTopologyDeviceDisconnected();
-        }
-
-        public synchronized void publish(final DOMNotification domNotification) {
-            checkNotNull(notificationService, "Device not set up yet, cannot handle notification %s", domNotification)
-                .publishNotification(domNotification);
-        }
-    }
-
-}
index 044c47d58a6072a989a6efb385dcd6a1224a5d53..a883e1c4c1279d805905b04f16d95b0e5537fd15 100644 (file)
@@ -57,7 +57,7 @@ public class MountInstanceTest {
     @Mock
     private DOMNotification notification;
 
-    private NetconfDeviceSalProvider.MountInstance mountInstance;
+    private NetconfDeviceMount mountInstance;
 
     @BeforeClass
     public static void suiteSetUp() throws Exception {
@@ -69,14 +69,14 @@ public class MountInstanceTest {
         when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
 
         when(mountPointBuilder.register()).thenReturn(registration);
-        mountInstance = new NetconfDeviceSalProvider.MountInstance(
+        mountInstance = new NetconfDeviceMount(
                 service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
     }
 
 
     @Test
     public void testOnTopologyDeviceConnected() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
             notificationService, broker, null);
         verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
         verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
@@ -86,7 +86,7 @@ public class MountInstanceTest {
 
     @Test
     public void testOnTopologyDeviceConnectedWithNetconfService() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
             notificationService, null, netconfService);
         verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
         verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService);
@@ -96,17 +96,17 @@ public class MountInstanceTest {
 
     @Test
     public void testOnTopologyDeviceDisconnected() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
             notificationService, broker, null);
-        mountInstance.onTopologyDeviceDisconnected();
+        mountInstance.onDeviceDisconnected();
         verify(registration).close();
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
             notificationService, broker, null);
     }
 
     @Test
     public void testClose() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
             notificationService, broker, null);
         mountInstance.close();
         verify(registration).close();
@@ -114,7 +114,7 @@ public class MountInstanceTest {
 
     @Test
     public void testPublishNotification() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
             notificationService, broker, null);
         verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
         verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
index dee82a8e69bf9d9740eb498a36206bec4d710722..2b698008cdcc114a36582b49bfadbe0311a50053 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netconf.sal.connect.netconf.sal;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -40,25 +39,22 @@ public class NetconfDeviceSalFacadeTest {
     private final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("test", new InetSocketAddress("127.0.0.1", 8000));
 
     @Mock
-    private NetconfDeviceSalProvider.MountInstance mountInstance;
-    @Mock
-    private NetconfDeviceSalProvider salProvider;
+    private NetconfDeviceMount mountInstance;
 
     private NetconfDeviceSalFacade deviceFacade;
 
     @Before
     public void setUp() throws Exception {
-        deviceFacade = new NetconfDeviceSalFacade(remoteDeviceId, salProvider, true);
+        doNothing().when(mountInstance).onDeviceDisconnected();
 
-        doReturn(mountInstance).when(salProvider).getMountInstance();
-        doNothing().when(mountInstance).onTopologyDeviceDisconnected();
+        deviceFacade = new NetconfDeviceSalFacade(remoteDeviceId, mountInstance, true);
     }
 
     @Test
     public void testOnDeviceDisconnected() {
         deviceFacade.onDeviceDisconnected();
 
-        verify(mountInstance, times(1)).onTopologyDeviceDisconnected();
+        verify(mountInstance, times(1)).onDeviceDisconnected();
     }
 
     @Test
@@ -66,13 +62,13 @@ public class NetconfDeviceSalFacadeTest {
         final Throwable throwable = new Throwable();
         deviceFacade.onDeviceFailed(throwable);
 
-        verify(mountInstance, times(1)).onTopologyDeviceDisconnected();
+        verify(mountInstance, times(1)).onDeviceDisconnected();
     }
 
     @Test
     public void testOnDeviceClose() throws Exception {
         deviceFacade.close();
-        verify(salProvider).close();
+        verify(mountInstance).close();
     }
 
     @Test
@@ -87,7 +83,7 @@ public class NetconfDeviceSalFacadeTest {
             new NetconfDeviceSchema(NetconfDeviceCapabilities.empty(), new EmptyMountPointContext(schemaContext)),
             netconfSessionPreferences, deviceServices);
 
-        verify(mountInstance, times(1)).onTopologyDeviceConnected(eq(schemaContext), eq(deviceServices),
+        verify(mountInstance, times(1)).onDeviceConnected(eq(schemaContext), eq(deviceServices),
             any(DOMDataBroker.class), any(NetconfDataTreeService.class));
     }
 
diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java
deleted file mode 100644 (file)
index d7095c8..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.sal.connect.netconf.sal;
-
-import java.net.InetSocketAddress;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfDeviceSalProviderTest {
-    @Mock
-    private DOMMountPointService mountPointService;
-
-    private NetconfDeviceSalProvider provider;
-
-    @Before
-    public void setUp() {
-        provider = new NetconfDeviceSalProvider(new RemoteDeviceId("device1",
-                InetSocketAddress.createUnresolved("localhost", 17830)), mountPointService);
-    }
-
-    @Test
-    public void close() {
-        provider.close();
-    }
-
-    @Test
-    public void closeWithoutNPE()  {
-        close();
-
-        // No further interations
-        provider.close();
-    }
-}