From 0f366ff59742b728025efa3db408c57f2794050e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 20 May 2014 09:45:36 +0200 Subject: [PATCH] BUG-509: Move ModificationApplyOperation This patch moves ModificationApplyOperation at al. to the data tree package, improving its isolation. Change-Id: I37081222e30c149a87baf6f4a5d3ce2e84f13acb Signed-off-by: Robert Varga --- .../dom/store/impl/InMemoryDOMDataStore.java | 86 ++++--------------- .../dom/store/impl/tree/DataTreeSnapshot.java | 14 +-- .../impl/tree/data/AlwaysFailOperation.java | 31 +++++++ .../impl/tree/data/InMemoryDataTree.java | 71 ++++++++------- .../data/InMemoryDataTreeModification.java | 28 +++--- .../tree/data/InMemoryDataTreeSnapshot.java | 16 ++-- .../ModificationApplyOperation.java | 24 +++--- .../impl/tree/data/NodeModification.java | 1 + .../data}/OperationWithModification.java | 7 +- .../data}/SchemaAwareApplyOperation.java | 9 +- .../impl/tree/data/StoreMetadataNode.java | 1 + .../tree/data/StoreNodeCompositeBuilder.java | 2 +- .../data/ModificationMetadataTreeTest.java | 13 +-- .../data}/SchemaAwareApplyOperationRoot.java | 2 +- 14 files changed, 145 insertions(+), 160 deletions(-) create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/AlwaysFailOperation.java rename opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/{ => data}/ModificationApplyOperation.java (82%) rename opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/{ => tree/data}/OperationWithModification.java (85%) rename opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/{ => tree/data}/SchemaAwareApplyOperation.java (98%) rename opendaylight/md-sal/sal-dom-broker/src/{main/java/org/opendaylight/controller/md/sal/dom/store/impl => test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data}/SchemaAwareApplyOperationRoot.java (95%) diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java index 7d647af539..9e11fc70fc 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java @@ -22,10 +22,7 @@ import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeCandidate; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeModification; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeSnapshot; import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation; import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.InMemoryDataTreeFactory; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.NodeModification; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode; import org.opendaylight.controller.sal.core.spi.data.DOMStore; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -36,7 +33,6 @@ import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; @@ -47,22 +43,17 @@ import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.primitives.UnsignedLong; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; public class InMemoryDOMDataStore implements DOMStore, Identifiable, SchemaContextListener { - private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class); - private static final InstanceIdentifier PUBLIC_ROOT_PATH = InstanceIdentifier.builder().build(); - + private final DataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); + private final ListenerTree listenerTree = ListenerTree.create(); + private final AtomicLong txCounter = new AtomicLong(0); private final ListeningExecutorService executor; private final String name; - private final AtomicLong txCounter = new AtomicLong(0); - private final ListenerTree listenerTree = ListenerTree.create(); - private final DataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); - private ModificationApplyOperation operationTree = new AlwaysFailOperation(); public InMemoryDOMDataStore(final String name, final ListeningExecutorService executor) { this.name = Preconditions.checkNotNull(name); @@ -81,25 +72,17 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch @Override public DOMStoreReadWriteTransaction newReadWriteTransaction() { - return new SnapshotBackedReadWriteTransaction(nextIdentifier(), dataTree.takeSnapshot(), this, operationTree); + return new SnapshotBackedReadWriteTransaction(nextIdentifier(), dataTree.takeSnapshot(), this); } @Override public DOMStoreWriteTransaction newWriteOnlyTransaction() { - return new SnapshotBackedWriteTransaction(nextIdentifier(), dataTree.takeSnapshot(), this, operationTree); + return new SnapshotBackedWriteTransaction(nextIdentifier(), dataTree.takeSnapshot(), this); } @Override public synchronized void onGlobalContextUpdated(final SchemaContext ctx) { - /* - * Order of operations is important: dataTree may reject the context - * and creation of ModificationApplyOperation may fail. So pre-construct - * the operation, then update the data tree and then move the operation - * into view. - */ - final ModificationApplyOperation newOperationTree = SchemaAwareApplyOperationRoot.from(ctx); dataTree.setSchemaContext(ctx); - operationTree = newOperationTree; } @Override @@ -180,7 +163,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch } private static final class SnapshotBackedReadTransaction extends AbstractDOMStoreTransaction implements - DOMStoreReadTransaction { + DOMStoreReadTransaction { private DataTreeSnapshot stableSnapshot; public SnapshotBackedReadTransaction(final Object identifier, final DataTreeSnapshot snapshot) { @@ -204,15 +187,15 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch } private static class SnapshotBackedWriteTransaction extends AbstractDOMStoreTransaction implements - DOMStoreWriteTransaction { + DOMStoreWriteTransaction { private DataTreeModification mutableTree; private InMemoryDOMDataStore store; private boolean ready = false; public SnapshotBackedWriteTransaction(final Object identifier, final DataTreeSnapshot snapshot, - final InMemoryDOMDataStore store, final ModificationApplyOperation applyOper) { + final InMemoryDOMDataStore store) { super(identifier); - mutableTree = snapshot.newModification(applyOper); + mutableTree = snapshot.newModification(); this.store = store; LOG.debug("Write Tx: {} allocated with snapshot {}", identifier, snapshot); } @@ -289,11 +272,11 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch } private static class SnapshotBackedReadWriteTransaction extends SnapshotBackedWriteTransaction implements - DOMStoreReadWriteTransaction { + DOMStoreReadWriteTransaction { protected SnapshotBackedReadWriteTransaction(final Object identifier, final DataTreeSnapshot snapshot, - final InMemoryDOMDataStore store, final ModificationApplyOperation applyOper) { - super(identifier, snapshot, store, applyOper); + final InMemoryDOMDataStore store) { + super(identifier, snapshot, store); } @Override @@ -327,7 +310,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch @Override public Boolean call() { try { - dataTree.validate(modification); + dataTree.validate(modification); LOG.debug("Store Transaction: {} can be committed", transaction.getIdentifier()); return true; } catch (DataPreconditionFailedException e) { @@ -343,16 +326,8 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch return executor.submit(new Callable() { @Override public Void call() { - candidate = dataTree.prepare(modification); - + candidate = dataTree.prepare(modification); listenerResolver = ResolveDataChangeEventsTask.create(candidate, listenerTree); - -// .setRootPath(PUBLIC_ROOT_PATH) // -// .setBeforeRoot(Optional.of(metadataTree)) // -// .setAfterRoot(proposedSubtree) // -// .setModificationRoot(modification.getRootModification()) // -// .setListenerRoot(listenerTree); - return null; } }); @@ -360,10 +335,10 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch @Override public ListenableFuture abort() { - if (candidate != null) { - candidate.close(); - candidate = null; - } + if (candidate != null) { + candidate.close(); + candidate = null; + } return Futures. immediateFuture(null); } @@ -388,29 +363,4 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch return Futures. immediateFuture(null); } } - - private static final class AlwaysFailOperation implements ModificationApplyOperation { - - @Override - public Optional apply(final NodeModification modification, - final Optional storeMeta, final UnsignedLong subtreeVersion) { - throw new IllegalStateException("Schema Context is not available."); - } - - @Override - public void checkApplicable(final InstanceIdentifier path,final NodeModification modification, final Optional storeMetadata) { - throw new IllegalStateException("Schema Context is not available."); - } - - @Override - public Optional getChild(final PathArgument child) { - throw new IllegalStateException("Schema Context is not available."); - } - - @Override - public void verifyStructure(final NodeModification modification) throws IllegalArgumentException { - throw new IllegalStateException("Schema Context is not available."); - } - - } } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeSnapshot.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeSnapshot.java index 4f3512807f..a94acc5658 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeSnapshot.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeSnapshot.java @@ -18,12 +18,12 @@ import com.google.common.base.Optional; * visible through the snapshot. */ public interface DataTreeSnapshot { - /** - * Read a particular node from the snapshot. - * - * @param path Path of the node - * @return Optional result encapsulating the presence and value of the node - */ + /** + * Read a particular node from the snapshot. + * + * @param path Path of the node + * @return Optional result encapsulating the presence and value of the node + */ Optional> readNode(InstanceIdentifier path); /** @@ -33,5 +33,5 @@ public interface DataTreeSnapshot { * @param strategy data modification strategy * @return A new data tree modification */ - DataTreeModification newModification(ModificationApplyOperation applyOper); + DataTreeModification newModification(); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/AlwaysFailOperation.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/AlwaysFailOperation.java new file mode 100644 index 0000000000..4e3aa49113 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/AlwaysFailOperation.java @@ -0,0 +1,31 @@ +package org.opendaylight.controller.md.sal.dom.store.impl.tree.data; + +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; + +import com.google.common.base.Optional; +import com.google.common.primitives.UnsignedLong; + +final class AlwaysFailOperation implements ModificationApplyOperation { + + @Override + public Optional apply(final NodeModification modification, + final Optional storeMeta, final UnsignedLong subtreeVersion) { + throw new IllegalStateException("Schema Context is not available."); + } + + @Override + public void checkApplicable(final InstanceIdentifier path,final NodeModification modification, final Optional storeMetadata) { + throw new IllegalStateException("Schema Context is not available."); + } + + @Override + public Optional getChild(final PathArgument child) { + throw new IllegalStateException("Schema Context is not available."); + } + + @Override + public void verifyStructure(final NodeModification modification) throws IllegalArgumentException { + throw new IllegalStateException("Schema Context is not available."); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTree.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTree.java index 1f2a775cdc..5a300a071d 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTree.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTree.java @@ -31,16 +31,21 @@ final class InMemoryDataTree implements DataTree { private static final InstanceIdentifier PUBLIC_ROOT_PATH = InstanceIdentifier.builder().build(); private final ReadWriteLock rwLock = new ReentrantReadWriteLock(true); - private StoreMetadataNode rootNode; + private ModificationApplyOperation applyOper = new AlwaysFailOperation(); private SchemaContext currentSchemaContext; + private StoreMetadataNode rootNode; public InMemoryDataTree(StoreMetadataNode rootNode, final SchemaContext schemaContext) { this.rootNode = Preconditions.checkNotNull(rootNode); - this.currentSchemaContext = schemaContext; + + if (schemaContext != null) { + // Also sets applyOper + setSchemaContext(schemaContext); + } } @Override - public synchronized void setSchemaContext(final SchemaContext newSchemaContext) { + public synchronized void setSchemaContext(final SchemaContext newSchemaContext) { Preconditions.checkNotNull(newSchemaContext); LOG.info("Attepting to install schema context {}", newSchemaContext); @@ -50,9 +55,13 @@ final class InMemoryDataTree implements DataTree { * whether they are compatible here. Reject incompatible changes. */ + // Instantiate new apply operation, this still may fail + final ModificationApplyOperation newApplyOper = SchemaAwareApplyOperation.from(newSchemaContext); + // Ready to change the context now, make sure no operations are running rwLock.writeLock().lock(); try { + this.applyOper = newApplyOper; this.currentSchemaContext = newSchemaContext; } finally { rwLock.writeLock().unlock(); @@ -60,53 +69,53 @@ final class InMemoryDataTree implements DataTree { } @Override - public InMemoryDataTreeSnapshot takeSnapshot() { + public InMemoryDataTreeSnapshot takeSnapshot() { rwLock.readLock().lock(); try { - return new InMemoryDataTreeSnapshot(currentSchemaContext, rootNode); + return new InMemoryDataTreeSnapshot(currentSchemaContext, rootNode, applyOper); } finally { rwLock.readLock().unlock(); } } - @Override - public void validate(DataTreeModification modification) throws DataPreconditionFailedException { - Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass()); + @Override + public void validate(DataTreeModification modification) throws DataPreconditionFailedException { + Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass()); - final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification; - m.getStrategy().checkApplicable(PUBLIC_ROOT_PATH, m.getRootModification(), Optional.of(rootNode)); - } + final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification; + m.getStrategy().checkApplicable(PUBLIC_ROOT_PATH, m.getRootModification(), Optional.of(rootNode)); + } - @Override - public synchronized DataTreeCandidate prepare(DataTreeModification modification) { - Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass()); + @Override + public synchronized DataTreeCandidate prepare(DataTreeModification modification) { + Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass()); - final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification; - final NodeModification root = m.getRootModification(); + final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification; + final NodeModification root = m.getRootModification(); if (root.getModificationType() == ModificationType.UNMODIFIED) { - return new NoopDataTreeCandidate(PUBLIC_ROOT_PATH, root); + return new NoopDataTreeCandidate(PUBLIC_ROOT_PATH, root); } rwLock.writeLock().lock(); try { - // FIXME: rootNode needs to be a read-write snapshot here... - final Optional newRoot = m.getStrategy().apply(m.getRootModification(), Optional.of(rootNode), StoreUtils.increase(rootNode.getSubtreeVersion())); - Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node"); - return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, rootNode, newRoot.get()); + // FIXME: rootNode needs to be a read-write snapshot here... + final Optional newRoot = m.getStrategy().apply(m.getRootModification(), Optional.of(rootNode), StoreUtils.increase(rootNode.getSubtreeVersion())); + Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node"); + return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, rootNode, newRoot.get()); } finally { - rwLock.writeLock().unlock(); + rwLock.writeLock().unlock(); } - } + } - @Override - public synchronized void commit(DataTreeCandidate candidate) { - if (candidate instanceof NoopDataTreeCandidate) { - return; - } + @Override + public synchronized void commit(DataTreeCandidate candidate) { + if (candidate instanceof NoopDataTreeCandidate) { + return; + } - Preconditions.checkArgument(candidate instanceof InMemoryDataTreeCandidate, "Invalid candidate class %s", candidate.getClass()); - final InMemoryDataTreeCandidate c = (InMemoryDataTreeCandidate)candidate; + Preconditions.checkArgument(candidate instanceof InMemoryDataTreeCandidate, "Invalid candidate class %s", candidate.getClass()); + final InMemoryDataTreeCandidate c = (InMemoryDataTreeCandidate)candidate; LOG.debug("Updating Store snapshot version: {} with version:{}", rootNode.getSubtreeVersion(), c.getAfterRoot().getSubtreeVersion()); @@ -123,5 +132,5 @@ final class InMemoryDataTree implements DataTree { } finally { rwLock.writeLock().unlock(); } - } + } } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java index bedf76172a..df3ef8b7e1 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java @@ -12,9 +12,7 @@ import static com.google.common.base.Preconditions.checkState; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import org.opendaylight.controller.md.sal.dom.store.impl.OperationWithModification; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeModification; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation; import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreUtils; import org.opendaylight.controller.md.sal.dom.store.impl.tree.TreeNodeUtils; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; @@ -53,18 +51,18 @@ final class InMemoryDataTreeModification implements DataTreeModification { return rootNode; } - ModificationApplyOperation getStrategy() { - return strategyTree; - } + ModificationApplyOperation getStrategy() { + return strategyTree; + } @Override - public void write(final InstanceIdentifier path, final NormalizedNode value) { + public void write(final InstanceIdentifier path, final NormalizedNode value) { checkSealed(); resolveModificationFor(path).write(value); } @Override - public void merge(final InstanceIdentifier path, final NormalizedNode data) { + public void merge(final InstanceIdentifier path, final NormalizedNode data) { checkSealed(); mergeImpl(resolveModificationFor(path),data); } @@ -83,13 +81,13 @@ final class InMemoryDataTreeModification implements DataTreeModification { } @Override - public void delete(final InstanceIdentifier path) { + public void delete(final InstanceIdentifier path) { checkSealed(); resolveModificationFor(path).delete(); } @Override - public Optional> readNode(final InstanceIdentifier path) { + public Optional> readNode(final InstanceIdentifier path) { Entry modification = TreeNodeUtils.findClosestsOrFirstMatch(rootNode, path, NodeModification.IS_TERMINAL_PREDICATE); Optional result = resolveSnapshot(modification); @@ -138,7 +136,7 @@ final class InMemoryDataTreeModification implements DataTreeModification { } @Override - public void seal() { + public void seal() { final boolean success = SEALED_UPDATER.compareAndSet(this, 0, 1); Preconditions.checkState(success, "Attempted to seal an already-sealed Data Tree."); rootNode.seal(); @@ -153,9 +151,9 @@ final class InMemoryDataTreeModification implements DataTreeModification { return "MutableDataTree [modification=" + rootNode + "]"; } - @Override - public DataTreeModification newModification(ModificationApplyOperation applyOper) { - // FIXME: transaction chaining - throw new UnsupportedOperationException("Implement this as part of transaction chaining"); - } + @Override + public DataTreeModification newModification() { + // FIXME: transaction chaining + throw new UnsupportedOperationException("Implement this as part of transaction chaining"); + } } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeSnapshot.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeSnapshot.java index 96f1565659..ce2d8c9bd4 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeSnapshot.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeSnapshot.java @@ -1,7 +1,6 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree.data; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeSnapshot; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeUtils; @@ -11,15 +10,18 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; final class InMemoryDataTreeSnapshot implements DataTreeSnapshot { + private final ModificationApplyOperation applyOper; private final SchemaContext schemaContext; private final StoreMetadataNode rootNode; - InMemoryDataTreeSnapshot(final SchemaContext schemaContext, final StoreMetadataNode rootNode) { + InMemoryDataTreeSnapshot(final SchemaContext schemaContext, final StoreMetadataNode rootNode, + final ModificationApplyOperation applyOper) { this.schemaContext = Preconditions.checkNotNull(schemaContext); this.rootNode = Preconditions.checkNotNull(rootNode); + this.applyOper = Preconditions.checkNotNull(applyOper); } - StoreMetadataNode getRootNode() { + StoreMetadataNode getRootNode() { return rootNode; } @@ -28,14 +30,14 @@ final class InMemoryDataTreeSnapshot implements DataTreeSnapshot { } @Override - public Optional> readNode(final InstanceIdentifier path) { + public Optional> readNode(final InstanceIdentifier path) { return NormalizedNodeUtils.findNode(rootNode.getData(), path); } @Override - public InMemoryDataTreeModification newModification(ModificationApplyOperation applyOper) { - return new InMemoryDataTreeModification(this, applyOper); - } + public InMemoryDataTreeModification newModification() { + return new InMemoryDataTreeModification(this, applyOper); + } @Override public String toString() { diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationApplyOperation.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationApplyOperation.java similarity index 82% rename from opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationApplyOperation.java rename to opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationApplyOperation.java index 50d404981b..5b4cd565e5 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationApplyOperation.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationApplyOperation.java @@ -5,10 +5,10 @@ * 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.md.sal.dom.store.impl.tree; +package org.opendaylight.controller.md.sal.dom.store.impl.tree.data; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.NodeModification; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode; +import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException; +import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreTreeNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; @@ -37,7 +37,7 @@ import com.google.common.primitives.UnsignedLong; * * */ -public interface ModificationApplyOperation extends StoreTreeNode { +interface ModificationApplyOperation extends StoreTreeNode { /** * @@ -79,14 +79,14 @@ public interface ModificationApplyOperation extends StoreTreeNode getChild(PathArgument child); /** - * - * Checks if provided node modification could be applied to current metadata node. - * - * @param modification Modification - * @param current Metadata Node to which modification should be applied - * @return true if modification is applicable - * false if modification is no applicable + * + * Checks if provided node modification could be applied to current metadata node. + * + * @param modification Modification + * @param current Metadata Node to which modification should be applied + * @return true if modification is applicable + * false if modification is no applicable * @throws DataPreconditionFailedException - */ + */ void checkApplicable(InstanceIdentifier path, NodeModification modification, Optional current) throws DataPreconditionFailedException; } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java index 0f9a335627..18179afd50 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java @@ -32,6 +32,7 @@ import com.google.common.base.Predicate; * and {@link StoreMetadataNode} which represents original state {@link #getOriginal()}. * */ +// FIXME: hide this class public class NodeModification implements StoreTreeNode, Identifiable { public static final Predicate IS_TERMINAL_PREDICATE = new Predicate() { diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/OperationWithModification.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/OperationWithModification.java similarity index 85% rename from opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/OperationWithModification.java rename to opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/OperationWithModification.java index 153df768ae..fda8407a95 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/OperationWithModification.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/OperationWithModification.java @@ -5,18 +5,15 @@ * 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.md.sal.dom.store.impl; +package org.opendaylight.controller.md.sal.dom.store.impl.tree.data; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.NodeModification; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import com.google.common.base.Optional; import com.google.common.primitives.UnsignedLong; -public class OperationWithModification { +final class OperationWithModification { private final NodeModification modification; diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperation.java similarity index 98% rename from opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java rename to opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperation.java index 909aaae1ca..02244d9f98 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperation.java @@ -5,7 +5,7 @@ * 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.md.sal.dom.store.impl; +package org.opendaylight.controller.md.sal.dom.store.impl.tree.data; import static com.google.common.base.Preconditions.checkArgument; @@ -16,12 +16,7 @@ import java.util.Set; import java.util.concurrent.ExecutionException; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation; import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreUtils; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.ModificationType; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.NodeModification; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreNodeCompositeBuilder; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier; @@ -73,7 +68,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.primitives.UnsignedLong; -public abstract class SchemaAwareApplyOperation implements ModificationApplyOperation { +abstract class SchemaAwareApplyOperation implements ModificationApplyOperation { public static SchemaAwareApplyOperation from(final DataSchemaNode schemaNode) { if (schemaNode instanceof ContainerSchemaNode) { diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreMetadataNode.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreMetadataNode.java index abccf1db16..8addb89bd1 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreMetadataNode.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreMetadataNode.java @@ -24,6 +24,7 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.primitives.UnsignedLong; +// FIXME: this should not be public public class StoreMetadataNode implements Immutable, Identifiable, StoreTreeNode { private final UnsignedLong nodeVersion; diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreNodeCompositeBuilder.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreNodeCompositeBuilder.java index 5f086b6614..6bce4fff0c 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreNodeCompositeBuilder.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreNodeCompositeBuilder.java @@ -20,7 +20,7 @@ import com.google.common.primitives.UnsignedLong; * */ @SuppressWarnings("rawtypes") -public class StoreNodeCompositeBuilder { +class StoreNodeCompositeBuilder { private final StoreMetadataNode.Builder metadata; diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationMetadataTreeTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationMetadataTreeTest.java index bc27c55155..8940e55d32 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationMetadataTreeTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/ModificationMetadataTreeTest.java @@ -26,7 +26,6 @@ import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.ma import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.md.sal.dom.store.impl.SchemaAwareApplyOperationRoot; import org.opendaylight.controller.md.sal.dom.store.impl.TestModel; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTree; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeModification; @@ -99,14 +98,16 @@ public class ModificationMetadataTreeTest { .withChild(mapEntry(INNER_LIST_QNAME, NAME_QNAME, TWO_ONE_NAME)) // .withChild(mapEntry(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME)) // .build()) // - .build(); + .build(); private SchemaContext schemaContext; + private ModificationApplyOperation applyOper; @Before public void prepare() { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); + applyOper = SchemaAwareApplyOperation.from(schemaContext); } /** @@ -141,14 +142,14 @@ public class ModificationMetadataTreeTest { .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) .withChild( mapNodeBuilder(OUTER_LIST_QNAME) - .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)) - .withChild(BAR_NODE).build()).build(); + .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)) + .withChild(BAR_NODE).build()).build(); } @Test public void basicReadWrites() { DataTreeModification modificationTree = new InMemoryDataTreeModification(new InMemoryDataTreeSnapshot(schemaContext, - StoreMetadataNode.createRecursively(createDocumentOne(), UnsignedLong.valueOf(5))), + StoreMetadataNode.createRecursively(createDocumentOne(), UnsignedLong.valueOf(5)), applyOper), new SchemaAwareApplyOperationRoot(schemaContext)); Optional> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH); assertTrue(originalBarNode.isPresent()); @@ -183,7 +184,7 @@ public class ModificationMetadataTreeTest { * context. * */ - return t.takeSnapshot().newModification(new SchemaAwareApplyOperationRoot(schemaContext)); + return t.takeSnapshot().newModification(); } @Test diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperationRoot.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperationRoot.java similarity index 95% rename from opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperationRoot.java rename to opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperationRoot.java index 8a539ff36e..f2cc533207 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperationRoot.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperationRoot.java @@ -5,7 +5,7 @@ * 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.md.sal.dom.store.impl; +package org.opendaylight.controller.md.sal.dom.store.impl.tree.data; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -- 2.36.6