Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginStatsTestCommandProvider.java
index d1053aaa2906e1ab5339d1eb5ce662c3481a56af..264736000bd438404d88313f922ce43be0d3227b 100644 (file)
@@ -1,12 +1,18 @@
+/*
+ * Copyright (c) 2014, 2015 IBM Corporation and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.Iterator;
 import java.util.List;
 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.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
@@ -36,6 +42,7 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("checkstyle:MethodName")
 public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginStatsTestCommandProvider.class);
@@ -46,7 +53,6 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         this.ctx = ctx;
     }
 
-
     public void onSessionInitiated(ProviderContext session) {
         dataProviderService = session.getSALService(DataBroker.class);
         ctx.registerService(CommandProvider.class.getName(), this, null);
@@ -57,22 +63,30 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int nodeConnectorCount = 0;
         int nodeConnectorStatsCount = 0;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<Node> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).toInstance();
-
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<Node> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            Node node = (Node) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<NodeConnector> ports = node.getNodeConnector();
-            for (Iterator<NodeConnector> iterator2 = ports.iterator(); iterator2.hasNext(); ) {
-                nodeConnectorCount++;
-                NodeConnectorKey nodeConnectorKey = iterator2.next().getKey();
-                InstanceIdentifier<NodeConnector> connectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).child(NodeConnector.class, nodeConnectorKey).toInstance();
-                NodeConnector nodeConnector = (NodeConnector) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, connectorRef);
-                FlowCapableNodeConnectorStatisticsData data = nodeConnector.getAugmentation(FlowCapableNodeConnectorStatisticsData.class);
-                if (null != data) {
-                    nodeConnectorStatsCount++;
+            Node node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                if (node.getNodeConnector() != null) {
+                    List<NodeConnector> ports = node.getNodeConnector();
+
+                    for (NodeConnector nodeConnector2 : ports) {
+                        nodeConnectorCount++;
+                        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
+                                    .augmentation(FlowCapableNodeConnectorStatisticsData.class);
+                            if (null != data) {
+                                nodeConnectorStatsCount++;
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -86,31 +100,38 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     }
 
-
     public void _portDescStats(CommandInterpreter ci) {
         int nodeConnectorCount = 0;
         int nodeConnectorDescStatsCount = 0;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<Node> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<Node> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey);
 
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            Node node = (Node) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<NodeConnector> ports = node.getNodeConnector();
-            for (Iterator<NodeConnector> iterator2 = ports.iterator(); iterator2.hasNext(); ) {
-                nodeConnectorCount++;
-                NodeConnectorKey nodeConnectorKey = iterator2.next().getKey();
-                InstanceIdentifier<FlowCapableNodeConnector> connectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).child(NodeConnector.class, nodeConnectorKey).augmentation(FlowCapableNodeConnector.class).toInstance();
-                FlowCapableNodeConnector nodeConnector = (FlowCapableNodeConnector) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, connectorRef);
-                if (null != nodeConnector.getName() &&
-                        null != nodeConnector.getCurrentFeature() &&
-                        null != nodeConnector.getState() &&
-                        null != nodeConnector.getHardwareAddress() &&
-                        null != nodeConnector.getPortNumber()) {
-                    nodeConnectorDescStatsCount++;
+            Node node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                if (node.getNodeConnector() != null) {
+                    List<NodeConnector> ports = node.getNodeConnector();
+                    for (NodeConnector nodeConnector2 : ports) {
+                        nodeConnectorCount++;
+                        NodeConnectorKey nodeConnectorKey = nodeConnector2.key();
+                        InstanceIdentifier<FlowCapableNodeConnector> connectorRef = InstanceIdentifier
+                                .create(Nodes.class).child(Node.class, nodeKey)
+                                .child(NodeConnector.class, nodeConnectorKey)
+                                .augmentation(FlowCapableNodeConnector.class);
+                        FlowCapableNodeConnector nodeConnector = TestProviderTransactionUtil
+                                .getDataObject(readOnlyTransaction, connectorRef);
+                        if (nodeConnector != null) {
+                            if (null != nodeConnector.getName() && null != nodeConnector.getCurrentFeature()
+                                    && null != nodeConnector.getState() && null != nodeConnector.getHardwareAddress()
+                                    && null != nodeConnector.getPortNumber()) {
+                                nodeConnectorDescStatsCount++;
+                            }
+                        }
+                    }
                 }
+
             }
         }
 
@@ -127,29 +148,43 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int flowCount = 0;
         int flowStatsCount = 0;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
 
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Table> tables = node.getTable();
-            for (Iterator<Table> iterator2 = tables.iterator(); iterator2.hasNext(); ) {
-                TableKey tableKey = iterator2.next().getKey();
-                InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey).toInstance();
-                Table table = (Table) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, tableRef);
-                List<Flow> flows = table.getFlow();
-                for (Iterator<Flow> iterator3 = flows.iterator(); iterator3.hasNext(); ) {
-                    flowCount++;
-                    FlowKey flowKey = iterator3.next().getKey();
-                    InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey).toInstance();
-                    Flow flow = (Flow) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, flowRef);
-                    FlowStatisticsData data = flow.getAugmentation(FlowStatisticsData.class);
-                    if (null != data) {
-                        flowStatsCount++;
-                        LOG.debug("--------------------------------------------");
-                        ci.print(data);
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+
+            if (node != null) {
+                List<Table> tables = node.getTable();
+                for (Table table2 : tables) {
+                    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();
+                            for (Flow flow2 : flows) {
+                                flowCount++;
+                                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.augmentation(FlowStatisticsData.class);
+                                    if (null != data) {
+                                        flowStatsCount++;
+                                        LOG.debug("--------------------------------------------");
+                                        ci.print(data);
+                                    }
+                                }
+
+                            }
+                        }
                     }
                 }
             }
@@ -164,27 +199,32 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     }
 
-
     public void _tableStats(CommandInterpreter ci) {
         int tableCount = 0;
         int tableStatsCount = 0;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
 
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Table> tables = node.getTable();
-            for (Iterator<Table> iterator2 = tables.iterator(); iterator2.hasNext(); ) {
-                tableCount++;
-                TableKey tableKey = iterator2.next().getKey();
-                InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey).toInstance();
-                Table table = (Table) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, tableRef);
-                FlowTableStatisticsData data = table.getAugmentation(FlowTableStatisticsData.class);
-                if (null != data) {
-                    tableStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                List<Table> tables = node.getTable();
+                for (Table table2 : tables) {
+                    tableCount++;
+                    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.augmentation(FlowTableStatisticsData.class);
+                        if (null != data) {
+                            tableStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -203,22 +243,31 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int groupStatsCount = 0;
         NodeGroupStatistics data = null;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Group> groups = node.getGroup();
-            for (Iterator<Group> iterator2 = groups.iterator(); iterator2.hasNext(); ) {
-                groupCount++;
-                GroupKey groupKey = iterator2.next().getKey();
-                InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Group.class, groupKey).toInstance();
-                Group group = (Group) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, groupRef);
-                data = group.getAugmentation(NodeGroupStatistics.class);
-                if (null != data) {
-                    groupStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                if (node.getGroup() != null) {
+                    List<Group> groups = node.getGroup();
+                    for (Group group2 : groups) {
+                        groupCount++;
+                        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.augmentation(NodeGroupStatistics.class);
+                            if (null != data) {
+                                groupStatsCount++;
+                            }
+                        }
+                    }
                 }
+
             }
         }
 
@@ -235,30 +284,40 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int groupDescStatsCount = 0;
         NodeGroupDescStats data = null;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Group> groups = node.getGroup();
-            for (Iterator<Group> iterator2 = groups.iterator(); iterator2.hasNext(); ) {
-                groupCount++;
-                GroupKey groupKey = iterator2.next().getKey();
-                InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Group.class, groupKey).toInstance();
-                Group group = (Group) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, groupRef);
-                data = group.getAugmentation(NodeGroupDescStats.class);
-                if (null != data) {
-                    groupDescStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+
+            if (node != null) {
+                if (node.getGroup() != null) {
+                    List<Group> groups = node.getGroup();
+                    for (Group group2 : groups) {
+                        groupCount++;
+                        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.augmentation(NodeGroupDescStats.class);
+                            if (null != data) {
+                                groupDescStatsCount++;
+                            }
+                        }
+
+                    }
                 }
             }
-        }
 
-        if (groupCount == groupDescStatsCount) {
-            LOG.debug("---------------------groupDescStats - Success-------------------------------");
-        } else {
-            LOG.debug("------------------------------groupDescStats - Failed--------------------------");
-            LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
+            if (groupCount == groupDescStatsCount) {
+                LOG.debug("---------------------groupDescStats - Success-------------------------------");
+            } else {
+                LOG.debug("------------------------------groupDescStats - Failed--------------------------");
+                LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
+            }
         }
     }
 
@@ -267,21 +326,30 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int meterStatsCount = 0;
         NodeMeterStatistics data = null;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Meter> meters = node.getMeter();
-            for (Iterator<Meter> iterator2 = meters.iterator(); iterator2.hasNext(); ) {
-                meterCount++;
-                MeterKey meterKey = iterator2.next().getKey();
-                InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Meter.class, meterKey).toInstance();
-                Meter meter = (Meter) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, meterRef);
-                data = meter.getAugmentation(NodeMeterStatistics.class);
-                if (null != data) {
-                    meterStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                if (node.getMeter() != null) {
+                    List<Meter> meters = node.getMeter();
+                    for (Meter meter2 : meters) {
+                        meterCount++;
+                        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.augmentation(NodeMeterStatistics.class);
+                            if (null != data) {
+                                meterStatsCount++;
+                            }
+                        }
+                    }
+
                 }
             }
         }
@@ -299,21 +367,30 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int meterConfigStatsCount = 0;
         NodeMeterConfigStats data = null;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Meter> meters = node.getMeter();
-            for (Iterator<Meter> iterator2 = meters.iterator(); iterator2.hasNext(); ) {
-                meterCount++;
-                MeterKey meterKey = iterator2.next().getKey();
-                InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Meter.class, meterKey).toInstance();
-                Meter meter = (Meter) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, meterRef);
-                data = meter.getAugmentation(NodeMeterConfigStats.class);
-                if (null != data) {
-                    meterConfigStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                if (node.getMeter() != null) {
+                    List<Meter> meters = node.getMeter();
+                    for (Meter meter2 : meters) {
+                        meterCount++;
+                        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.augmentation(NodeMeterConfigStats.class);
+                            if (null != data) {
+                                meterConfigStatsCount++;
+                            }
+                        }
+                    }
+
                 }
             }
         }
@@ -327,26 +404,31 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         }
     }
 
-
     public void _aggregateStats(CommandInterpreter ci) {
         int aggregateFlowCount = 0;
         int aggerateFlowStatsCount = 0;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+        for (Node node2 : nodes) {
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-
-            List<Table> tables = node.getTable();
-            for (Iterator<Table> iterator2 = tables.iterator(); iterator2.hasNext(); ) {
-                aggregateFlowCount++;
-                TableKey tableKey = iterator2.next().getKey();
-                InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey).toInstance();
-                Table table = (Table) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, tableRef);
-                AggregateFlowStatisticsData data = table.getAugmentation(AggregateFlowStatisticsData.class);
-                if (null != data) {
-                    aggerateFlowStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                List<Table> tables = node.getTable();
+                for (Table table2 : tables) {
+                    aggregateFlowCount++;
+                    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.augmentation(AggregateFlowStatisticsData.class);
+                        if (null != data) {
+                            aggerateFlowStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -364,16 +446,17 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         int descCount = 0;
         int descStatsCount = 0;
         List<Node> nodes = getNodes();
-        for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
+        for (Node node2 : nodes) {
             descCount++;
-            NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+            NodeKey nodeKey = node2.key();
+            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
             ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-            FlowCapableNode node = (FlowCapableNode) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodeRef);
-            if (null != node.getHardware() &&
-                    null != node.getManufacturer() &&
-                    null != node.getSoftware()) {
-                descStatsCount++;
+            FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
+            if (node != null) {
+                if (null != node.getHardware() && null != node.getManufacturer() && null != node.getSoftware()) {
+                    descStatsCount++;
+                }
             }
         }
 
@@ -381,28 +464,26 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
             LOG.debug("descStats - Success");
         } else {
             LOG.debug("descStats - Failed");
-            LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
+            LOG.debug("System fetches stats data in 50 seconds interval, so please wait and try again.");
         }
 
     }
 
     private List<Node> getNodes() {
         ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
-        Nodes nodes = (Nodes) readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(Nodes.class).toInstance());
-        if (null == nodes) {
+        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.");
         }
         return nodes.getNode();
-
     }
 
-
     @Override
     public String getHelp() {
-        StringBuffer help = new StringBuffer();
+        StringBuilder help = new StringBuilder();
         help.append("---MD-SAL Stats test module---\n");
         return help.toString();
     }
 
-
 }