Bug 3868: Introduction of DOM Cursor APIs. 05/25905/7
authorTony Tkacik <ttkacik@cisco.com>
Mon, 24 Aug 2015 19:41:43 +0000 (21:41 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 29 Sep 2015 07:22:09 +0000 (07:22 +0000)
Change-Id: I722216172dcf4ee2b40f25daf4adf55d3ce3291f
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeCursor.java [new file with mode: 0644]
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeCursorProvider.java [new file with mode: 0644]
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeReadCursor.java [new file with mode: 0644]
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeReadTransaction.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeWriteCursor.java [new file with mode: 0644]

diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeCursor.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeCursor.java
new file mode 100644 (file)
index 0000000..7f758c3
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.mdsal.dom.api;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.NotThreadSafe;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+
+/**
+ * A cursor holding a logical position within a conceptual data tree. It allows operations relative
+ * to that position, as well as moving the position up or down the tree.
+ */
+@Beta
+@NotThreadSafe
+public interface DOMDataTreeCursor extends AutoCloseable {
+    /**
+     * Move the cursor to the specified child of the current position.
+     *
+     * @param child Child identifier
+     * @throws IllegalArgumentException when specified identifier does not identify a valid child,
+     *         or if that child is not an instance of {@link NormalizedNodeContainer}.
+     */
+    void enter(@Nonnull PathArgument child);
+
+    /**
+     * Move the cursor to the specified child of the current position. This is the equivalent of
+     * multiple invocations of {@link #enter(PathArgument)}, except the operation is performed all
+     * at once.
+     *
+     * @param path Nested child identifier
+     * @throws IllegalArgumentException when specified path does not identify a valid child, or if
+     *         that child is not an instance of {@link NormalizedNodeContainer}.
+     */
+    void enter(@Nonnull PathArgument... path);
+
+    /**
+     * Move the cursor to the specified child of the current position. This is equivalent to
+     * {@link #enter(PathArgument...)}, except it takes an {@link Iterable} argument.
+     *
+     * @param path Nested child identifier
+     * @throws IllegalArgumentException when specified path does not identify a valid child, or if
+     *         that child is not an instance of {@link NormalizedNodeContainer}.
+     */
+    void enter(@Nonnull Iterable<PathArgument> path);
+
+    /**
+     * Move the cursor up to the parent of current position. This is equivalent of invoking
+     * <code>exit(1)</code>.
+     *
+     * @throws IllegalStateException when exiting would violate containment, typically by attempting
+     *         to exit more levels than previously entered.
+     */
+    void exit();
+
+    /**
+     * Move the cursor up by specified amounts of steps from the current position. This is
+     * equivalent of invoking {@link #exit()} multiple times, except the operation is performed
+     * atomically.
+     *
+     * @param depth number of steps to exit
+     * @throws IllegalArgumentException when depth is negative.
+     * @throws IllegalStateException when exiting would violate containment, typically by attempting
+     *         to exit more levels than previously entered.
+     */
+    void exit(int depth);
+
+    /**
+     * Close this cursor. Attempting any further operations on the cursor will lead to undefined
+     * behavior.
+     */
+    @Override
+    void close();
+}
diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeCursorProvider.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeCursorProvider.java
new file mode 100644 (file)
index 0000000..f8f0396
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.mdsal.dom.api;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
+
+public interface DOMDataTreeCursorProvider {
+
+    /**
+     * Create a new {@link DataTreeModificationCursor} at specified path. May fail if specified path
+     * does not exist.
+     *
+     * @param path Path at which the cursor is to be anchored
+     * @return A new cursor, or null if the path does not exist.
+     * @throws IllegalStateException if there is another cursor currently open, or the transaction
+     *         is already closed (closed or submitted).
+     */
+    @Nullable
+    DOMDataTreeCursor createCursor(@Nonnull DOMDataTreeIdentifier path);
+
+}
diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeReadCursor.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeReadCursor.java
new file mode 100644 (file)
index 0000000..0664838
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.mdsal.dom.api;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public interface DOMDataTreeReadCursor extends DOMDataTreeCursor {
+
+    /**
+     * Read a particular node from the snapshot.
+     *
+     * @param child Child identifier
+     * @return Optional result encapsulating the presence and value of the node
+     * @throws IllegalArgumentException when specified path does not identify a valid child.
+     */
+    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readNode(@Nonnull PathArgument child);
+
+    /**
+     * Checks if data is available in the logical data store located at provided path.
+     * <p>
+     *
+     * Note: a successful result from this method makes no guarantee that a subsequent call to
+     * {@link #readNode(PathArgument)} will succeed. It is possible that the data resides in a data store on a remote
+     * node and, if that node goes down or a network failure occurs, a subsequent read would fail.
+     * Another scenario is if the data is deleted in between the calls to <code>exists</code> and
+     * <code>readNode</code>
+     *
+     * @param child Child identifier
+     * @return a CheckFuture containing the result of the check.
+     *         <ul>
+     *         <li>If the data at the supplied path exists, the Future returns a Boolean whose value
+     *         is true, false otherwise</li> <li>If checking for the data fails, the Future will
+     *         fail with a {@link ReadFailedException} or an exception derived from
+     *         ReadFailedException.</li>
+     *         </ul>
+     */
+    CheckedFuture<Boolean, ReadFailedException> exists(@Nonnull PathArgument child);
+}
index f07d39b839e66671288ffe70d29335e69dfcc0a7..bdd6629b3f2aea0e6012c20031546b0dc6ad7206 100644 (file)
@@ -7,14 +7,13 @@
  */
 package org.opendaylight.mdsal.dom.api;
 
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
 import org.opendaylight.mdsal.common.api.AsyncReadTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.ReadFailedException;
-
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
 
 /**
  * A transaction that provides read access to a logical data store.
@@ -49,7 +48,6 @@ public interface DOMDataTreeReadTransaction extends AsyncReadTransaction<YangIns
             LogicalDatastoreType store, YangInstanceIdentifier path);
 
     /**
-     /**
      * Checks if data is available in the logical data store located at provided path.
      * <p>
      *
diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeWriteCursor.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMDataTreeWriteCursor.java
new file mode 100644 (file)
index 0000000..6d522a9
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.mdsal.dom.api;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.BackendFailedException;
+
+public interface DOMDataTreeWriteCursor extends DOMDataTreeCursor {
+
+    /**
+     * Delete the specified child.
+     *
+     * @param child Child identifier
+     * @throws BackendFailedException when implementation-specific errors occurs while servicing the
+     *         request.
+     */
+    void delete(PathArgument child);
+
+    /**
+     * Merge the specified data with the currently-present data at specified path.
+     *
+     * @param child Child identifier
+     * @param data Data to be merged
+     * @throws BackendFailedException when implementation-specific errors occurs while servicing the
+     *         request.
+     */
+    void merge(PathArgument child, NormalizedNode<?, ?> data);
+
+    /**
+     * Replace the data at specified path with supplied data.
+     *
+     * @param child Child identifier
+     * @param data New node data
+     * @throws BackendFailedException when implementation-specific errors occurs while servicing the
+     *         request.
+     */
+    void write(PathArgument child, NormalizedNode<?, ?> data);
+}