From bc3f1847ffc80609fb85c15b08b2f20ae06964cd Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 1 Mar 2024 18:26:16 +0100 Subject: [PATCH] Modernize bgp-rib-impl Remove references to ClusteredDataTreeChangeListener, as we are using the correct method already. Also migrate other users of MD-SAL-deprecated methods. Change-Id: Ibf2b194550e50676776f61643eeb0e5069161a77 Signed-off-by: Robert Varga --- .../bgp/rib/impl/ApplicationPeer.java | 21 +++++----- .../config/BGPClusterSingletonService.java | 12 +++--- .../rib/impl/config/DefaultBgpDeployer.java | 42 +++++++++---------- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeer.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeer.java index e1759d8d5a..f55b10a5dd 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeer.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeer.java @@ -28,8 +28,8 @@ import java.util.Map; import java.util.Set; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener; import org.opendaylight.mdsal.dom.api.DOMDataBroker.DataTreeChangeExtension; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMTransactionChain; @@ -75,7 +75,7 @@ import org.slf4j.LoggerFactory; * For purposed of import policies such as Best Path Selection, application * peer needs to have a BGP-ID that is configurable. */ -public class ApplicationPeer extends AbstractPeer implements ClusteredDOMDataTreeChangeListener { +public class ApplicationPeer extends AbstractPeer implements DOMDataTreeChangeListener { private static final Logger LOG = LoggerFactory.getLogger(ApplicationPeer.class); private static final String APP_PEER_GROUP = "application-peers"; @@ -143,16 +143,15 @@ public class ApplicationPeer extends AbstractPeer implements ClusteredDOMDataTre createDomChain(); adjRibInWriter = AdjRibInWriter.create(rib.getYangRibId(), PeerRole.Internal, this); final RIBSupportContextRegistry context = rib.getRibSupportContext(); - final RegisterAppPeerListener registerAppPeerListener = () -> { - synchronized (this) { - if (getDomChain() != null) { - registration = dataTreeChangeService.registerTreeChangeListener(appPeerDOMId, this); - } - } - }; peerPath = createPeerPath(peerId); - adjRibInWriter = adjRibInWriter.transform(peerId, peerPath, context, localTables, - Map.of(), registerAppPeerListener); + adjRibInWriter = adjRibInWriter.transform(peerId, peerPath, context, localTables, Map.of(), + () -> { + synchronized (this) { + if (getDomChain() != null) { + registration = dataTreeChangeService.registerTreeChangeListener(appPeerDOMId, this); + } + } + }); final var chain = rib.createPeerDOMChain(); chain.addCallback(this); diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BGPClusterSingletonService.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BGPClusterSingletonService.java index 47d399bdb6..c928895f01 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BGPClusterSingletonService.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BGPClusterSingletonService.java @@ -158,7 +158,7 @@ public class BGPClusterSingletonService implements ClusterSingletonService, Auto } synchronized void onGlobalChanged(final DataObjectModification dataObjectModification) { - switch (dataObjectModification.getModificationType()) { + switch (dataObjectModification.modificationType()) { case DELETE: LOG.debug("Removing RIB instance: {}", bgpIid); if (ribImpl != null) { @@ -170,7 +170,7 @@ public class BGPClusterSingletonService implements ClusterSingletonService, Auto break; case SUBTREE_MODIFIED: case WRITE: - final Global global = dataObjectModification.getDataAfter(); + final Global global = dataObjectModification.dataAfter(); if (ribImpl == null) { onGlobalCreated(global); } else if (!ribImpl.isGlobalEqual(requireNonNull(global))) { @@ -252,14 +252,14 @@ public class BGPClusterSingletonService implements ClusterSingletonService, Auto @VisibleForTesting @Holding("this") void onNeighborsChanged(final DataObjectModification dataObjectModification) { - for (final DataObjectModification neighborModification : dataObjectModification.getModifiedChildren()) { - switch (neighborModification.getModificationType()) { + for (var neighborModification : dataObjectModification.modifiedChildren()) { + switch (neighborModification.modificationType()) { case DELETE: - onNeighborRemoved((Neighbor) neighborModification.getDataBefore()); + onNeighborRemoved((Neighbor) neighborModification.dataBefore()); break; case SUBTREE_MODIFIED: case WRITE: - onNeighborModified((Neighbor) neighborModification.getDataAfter()); + onNeighborModified((Neighbor) neighborModification.dataAfter()); break; default: break; diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/DefaultBgpDeployer.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/DefaultBgpDeployer.java index 3f784b066f..fe4eb10864 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/DefaultBgpDeployer.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/DefaultBgpDeployer.java @@ -27,9 +27,9 @@ import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Singleton; import org.checkerframework.checker.lock.qual.GuardedBy; -import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.DataObjectModification; +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.ReadTransaction; @@ -68,7 +68,7 @@ import org.slf4j.LoggerFactory; @Singleton // Non-final because of Mockito.spy() -public class DefaultBgpDeployer implements ClusteredDataTreeChangeListener, PeerGroupConfigLoader, AutoCloseable { +public class DefaultBgpDeployer implements DataTreeChangeListener, PeerGroupConfigLoader, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DefaultBgpDeployer.class); private final InstanceIdentifier networkInstanceIId; @@ -140,7 +140,7 @@ public class DefaultBgpDeployer implements ClusteredDataTreeChangeListener, @PostConstruct // Split out of constructor to support partial mocking public synchronized void init() { - registration = dataBroker.registerDataTreeChangeListener( + registration = dataBroker.registerTreeChangeListener( DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, networkInstanceIId.child(Protocols.class).child(Protocol.class) .augmentation(NetworkInstanceProtocol.class).child(Bgp.class)), this); @@ -163,17 +163,17 @@ public class DefaultBgpDeployer implements ClusteredDataTreeChangeListener, return; } - for (final DataTreeModification dataTreeModification : changes) { - final InstanceIdentifier rootIdentifier = dataTreeModification.getRootPath().getRootIdentifier(); + for (var dataTreeModification : changes) { + final InstanceIdentifier rootIdentifier = dataTreeModification.getRootPath().path(); final DataObjectModification rootNode = dataTreeModification.getRootNode(); - final List> deletedConfig - = rootNode.getModifiedChildren().stream() - .filter(mod -> mod.getModificationType() == DataObjectModification.ModificationType.DELETE) - .collect(Collectors.toList()); - final List> changedConfig - = rootNode.getModifiedChildren().stream() - .filter(mod -> mod.getModificationType() != DataObjectModification.ModificationType.DELETE) - .collect(Collectors.toList()); + final List> deletedConfig = rootNode.modifiedChildren() + .stream() + .filter(mod -> mod.modificationType() == DataObjectModification.ModificationType.DELETE) + .collect(Collectors.toList()); + final List> changedConfig = rootNode.modifiedChildren() + .stream() + .filter(mod -> mod.modificationType() != DataObjectModification.ModificationType.DELETE) + .collect(Collectors.toList()); handleDeletions(deletedConfig, rootIdentifier); handleModifications(changedConfig, rootIdentifier); } @@ -182,10 +182,10 @@ public class DefaultBgpDeployer implements ClusteredDataTreeChangeListener, private void handleModifications(final List> changedConfig, final InstanceIdentifier rootIdentifier) { final List> globalMod = changedConfig.stream() - .filter(mod -> mod.getDataType().equals(Global.class)) + .filter(mod -> mod.dataType().equals(Global.class)) .collect(Collectors.toList()); final List> peerMod = changedConfig.stream() - .filter(mod -> !mod.getDataType().equals(Global.class)) + .filter(mod -> !mod.dataType().equals(Global.class)) .collect(Collectors.toList()); if (!globalMod.isEmpty()) { handleGlobalChange(globalMod, rootIdentifier); @@ -198,10 +198,10 @@ public class DefaultBgpDeployer implements ClusteredDataTreeChangeListener, private void handleDeletions(final List> deletedConfig, final InstanceIdentifier rootIdentifier) { final List> globalMod = deletedConfig.stream() - .filter(mod -> mod.getDataType().equals(Global.class)) + .filter(mod -> mod.dataType().equals(Global.class)) .collect(Collectors.toList()); final List> peerMod = deletedConfig.stream() - .filter(mod -> !mod.getDataType().equals(Global.class)) + .filter(mod -> !mod.dataType().equals(Global.class)) .collect(Collectors.toList()); if (!globalMod.isEmpty()) { handleGlobalChange(globalMod, rootIdentifier); @@ -223,18 +223,18 @@ public class DefaultBgpDeployer implements ClusteredDataTreeChangeListener, final List> config, final InstanceIdentifier rootIdentifier) { for (final DataObjectModification dataObjectModification : config) { - if (dataObjectModification.getDataType().equals(Neighbors.class)) { + if (dataObjectModification.dataType().equals(Neighbors.class)) { onNeighborsChanged((DataObjectModification) dataObjectModification, rootIdentifier); - } else if (dataObjectModification.getDataType().equals(PeerGroups.class)) { + } else if (dataObjectModification.dataType().equals(PeerGroups.class)) { rebootNeighbors((DataObjectModification) dataObjectModification); } } } private synchronized void rebootNeighbors(final DataObjectModification dataObjectModification) { - PeerGroups extPeerGroups = dataObjectModification.getDataAfter(); + PeerGroups extPeerGroups = dataObjectModification.dataAfter(); if (extPeerGroups == null) { - extPeerGroups = dataObjectModification.getDataBefore(); + extPeerGroups = dataObjectModification.dataBefore(); } if (extPeerGroups == null) { return; -- 2.36.6