From 176eedbf480eccf31bfd073526cb8c9ae6f782f9 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 11 Jan 2021 13:13:47 +0100 Subject: [PATCH] Remove netconf-topology-singleton's NetconfConnectorDTO 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 --- .../topology/impl/NetconfTopologyImpl.java | 1 + netconf/netconf-topology-singleton/pom.xml | 9 +++-- .../impl/RemoteDeviceConnectorImpl.java | 9 ++--- .../impl/utils/NetconfTopologyUtils.java | 5 --- .../impl/RemoteDeviceConnectorImplTest.java | 2 +- .../TestingRemoteDeviceConnectorImpl.java | 8 ++--- .../topology/spi/AbstractNetconfTopology.java | 33 ------------------- .../topology/spi}/NetconfConnectorDTO.java | 24 +++++++------- 8 files changed, 25 insertions(+), 66 deletions(-) rename netconf/{netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils => netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi}/NetconfConnectorDTO.java (62%) diff --git a/netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java b/netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java index 6329f8595b..03f5b61cc5 100644 --- a/netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java +++ b/netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java @@ -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; diff --git a/netconf/netconf-topology-singleton/pom.xml b/netconf/netconf-topology-singleton/pom.xml index 33d76043d6..03fdede533 100644 --- a/netconf/netconf-topology-singleton/pom.xml +++ b/netconf/netconf-topology-singleton/pom.xml @@ -24,11 +24,6 @@ ${project.artifactId} bundle - - - false - - org.opendaylight.controller @@ -43,6 +38,10 @@ org.opendaylight.netconf sal-netconf-connector + + org.opendaylight.netconf + netconf-topology + org.opendaylight.controller sal-clustering-commons diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index aedc22dc42..a440979a56 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -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> registeredYangLibSources = Lists.newArrayList(); + final List> 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 getUserCapabilities(final NetconfNode node) { diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java index a005f53d24..aa8ed9bd66 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java @@ -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; diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java index f4ddb9d14b..3d26a86067 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java @@ -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; diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java index 8b630829ec..47a57d279a 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/TestingRemoteDeviceConnectorImpl.java @@ -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 salFacade) { - final NetconfConnectorDTO connectorDTO = new NetconfConnectorDTO(communicator, salFacade); + final RemoteDeviceHandler salFacade) { + final NetconfConnectorDTO connectorDTO = new NetconfConnectorDTO(communicator, salFacade, List.of()); doReturn(FluentFutures.immediateNullFluentFuture()).when(communicator).initializeRemoteConnection(any(), any()); return connectorDTO; } diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java index 4a5c074eb1..8feec9d0e5 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java @@ -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> yanglibRegistrations; - private final NetconfDeviceCommunicator communicator; - private final RemoteDeviceHandler facade; - - public NetconfConnectorDTO(final NetconfDeviceCommunicator communicator, - final RemoteDeviceHandler facade, - final List> yanglibRegistrations) { - this.communicator = communicator; - this.facade = facade; - this.yanglibRegistrations = yanglibRegistrations; - } - - public NetconfDeviceCommunicator getCommunicator() { - return communicator; - } - - public RemoteDeviceHandler getFacade() { - return facade; - } - - public NetconfClientSessionListener getSessionListener() { - return communicator; - } - - @Override - public void close() { - communicator.close(); - facade.close(); - yanglibRegistrations.forEach(SchemaSourceRegistration::close); - } - } } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfConnectorDTO.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfConnectorDTO.java similarity index 62% rename from netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfConnectorDTO.java rename to netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfConnectorDTO.java index 53d7e6b7e5..9b579341b6 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfConnectorDTO.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfConnectorDTO.java @@ -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> yanglibRegistrations; private final NetconfDeviceCommunicator communicator; private final RemoteDeviceHandler facade; public NetconfConnectorDTO(final NetconfDeviceCommunicator communicator, - final RemoteDeviceHandler facade) { + final RemoteDeviceHandler facade, + final List> 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 -- 2.36.6