BUG 2970 : Handle SchemaValidationFailedException instead of IllegalArgumentException 99/21599/2
authorMoiz Raja <moraja@cisco.com>
Tue, 2 Jun 2015 01:28:32 +0000 (18:28 -0700)
committerMoiz Raja <moraja@cisco.com>
Thu, 4 Jun 2015 18:08:18 +0000 (18:08 +0000)
Switch to handling the more specific SchemaValidationFailedException.

Change-Id: Id2f07aae4f45bb11257906fcc157e679b7e34948
Signed-off-by: Moiz Raja <moraja@cisco.com>
(cherry picked from commit 796434267bba9c66f35fbab0648dd06c3d1206fc)

opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/PruningShardDataTreeSnapshot.java [moved from opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeSnapshot.java with 83% similarity]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModification.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/PruningShardDataTreeSnapshotTest.java [moved from opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeSnapshotTest.java with 78% similarity]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java

@@ -17,12 +17,15 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 
-class ShardDataTreeSnapshot implements DataTreeSnapshot {
+/**
+ * The PruningShardDataTreeSnapshot returns a PruningDataTreeModification when a newModification is created
+ */
+class PruningShardDataTreeSnapshot implements DataTreeSnapshot {
 
     private final DataTreeSnapshot dataTreeSnapshot;
     private final Set<URI> validNamespaces;
 
-    public ShardDataTreeSnapshot(DataTreeSnapshot dataTreeSnapshot, Set<URI> validNamespaces) {
+    public PruningShardDataTreeSnapshot(DataTreeSnapshot dataTreeSnapshot, Set<URI> validNamespaces) {
         this.dataTreeSnapshot = dataTreeSnapshot;
         this.validNamespaces = validNamespaces;
     }
index 7a7eceb87628b7c8636f26917f8cefc8ecb5abe2..d83dd22fcfe6766047b012f44938876ec9fdedd7 100644 (file)
@@ -205,13 +205,13 @@ public final class ShardDataTree extends ShardDataTreeTransactionParent {
         @Override
         public ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(String txId, String chainId) {
             return new ReadOnlyShardDataTreeTransaction(txId,
-                    new ShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces));
+                    new PruningShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces));
         }
 
         @Override
         public ReadWriteShardDataTreeTransaction newReadWriteTransaction(String txId, String chainId) {
             return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId,
-                    new ShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces).newModification());
+                    new PruningShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces).newModification());
         }
     }
 
index 2427223293e79de89d59e936390627fcb822db6e..cc976b381f98b7c76b9811f28aa6dbf5e1cfbe04 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
+import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,7 +42,7 @@ public class PruningDataTreeModification implements DataTreeModification {
     public void delete(YangInstanceIdentifier yangInstanceIdentifier) {
         try {
             delegate.delete(yangInstanceIdentifier);
-        } catch(IllegalArgumentException e){
+        } catch(SchemaValidationFailedException e){
             LOG.warn("Node at path : {} does not exist ignoring delete", yangInstanceIdentifier);
         }
     }
@@ -50,7 +51,7 @@ public class PruningDataTreeModification implements DataTreeModification {
     public void merge(YangInstanceIdentifier yangInstanceIdentifier, NormalizedNode<?, ?> normalizedNode) {
         try {
             delegate.merge(yangInstanceIdentifier, normalizedNode);
-        } catch (IllegalArgumentException e){
+        } catch (SchemaValidationFailedException e){
             if(!isValidYangInstanceIdentifier(yangInstanceIdentifier)){
                 LOG.warn("Invalid node identifier {} ignoring merge", yangInstanceIdentifier);
                 return;
@@ -71,7 +72,7 @@ public class PruningDataTreeModification implements DataTreeModification {
     public void write(YangInstanceIdentifier yangInstanceIdentifier, NormalizedNode<?, ?> normalizedNode) {
         try {
             delegate.write(yangInstanceIdentifier, normalizedNode);
-        } catch (IllegalArgumentException e){
+        } catch (SchemaValidationFailedException e){
             if(!isValidYangInstanceIdentifier(yangInstanceIdentifier)){
                 LOG.warn("Invalid node identifier {} ignoring write", yangInstanceIdentifier);
                 return;
@@ -13,7 +13,7 @@ import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 
-public class ShardDataTreeSnapshotTest {
+public class PruningShardDataTreeSnapshotTest {
 
     @Mock
     DataTreeSnapshot dataTreeSnapshot;
@@ -28,8 +28,8 @@ public class ShardDataTreeSnapshotTest {
 
     @Test
     public void testNewModification(){
-        ShardDataTreeSnapshot snapshot1
-                = new ShardDataTreeSnapshot(dataTreeSnapshot, validNamespaces);
+        PruningShardDataTreeSnapshot snapshot1
+                = new PruningShardDataTreeSnapshot(dataTreeSnapshot, validNamespaces);
 
         DataTreeModification dataTreeModification1 = snapshot1.newModification();
 
@@ -38,8 +38,8 @@ public class ShardDataTreeSnapshotTest {
 
     @Test
     public void testReadNode(){
-        ShardDataTreeSnapshot snapshot
-                = new ShardDataTreeSnapshot(dataTreeSnapshot, validNamespaces);
+        PruningShardDataTreeSnapshot snapshot
+                = new PruningShardDataTreeSnapshot(dataTreeSnapshot, validNamespaces);
 
         snapshot.readNode(CarsModel.BASE_PATH);
 
index b5e6caee9aa2353f399b26e8f5a64e071139d6a7..67f60485df87b68eb9aaf304b3b82ba31a722503 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
+import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException;
 
 public class PruningDataTreeModificationTest {
 
@@ -53,7 +54,7 @@ public class PruningDataTreeModificationTest {
     @Test
     public void testDeleteOnException(){
         YangInstanceIdentifier path = CarsModel.BASE_PATH;
-        doThrow(IllegalArgumentException.class).when(delegate).delete(path);
+        doThrow(SchemaValidationFailedException.class).when(delegate).delete(path);
 
         pruningDataTreeModification.delete(path);
 
@@ -75,7 +76,7 @@ public class PruningDataTreeModificationTest {
         NormalizedNode<?, ?> normalizedNode = CarsModel.create();
         YangInstanceIdentifier path = CarsModel.BASE_PATH;
 
-        doThrow(IllegalArgumentException.class).when(delegate).merge(path, normalizedNode);
+        doThrow(SchemaValidationFailedException.class).when(delegate).merge(path, normalizedNode);
         doReturn(true).when(validNamespaces).contains(any(YangInstanceIdentifier.PathArgument.class));
 
         pruningDataTreeModification.merge(path, normalizedNode);
@@ -98,7 +99,7 @@ public class PruningDataTreeModificationTest {
         NormalizedNode<?, ?> normalizedNode = CarsModel.create();
         YangInstanceIdentifier path = CarsModel.BASE_PATH;
 
-        doThrow(IllegalArgumentException.class).when(delegate).write(path, normalizedNode);
+        doThrow(SchemaValidationFailedException.class).when(delegate).write(path, normalizedNode);
         doReturn(true).when(validNamespaces).contains(any(YangInstanceIdentifier.PathArgument.class));
 
         pruningDataTreeModification.write(path, normalizedNode);