Switch to using DataObject{Identifier,Reference} 60/114060/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 17 Oct 2024 13:11:38 +0000 (15:11 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 17 Oct 2024 13:47:07 +0000 (15:47 +0200)
Switch primary tracking away from InstanceIdentifier, so it is more
obvious what is going on.

Change-Id: Ib262d59a1c458f883d040755c7106de533d3997c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyTracker.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpc.java
pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcTest.java

index aad38c012e3c3792a4cc7c4c1032666068f6846e..be7e30c94d4c9ba2c5b4f9f035550a48f1bd7d81 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.bgpcep.pcep.server.PceServerProvider;
 import org.opendaylight.bgpcep.programming.spi.InstructionSchedulerFactory;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -43,8 +42,8 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 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.TopologyTypes;
+import org.opendaylight.yangtools.binding.DataObjectReference;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -131,9 +130,9 @@ public final class PCEPTopologyTracker
         statsProvider = new TopologyStatsProvider(timer);
         statsRpcs = new TopologyStatsRpc(dataBroker, rpcProviderRegistry);
 
-        reg = dataBroker.registerTreeChangeListener(DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION,
-            InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class).child(TopologyTypes.class)
-                .augmentation(TopologyTypes1.class).child(TopologyPcep.class).build()), this);
+        reg = dataBroker.registerTreeChangeListener(LogicalDatastoreType.CONFIGURATION,
+            DataObjectReference.builder(NetworkTopology.class).child(Topology.class).child(TopologyTypes.class)
+                .augmentation(TopologyTypes1.class).child(TopologyPcep.class).build(), this);
         LOG.info("PCEP Topology tracker initialized");
     }
 
index 9e5071ac1828521d92688585c7157ed2bc6f51e6..6d4749705235bf0a9e939a459dddfffb66b35789 100644 (file)
@@ -47,10 +47,10 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.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.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier;
 import org.opendaylight.yangtools.binding.DataObjectReference;
 import org.opendaylight.yangtools.binding.util.BindingMap;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
 final class TopologyStatsRpc implements DataTreeChangeListener<PcepSessionState>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(TopologyStatsRpc.class);
 
-    private final ConcurrentMap<InstanceIdentifier<PcepSessionState>, PcepSessionState> sessionStateMap =
+    private final ConcurrentMap<DataObjectIdentifier<PcepSessionState>, PcepSessionState> sessionStateMap =
             new ConcurrentHashMap<>();
     private Registration listenerRegistration;
     private Registration rpcRegistration;
@@ -78,7 +78,7 @@ final class TopologyStatsRpc implements DataTreeChangeListener<PcepSessionState>
     @Override
     public void onDataTreeChanged(final List<DataTreeModification<PcepSessionState>> changes) {
         changes.forEach(change -> {
-            final var iid = change.path().toLegacy();
+            final var iid = change.path();
             final var mod = change.getRootNode();
             switch (mod.modificationType()) {
                 case SUBTREE_MODIFIED, WRITE:
@@ -148,8 +148,8 @@ final class TopologyStatsRpc implements DataTreeChangeListener<PcepSessionState>
                         .setTopologyId(iTopologyId)
                         .setNode(iNodeIds.stream()
                             .map(iNodeId -> {
-                                final PcepSessionState state = sessionStateMap.get(
-                                    InstanceIdentifier.builder(NetworkTopology.class)
+                                final var state = sessionStateMap.get(
+                                    DataObjectIdentifier.builder(NetworkTopology.class)
                                         .child(Topology.class, new TopologyKey(iTopologyId))
                                         .child(Node.class, new NodeKey(iNodeId))
                                         .augmentation(PcepTopologyNodeStatsAug.class)
@@ -232,13 +232,18 @@ final class TopologyStatsRpc implements DataTreeChangeListener<PcepSessionState>
     }
 
     private List<TopologyId> getAvailableTopologyIds() {
-        return sessionStateMap.keySet().stream().map(iid -> iid.firstKeyOf(Topology.class).getTopologyId()).distinct()
-                .collect(Collectors.toList());
+        return sessionStateMap.keySet().stream()
+            .map(DataObjectIdentifier::toLegacy)
+            .map(iid -> iid.firstKeyOf(Topology.class).getTopologyId())
+            .distinct()
+            .collect(Collectors.toList());
     }
 
     private List<NodeId> getAvailableNodeIds(final TopologyId topologyId) {
         return sessionStateMap.keySet().stream()
-                .filter(iid -> iid.firstKeyOf(Topology.class).getTopologyId().equals(topologyId))
-                .map(iid -> iid.firstKeyOf(Node.class).getNodeId()).collect(Collectors.toList());
+            .map(DataObjectIdentifier::toLegacy)
+            .filter(iid -> iid.firstKeyOf(Topology.class).getTopologyId().equals(topologyId))
+            .map(iid -> iid.firstKeyOf(Node.class).getNodeId())
+            .collect(Collectors.toList());
     }
 }
index 2f0a6afc0182a63ca2e4b6a06d2061d9a19d5134..36906238652c1a83e83f94f2d8104ae2f1f9ba51 100644 (file)
@@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stateful.stats.rev181109.PcepEntityIdRpcAugBuilder;
@@ -60,9 +59,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 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.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier;
 import org.opendaylight.yangtools.binding.util.BindingMap;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
@@ -104,11 +103,9 @@ public class TopologyStatsRpcTest extends AbstractConcurrentDataBrokerTest {
         final Topology t3 = createTopology(NONPCEP_TOPOLOGY,
                 BindingMap.of(new NodeBuilder().setNodeId(new NodeId(NONPCEP_NODE)).build()));
 
-        final WriteTransaction wtx = getDataBroker().newWriteOnlyTransaction();
-        final NetworkTopologyBuilder ntb = new NetworkTopologyBuilder();
-        ntb.setTopology(BindingMap.of(t1, t2, t3));
-        wtx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class).build(),
-                ntb.build());
+        final var wtx = getDataBroker().newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, DataObjectIdentifier.builder(NetworkTopology.class).build(),
+            new NetworkTopologyBuilder().setTopology(BindingMap.of(t1, t2, t3)).build());
         wtx.commit().get();
     }