Eliminate TopologyUtil 31/89331/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 24 Apr 2020 06:52:05 +0000 (08:52 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 24 Apr 2020 07:25:32 +0000 (09:25 +0200)
This class has a single user, which will benefit from inlining.

JIRA: NETCONF-671
Change-Id: I1fc00f2c373b630760089e67aadee02a5af59569
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/TopologyUtil.java [deleted file]
netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImplTest.java

index c4c2196f93484a2fd789547a0aa576638240ae2f..f1a0e6b49abab2660d18a95cd91e13196f1518c7 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netconf.topology.impl;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.concurrent.EventExecutor;
@@ -33,13 +34,17 @@ import org.opendaylight.netconf.topology.AbstractNetconfTopology;
 import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider;
 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;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+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;
 
@@ -111,32 +116,34 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
 
         LOG.debug("Registering datastore listener");
         datastoreListenerRegistration = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
-            LogicalDatastoreType.CONFIGURATION, TopologyUtil.createTopologyListPath(topologyId).child(Node.class)),
-            this);
+            LogicalDatastoreType.CONFIGURATION, createTopologyListPath(topologyId).child(Node.class)), this);
     }
 
     @Override
     public void onDataTreeChanged(final Collection<DataTreeModification<Node>> collection) {
         for (final DataTreeModification<Node> change : collection) {
             final DataObjectModification<Node> rootNode = change.getRootNode();
+            final NodeId nodeId;
             switch (rootNode.getModificationType()) {
                 case SUBTREE_MODIFIED:
-                    LOG.debug("Config for node {} updated", TopologyUtil.getNodeId(rootNode.getIdentifier()));
-                    disconnectNode(TopologyUtil.getNodeId(rootNode.getIdentifier()));
-                    connectNode(TopologyUtil.getNodeId(rootNode.getIdentifier()), rootNode.getDataAfter());
+                    nodeId = getNodeId(rootNode.getIdentifier());
+                    LOG.debug("Config for node {} updated", nodeId);
+                    disconnectNode(nodeId);
+                    connectNode(nodeId, rootNode.getDataAfter());
                     break;
                 case WRITE:
-                    LOG.debug("Config for node {} created", TopologyUtil.getNodeId(rootNode.getIdentifier()));
-                    if (activeConnectors.containsKey(TopologyUtil.getNodeId(rootNode.getIdentifier()))) {
-                        LOG.warn("RemoteDevice{{}} was already configured, reconfiguring..",
-                                TopologyUtil.getNodeId(rootNode.getIdentifier()));
-                        disconnectNode(TopologyUtil.getNodeId(rootNode.getIdentifier()));
+                    nodeId = getNodeId(rootNode.getIdentifier());
+                    LOG.debug("Config for node {} created", nodeId);
+                    if (activeConnectors.containsKey(nodeId)) {
+                        LOG.warn("RemoteDevice{{}} was already configured, reconfiguring..", nodeId);
+                        disconnectNode(nodeId);
                     }
-                    connectNode(TopologyUtil.getNodeId(rootNode.getIdentifier()), rootNode.getDataAfter());
+                    connectNode(nodeId, rootNode.getDataAfter());
                     break;
                 case DELETE:
-                    LOG.debug("Config for node {} deleted", TopologyUtil.getNodeId(rootNode.getIdentifier()));
-                    disconnectNode(TopologyUtil.getNodeId(rootNode.getIdentifier()));
+                    nodeId = getNodeId(rootNode.getIdentifier());
+                    LOG.debug("Config for node {} deleted", nodeId);
+                    disconnectNode(nodeId);
                     break;
                 default:
                     LOG.debug("Unsupported modification type: {}.", rootNode.getModificationType());
@@ -154,4 +161,27 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
                 networkTopologyId.child(Topology.class, new TopologyKey(new TopologyId(topologyId))), topology);
     }
 
+    /**
+     * Determines the Netconf Node Node ID, given the node's instance
+     * identifier.
+     *
+     * @param pathArgument Node's path argument
+     * @return     NodeId for the node
+     */
+    @VisibleForTesting
+    static NodeId getNodeId(final InstanceIdentifier.PathArgument pathArgument) {
+        if (pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?>) {
+            final Identifier key = ((InstanceIdentifier.IdentifiableItem) pathArgument).getKey();
+            if (key instanceof NodeKey) {
+                return ((NodeKey) key).getNodeId();
+            }
+        }
+        throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
+    }
+
+    @VisibleForTesting
+    static KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(final String topologyId) {
+        final InstanceIdentifier<NetworkTopology> networkTopology = InstanceIdentifier.create(NetworkTopology.class);
+        return networkTopology.child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
+    }
 }
diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/TopologyUtil.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/TopologyUtil.java
deleted file mode 100644 (file)
index 1a58dbe..0000000
+++ /dev/null
@@ -1,49 +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.topology.impl;
-
-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.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yangtools.yang.binding.Identifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-public final class TopologyUtil {
-
-    private TopologyUtil() {
-        throw new AssertionError("Instantiating utility class.");
-    }
-
-    /**
-     * Determines the Netconf Node Node ID, given the node's instance
-     * identifier.
-     *
-     * @param pathArgument Node's path argument
-     * @return     NodeId for the node
-     */
-    public static NodeId getNodeId(final InstanceIdentifier.PathArgument pathArgument) {
-        if (pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?>) {
-
-            final Identifier key = ((InstanceIdentifier.IdentifiableItem) pathArgument).getKey();
-            if (key instanceof NodeKey) {
-                return ((NodeKey) key).getNodeId();
-            }
-        }
-        throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
-    }
-
-    public static KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(final String topologyId) {
-        final InstanceIdentifier<NetworkTopology> networkTopology = InstanceIdentifier.create(NetworkTopology.class);
-        return networkTopology.child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
-    }
-}
index 8062edee4597f88a212a42a52643d5efa7072e09..c3fd08c0200a7fa455e62092cb3b872c44fffe1b 100644 (file)
@@ -153,7 +153,7 @@ public class NetconfTopologyImplTest {
         InstanceIdentifier.PathArgument pa = null;
 
         for (final InstanceIdentifier.PathArgument p
-                : TopologyUtil.createTopologyListPath(TOPOLOGY_ID)
+                : NetconfTopologyImpl.createTopologyListPath(TOPOLOGY_ID)
                     .child(Node.class, new NodeKey(NODE_ID)).getPathArguments()) {
             pa = p;
         }
@@ -183,18 +183,18 @@ public class NetconfTopologyImplTest {
         when(ch.getRootNode()).thenReturn(newNode);
         changes.add(ch);
         spyTopology.onDataTreeChanged(changes);
-        verify(spyTopology).connectNode(TopologyUtil.getNodeId(pa), nn.build());
+        verify(spyTopology).connectNode(NetconfTopologyImpl.getNodeId(pa), nn.build());
 
         when(newNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
         spyTopology.onDataTreeChanged(changes);
-        verify(spyTopology).disconnectNode(TopologyUtil.getNodeId(pa));
+        verify(spyTopology).disconnectNode(NetconfTopologyImpl.getNodeId(pa));
 
         when(newNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
         spyTopology.onDataTreeChanged(changes);
 
         //one in previous creating and deleting node and one in updating
-        verify(spyTopology, times(2)).disconnectNode(TopologyUtil.getNodeId(pa));
-        verify(spyTopology, times(2)).connectNode(TopologyUtil.getNodeId(pa), nn.build());
+        verify(spyTopology, times(2)).disconnectNode(NetconfTopologyImpl.getNodeId(pa));
+        verify(spyTopology, times(2)).connectNode(NetconfTopologyImpl.getNodeId(pa), nn.build());
 
 
     }