Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / NormalizedNodeAggregator.java
index a406b9a..f587889 100644 (file)
@@ -9,40 +9,40 @@ package org.opendaylight.controller.cluster.datastore.utils;
 
 import com.google.common.base.Optional;
 import java.util.List;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class NormalizedNodeAggregator {
+public final class NormalizedNodeAggregator {
     private final YangInstanceIdentifier rootIdentifier;
     private final List<Optional<NormalizedNode<?, ?>>> nodes;
     private final DataTree dataTree;
 
-    private NormalizedNodeAggregator(YangInstanceIdentifier rootIdentifier, List<Optional<NormalizedNode<?, ?>>> nodes,
-                             SchemaContext schemaContext) {
+    private NormalizedNodeAggregator(final YangInstanceIdentifier rootIdentifier,
+            final List<Optional<NormalizedNode<?, ?>>> nodes, final SchemaContext schemaContext,
+            final LogicalDatastoreType logicalDatastoreType) {
         this.rootIdentifier = rootIdentifier;
         this.nodes = nodes;
-        this.dataTree = InMemoryDataTreeFactory.getInstance().create();
+        this.dataTree = new InMemoryDataTreeFactory().create(
+            logicalDatastoreType == LogicalDatastoreType.CONFIGURATION ? DataTreeConfiguration.DEFAULT_CONFIGURATION
+                    : DataTreeConfiguration.DEFAULT_OPERATIONAL);
         this.dataTree.setSchemaContext(schemaContext);
     }
 
     /**
-     * Combine data from all the nodes in the list into a tree with root as rootIdentifier
-     *
-     * @param nodes
-     * @param schemaContext
-     * @return
-     * @throws DataValidationFailedException
+     * Combine data from all the nodes in the list into a tree with root as rootIdentifier.
      */
-    public static Optional<NormalizedNode<?,?>> aggregate(YangInstanceIdentifier rootIdentifier,
-                                                          List<Optional<NormalizedNode<?, ?>>> nodes,
-                                                          SchemaContext schemaContext) throws DataValidationFailedException {
-        return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext).aggregate();
+    public static Optional<NormalizedNode<?,?>> aggregate(final YangInstanceIdentifier rootIdentifier,
+            final List<Optional<NormalizedNode<?, ?>>> nodes, final SchemaContext schemaContext,
+            final LogicalDatastoreType logicalDatastoreType) throws DataValidationFailedException {
+        return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext, logicalDatastoreType).aggregate();
     }
 
     private Optional<NormalizedNode<?,?>> aggregate() throws DataValidationFailedException {
@@ -50,14 +50,14 @@ public class NormalizedNodeAggregator {
     }
 
     private NormalizedNodeAggregator combine() throws DataValidationFailedException {
-        DataTreeModification mod = dataTree.takeSnapshot().newModification();
+        final DataTreeModification mod = dataTree.takeSnapshot().newModification();
 
-        for (Optional<NormalizedNode<?,?>> node : nodes) {
+        for (final Optional<NormalizedNode<?,?>> node : nodes) {
             if (node.isPresent()) {
                 mod.merge(rootIdentifier, node.get());
             }
         }
-
+        mod.ready();
         dataTree.validate(mod);
         final DataTreeCandidate candidate = dataTree.prepare(mod);
         dataTree.commit(candidate);
@@ -66,6 +66,6 @@ public class NormalizedNodeAggregator {
     }
 
     private Optional<NormalizedNode<?, ?>> getRootNode() {
-        return dataTree.takeSnapshot().readNode(rootIdentifier);
+        return Optional.fromJavaUtil(dataTree.takeSnapshot().readNode(rootIdentifier));
     }
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.