Modernize bmp-impl 24/110424/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 1 Mar 2024 21:03:44 +0000 (22:03 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 2 Mar 2024 09:34:25 +0000 (10:34 +0100)
Use new ImmutableNodes and take advantage of getName() method generated
for YANG enumerations.

Change-Id: I9a452d936dd4bfcb9c7cf55249ef1f4cb29883dd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bmp/bmp-impl/pom.xml
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitoringStationImpl.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterImpl.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterPeerImpl.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/TableContext.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/config/BmpDeployerImpl.java
bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java

index f10e26e048dd933ae4a914baba0ed864d8f5bf3c..976982ce84e35ed0b5b889ad5a68bc75454c6e48 100644 (file)
@@ -88,7 +88,7 @@
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-data-impl</artifactId>
+            <artifactId>yang-data-spi</artifactId>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
index 5e6e65f67adaf3ef38403a5fed411822b7655e32..4bee83912ba381e5cae10cdcfd4017bb317b3aa7 100644 (file)
@@ -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) {
index f7ab0a8c67a865b70f5ac2a97e9bda1dd59f2609..87f20dea7f7bee0eb6e81805851f6fa098fca727 100644 (file)
@@ -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;
 
index ab33bb7b2a7330639b59adf7e4c2271891583ba6..a2b9a875a770f1e329a9d8a4188ec41782940c27 100644 (file)
@@ -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<Empty> {
     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<CommitInfo>() {
             @Override
             public void onSuccess(final CommitInfo result) {
@@ -220,15 +220,15 @@ public final class BmpRouterImpl implements BmpRouter, FutureCallback<Empty> {
     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<CommitInfo>() {
             @Override
             public void onSuccess(final CommitInfo result) {
index 3c49af073fbfd12a215dc2b23fcccaae48ef3523..bf663b0d2a154fafe910e4421279619d0773747f 100644 (file)
@@ -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<NodeIdentifier, ContainerNode> 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<NodeIdentifierWithPredicates, MapEntryNode> 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<NodeIdentifier, ContainerNode> 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<NodeIdentifier, ContainerNode> 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) {
index 3f2cd16f30b014f597c63d932170436ee4b07759..f7ec7a628cdb206d73970c34b1997e86e9d8a1c8 100644 (file)
@@ -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<Attributes> attributesCodec;
     private final BindingNormalizedNodeCachingCodec<MpReachNlri> reachNlriCodec;
     private final BindingNormalizedNodeCachingCodec<MpUnreachNlri> 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) {
index 499d3f0cdf613d0726e87c6236ef6b658eb5c03a..fe5d9a4f22dc9f78027c56695b147507a7f7510e 100644 (file)
@@ -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<OdlBmpMonitors>, AutoCloseable {
+public final class BmpDeployerImpl implements DataTreeChangeListener<OdlBmpMonitors>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(BmpDeployerImpl.class);
 
     private static final long TIMEOUT_NS = TimeUnit.SECONDS.toNanos(5);
     private static final InstanceIdentifier<OdlBmpMonitors> 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<Od
                 LOG.error("Failed commit", trw);
             }
         }, MoreExecutors.directExecutor());
-        registration = dataBroker.registerDataTreeChangeListener(
-            DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, ODL_BMP_MONITORS_IID), this);
+        registration = dataBroker.registerTreeChangeListener(
+            DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, ODL_BMP_MONITORS_IID), this);
     }
 
     @Override
     public synchronized void onDataTreeChanged(final List<DataTreeModification<OdlBmpMonitors>> changes) {
-        final DataTreeModification<OdlBmpMonitors> dataTreeModification = Iterables.getOnlyElement(changes);
-        final Collection<? extends DataObjectModification<? extends DataObject>> 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<Od
     }
 
     private synchronized void handleModification(final DataObjectModification<BmpMonitorConfig> 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<Od
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     private synchronized void removeBmpMonitor(final MonitorId monitorId) {
-        final BmpMonitoringStation service = bmpMonitorServices.remove(monitorId);
+        final var service = bmpMonitorServices.remove(monitorId);
         if (service != null) {
             LOG.debug("Closing Bmp Monitor {}.", monitorId);
             try {
index 16e367789aa3627c706d66de8efd74c892b9b5c9..645196472eae7a563637f6a37860d88099a43dd6 100644 (file)
@@ -97,8 +97,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 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;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
@@ -111,8 +110,8 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
     private static final String REMOTE_ROUTER_ADDRESS_2 = "127.0.0.13";
     private static final Ipv4AddressNoZone PEER1 = new Ipv4AddressNoZone("20.20.20.20");
     private static final MonitorId MONITOR_ID = new MonitorId("monitor");
-    private static final KeyedInstanceIdentifier<Monitor, MonitorKey> MONITOR_IID = InstanceIdentifier
-        .create(BmpMonitor.class).child(Monitor.class, new MonitorKey(MONITOR_ID));
+    private static final KeyedInstanceIdentifier<Monitor, MonitorKey> 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<BmpMonitor> 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)