Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginStatsTestCommandProvider.java
index dd6eb4bc64e69791b2846fe1542c75697db19c40..8ef877f03b2a445be9a3f96242a111c2e8ce5da2 100644 (file)
@@ -5,15 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.test;
 
-import java.util.List;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.Collection;
 import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
@@ -46,15 +45,15 @@ import org.slf4j.LoggerFactory;
 public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginStatsTestCommandProvider.class);
-    private DataBroker dataProviderService;
+    private final DataBroker dataProviderService;
     private final BundleContext ctx;
 
-    public OpenflowpluginStatsTestCommandProvider(BundleContext ctx) {
+    public OpenflowpluginStatsTestCommandProvider(DataBroker dataProviderService, BundleContext ctx) {
+        this.dataProviderService = dataProviderService;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        dataProviderService = session.getSALService(DataBroker.class);
+    public void init() {
         ctx.registerService(CommandProvider.class.getName(), this, null);
 
     }
@@ -62,26 +61,26 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
     public void _portStats(CommandInterpreter ci) {
         int nodeConnectorCount = 0;
         int nodeConnectorStatsCount = 0;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<Node> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             Node node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
                 if (node.getNodeConnector() != null) {
-                    List<NodeConnector> ports = node.getNodeConnector();
+                    Collection<NodeConnector> ports = node.nonnullNodeConnector().values();
 
                     for (NodeConnector nodeConnector2 : ports) {
                         nodeConnectorCount++;
-                        NodeConnectorKey nodeConnectorKey = nodeConnector2.getKey();
+                        NodeConnectorKey nodeConnectorKey = nodeConnector2.key();
                         InstanceIdentifier<NodeConnector> connectorRef = InstanceIdentifier.create(Nodes.class)
                                 .child(Node.class, nodeKey).child(NodeConnector.class, nodeConnectorKey);
                         NodeConnector nodeConnector = TestProviderTransactionUtil.getDataObject(readOnlyTransaction,
                                 connectorRef);
                         if (nodeConnector != null) {
                             FlowCapableNodeConnectorStatisticsData data = nodeConnector
-                                    .getAugmentation(FlowCapableNodeConnectorStatisticsData.class);
+                                    .augmentation(FlowCapableNodeConnectorStatisticsData.class);
                             if (null != data) {
                                 nodeConnectorStatsCount++;
                             }
@@ -103,19 +102,19 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
     public void _portDescStats(CommandInterpreter ci) {
         int nodeConnectorCount = 0;
         int nodeConnectorDescStatsCount = 0;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<Node> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey);
 
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             Node node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
                 if (node.getNodeConnector() != null) {
-                    List<NodeConnector> ports = node.getNodeConnector();
+                    Collection<NodeConnector> ports = node.nonnullNodeConnector().values();
                     for (NodeConnector nodeConnector2 : ports) {
                         nodeConnectorCount++;
-                        NodeConnectorKey nodeConnectorKey = nodeConnector2.getKey();
+                        NodeConnectorKey nodeConnectorKey = nodeConnector2.key();
                         InstanceIdentifier<FlowCapableNodeConnector> connectorRef = InstanceIdentifier
                                 .create(Nodes.class).child(Node.class, nodeKey)
                                 .child(NodeConnector.class, nodeConnectorKey)
@@ -144,38 +143,39 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     }
 
+    @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
     public void _flowStats(CommandInterpreter ci) {
         int flowCount = 0;
         int flowStatsCount = 0;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
 
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
 
             if (node != null) {
-                List<Table> tables = node.getTable();
+                Collection<Table> tables = node.nonnullTable().values();
                 for (Table table2 : tables) {
-                    TableKey tableKey = table2.getKey();
+                    TableKey tableKey = table2.key();
                     InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class)
                             .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                             .child(Table.class, tableKey);
                     Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                     if (table != null) {
                         if (table.getFlow() != null) {
-                            List<Flow> flows = table.getFlow();
+                            Collection<Flow> flows = table.nonnullFlow().values();
                             for (Flow flow2 : flows) {
                                 flowCount++;
-                                FlowKey flowKey = flow2.getKey();
+                                FlowKey flowKey = flow2.key();
                                 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.create(Nodes.class)
                                         .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                                         .child(Table.class, tableKey).child(Flow.class, flowKey);
                                 Flow flow = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, flowRef);
                                 if (flow != null) {
-                                    FlowStatisticsData data = flow.getAugmentation(FlowStatisticsData.class);
+                                    FlowStatisticsData data = flow.augmentation(FlowStatisticsData.class);
                                     if (null != data) {
                                         flowStatsCount++;
                                         LOG.debug("--------------------------------------------");
@@ -202,25 +202,25 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
     public void _tableStats(CommandInterpreter ci) {
         int tableCount = 0;
         int tableStatsCount = 0;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
 
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
-                List<Table> tables = node.getTable();
+                Collection<Table> tables = node.nonnullTable().values();
                 for (Table table2 : tables) {
                     tableCount++;
-                    TableKey tableKey = table2.getKey();
+                    TableKey tableKey = table2.key();
                     InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class)
                             .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                             .child(Table.class, tableKey);
                     Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                     if (table != null) {
-                        FlowTableStatisticsData data = table.getAugmentation(FlowTableStatisticsData.class);
+                        FlowTableStatisticsData data = table.augmentation(FlowTableStatisticsData.class);
                         if (null != data) {
                             tableStatsCount++;
                         }
@@ -242,25 +242,25 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int groupCount = 0;
         int groupStatsCount = 0;
         NodeGroupStatistics data = null;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
                 if (node.getGroup() != null) {
-                    List<Group> groups = node.getGroup();
+                    Collection<Group> groups = node.nonnullGroup().values();
                     for (Group group2 : groups) {
                         groupCount++;
-                        GroupKey groupKey = group2.getKey();
+                        GroupKey groupKey = group2.key();
                         InstanceIdentifier<Group> groupRef = InstanceIdentifier.create(Nodes.class)
                                 .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                                 .child(Group.class, groupKey);
                         Group group = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, groupRef);
                         if (group != null) {
-                            data = group.getAugmentation(NodeGroupStatistics.class);
+                            data = group.augmentation(NodeGroupStatistics.class);
                             if (null != data) {
                                 groupStatsCount++;
                             }
@@ -283,26 +283,26 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int groupCount = 0;
         int groupDescStatsCount = 0;
         NodeGroupDescStats data = null;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
 
             if (node != null) {
                 if (node.getGroup() != null) {
-                    List<Group> groups = node.getGroup();
+                    Collection<Group> groups = node.nonnullGroup().values();
                     for (Group group2 : groups) {
                         groupCount++;
-                        GroupKey groupKey = group2.getKey();
+                        GroupKey groupKey = group2.key();
                         InstanceIdentifier<Group> groupRef = InstanceIdentifier.create(Nodes.class)
                                 .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                                 .child(Group.class, groupKey);
                         Group group = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, groupRef);
                         if (group != null) {
-                            data = group.getAugmentation(NodeGroupDescStats.class);
+                            data = group.augmentation(NodeGroupDescStats.class);
                             if (null != data) {
                                 groupDescStatsCount++;
                             }
@@ -325,25 +325,25 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int meterCount = 0;
         int meterStatsCount = 0;
         NodeMeterStatistics data = null;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
                 if (node.getMeter() != null) {
-                    List<Meter> meters = node.getMeter();
+                    Collection<Meter> meters = node.nonnullMeter().values();
                     for (Meter meter2 : meters) {
                         meterCount++;
-                        MeterKey meterKey = meter2.getKey();
+                        MeterKey meterKey = meter2.key();
                         InstanceIdentifier<Meter> meterRef = InstanceIdentifier.create(Nodes.class)
                                 .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                                 .child(Meter.class, meterKey);
                         Meter meter = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, meterRef);
                         if (meter != null) {
-                            data = meter.getAugmentation(NodeMeterStatistics.class);
+                            data = meter.augmentation(NodeMeterStatistics.class);
                             if (null != data) {
                                 meterStatsCount++;
                             }
@@ -366,25 +366,25 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int meterCount = 0;
         int meterConfigStatsCount = 0;
         NodeMeterConfigStats data = null;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
                 if (node.getMeter() != null) {
-                    List<Meter> meters = node.getMeter();
+                    Collection<Meter> meters = node.nonnullMeter().values();
                     for (Meter meter2 : meters) {
                         meterCount++;
-                        MeterKey meterKey = meter2.getKey();
+                        MeterKey meterKey = meter2.key();
                         InstanceIdentifier<Meter> meterRef = InstanceIdentifier.create(Nodes.class)
                                 .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                                 .child(Meter.class, meterKey);
                         Meter meter = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, meterRef);
                         if (meter != null) {
-                            data = meter.getAugmentation(NodeMeterConfigStats.class);
+                            data = meter.augmentation(NodeMeterConfigStats.class);
                             if (null != data) {
                                 meterConfigStatsCount++;
                             }
@@ -407,24 +407,24 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
     public void _aggregateStats(CommandInterpreter ci) {
         int aggregateFlowCount = 0;
         int aggerateFlowStatsCount = 0;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
-                List<Table> tables = node.getTable();
+                Collection<Table> tables = node.nonnullTable().values();
                 for (Table table2 : tables) {
                     aggregateFlowCount++;
-                    TableKey tableKey = table2.getKey();
+                    TableKey tableKey = table2.key();
                     InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class)
                             .child(Node.class, nodeKey).augmentation(FlowCapableNode.class)
                             .child(Table.class, tableKey);
                     Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                     if (table != null) {
-                        AggregateFlowStatisticsData data = table.getAugmentation(AggregateFlowStatisticsData.class);
+                        AggregateFlowStatisticsData data = table.augmentation(AggregateFlowStatisticsData.class);
                         if (null != data) {
                             aggerateFlowStatsCount++;
                         }
@@ -445,13 +445,13 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
     public void _descStats(CommandInterpreter ci) {
         int descCount = 0;
         int descStatsCount = 0;
-        List<Node> nodes = getNodes();
+        Collection<Node> nodes = getNodes();
         for (Node node2 : nodes) {
             descCount++;
-            NodeKey nodeKey = node2.getKey();
+            NodeKey nodeKey = node2.key();
             InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
                     .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
-            ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+            ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
             FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
             if (node != null) {
                 if (null != node.getHardware() && null != node.getManufacturer() && null != node.getSoftware()) {
@@ -469,14 +469,14 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     }
 
-    private List<Node> getNodes() {
-        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
+    private Collection<Node> getNodes() {
+        ReadTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
         InstanceIdentifier<Nodes> nodesID = InstanceIdentifier.create(Nodes.class);
         Nodes nodes = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodesID);
         if (nodes == null) {
-            throw new RuntimeException("nodes are not found, pls add the node.");
+            throw new IllegalStateException("nodes are not found, pls add the node.");
         }
-        return nodes.getNode();
+        return nodes.nonnullNode().values();
     }
 
     @Override