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=18604587f12465d8b57d274f4042fa712e69b3b9;hb=23472d531aca7f695082a3d57719894bfa34d0ac;hp=eb1307897a761c099105ca4465fb5dc6070ff77e;hpb=f89552de4942d3709d6ee84415e672c6c7de489f;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 eb1307897a..18604587f1 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 @@ -5,39 +5,31 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore.utils; import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.MoreExecutors; import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; 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.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 { - - private static final ExecutorService executorService = MoreExecutors.newDirectExecutorService(); - private final YangInstanceIdentifier rootIdentifier; private final List>> nodes; - private final InMemoryDOMDataStore dataStore; - - NormalizedNodeAggregator(YangInstanceIdentifier rootIdentifier, List>> nodes, - SchemaContext schemaContext){ + private final DataTree dataTree; + private NormalizedNodeAggregator(final YangInstanceIdentifier rootIdentifier, final List>> nodes, + final SchemaContext schemaContext) { this.rootIdentifier = rootIdentifier; this.nodes = nodes; - this.dataStore = new InMemoryDOMDataStore("aggregator", executorService); - this.dataStore.onGlobalContextUpdated(schemaContext); + // FIXME: BUG-1014: pass down proper DataTree + this.dataTree = InMemoryDataTreeFactory.getInstance().create(); + this.dataTree.setSchemaContext(schemaContext); } /** @@ -46,44 +38,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 { + public static Optional> aggregate(final YangInstanceIdentifier rootIdentifier, + final List>> nodes, + final 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 { + final DataTreeModification mod = dataTree.takeSnapshot().newModification(); - for(Optional> node : nodes) { - if(node.isPresent()) { - domStoreWriteTransaction.merge(rootIdentifier, node.get()); + for (final Optional> node : nodes) { + if (node.isPresent()) { + mod.merge(rootIdentifier, node.get()); } } - DOMStoreThreePhaseCommitCohort ready = domStoreWriteTransaction.ready(); - ready.canCommit().get(); - ready.preCommit().get(); - ready.commit().get(); + mod.ready(); + 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); } - - }