Remove netconf-topology-singleton's NetconfConnectorDTO 95/94595/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Jan 2021 12:13:47 +0000 (13:13 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Jan 2021 12:14:41 +0000 (13:14 +0100)
This DTO is readily available from netconf.topology.spi, remove
code duplication and fix source registration leak -- allowing
modernizer to be enabled.

Change-Id: If5e619f74d451856d87f8d52500325166d2f6279
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java
netconf/netconf-topology-singleton/pom.xml
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfConnectorDTO.java [moved from netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfConnectorDTO.java with 62% similarity]

index 6329f8595b39df84b58056b03a254e5e73b53ab1..03f5b61cc50d6d2c85b2615ce0e8114d4fffc71b 100644 (file)
@@ -37,6 +37,7 @@ import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSc
 import org.opendaylight.netconf.sal.connect.util.NetconfTopologyRPCProvider;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
+import org.opendaylight.netconf.topology.spi.NetconfConnectorDTO;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeTopologyService;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder;
index 33d76043d6960216ffa43eea4ab6b4f64c2fbaeb..03fdede533802161a9029253f970a3af9d442dc5 100644 (file)
     <name>${project.artifactId}</name>
     <packaging>bundle</packaging>
 
-    <properties>
-        <!-- FIXME: Remove this -->
-        <odlparent.modernizer.enforce>false</odlparent.modernizer.enforce>
-    </properties>
-
     <dependencies>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <groupId>org.opendaylight.netconf</groupId>
             <artifactId>sal-netconf-connector</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.netconf</groupId>
+            <artifactId>netconf-topology</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-clustering-commons</artifactId>
index aedc22dc42b92938b60a8a2b6b650593f2f8cd75..a440979a562e46937995eb3e111260ca19b3026f 100644 (file)
@@ -11,7 +11,6 @@ import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -51,9 +50,9 @@ import org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYang
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl;
 import org.opendaylight.netconf.topology.singleton.api.RemoteDeviceConnector;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfConnectorDTO;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
+import org.opendaylight.netconf.topology.spi.NetconfConnectorDTO;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
@@ -169,9 +168,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = netconfTopologyDeviceSetup.getSchemaResourcesDTO();
 
         // pre register yang library sources as fallback schemas to schema registry
-        // FIXME: this list not used anywhere. Should it be retained or discarded? (why?)
-        //        it would seem those registrations should be bound to NetconfConnectorDTO
-        final List<SchemaSourceRegistration<YangTextSchemaSource>> registeredYangLibSources = Lists.newArrayList();
+        final List<SchemaSourceRegistration<?>> registeredYangLibSources = new ArrayList<>();
         if (node.getYangLibrary() != null) {
             final String yangLibURL = node.getYangLibrary().getYangLibraryUrl().getValue();
             final String yangLibUsername = node.getYangLibrary().getUsername();
@@ -233,7 +230,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         if (salFacade instanceof KeepaliveSalFacade) {
             ((KeepaliveSalFacade)salFacade).setListener(netconfDeviceCommunicator);
         }
-        return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade);
+        return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade, registeredYangLibSources);
     }
 
     private static Optional<NetconfSessionPreferences> getUserCapabilities(final NetconfNode node) {
index a005f53d249659ad2482c094b8ce656e1026835c..aa8ed9bd665c25207a820dbd96bd88961b731865 100644 (file)
@@ -5,7 +5,6 @@
  * 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.topology.singleton.impl.utils;
 
 import java.math.BigDecimal;
@@ -24,12 +23,8 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.yang.binding.Identifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public final class NetconfTopologyUtils {
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfTopologyUtils.class);
-
     public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
     public static final int DEFAULT_KEEPALIVE_DELAY = 0;
     public static final boolean DEFAULT_RECONNECT_ON_CHANGED_SCHEMA = false;
index f4ddb9d14b763de2b3cc8d9c6448f1ec67916ea4..3d26a86067dd1468e806cdd047954cde472484ac 100644 (file)
@@ -42,8 +42,8 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommun
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfConnectorDTO;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
+import org.opendaylight.netconf.topology.spi.NetconfConnectorDTO;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
index 8b630829ec9b547b944b0f356e3302891d23c3b2..47a57d279a203209bd9b8ab1ee7fff31c4e71ad0 100644 (file)
@@ -5,19 +5,19 @@
  * 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.topology.singleton.impl;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 
+import java.util.List;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfConnectorDTO;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
+import org.opendaylight.netconf.topology.spi.NetconfConnectorDTO;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
@@ -37,8 +37,8 @@ class TestingRemoteDeviceConnectorImpl extends RemoteDeviceConnectorImpl {
 
     @Override
     public NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node,
-            RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
-        final NetconfConnectorDTO connectorDTO = new NetconfConnectorDTO(communicator, salFacade);
+            final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
+        final NetconfConnectorDTO connectorDTO = new NetconfConnectorDTO(communicator, salFacade, List.of());
         doReturn(FluentFutures.immediateNullFluentFuture()).when(communicator).initializeRemoteConnection(any(), any());
         return connectorDTO;
     }
index 4a5c074eb12008fedb354593a69b0afa4314123e..8feec9d0e58a0a379b3e3e37ed62f7f9a7b9f6de 100644 (file)
@@ -452,37 +452,4 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
         return Optional.of(new UserPreferences(NetconfSessionPreferences
             .fromStrings(capabilities, CapabilityOrigin.UserDefined), overrideYangModuleCaps, overrideNonModuleCaps));
     }
-
-    protected static class NetconfConnectorDTO implements AutoCloseable {
-        private final List<SchemaSourceRegistration<?>> yanglibRegistrations;
-        private final NetconfDeviceCommunicator communicator;
-        private final RemoteDeviceHandler<NetconfSessionPreferences> facade;
-
-        public NetconfConnectorDTO(final NetconfDeviceCommunicator communicator,
-                final RemoteDeviceHandler<NetconfSessionPreferences> facade,
-                final List<SchemaSourceRegistration<?>> yanglibRegistrations) {
-            this.communicator = communicator;
-            this.facade = facade;
-            this.yanglibRegistrations = yanglibRegistrations;
-        }
-
-        public NetconfDeviceCommunicator getCommunicator() {
-            return communicator;
-        }
-
-        public RemoteDeviceHandler<NetconfSessionPreferences> getFacade() {
-            return facade;
-        }
-
-        public NetconfClientSessionListener getSessionListener() {
-            return communicator;
-        }
-
-        @Override
-        public void close() {
-            communicator.close();
-            facade.close();
-            yanglibRegistrations.forEach(SchemaSourceRegistration::close);
-        }
-    }
 }
@@ -1,27 +1,30 @@
 /*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2020 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.topology.spi;
 
-package org.opendaylight.netconf.topology.singleton.impl.utils;
-
+import java.util.List;
 import org.opendaylight.netconf.client.NetconfClientSessionListener;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
 
-public class NetconfConnectorDTO implements AutoCloseable {
-
+public final class NetconfConnectorDTO implements AutoCloseable {
+    private final List<SchemaSourceRegistration<?>> yanglibRegistrations;
     private final NetconfDeviceCommunicator communicator;
     private final RemoteDeviceHandler<NetconfSessionPreferences> facade;
 
     public NetconfConnectorDTO(final NetconfDeviceCommunicator communicator,
-                               final RemoteDeviceHandler<NetconfSessionPreferences> facade) {
+            final RemoteDeviceHandler<NetconfSessionPreferences> facade,
+            final List<SchemaSourceRegistration<?>> yanglibRegistrations) {
         this.communicator = communicator;
         this.facade = facade;
+        this.yanglibRegistrations = yanglibRegistrations;
     }
 
     public NetconfDeviceCommunicator getCommunicator() {
@@ -38,11 +41,8 @@ public class NetconfConnectorDTO implements AutoCloseable {
 
     @Override
     public void close() {
-        if (communicator != null) {
-            communicator.close();
-        }
-        if (facade != null) {
-            facade.close();
-        }
+        communicator.close();
+        facade.close();
+        yanglibRegistrations.forEach(SchemaSourceRegistration::close);
     }
 }
\ No newline at end of file