summaryrefslogtreecommitdiffstats
path: root/v3po/translate-api/src/main/java/io/fd
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-05-17 09:10:39 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-05-23 09:24:12 +0000
commit799ee62f15dff07534beaf98a3ac551deffade38 (patch)
treea47c4696cf6ecff4fbb83c161c5d8e7e6b8af3c8 /v3po/translate-api/src/main/java/io/fd
parentf19306a9263cb8dd8c10a4867633fbbe14db2e4c (diff)
HONEYCOMB-61: Add BA broker for context data tree
With broker, context data can be accessed in a transactional manner, same as config data + Renamed data-api concepts to not include DataTree + Renamed context related concepts to better distinguish between them + Now passing full ReadContext to read customizers + Naming context is backed by context data broker Change-Id: I0b2876dd74a31a9ced7d9b5145672868e12f8b82 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/translate-api/src/main/java/io/fd')
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/MappingContext.java66
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationCache.java (renamed from v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/Context.java)4
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationContext.java44
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReadContext.java17
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteContext.java22
5 files changed, 121 insertions, 32 deletions
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/MappingContext.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/MappingContext.java
new file mode 100644
index 000000000..cff766e2a
--- /dev/null
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/MappingContext.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate;
+
+import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Mapping context is persisted storage where mapping matadata are stored.
+ * A snapshot is created for each transaction to provide consistent view over context data.
+ * After a transaction is successfully finished, objects added to this context are propagated to backing storage.
+ */
+public interface MappingContext extends AutoCloseable {
+
+ /**
+ * Read any mapping context data
+ *
+ * @param currentId Id of an object to read
+ *
+ * @return Relevant mapping context data
+ */
+ <T extends DataObject> Optional<T> read(@Nonnull final InstanceIdentifier<T> currentId);
+
+ /**
+ * Delete the node at specified path.
+ *
+ * @param path Node path
+ */
+ void delete(InstanceIdentifier<?> path);
+
+ /**
+ * Merge the specified data with the currently-present data
+ * at specified path.
+ *
+ * @param path Node path
+ * @param data Data to be merged
+ */
+ <T extends DataObject> void merge(InstanceIdentifier<T> path, T data);
+
+ /**
+ * Replace the data at specified path with supplied data.
+ *
+ * @param path Node path
+ * @param data New node data
+ */
+ <T extends DataObject> void put(InstanceIdentifier<T> path, T data);
+
+ @Override
+ void close();
+}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/Context.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationCache.java
index b60963678..cb2d4fde0 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/Context.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationCache.java
@@ -22,11 +22,11 @@ import java.util.HashMap;
/**
* Simple context class that provides transient storage during one or more read/write operations
*/
-public class Context implements AutoCloseable {
+public class ModificationCache implements AutoCloseable {
protected final HashMap<Object, Object> map;
- public Context() {
+ public ModificationCache() {
map = Maps.newHashMap();
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationContext.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationContext.java
new file mode 100644
index 000000000..2c039aba0
--- /dev/null
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/ModificationContext.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Common context for both writes and reads
+ */
+public interface ModificationContext extends AutoCloseable {
+
+ /**
+ * Get key value transient storage for customizers. Is cleared for each new transaction.
+ *
+ * @return Context for customizers
+ */
+ @Nonnull
+ ModificationCache getModificationCache();
+
+ /**
+ * Get persistent storage for mapping context. This context survives a modification.
+ *
+ * @return Mapping context accessor
+ */
+ @Nonnull
+ MappingContext getMappingContext();
+
+ @Override
+ void close();
+}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReadContext.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReadContext.java
index 6b1473548..e3ddd420c 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReadContext.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReadContext.java
@@ -16,22 +16,11 @@
package io.fd.honeycomb.v3po.translate.read;
-import io.fd.honeycomb.v3po.translate.Context;
-import javax.annotation.Nonnull;
+import io.fd.honeycomb.v3po.translate.ModificationContext;
/**
- * Read Context
+ * Context providing information about current state of DataTree to readers
*/
-public interface ReadContext extends AutoCloseable {
+public interface ReadContext extends ModificationContext {
- /**
- * Get key value storage for customizers
- *
- * @return Context for customizers
- */
- @Nonnull
- Context getContext();
-
- @Override
- void close();
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteContext.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteContext.java
index bb0b33145..3433b3f34 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteContext.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/write/WriteContext.java
@@ -18,7 +18,7 @@ package io.fd.honeycomb.v3po.translate.write;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
-import io.fd.honeycomb.v3po.translate.Context;
+import io.fd.honeycomb.v3po.translate.ModificationContext;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -27,34 +27,24 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
* Context providing information about current state of DataTree to writers
*/
@Beta
-public interface WriteContext extends AutoCloseable {
+public interface WriteContext extends ModificationContext {
/**
- * Read any data object before current modification was applied
+ * Read any config data object before current modification was applied
*
* @param currentId Id of an object to read
*
* @return Data before the modification was applied
*/
- Optional<DataObject> readBefore(@Nonnull final InstanceIdentifier<? extends DataObject> currentId);
+ <T extends DataObject> Optional<T> readBefore(@Nonnull final InstanceIdentifier<T> currentId);
/**
- * Read any data object from current modification
+ * Read any config data object from current modification
*
* @param currentId Id of an object to read
*
* @return Data from the modification
*/
- Optional<DataObject> readAfter(@Nonnull final InstanceIdentifier<? extends DataObject> currentId);
+ <T extends DataObject> Optional<T> readAfter(@Nonnull final InstanceIdentifier<T> currentId);
- /**
- * Get key value storage for customizers
- *
- * @return Context for customizers
- */
- @Nonnull
- Context getContext();
-
- @Override
- void close();
}