From: Robert Varga Date: Thu, 17 Oct 2024 13:11:38 +0000 (+0200) Subject: Switch to using DataObject{Identifier,Reference} X-Git-Tag: v0.22.5~6 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=bb1cf5a53f078e26720fd9f06027ab6b450601cc;p=bgpcep.git Switch to using DataObject{Identifier,Reference} Switch primary tracking away from InstanceIdentifier, so it is more obvious what is going on. Change-Id: Ib262d59a1c458f883d040755c7106de533d3997c Signed-off-by: Robert Varga --- diff --git a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyTracker.java b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyTracker.java index aad38c012e..be7e30c94d 100644 --- a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyTracker.java +++ b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyTracker.java @@ -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"); } diff --git a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpc.java b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpc.java index 9e5071ac18..6d47497052 100644 --- a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpc.java +++ b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpc.java @@ -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, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(TopologyStatsRpc.class); - private final ConcurrentMap, PcepSessionState> sessionStateMap = + private final ConcurrentMap, PcepSessionState> sessionStateMap = new ConcurrentHashMap<>(); private Registration listenerRegistration; private Registration rpcRegistration; @@ -78,7 +78,7 @@ final class TopologyStatsRpc implements DataTreeChangeListener @Override public void onDataTreeChanged(final List> 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 .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 } private List 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 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()); } } diff --git a/pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcTest.java b/pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcTest.java index 2f0a6afc01..3690623865 100644 --- a/pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcTest.java +++ b/pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcTest.java @@ -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(); }