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=3402cfce32b05957219e54754dd7ca5b0a54cd0e;hp=c0965675e0cf8675f9b5a13157d2ba47bd6f9c99;hpb=bdaf6bbf2576f28e77c19251dc462c394303aced;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 c0965675e0..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,58 +7,52 @@ */ 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 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.api.schema.tree.TreeType; 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, LogicalDatastoreType logicalDatastoreType) { + private NormalizedNodeAggregator(final YangInstanceIdentifier rootIdentifier, + final List> nodes, final EffectiveModelContext schemaContext, + final LogicalDatastoreType logicalDatastoreType) { this.rootIdentifier = rootIdentifier; this.nodes = nodes; - this.dataTree = InMemoryDataTreeFactory.getInstance().create( - logicalDatastoreType == LogicalDatastoreType.CONFIGURATION ? TreeType.CONFIGURATION : - TreeType.OPERATIONAL); - 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 - * @param logicalDatastoreType - * @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, - LogicalDatastoreType logicalDatastoreType) throws DataValidationFailedException { + 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()); } @@ -71,7 +65,7 @@ public class NormalizedNodeAggregator { return this; } - private Optional> getRootNode() { + private Optional getRootNode() { return dataTree.takeSnapshot().readNode(rootIdentifier); } }