X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FNormalizedNodeAggregator.java;h=a78e36c811e93dc6e9f76352686170a0ed7fc8a3;hb=824dce54df4b23120461e112574d2ff2effafcf6;hp=18604587f12465d8b57d274f4042fa712e69b3b9;hpb=43aab07cdbc80eda69e84a26085afe1b37f4002e;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java index 18604587f1..a78e36c811 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java @@ -7,53 +7,52 @@ */ package org.opendaylight.controller.cluster.datastore.utils; -import com.google.common.base.Optional; import java.util.List; +import java.util.Optional; +import org.opendaylight.mdsal.common.api.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; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; -public class NormalizedNodeAggregator { +public final class NormalizedNodeAggregator { private final YangInstanceIdentifier rootIdentifier; - private final List>> nodes; + private final List> nodes; private final DataTree dataTree; - private NormalizedNodeAggregator(final YangInstanceIdentifier rootIdentifier, final List>> nodes, - final SchemaContext schemaContext) { + private NormalizedNodeAggregator(final YangInstanceIdentifier rootIdentifier, + final List> nodes, final EffectiveModelContext schemaContext, + final LogicalDatastoreType logicalDatastoreType) { this.rootIdentifier = rootIdentifier; this.nodes = nodes; - // FIXME: BUG-1014: pass down proper DataTree - this.dataTree = InMemoryDataTreeFactory.getInstance().create(); - this.dataTree.setSchemaContext(schemaContext); + this.dataTree = new InMemoryDataTreeFactory().create( + logicalDatastoreType == LogicalDatastoreType.CONFIGURATION ? DataTreeConfiguration.DEFAULT_CONFIGURATION + : DataTreeConfiguration.DEFAULT_OPERATIONAL); + this.dataTree.setEffectiveModelContext(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> aggregate(final YangInstanceIdentifier rootIdentifier, - final List>> nodes, - final SchemaContext schemaContext) throws DataValidationFailedException { - return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext).aggregate(); + public static Optional aggregate(final YangInstanceIdentifier rootIdentifier, + final List> nodes, final EffectiveModelContext schemaContext, + final LogicalDatastoreType logicalDatastoreType) throws DataValidationFailedException { + return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext, logicalDatastoreType).aggregate(); } - private Optional> aggregate() throws DataValidationFailedException { + private Optional aggregate() throws DataValidationFailedException { return combine().getRootNode(); } private NormalizedNodeAggregator combine() throws DataValidationFailedException { final DataTreeModification mod = dataTree.takeSnapshot().newModification(); - for (final Optional> node : nodes) { + for (final Optional node : nodes) { if (node.isPresent()) { mod.merge(rootIdentifier, node.get()); } @@ -66,7 +65,7 @@ public class NormalizedNodeAggregator { return this; } - private Optional> getRootNode() { + private Optional getRootNode() { return dataTree.takeSnapshot().readNode(rootIdentifier); } }