Bug 1596 - OpenflowpluginTestCommandProvider stopped working 66/10166/2
authorMartin Bobak <mbobak@cisco.com>
Wed, 20 Aug 2014 00:14:51 +0000 (02:14 +0200)
committerMartin Bobak <mbobak@cisco.com>
Wed, 20 Aug 2014 05:18:48 +0000 (07:18 +0200)
Change-Id: I83a0dd0a48722e3726caa5607d8914251eebf4db
Signed-off-by: Martin Bobak <mbobak@cisco.com>
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowPluginBulkGroupTransactionProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowPluginBulkTransactionProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginGroupTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginMeterTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginStatsTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTableFeaturesTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/TestProviderTransactionUtil.java [new file with mode: 0644]

index e2e4e4c672faebeb89255e9ddbf7f1ebd200432f..66f45351bfeb713c69c4192fa3f553e8f121711f 100644 (file)
@@ -148,9 +148,7 @@ public class OpenflowPluginBulkGroupTransactionProvider implements CommandProvid
 
     private static NodeRef createNodeRef(String string) {
         NodeKey key = new NodeKey(new NodeId(string));
-        InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
-                .toInstance();
-
+        InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
         return new NodeRef(path);
     }
 
@@ -665,7 +663,7 @@ public class OpenflowPluginBulkGroupTransactionProvider implements CommandProvid
     }
 
     private InstanceIdentifier<Node> nodeToInstanceId(Node node) {
-        return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
     private void createTestNode() {
@@ -738,17 +736,17 @@ public class OpenflowPluginBulkGroupTransactionProvider implements CommandProvid
     private void writeGroup(final CommandInterpreter ci, Group group, Group group1) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
 
-        InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Group> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode12.getKey()).augmentation(FlowCapableNode.class)
-                .child(Group.class, new GroupKey(group.getGroupId())).build();
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode12), testNode12);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, group);
+                .child(Group.class, new GroupKey(group.getGroupId()));
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode12), testNode12, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, group, true);
 
-        InstanceIdentifier<Group> path2 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Group> path2 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode12.getKey()).augmentation(FlowCapableNode.class)
-                .child(Group.class, new GroupKey(group1.getGroupId())).build();
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode12), testNode12);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path2, group1);
+                .child(Group.class, new GroupKey(group1.getGroupId()));
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode12), testNode12, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path2, group1, true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
@@ -765,14 +763,14 @@ public class OpenflowPluginBulkGroupTransactionProvider implements CommandProvid
 
     private void deleteGroup(final CommandInterpreter ci, Group group, Group group1) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Group> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode12.getKey()).augmentation(FlowCapableNode.class)
-                .child(Group.class, new GroupKey(group.getGroupId())).build();
+                .child(Group.class, new GroupKey(group.getGroupId()));
         modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
-        InstanceIdentifier<Group> path2 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Group> path2 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode12.getKey()).augmentation(FlowCapableNode.class)
-                .child(Group.class, new GroupKey(group1.getGroupId())).build();
+                .child(Group.class, new GroupKey(group1.getGroupId()));
         modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
         modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
index 55a4b5ff8285198f52a5f384cfe149febb2b10ce..35ac71592ee18ab48dd0e139a3e496343fffc448 100644 (file)
@@ -6,13 +6,10 @@ import com.google.common.util.concurrent.Futures;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
 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.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
@@ -108,7 +105,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -158,8 +154,7 @@ public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
 
     private static NodeRef createNodeRef(String string) {
         NodeKey key = new NodeKey(new NodeId(string));
-        InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
-                .toInstance();
+        InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
 
         return new NodeRef(path);
     }
@@ -513,7 +508,7 @@ public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
     }
 
     private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
-        return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
     public void _modifyFlows(CommandInterpreter ci) {
@@ -647,28 +642,28 @@ public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
                 break;
         }
 
-        InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
+        InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
-                .child(Flow.class, tf.getKey()).build();
+                .child(Flow.class, tf.getKey());
         modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
-        InstanceIdentifier<Flow> path2 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
+        InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId()))
-                .child(Flow.class, tf1.getKey()).build();
+                .child(Flow.class, tf1.getKey());
         modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
 
-        InstanceIdentifier<Flow> path3 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
+        InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId()))
-                .child(Flow.class, tf2.getKey()).build();
+                .child(Flow.class, tf2.getKey());
         modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
-        InstanceIdentifier<Flow> path4 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
+        InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId()))
-                .child(Flow.class, tf3.getKey()).build();
+                .child(Flow.class, tf3.getKey());
         modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
         modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
@@ -691,36 +686,36 @@ public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
     private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2,
                            FlowBuilder flow3, NodeBuilder nodeBuilder) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey()).build();
-        modification.put(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.OPERATIONAL, path1, flow.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, flow.build());
-        InstanceIdentifier<Flow> path2 = InstanceIdentifier.builder(Nodes.class)
+                .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
+        modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
+        InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey()).build();
-        modification.put(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.OPERATIONAL, path2, flow1.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, path2, flow1.build());
+                .child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey());
+        modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
 
-        InstanceIdentifier<Flow> path3 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey()).build();
-        modification.put(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.OPERATIONAL, path3, flow2.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, path3, flow2.build());
+                .child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey());
+        modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
 
-        InstanceIdentifier<Flow> path4 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey()).build();
-        modification.put(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.OPERATIONAL, path4, flow3.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, path4, flow3.build());
+                .child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey());
+        modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
index e7bc9ca81f62cd2658c442be3d85042b199ca0cb..29945b0b034ddaa96d41957c4c0f600785d2fb41 100644 (file)
@@ -118,7 +118,7 @@ public class OpenflowpluginGroupTestCommandProvider implements CommandProvider {
     }
 
     private InstanceIdentifier<Node> nodeToInstanceId(Node node) {
-        return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
     private GroupBuilder createTestGroup(String actiontype, String type, String mod) {
@@ -628,8 +628,8 @@ public class OpenflowpluginGroupTestCommandProvider implements CommandProvider {
         }
         GroupBuilder gbuilder = createTestGroup(ci.nextArgument(), ci.nextArgument(), "add");
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, testNode.getKey())
-                .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(gbuilder.getGroupId())).build();
+        InstanceIdentifier<Group> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey())
+                .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(gbuilder.getGroupId()));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@@ -661,12 +661,11 @@ public class OpenflowpluginGroupTestCommandProvider implements CommandProvider {
 
     private void writeGroup(final CommandInterpreter ci, Group group) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Group> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                .child(Group.class, new GroupKey(group.getGroupId()))
-                .build();
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, group);
+                .child(Group.class, new GroupKey(group.getGroupId()));
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, group, true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
@@ -712,7 +711,7 @@ public class OpenflowpluginGroupTestCommandProvider implements CommandProvider {
     private static NodeRef createNodeRef(String string) {
         NodeKey key = new NodeKey(new NodeId(string));
         InstanceIdentifier<Node> path =
-                InstanceIdentifier.builder(Nodes.class).child(Node.class, key).toInstance();
+                InstanceIdentifier.create(Nodes.class).child(Node.class, key);
 
         return new NodeRef(path);
     }
index 2e01b2f8350bb67c6ca9a226fad265e0c67b14bb..732354672853db430d4c2ad8bb713fc55c38e72f 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
@@ -96,7 +95,7 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
     }
 
     private InstanceIdentifier<Node> nodeToInstanceId(Node node) {
-        return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
     final class MeterEventListener implements SalMeterListener {
@@ -226,8 +225,8 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
         }
         MeterBuilder mBuilder = createTestMeter();
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Meter> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, testNode.getKey())
-                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter.getMeterId())).build();
+        InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey())
+                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter.getMeterId()));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@@ -260,51 +259,51 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
         switch (count) {
             case 1:
                 MeterBuilder mBuilder = createTestMeters("1", "remove");
-                InstanceIdentifier<Meter> path1 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter1.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter1.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
                 MeterBuilder mBuilder1 = createTestMeters("2", "remove");
-                InstanceIdentifier<Meter> path2 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path2 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter2.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter2.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
 
                 break;
             case 2:
                 MeterBuilder mBuilder2 = createTestMeters("3", "remove");
-                InstanceIdentifier<Meter> path3 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path3 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter1.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter1.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
                 MeterBuilder mBuilder22 = createTestMeters("4", "remove");
-                InstanceIdentifier<Meter> path4 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path4 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter2.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter2.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
                 break;
             case 3:
                 MeterBuilder mBuilder3 = createTestMeters("5", "remove");
-                InstanceIdentifier<Meter> path5 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path5 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter1.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter1.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path5);
                 MeterBuilder mBuilder4 = createTestMeters("6", "remove");
-                InstanceIdentifier<Meter> path6 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path6 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter2.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter2.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path6);
                 break;
             case 4:
                 MeterBuilder mBuilder5 = createTestMeters("7", "remove");
-                InstanceIdentifier<Meter> path7 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path7 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter1.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter1.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path7);
                 MeterBuilder mBuilder6 = createTestMeters("8", "remove");
-                InstanceIdentifier<Meter> path8 = InstanceIdentifier.builder(Nodes.class)
+                InstanceIdentifier<Meter> path8 = InstanceIdentifier.create(Nodes.class)
                         .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class)
-                        .child(Meter.class, new MeterKey(testMeter2.getMeterId())).build();
+                        .child(Meter.class, new MeterKey(testMeter2.getMeterId()));
                 modification.delete(LogicalDatastoreType.CONFIGURATION, path8);
                 break;
 
@@ -378,11 +377,10 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
 
     private void writeMeter(final CommandInterpreter ci, Meter meter) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Meter> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, testNode.getKey())
-                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId())).build();
-        DataObject cls = (DataObject) modification.read(LogicalDatastoreType.CONFIGURATION, path1);
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, meter);
+        InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey())
+                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId()));
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, meter, true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
@@ -399,16 +397,14 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
 
     private void writeMeter(final CommandInterpreter ci, Meter meter, Meter meter1) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Meter> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, testNode.getKey())
-                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId())).build();
-        DataObject cls = (DataObject) modification.read(LogicalDatastoreType.CONFIGURATION, path1);
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, meter);
-        InstanceIdentifier<Meter> path2 = InstanceIdentifier.builder(Nodes.class).child(Node.class, testNode.getKey())
-                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter1.getMeterId())).build();
-        DataObject cls1 = (DataObject) modification.read(LogicalDatastoreType.CONFIGURATION, path2);
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path2, meter1);
+        InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey())
+                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId()));
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, meter, true);
+        InstanceIdentifier<Meter> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey())
+                .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter1.getMeterId()));
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path2, meter1, true);
 
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
index d1053aaa2906e1ab5339d1eb5ce662c3481a56af..8ee8833175b273a35e88a9bebee93a3b458f3dbd 100644 (file)
@@ -6,7 +6,6 @@ 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;
@@ -59,20 +58,23 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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) {
+                List<NodeConnector> ports = node.getNodeConnector();
+                for (Iterator<NodeConnector> iterator2 = ports.iterator(); iterator2.hasNext(); ) {
+                    nodeConnectorCount++;
+                    NodeConnectorKey nodeConnectorKey = iterator2.next().getKey();
+                    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);
+                        if (null != data) {
+                            nodeConnectorStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -93,23 +95,26 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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) {
+                List<NodeConnector> ports = node.getNodeConnector();
+                for (Iterator<NodeConnector> iterator2 = ports.iterator(); iterator2.hasNext(); ) {
+                    nodeConnectorCount++;
+                    NodeConnectorKey nodeConnectorKey = iterator2.next().getKey();
+                    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++;
+                        }
+                    }
                 }
             }
         }
@@ -129,27 +134,33 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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 (Iterator<Table> iterator2 = tables.iterator(); iterator2.hasNext(); ) {
+                    TableKey tableKey = iterator2.next().getKey();
+                    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) {
+                        List<Flow> flows = table.getFlow();
+                        for (Iterator<Flow> iterator3 = flows.iterator(); iterator3.hasNext(); ) {
+                            flowCount++;
+                            FlowKey flowKey = iterator3.next().getKey();
+                            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);
+                                if (null != data) {
+                                    flowStatsCount++;
+                                    LOG.debug("--------------------------------------------");
+                                    ci.print(data);
+                                }
+                            }
+                        }
                     }
                 }
             }
@@ -171,20 +182,23 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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 (Iterator<Table> iterator2 = tables.iterator(); iterator2.hasNext(); ) {
+                    tableCount++;
+                    TableKey tableKey = iterator2.next().getKey();
+                    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);
+                        if (null != data) {
+                            tableStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -205,19 +219,22 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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) {
+                List<Group> groups = node.getGroup();
+                for (Iterator<Group> iterator2 = groups.iterator(); iterator2.hasNext(); ) {
+                    groupCount++;
+                    GroupKey groupKey = iterator2.next().getKey();
+                    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);
+                        if (null != data) {
+                            groupStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -237,28 +254,32 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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) {
+                List<Group> groups = node.getGroup();
+                for (Iterator<Group> iterator2 = groups.iterator(); iterator2.hasNext(); ) {
+                    groupCount++;
+                    GroupKey groupKey = iterator2.next().getKey();
+                    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);
+                        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.");
+            }
         }
     }
 
@@ -269,19 +290,22 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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) {
+                List<Meter> meters = node.getMeter();
+                for (Iterator<Meter> iterator2 = meters.iterator(); iterator2.hasNext(); ) {
+                    meterCount++;
+                    MeterKey meterKey = iterator2.next().getKey();
+                    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);
+                        if (null != data) {
+                            meterStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -294,6 +318,7 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         }
     }
 
+
     public void _meterConfigStats(CommandInterpreter ci) {
         int meterCount = 0;
         int meterConfigStatsCount = 0;
@@ -301,19 +326,22 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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) {
+                List<Meter> meters = node.getMeter();
+                for (Iterator<Meter> iterator2 = meters.iterator(); iterator2.hasNext(); ) {
+                    meterCount++;
+                    MeterKey meterKey = iterator2.next().getKey();
+                    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);
+                        if (null != data) {
+                            meterConfigStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -334,19 +362,22 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         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();
+            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 (Iterator<Table> iterator2 = tables.iterator(); iterator2.hasNext(); ) {
+                    aggregateFlowCount++;
+                    TableKey tableKey = iterator2.next().getKey();
+                    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);
+                        if (null != data) {
+                            aggerateFlowStatsCount++;
+                        }
+                    }
                 }
             }
         }
@@ -367,13 +398,15 @@ public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
         for (Iterator<Node> iterator = nodes.iterator(); iterator.hasNext(); ) {
             descCount++;
             NodeKey nodeKey = iterator.next().getKey();
-            InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).toInstance();
+            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,19 +414,19 @@ 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();
-
     }
 
 
index 3a2cf4fb868377a2bef4c94fb71d43908a098eea..0add3c3b24fcb2037b210ab07ef157524a20e1b8 100644 (file)
@@ -16,13 +16,10 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
 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.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
@@ -76,7 +73,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.osgi.framework.BundleContext;
 
 
@@ -117,7 +113,7 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
     }
 
     private InstanceIdentifier<Node> nodeToInstanceId(Node node) {
-        return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
     private TableBuilder createTestTable(String tableFeatureTypeArg) {
@@ -602,15 +598,15 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
     private void writeTable(final CommandInterpreter ci, Table table) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
 
-        InstanceIdentifier<Table> path1 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Table> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).
-                        child(Table.class, new TableKey(table.getId())).build();
+                        child(Table.class, new TableKey(table.getId()));
 
 
-        modification.put(LogicalDatastoreType.OPERATIONAL, nodeToInstanceId(testNode), testNode);
-        modification.put(LogicalDatastoreType.OPERATIONAL, path1, table);
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode);
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, table);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, nodeToInstanceId(testNode), testNode, true);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, path1, table, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, table, true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
index 1598c968d5655bb340e4e80dd16551c22d986dc2..8e9d0cb843a7a363ccfe525c72012a9307307b51 100644 (file)
@@ -15,16 +15,13 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 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.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
@@ -180,7 +177,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.node.error.service.rev140410.NodeErrorListener;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -230,7 +226,7 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
     }
 
     private InstanceIdentifier<Node> nodeBuilderToInstanceId(NodeBuilder node) {
-        return InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).toInstance();
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
     private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
@@ -3336,9 +3332,9 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
         } else {
             tf = createTestFlow(tn, flowtype, ci.nextArgument());
         }
-        InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(Node.class, tn.getKey())
+        InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey())
                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId()))
-                .child(Flow.class, tf.getKey()).build();
+                .child(Flow.class, tf.getKey());
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@@ -3359,8 +3355,8 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
      * @param ci arguments: switchId flowType tableNum
      *           <p/>
      *           <pre>
-     *           e.g.: addMDFlow openflow:1 f1 42
-     *           </pre>
+     *                     e.g.: addMDFlow openflow:1 f1 42
+     *                     </pre>
      */
     public void _addMDFlow(CommandInterpreter ci) {
         NodeBuilder tn = createTestNode(ci.nextArgument());
@@ -3376,11 +3372,11 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
 
     private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, NodeBuilder nodeBuilder) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
-        InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
+        InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey()).build();
-        modification.put(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
-        modification.put(LogicalDatastoreType.CONFIGURATION, path1, flow.build());
+                .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
+        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
@@ -3407,8 +3403,7 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
 
     private static NodeRef createNodeRef(String string) {
         NodeKey key = new NodeKey(new NodeId(string));
-        InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
-                .toInstance();
+        InstanceIdentifier<Node> path = InstanceIdentifier.create(Nodes.class).child(Node.class, key);
 
         return new NodeRef(path);
     }
diff --git a/test-provider/src/main/java/org/opendaylight/openflowplugin/test/TestProviderTransactionUtil.java b/test-provider/src/main/java/org/opendaylight/openflowplugin/test/TestProviderTransactionUtil.java
new file mode 100644 (file)
index 0000000..ac17ed5
--- /dev/null
@@ -0,0 +1,36 @@
+package org.opendaylight.openflowplugin.test;
+
+import com.google.common.base.Optional;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by Martin Bobak mbobak@cisco.com on 8/20/14.
+ */
+public final class TestProviderTransactionUtil {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TestProviderTransactionUtil.class);
+
+    private TestProviderTransactionUtil() {
+        throw new AssertionError("TestProviderTransactionUtil was not meant to be instantiated.");
+    }
+
+    public static <T extends DataObject> T getDataObject(ReadTransaction readOnlyTransaction, InstanceIdentifier<T> identifier) {
+        Optional<T> optionalData = null;
+        try {
+            optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get();
+            if (optionalData.isPresent()) {
+                return optionalData.get();
+            }
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("Read transaction for identifier {} failed.", identifier, e);
+        }
+        return null;
+    }
+
+}