BUG 2970 : Create a PruningDataTreeModification
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / SimpleShardDataTreeCohort.java
index 9f22ce8a73e2380625f2f03c0e1ab5e7b35a2c29..bfbfb138a1791ea8dc577e095b0dd38fa5164d14 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.slf4j.Logger;
@@ -36,7 +37,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
     @Override
     public ListenableFuture<Boolean> canCommit() {
         try {
-            dataTree.getDataTree().validate(transaction);
+            dataTree.getDataTree().validate(dataTreeModification());
             LOG.debug("Transaction {} validated", transaction);
             return TRUE_FUTURE;
         } catch (Exception e) {
@@ -47,7 +48,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
     @Override
     public ListenableFuture<Void> preCommit() {
         try {
-            candidate = dataTree.getDataTree().prepare(transaction);
+            candidate = dataTree.getDataTree().prepare(dataTreeModification());
             /*
              * FIXME: this is the place where we should be interacting with persistence, specifically by invoking
              *        persist on the candidate (which gives us a Future).
@@ -60,6 +61,14 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
         }
     }
 
+    private DataTreeModification dataTreeModification() {
+        DataTreeModification dataTreeModification = transaction;
+        if(transaction instanceof PruningDataTreeModification){
+            dataTreeModification = ((PruningDataTreeModification) transaction).getDelegate();
+        }
+        return dataTreeModification;
+    }
+
     @Override
     public ListenableFuture<Void> abort() {
         // No-op, really