BUG-1014: expose a proper ShardDataTree constructor
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / NormalizedNodeAggregator.java
index a406b9aaf5707c305b497f49096509a44f23c188..18604587f12465d8b57d274f4042fa712e69b3b9 100644 (file)
@@ -23,10 +23,11 @@ public class NormalizedNodeAggregator {
     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) {
         this.rootIdentifier = rootIdentifier;
         this.nodes = nodes;
+        // FIXME: BUG-1014: pass down proper DataTree
         this.dataTree = InMemoryDataTreeFactory.getInstance().create();
         this.dataTree.setSchemaContext(schemaContext);
     }
@@ -39,9 +40,9 @@ public class NormalizedNodeAggregator {
      * @return
      * @throws DataValidationFailedException
      */
-    public static Optional<NormalizedNode<?,?>> aggregate(YangInstanceIdentifier rootIdentifier,
-                                                          List<Optional<NormalizedNode<?, ?>>> nodes,
-                                                          SchemaContext schemaContext) throws DataValidationFailedException {
+    public static Optional<NormalizedNode<?,?>> aggregate(final YangInstanceIdentifier rootIdentifier,
+                                                          final List<Optional<NormalizedNode<?, ?>>> nodes,
+                                                          final SchemaContext schemaContext) throws DataValidationFailedException {
         return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext).aggregate();
     }
 
@@ -50,14 +51,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);