From a2bdd015673e5b938be0d9b4693da8946ca2bd7d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 13 Apr 2015 15:20:43 +0200 Subject: [PATCH] BUG-2953: do not use a complete InMemoryDataStore Aggregator functionality does not require sequencing or listener, but rather simple manipulation. Instantiate a DataTree instead, simplifying the class. Change-Id: I1edc38f0722ddbd1145149bbc5efef5ab41b0146 Signed-off-by: Robert Varga --- .../cluster/datastore/TransactionProxy.java | 3 +- .../utils/NormalizedNodeAggregator.java | 66 +++++++------------ .../utils/NormalizedNodeAggregatorTest.java | 3 +- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index a0987cd5d6..71799c92d4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -40,6 +40,7 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransactio import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture; 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.DataValidationFailedException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -219,7 +220,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction>> nodes; - private final InMemoryDOMDataStore dataStore; - - NormalizedNodeAggregator(YangInstanceIdentifier rootIdentifier, List>> nodes, - SchemaContext schemaContext){ + private final DataTree dataTree; + private NormalizedNodeAggregator(YangInstanceIdentifier rootIdentifier, List>> nodes, + SchemaContext schemaContext) { this.rootIdentifier = rootIdentifier; this.nodes = nodes; - this.dataStore = new InMemoryDOMDataStore("aggregator", executorService); - this.dataStore.onGlobalContextUpdated(schemaContext); + this.dataTree = InMemoryDataTreeFactory.getInstance().create(); + this.dataTree.setSchemaContext(schemaContext); } /** @@ -46,44 +37,35 @@ public class NormalizedNodeAggregator { * @param nodes * @param schemaContext * @return - * @throws ExecutionException - * @throws InterruptedException + * @throws DataValidationFailedException */ public static Optional> aggregate(YangInstanceIdentifier rootIdentifier, List>> nodes, - SchemaContext schemaContext) - throws ExecutionException, InterruptedException { + SchemaContext schemaContext) throws DataValidationFailedException { return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext).aggregate(); } - private Optional> aggregate() throws ExecutionException, InterruptedException { + private Optional> aggregate() throws DataValidationFailedException { return combine().getRootNode(); } - private NormalizedNodeAggregator combine() throws InterruptedException, ExecutionException { - DOMStoreWriteTransaction domStoreWriteTransaction = dataStore.newWriteOnlyTransaction(); + private NormalizedNodeAggregator combine() throws DataValidationFailedException { + DataTreeModification mod = dataTree.takeSnapshot().newModification(); - for(Optional> node : nodes) { - if(node.isPresent()) { - domStoreWriteTransaction.merge(rootIdentifier, node.get()); + for (Optional> node : nodes) { + if (node.isPresent()) { + mod.merge(rootIdentifier, node.get()); } } - DOMStoreThreePhaseCommitCohort ready = domStoreWriteTransaction.ready(); - ready.canCommit().get(); - ready.preCommit().get(); - ready.commit().get(); + + dataTree.validate(mod); + final DataTreeCandidate candidate = dataTree.prepare(mod); + dataTree.commit(candidate); return this; } - private Optional> getRootNode() throws InterruptedException, ExecutionException { - DOMStoreReadTransaction readTransaction = dataStore.newReadOnlyTransaction(); - - CheckedFuture>, ReadFailedException> read = - readTransaction.read(rootIdentifier); - - return read.get(); + private Optional> getRootNode() { + return dataTree.takeSnapshot().readNode(rootIdentifier); } - - } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java index 40d3704d2c..8c8631089c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java @@ -29,13 +29,14 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class NormalizedNodeAggregatorTest { @Test - public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException { + public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException, DataValidationFailedException { SchemaContext schemaContext = SchemaContextHelper.full(); NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); -- 2.36.6