summaryrefslogtreecommitdiffstats
path: root/infra/translate-spi/src/main
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-10-26 12:18:11 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-10-28 12:32:11 +0200
commit04c868333214c0e5bfce3926c43a4302615f2ac5 (patch)
tree4c3f4b8fd3c833e807abdc25aa7f74e05cfa0b38 /infra/translate-spi/src/main
parentb0615e61b93ef8530193bd45c270ed313dcc23a7 (diff)
Honeycomb-73 Extensible initializers framework
Change-Id: Ib23453d4040d59a512686315995a5cf9e532cefc Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/translate-spi/src/main')
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/Initialized.java77
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingCustomizer.java45
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingListReaderCustomizer.java29
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingReaderCustomizer.java27
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ListReaderCustomizer.java12
-rw-r--r--infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java10
6 files changed, 189 insertions, 11 deletions
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/Initialized.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/Initialized.java
new file mode 100644
index 000000000..94fb3cd98
--- /dev/null
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/Initialized.java
@@ -0,0 +1,77 @@
+/*
+ * 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.translate.spi.read;
+
+import com.google.common.base.Preconditions;
+import java.util.Objects;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Just a DTO holding configuration data ID and the data itself.
+ */
+public final class Initialized<T extends DataObject> {
+
+ private final InstanceIdentifier<T> id;
+ private final T data;
+
+ private Initialized(final InstanceIdentifier<T> id, final T data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public InstanceIdentifier<T> getId() {
+ return id;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final Initialized<?> that = (Initialized<?>) o;
+ return Objects.equals(id, that.id) &&
+ Objects.equals(data, that.data);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, data);
+ }
+
+ @Override
+ public String toString() {
+ return "Initialized{" +
+ "id=" + id +
+ ", data=" + data +
+ '}';
+ }
+
+ public static <C extends DataObject> Initialized<C> create(@Nonnull final InstanceIdentifier<C> id,
+ @Nonnull final C data) {
+ return new Initialized<>(Preconditions.checkNotNull(id, "Id cannot be null"),
+ Preconditions.checkNotNull(data, "Data cannot be null"));
+ }
+}
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingCustomizer.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingCustomizer.java
new file mode 100644
index 000000000..ce4b2a6e9
--- /dev/null
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingCustomizer.java
@@ -0,0 +1,45 @@
+/*
+ * 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.translate.spi.read;
+
+import io.fd.honeycomb.translate.read.ReadContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * ReadCustomizers which want to participate in the initializing process need to implement this interface.
+ * <p/>
+ * It is triggered after Honeycomb initializes the plugins to give them a change
+ * reconcile(put data in HC in sync with underlying layer) with the underlying layer.
+ */
+public interface InitializingCustomizer<O extends DataObject> {
+
+ /**
+ * Transform Operational data into Config data.
+ *
+ * @param id InstanceIdentifier of operational data being initialized
+ * @param readValue Operational data being initialized(converted into config)
+ * @param ctx Standard read context to assist during initialization e.g. caching data between customizers
+ *
+ * @return Initialized, config data and its identifier
+ */
+ @Nonnull
+ Initialized<? extends DataObject> init(@Nonnull InstanceIdentifier<O> id,
+ @Nonnull O readValue,
+ @Nonnull ReadContext ctx);
+}
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingListReaderCustomizer.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingListReaderCustomizer.java
new file mode 100644
index 000000000..20cc83364
--- /dev/null
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingListReaderCustomizer.java
@@ -0,0 +1,29 @@
+/*
+ * 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.translate.spi.read;
+
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+
+/**
+ * Special type of list customizer capable of participating in the initialization process.
+ */
+public interface InitializingListReaderCustomizer<O extends DataObject & Identifiable<K>, K extends Identifier<O>, B extends Builder<O>>
+ extends ListReaderCustomizer<O, K, B>, InitializingCustomizer<O> {
+}
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingReaderCustomizer.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingReaderCustomizer.java
new file mode 100644
index 000000000..dccc920ef
--- /dev/null
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingReaderCustomizer.java
@@ -0,0 +1,27 @@
+/*
+ * 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.translate.spi.read;
+
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+/**
+ * Special type of customizer capable of participating in the initialization process.
+ */
+public interface InitializingReaderCustomizer<O extends DataObject, B extends Builder<O>>
+ extends ReaderCustomizer<O, B>, InitializingCustomizer<O> {
+}
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ListReaderCustomizer.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ListReaderCustomizer.java
index 7c64e7f7b..fab91ffc7 100644
--- a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ListReaderCustomizer.java
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ListReaderCustomizer.java
@@ -31,13 +31,13 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* CompositeListReader SPI to customize its behavior.
*
- * @param <C> Specific DataObject derived type (Identifiable), that is handled by this customizer
+ * @param <O> Specific DataObject derived type (Identifiable), that is handled by this customizer
* @param <K> Specific Identifier for handled type (C)
* @param <B> Specific Builder for handled type (C)
*/
@Beta
-public interface ListReaderCustomizer<C extends DataObject & Identifiable<K>, K extends Identifier<C>, B extends Builder<C>>
- extends ReaderCustomizer<C, B> {
+public interface ListReaderCustomizer<O extends DataObject & Identifiable<K>, K extends Identifier<O>, B extends Builder<O>>
+ extends ReaderCustomizer<O, B> {
/**
* Return list with IDs of all list nodes to be read.
@@ -47,16 +47,16 @@ public interface ListReaderCustomizer<C extends DataObject & Identifiable<K>, K
* @throws ReadFailedException if the list of IDs could not be read
*/
@Nonnull
- List<K> getAllIds(@Nonnull final InstanceIdentifier<C> id, @Nonnull final ReadContext context) throws
+ List<K> getAllIds(@Nonnull final InstanceIdentifier<O> id, @Nonnull final ReadContext context) throws
ReadFailedException;
/**
* Merge read data into provided parent builder.
*/
- void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<C> readData);
+ void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<O> readData);
@Override
- default void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final C readValue) {
+ default void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final O readValue) {
merge(parentBuilder, Collections.singletonList(readValue));
}
}
diff --git a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java
index a13e518a6..acfabf5bc 100644
--- a/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java
+++ b/infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/ReaderCustomizer.java
@@ -27,17 +27,17 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* CompositeChildReader SPI to customize its behavior.
*
- * @param <C> Specific DataObject derived type (Identifiable), that is handled by this customizer
+ * @param <O> Specific DataObject derived type (Identifiable), that is handled by this customizer
* @param <B> Specific Builder for handled type (C)
*/
@Beta
-public interface ReaderCustomizer<C extends DataObject, B extends Builder<C>> {
+public interface ReaderCustomizer<O extends DataObject, B extends Builder<O>> {
/**
* Creates new builder that will be used to build read value.
*/
@Nonnull
- B getBuilder(@Nonnull final InstanceIdentifier<C> id);
+ B getBuilder(@Nonnull final InstanceIdentifier<O> id);
/**
* Adds current data (identified by id) to the provided builder.
@@ -47,14 +47,14 @@ public interface ReaderCustomizer<C extends DataObject, B extends Builder<C>> {
* @param ctx context for current read
* @throws ReadFailedException if read was unsuccessful
*/
- void readCurrentAttributes(@Nonnull final InstanceIdentifier<C> id,
+ void readCurrentAttributes(@Nonnull final InstanceIdentifier<O> id,
@Nonnull final B builder,
@Nonnull final ReadContext ctx) throws ReadFailedException;
/**
* Merge read data into provided parent builder.
*/
- void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final C readValue);
+ void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final O readValue);
}