From 11781976bd88c289d04aa9a4988604dac441004c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 1 Mar 2024 22:03:44 +0100 Subject: [PATCH] Modernize bmp-impl Use new ImmutableNodes and take advantage of getName() method generated for YANG enumerations. Change-Id: I9a452d936dd4bfcb9c7cf55249ef1f4cb29883dd Signed-off-by: Robert Varga --- bmp/bmp-impl/pom.xml | 2 +- .../impl/app/BmpMonitoringStationImpl.java | 20 ++- .../protocol/bmp/impl/app/BmpRibInWriter.java | 2 +- .../protocol/bmp/impl/app/BmpRouterImpl.java | 34 ++--- .../bmp/impl/app/BmpRouterPeerImpl.java | 139 +++++++++--------- .../protocol/bmp/impl/app/TableContext.java | 19 +-- .../bmp/impl/config/BmpDeployerImpl.java | 33 ++--- .../bmp/impl/app/BmpMonitorImplTest.java | 31 ++-- 8 files changed, 138 insertions(+), 142 deletions(-) diff --git a/bmp/bmp-impl/pom.xml b/bmp/bmp-impl/pom.xml index f10e26e048..976982ce84 100644 --- a/bmp/bmp-impl/pom.xml +++ b/bmp/bmp-impl/pom.xml @@ -88,7 +88,7 @@ org.opendaylight.yangtools - yang-data-impl + yang-data-spi org.opendaylight.mdsal diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitoringStationImpl.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitoringStationImpl.java index 5e6e65f67a..4bee83912b 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitoringStationImpl.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitoringStationImpl.java @@ -44,7 +44,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -169,12 +171,16 @@ public final class BmpMonitoringStationImpl implements BmpMonitoringStation, Clu private synchronized void createEmptyMonitor() { final DOMDataTreeWriteTransaction wTx = domDataBroker.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, - YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME) - .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, monitorId.getValue()).build(), - ImmutableNodes.mapEntryBuilder(Monitor.QNAME, MONITOR_ID_QNAME, monitorId.getValue()) - .addChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, monitorId.getValue())) - .addChild(ImmutableNodes.mapNodeBuilder(Router.QNAME).build()) - .build()); + YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME) + .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, monitorId.getValue()).build(), + ImmutableNodes.newMapEntryBuilder() + .withNodeIdentifier(NodeIdentifierWithPredicates.of(Monitor.QNAME, MONITOR_ID_QNAME, + monitorId.getValue())) + .withChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, monitorId.getValue())) + .withChild(ImmutableNodes.newSystemMapBuilder() + .withNodeIdentifier(new NodeIdentifier(Router.QNAME)) + .build()) + .build()); try { wTx.commit().get(); } catch (final ExecutionException | InterruptedException e) { diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java index f7ab0a8c67..87f20dea7f 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java @@ -44,7 +44,7 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterImpl.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterImpl.java index ab33bb7b2a..a2b9a875a7 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterImpl.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterImpl.java @@ -46,9 +46,9 @@ import org.opendaylight.yangtools.yang.binding.Notification; import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -198,12 +198,12 @@ public final class BmpRouterImpl implements BmpRouter, FutureCallback { private synchronized void createRouterEntry() { Preconditions.checkState(isDatastoreWritable()); final DOMDataTreeWriteTransaction wTx = domTxChain.newWriteOnlyTransaction(); - wTx.put(LogicalDatastoreType.OPERATIONAL, routerYangIId, - Builders.mapEntryBuilder() - .withNodeIdentifier(NodeIdentifierWithPredicates.of(Router.QNAME, ROUTER_ID_QNAME, routerIp)) - .withChild(ImmutableNodes.leafNode(ROUTER_ID_QNAME, routerIp)) - .withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, DOWN)) - .withChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build()).build()); + wTx.put(LogicalDatastoreType.OPERATIONAL, routerYangIId, ImmutableNodes.newMapEntryBuilder() + .withNodeIdentifier(NodeIdentifierWithPredicates.of(Router.QNAME, ROUTER_ID_QNAME, routerIp)) + .withChild(ImmutableNodes.leafNode(ROUTER_ID_QNAME, routerIp)) + .withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, DOWN)) + .withChild(ImmutableNodes.newSystemMapBuilder().withNodeIdentifier(new NodeIdentifier(Peer.QNAME)).build()) + .build()); wTx.commit().addCallback(new FutureCallback() { @Override public void onSuccess(final CommitInfo result) { @@ -220,15 +220,15 @@ public final class BmpRouterImpl implements BmpRouter, FutureCallback { private synchronized void onInitiate(final InitiationMessage initiation) { Preconditions.checkState(isDatastoreWritable()); final DOMDataTreeWriteTransaction wTx = domTxChain.newWriteOnlyTransaction(); - wTx.merge(LogicalDatastoreType.OPERATIONAL, routerYangIId, - Builders.mapEntryBuilder() - .withNodeIdentifier(NodeIdentifierWithPredicates.of(Router.QNAME, ROUTER_ID_QNAME, routerIp)) - .withChild(ImmutableNodes.leafNode(ROUTER_NAME_QNAME, initiation.getTlvs().getNameTlv().getName())) - .withChild(ImmutableNodes.leafNode(ROUTER_DESCRIPTION_QNAME, initiation.getTlvs().getDescriptionTlv() - .getDescription())) - .withChild(ImmutableNodes.leafNode(ROUTER_INFO_QNAME, getStringInfo(initiation.getTlvs() - .getStringInformation()))) - .withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, UP)).build()); + wTx.merge(LogicalDatastoreType.OPERATIONAL, routerYangIId, ImmutableNodes.newMapEntryBuilder() + .withNodeIdentifier(NodeIdentifierWithPredicates.of(Router.QNAME, ROUTER_ID_QNAME, routerIp)) + .withChild(ImmutableNodes.leafNode(ROUTER_NAME_QNAME, initiation.getTlvs().getNameTlv().getName())) + .withChild(ImmutableNodes.leafNode(ROUTER_DESCRIPTION_QNAME, + initiation.getTlvs().getDescriptionTlv().getDescription())) + .withChild(ImmutableNodes.leafNode(ROUTER_INFO_QNAME, + getStringInfo(initiation.getTlvs().getStringInformation()))) + .withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, UP)) + .build()); wTx.commit().addCallback(new FutureCallback() { @Override public void onSuccess(final CommitInfo result) { diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterPeerImpl.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterPeerImpl.java index 3c49af073f..bf663b0d2a 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterPeerImpl.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterPeerImpl.java @@ -16,7 +16,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.MoreExecutors; -import java.util.Locale; import java.util.Set; import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree; import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode; @@ -39,7 +38,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.AdjRibInType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Mirror; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.MirrorInformationCode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerDownNotification; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerUp; @@ -48,7 +46,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.mess import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.RouteMonitoringMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Stat; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.StatsReportsMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.up.ReceivedOpen; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.up.SentOpen; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.stat.Tlvs; @@ -70,8 +67,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -179,12 +175,12 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer { public void onPeerMessage(final Notification message) { if (message instanceof PeerDownNotification) { onPeerDown(); - } else if (message instanceof RouteMonitoringMessage) { - onRouteMonitoring((RouteMonitoringMessage) message); - } else if (message instanceof StatsReportsMessage) { - onStatsReports((StatsReportsMessage) message); - } else if (message instanceof RouteMirroringMessage) { - onRouteMirror((RouteMirroringMessage) message); + } else if (message instanceof RouteMonitoringMessage routeMonitoring) { + onRouteMonitoring(routeMonitoring); + } else if (message instanceof StatsReportsMessage statsReports) { + onStatsReports(statsReports); + } else if (message instanceof RouteMirroringMessage routeMirroring) { + onRouteMirror(routeMirroring); } } @@ -283,17 +279,13 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer { } private ContainerNode createPeerSessionUp(final PeerUp peerUp, final Timestamp timestamp) { - final DataContainerNodeBuilder builder = Builders.containerBuilder() - .withNodeIdentifier(new NodeIdentifier(PeerSession.QNAME)) - .withChild(ImmutableNodes.leafNode(PEER_LOCAL_ADDRESS_QNAME, - getStringIpAddress(peerUp.getLocalAddress()))) - .withChild(ImmutableNodes.leafNode(PEER_LOCAL_PORT_QNAME, peerUp - .getLocalPort().getValue())) - .withChild(ImmutableNodes.leafNode(PEER_REMOTE_PORT_QNAME, peerUp - .getRemotePort().getValue())) - .withChild(ImmutableNodes.leafNode(PEER_STATUS_QNAME, "up")) - .withChild(ImmutableNodes.leafNode(PEER_UP_TIMESTAMP_QNAME, - timestamp.getValue())); + final var builder = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(PeerSession.QNAME)) + .withChild(ImmutableNodes.leafNode(PEER_LOCAL_ADDRESS_QNAME, getStringIpAddress(peerUp.getLocalAddress()))) + .withChild(ImmutableNodes.leafNode(PEER_LOCAL_PORT_QNAME, peerUp.getLocalPort().getValue())) + .withChild(ImmutableNodes.leafNode(PEER_REMOTE_PORT_QNAME, peerUp.getRemotePort().getValue())) + .withChild(ImmutableNodes.leafNode(PEER_STATUS_QNAME, "up")) + .withChild(ImmutableNodes.leafNode(PEER_UP_TIMESTAMP_QNAME, timestamp.getValue())); if (receivedOpenCodec != null) { builder.withChild((ContainerNode) receivedOpenCodec.serialize(peerUp.getReceivedOpen())); } @@ -304,25 +296,28 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer { } private MapEntryNode createPeerEntry(final PeerUpNotification peerUp) { - final PeerHeader peerHeader = peerUp.getPeerHeader(); - final DataContainerNodeBuilder mapEntryBuilder = - Builders.mapEntryBuilder() - .withNodeIdentifier(NodeIdentifierWithPredicates.of(Peer.QNAME, PEER_ID_QNAME, - peerId.getValue())) - .withChild(ImmutableNodes.leafNode(PEER_ID_QNAME, peerId.getValue())) - .withChild(ImmutableNodes.leafNode(PEER_TYPE_QNAME, - peerHeader.getType().name().toLowerCase(Locale.ENGLISH))) - .withChild(ImmutableNodes.leafNode(PEER_ADDRESS_QNAME, - getStringIpAddress(peerHeader.getAddress()))) - .withChild(ImmutableNodes.leafNode(PEER_AS_QNAME, peerHeader.getAs().getValue())) - .withChild(ImmutableNodes.leafNode(PEER_BGP_ID_QNAME, peerHeader.getBgpId().getValue())) - .withChild(createPeerSessionUp(peerUp, peerHeader.getTimestampSec())) - .withChild( - Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PrePolicyRib.QNAME)) - .withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build()) - .withChild( - Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PostPolicyRib.QNAME)) - .withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build()); + final var peerHeader = peerUp.getPeerHeader(); + final var mapEntryBuilder = ImmutableNodes.newMapEntryBuilder() + .withNodeIdentifier(NodeIdentifierWithPredicates.of(Peer.QNAME, PEER_ID_QNAME, peerId.getValue())) + .withChild(ImmutableNodes.leafNode(PEER_ID_QNAME, peerId.getValue())) + .withChild(ImmutableNodes.leafNode(PEER_TYPE_QNAME, peerHeader.getType().getName())) + .withChild(ImmutableNodes.leafNode(PEER_ADDRESS_QNAME, + getStringIpAddress(peerHeader.getAddress()))) + .withChild(ImmutableNodes.leafNode(PEER_AS_QNAME, peerHeader.getAs().getValue())) + .withChild(ImmutableNodes.leafNode(PEER_BGP_ID_QNAME, peerHeader.getBgpId().getValue())) + .withChild(createPeerSessionUp(peerUp, peerHeader.getTimestampSec())) + .withChild(ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(PrePolicyRib.QNAME)) + .withChild(ImmutableNodes.newSystemMapBuilder() + .withNodeIdentifier(new NodeIdentifier(BMP_TABLES_QNAME)) + .build()) + .build()) + .withChild(ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(PostPolicyRib.QNAME)) + .withChild(ImmutableNodes.newSystemMapBuilder() + .withNodeIdentifier(new NodeIdentifier(BMP_TABLES_QNAME)) + .build()) + .build()); final PeerDistinguisher pd = peerHeader.getPeerDistinguisher(); if (pd != null) { mapEntryBuilder.withChild(ImmutableNodes.leafNode(PEER_DISTINGUISHER_QNAME, pd.getRouteDistinguisher())); @@ -331,8 +326,7 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer { } private static ContainerNode createStats(final Stat stat, final Timestamp timestamp) { - final DataContainerNodeBuilder builder = - Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(Stats.QNAME)); + final var builder = ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(Stats.QNAME)); builder.withChild(ImmutableNodes.leafNode(PEER_STATS_TIMESTAMP_QNAME, timestamp.getValue())); final Tlvs tlvs = stat.getTlvs(); if (tlvs != null) { @@ -372,29 +366,36 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer { tlvs.getInvalidatedAsConfedLoopTlv().getCount().getValue())); } if (tlvs.getAdjRibsInRoutesTlv() != null) { - builder.withChild(ImmutableNodes.leafNode(STAT7_QNAME, - tlvs.getAdjRibsInRoutesTlv().getCount().getValue())); + builder.withChild(ImmutableNodes.leafNode(STAT7_QNAME, tlvs.getAdjRibsInRoutesTlv().getCount().getValue())); } if (tlvs.getLocRibRoutesTlv() != null) { - builder.withChild(ImmutableNodes.leafNode(STAT8_QNAME, - tlvs.getLocRibRoutesTlv().getCount().getValue())); + builder.withChild(ImmutableNodes.leafNode(STAT8_QNAME, tlvs.getLocRibRoutesTlv().getCount().getValue())); } if (tlvs.getPerAfiSafiAdjRibInTlv() != null) { - builder.withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(STAT9_QNAME)) - .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME).withChild(Builders.mapEntryBuilder() - .withChild(ImmutableNodes.leafNode(COUNT_QNAME, + builder.withChild(ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(STAT9_QNAME)) + .withChild(ImmutableNodes.newSystemMapBuilder() + .withNodeIdentifier(new NodeIdentifier(AF_QNAME)) + .withChild(ImmutableNodes.newMapEntryBuilder() + .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiAdjRibInTlv().getCount().getValue())) - .withNodeIdentifier(AFI_ITEM) - .build()).build()).build()); + .withNodeIdentifier(AFI_ITEM) + .build()) + .build()) + .build()); } if (tlvs.getPerAfiSafiLocRibTlv() != null) { - builder.withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(STAT10_QNAME)) - .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME) - .withChild(Builders.mapEntryBuilder() - .withChild(ImmutableNodes.leafNode(COUNT_QNAME, - tlvs.getPerAfiSafiLocRibTlv().getCount().getValue())) - .withNodeIdentifier(AFI_ITEM) - .build()).build()).build()); + builder.withChild(ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(STAT10_QNAME)) + .withChild(ImmutableNodes.newSystemMapBuilder() + .withNodeIdentifier(new NodeIdentifier(AF_QNAME)) + .withChild(ImmutableNodes.newMapEntryBuilder() + .withChild(ImmutableNodes.leafNode(COUNT_QNAME, + tlvs.getPerAfiSafiLocRibTlv().getCount().getValue())) + .withNodeIdentifier(AFI_ITEM) + .build()) + .build()) + .build()); } if (tlvs.getUpdatesTreatedAsWithdrawTlv() != null) { builder.withChild(ImmutableNodes.leafNode(STAT11_QNAME, @@ -411,20 +412,12 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer { } private static ContainerNode createMirrors(final Mirror mirror, final Timestamp timestamp) { - final DataContainerNodeBuilder builder = - Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(Mirrors.QNAME)); - builder.withChild(ImmutableNodes.leafNode(PEER_MIRROR_INFORMATION_QNAME, toDom(MirrorInformationCode.forValue( - mirror.getTlvs().getMirrorInformationTlv().getCode().getIntValue())))); - builder.withChild(ImmutableNodes.leafNode(PEER_MIRROR_TIMESTAMP_QNAME, timestamp.getValue())); - return builder.build(); - } - - private static String toDom(final MirrorInformationCode informationCode) { - return switch (informationCode) { - case ErroredPdu -> "errored-pdu"; - case MessageLost -> "message-lost"; - default -> null; - }; + return ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(Mirrors.QNAME)) + .withChild(ImmutableNodes.leafNode(PEER_MIRROR_INFORMATION_QNAME, + mirror.getTlvs().getMirrorInformationTlv().getCode().getName())) + .withChild(ImmutableNodes.leafNode(PEER_MIRROR_TIMESTAMP_QNAME, timestamp.getValue())) + .build(); } private static String getStringIpAddress(final IpAddressNoZone ipAddress) { diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/TableContext.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/TableContext.java index 3f2cd16f30..f7ec7a628c 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/TableContext.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/TableContext.java @@ -33,17 +33,18 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; // This class is NOT thread-safe final class TableContext { - private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(BMP_ATTRIBUTES_QNAME); + private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(NodeIdentifier.create(BMP_ATTRIBUTES_QNAME)) + .build(); private static final NodeIdentifier BGP_ROUTES_NODE_ID = new NodeIdentifier(BMP_ROUTES_QNAME); private final YangInstanceIdentifier tableId; - private final RIBSupport tableSupport; + private final RIBSupport tableSupport; private final BindingNormalizedNodeCachingCodec attributesCodec; private final BindingNormalizedNodeCachingCodec reachNlriCodec; private final BindingNormalizedNodeCachingCodec unreachNlriCodec; @@ -79,7 +80,7 @@ final class TableContext { } void createTable(final DOMDataTreeWriteTransaction tx) { - final var tb = ImmutableNodes.mapEntryBuilder() + final var tb = ImmutableNodes.newMapEntryBuilder() .withNodeIdentifier((NodeIdentifierWithPredicates) tableId.getLastPathArgument()) .withChild(EMPTY_TABLE_ATTRIBUTES); @@ -90,10 +91,10 @@ final class TableContext { } tx.put(LogicalDatastoreType.OPERATIONAL, tableId, - tb.withChild(Builders.choiceBuilder() - .withNodeIdentifier(new NodeIdentifier(TablesUtil.BMP_ROUTES_QNAME)) - .build()) - .build()); + tb.withChild(ImmutableNodes.newChoiceBuilder() + .withNodeIdentifier(new NodeIdentifier(TablesUtil.BMP_ROUTES_QNAME)) + .build()) + .build()); } void writeRoutes(final DOMDataTreeWriteTransaction tx, final MpReachNlri nlri, final Attributes attributes) { diff --git a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/config/BmpDeployerImpl.java b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/config/BmpDeployerImpl.java index 499d3f0cdf..fe5d9a4f22 100644 --- a/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/config/BmpDeployerImpl.java +++ b/bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/config/BmpDeployerImpl.java @@ -13,7 +13,6 @@ import com.google.common.collect.Iterables; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.MoreExecutors; import java.net.InetSocketAddress; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,10 +21,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.DataObjectModification.ModificationType; +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.dom.codec.api.BindingCodecTree; @@ -37,7 +35,6 @@ import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext; import org.opendaylight.protocol.bmp.api.BmpDispatcher; import org.opendaylight.protocol.bmp.impl.app.BmpMonitoringStationImpl; -import org.opendaylight.protocol.bmp.impl.spi.BmpMonitoringStation; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.OdlBmpMonitors; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.odl.bmp.monitors.BmpMonitorConfig; @@ -46,13 +43,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.moni import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor; import org.opendaylight.yangtools.concepts.Registration; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -62,16 +57,16 @@ import org.slf4j.LoggerFactory; @Singleton @Component(service = {}) -public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener, AutoCloseable { +public final class BmpDeployerImpl implements DataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(BmpDeployerImpl.class); private static final long TIMEOUT_NS = TimeUnit.SECONDS.toNanos(5); private static final InstanceIdentifier ODL_BMP_MONITORS_IID = InstanceIdentifier.create(OdlBmpMonitors.class); private static final YangInstanceIdentifier BMP_MONITOR_YII = YangInstanceIdentifier.of(BmpMonitor.QNAME); - private static final ContainerNode EMPTY_PARENT_NODE = Builders.containerBuilder() + private static final ContainerNode EMPTY_PARENT_NODE = ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(BmpMonitor.QNAME)) - .addChild(ImmutableNodes.mapNodeBuilder(Monitor.QNAME).build()) + .addChild(ImmutableNodes.newSystemMapBuilder().withNodeIdentifier(new NodeIdentifier(Monitor.QNAME)).build()) .build(); private final BmpDispatcher dispatcher; @@ -110,15 +105,15 @@ public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener> changes) { - final DataTreeModification dataTreeModification = Iterables.getOnlyElement(changes); - final Collection> rootNode = - dataTreeModification.getRootNode().getModifiedChildren(); + // FIXME: what about multiple events?! + final var dataTreeModification = Iterables.getOnlyElement(changes); + final var rootNode = dataTreeModification.getRootNode().modifiedChildren(); if (rootNode.isEmpty()) { return; } @@ -126,15 +121,15 @@ public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener config) { - final ModificationType modificationType = config.getModificationType(); + final var modificationType = config.modificationType(); LOG.trace("Bmp Monitor configuration has changed: {}, type modification {}", config, modificationType); switch (modificationType) { case DELETE: - removeBmpMonitor(config.getDataBefore().getMonitorId()); + removeBmpMonitor(config.dataBefore().getMonitorId()); break; case SUBTREE_MODIFIED: case WRITE: - updateBmpMonitor(config.getDataAfter()); + updateBmpMonitor(config.dataAfter()); break; default: break; @@ -166,7 +161,7 @@ public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener MONITOR_IID = InstanceIdentifier - .create(BmpMonitor.class).child(Monitor.class, new MonitorKey(MONITOR_ID)); + private static final KeyedInstanceIdentifier MONITOR_IID = + InstanceIdentifier.create(BmpMonitor.class).child(Monitor.class, new MonitorKey(MONITOR_ID)); private static final PeerId PEER_ID = new PeerId(PEER1.getValue()); private static final InstanceIdentifier BMP_II = InstanceIdentifier.create(BmpMonitor.class); private AdapterContext mappingService; @@ -171,9 +170,12 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { MONITOR_LOCAL_PORT); final DOMDataTreeWriteTransaction wTx = getDomBroker().newWriteOnlyTransaction(); - final ContainerNode parentNode = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(BmpMonitor.QNAME)) - .addChild(ImmutableNodes.mapNodeBuilder(Monitor.QNAME).build()).build(); + final ContainerNode parentNode = ImmutableNodes.newContainerBuilder() + .withNodeIdentifier(new NodeIdentifier(BmpMonitor.QNAME)) + .addChild(ImmutableNodes.newSystemMapBuilder() + .withNodeIdentifier(new NodeIdentifier(Monitor.QNAME)) + .build()) + .build(); wTx.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of(BmpMonitor.QNAME), parentNode); wTx.commit().get(); @@ -422,16 +424,15 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { @Test public void deploySecondInstance() throws Exception { - final BmpMonitoringStation monitoringStation2 = new BmpMonitoringStationImpl(getDomBroker(), dispatcher, + try (var monitoringStation2 = new BmpMonitoringStationImpl(getDomBroker(), dispatcher, ribExtension, mappingService.currentSerializer(), clusterSSProv2, new MonitorId("monitor2"), - new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS_2), MONITOR_LOCAL_PORT), null); + new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS_2), MONITOR_LOCAL_PORT), null)) { - readDataOperational(getDataBroker(), BMP_II, monitor -> { - assertEquals(2, monitor.nonnullMonitor().size()); - return monitor; - }); - - monitoringStation2.close(); + readDataOperational(getDataBroker(), BMP_II, monitor -> { + assertEquals(2, monitor.nonnullMonitor().size()); + return monitor; + }); + } } private static Channel connectTestClient(final String routerIp, final BmpMessageRegistry msgRegistry) -- 2.36.6