Adjust to DOMDataTreeCommitCohort API change
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / CarEntryDataTreeCommitCohort.java
index 00ae5f48b31bc1b7971488e9b7178ad79283287f..1b55dbac58cf4465c17f9cd6a9ae70c0164ff838 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.controller.clustering.it.provider;
 
 import com.google.common.base.Verify;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.FluentFuture;
+import java.util.Collection;
 import java.util.Optional;
 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
@@ -17,6 +17,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeCandidate;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -40,42 +41,44 @@ public class CarEntryDataTreeCommitCohort implements DOMDataTreeCommitCohort {
     private static final NodeIdentifier YEAR_NODE_ID = new NodeIdentifier(YEAR_QNAME);
 
     @Override
-    public CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(final Object txId,
-            final DOMDataTreeCandidate candidate, final SchemaContext ctx) {
+    public FluentFuture<PostCanCommitStep> canCommit(Object txId, SchemaContext ctx,
+            Collection<DOMDataTreeCandidate> candidates) {
 
-        // Simple data validation - verify the year, if present, is >= 1990
+        for (DOMDataTreeCandidate candidate : candidates) {
+            // Simple data validation - verify the year, if present, is >= 1990
 
-        final DataTreeCandidateNode rootNode = candidate.getRootNode();
-        final Optional<NormalizedNode<?, ?>> dataAfter = rootNode.getDataAfter();
+            final DataTreeCandidateNode rootNode = candidate.getRootNode();
+            final Optional<NormalizedNode<?, ?>> dataAfter = rootNode.getDataAfter();
 
-        LOG.info("In canCommit: modificationType: {}, dataBefore: {}, dataAfter: {}", rootNode.getModificationType(),
-                rootNode.getDataBefore(), dataAfter);
+            LOG.info("In canCommit: modificationType: {}, dataBefore: {}, dataAfter: {}",
+                    rootNode.getModificationType(), rootNode.getDataBefore(), dataAfter);
 
-        // Note: we don't want to process DELETE modifications but we don't need to explicitly check the
-        // ModificationType because dataAfter will not be present. Also dataAfter *should* always contain a
-        // MapEntryNode but we verify anyway.
-        if (dataAfter.isPresent()) {
-            final NormalizedNode<?, ?> normalizedNode = dataAfter.get();
-            Verify.verify(normalizedNode instanceof DataContainerNode, "Expected type DataContainerNode, actual was %s",
-                    normalizedNode.getClass());
-            DataContainerNode<?> entryNode = (DataContainerNode<?>) normalizedNode;
-            final Optional<DataContainerChild<? extends PathArgument, ?>> possibleYear =
-                    entryNode.getChild(YEAR_NODE_ID);
-            if (possibleYear.isPresent()) {
-                final Number year = (Number) possibleYear.get().getValue();
+            // Note: we don't want to process DELETE modifications but we don't need to explicitly check the
+            // ModificationType because dataAfter will not be present. Also dataAfter *should* always contain a
+            // MapEntryNode but we verify anyway.
+            if (dataAfter.isPresent()) {
+                final NormalizedNode<?, ?> normalizedNode = dataAfter.get();
+                Verify.verify(normalizedNode instanceof DataContainerNode,
+                        "Expected type DataContainerNode, actual was %s", normalizedNode.getClass());
+                DataContainerNode<?> entryNode = (DataContainerNode<?>) normalizedNode;
+                final Optional<DataContainerChild<? extends PathArgument, ?>> possibleYear =
+                        entryNode.getChild(YEAR_NODE_ID);
+                if (possibleYear.isPresent()) {
+                    final Number year = (Number) possibleYear.get().getValue();
 
-                LOG.info("year is {}", year);
+                    LOG.info("year is {}", year);
 
-                if (!(year.longValue() >= 1990)) {
-                    return Futures.immediateFailedCheckedFuture(new DataValidationFailedException(
-                            DOMDataTreeIdentifier.class, candidate.getRootPath(),
+                    if (!(year.longValue() >= 1990)) {
+                        return FluentFutures.immediateFailedFluentFuture(new DataValidationFailedException(
+                                DOMDataTreeIdentifier.class, candidate.getRootPath(),
                                 String.format("Invalid year %d - year must be >= 1990", year)));
+                    }
                 }
             }
         }
 
         // Return the noop PostCanCommitStep as we're only validating input data and not participating in the
         // remaining 3PC stages (pre-commit and commit).
-        return PostCanCommitStep.NOOP_SUCCESS_FUTURE;
+        return PostCanCommitStep.NOOP_SUCCESSFUL_FUTURE;
     }
 }