From f7a7694b1604dfcd231c70506b468bdfad34c21d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 1 Jan 2023 18:20:58 +0100 Subject: [PATCH] Rename MountInstance to NetconfDeviceMount 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 --- .../singleton/impl/MasterSalFacade.java | 34 ++--- .../singleton/impl/SlaveSalFacade.java | 28 ++-- .../netconf/sal/NetconfDeviceMount.java | 113 ++++++++++++++ .../netconf/sal/NetconfDeviceSalFacade.java | 35 ++--- .../netconf/sal/NetconfDeviceSalProvider.java | 141 ------------------ .../netconf/sal/MountInstanceTest.java | 18 +-- .../sal/NetconfDeviceSalFacadeTest.java | 18 +-- .../sal/NetconfDeviceSalProviderTest.java | 44 ------ 8 files changed, 158 insertions(+), 273 deletions(-) create mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceMount.java delete mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java delete mode 100644 netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java index c3e801a785..3ff56c9f8d 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java @@ -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); - } - } - } } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java index b7d44cb03c..5c2b6bd570 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/SlaveSalFacade.java @@ -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 index 0000000000..33e999c4d8 --- /dev/null +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceMount.java @@ -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 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 diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java index d2fa6e573d..931ce6e941 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java @@ -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 index ff4af4649e..0000000000 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java +++ /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 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); - } - } - -} diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java index 044c47d58a..a883e1c4c1 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java @@ -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); diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java index dee82a8e69..2b698008cd 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java @@ -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 index d7095c8055..0000000000 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java +++ /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(); - } -} -- 2.36.6