summaryrefslogtreecommitdiffstats
path: root/infra/translate-api/src/main/java/io
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-api/src/main/java/io
parentb0615e61b93ef8530193bd45c270ed313dcc23a7 (diff)
Honeycomb-73 Extensible initializers framework
Change-Id: Ib23453d4040d59a512686315995a5cf9e532cefc Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/translate-api/src/main/java/io')
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitFailedException.java30
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitListReader.java31
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitReader.java29
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/Initializer.java42
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/ReadFailedException.java8
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/InitRegistry.java34
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/ReaderRegistry.java2
7 files changed, 174 insertions, 2 deletions
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitFailedException.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitFailedException.java
new file mode 100644
index 000000000..4e057c51e
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitFailedException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.read;
+
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Exception indicating a failure during the initialization process.
+ */
+public class InitFailedException extends ReadFailedException {
+
+ public InitFailedException(@Nonnull final InstanceIdentifier<?> failedId, final Throwable cause) {
+ super("Failed to initialize: ", failedId, cause);
+ }
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitListReader.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitListReader.java
new file mode 100644
index 000000000..a7d3ee2ac
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitListReader.java
@@ -0,0 +1,31 @@
+/*
+ * 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.read;
+
+import com.google.common.annotations.Beta;
+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 reader capable of participating in the initialization process.
+ */
+@Beta
+public interface InitListReader<O extends DataObject & Identifiable<K>, K extends Identifier<O>, B extends Builder<O>>
+ extends ListReader<O, K, B>, Initializer<O> {
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitReader.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitReader.java
new file mode 100644
index 000000000..e5b81b947
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/InitReader.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.read;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+/**
+ * Special type of reader capable of participating in the initialization process.
+ */
+@Beta
+public interface InitReader<O extends DataObject, B extends Builder<O>>
+ extends Reader<O, B>, Initializer<O> {
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/Initializer.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/Initializer.java
new file mode 100644
index 000000000..e26ab55bc
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/Initializer.java
@@ -0,0 +1,42 @@
+/*
+ * 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.read;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Generic initializer.
+ * <p/>
+ * Capable of invoking 0..n edits as a result of existing operational data.
+ */
+@Beta
+public interface Initializer<O extends DataObject> {
+
+ /**
+ * Transform operational data located under provided (keyed) id.
+ *
+ * @param broker DataBroker that accepts the resulting config data
+ * @param id InstanceIdentifier of the operational data to initialize from
+ * @param ctx Standard read context to assist during initialization e.g. caching data between customizers
+ */
+ void init(@Nonnull DataBroker broker, @Nonnull InstanceIdentifier<O> id, @Nonnull ReadContext ctx)
+ throws InitFailedException;
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/ReadFailedException.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/ReadFailedException.java
index fc429b1d0..349e27451 100644
--- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/ReadFailedException.java
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/ReadFailedException.java
@@ -36,7 +36,13 @@ public class ReadFailedException extends TranslationException {
* @param cause the cause of read failure
*/
public ReadFailedException(@Nonnull final InstanceIdentifier<?> failedId, final Throwable cause) {
- super("Failed to read " + failedId, cause);
+ this("Failed to read: ", failedId, cause);
+ }
+
+ protected ReadFailedException(@Nonnull final String msgPrefix,
+ @Nonnull final InstanceIdentifier<?> failedId,
+ @Nonnull final Throwable cause) {
+ super(msgPrefix + failedId, cause);
this.failedId = checkNotNull(failedId, "failedId should not be null");
}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/InitRegistry.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/InitRegistry.java
new file mode 100644
index 000000000..8a97a7141
--- /dev/null
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/InitRegistry.java
@@ -0,0 +1,34 @@
+/*
+ * 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.read.registry;
+
+
+import io.fd.honeycomb.translate.read.InitFailedException;
+import io.fd.honeycomb.translate.read.ReadContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+/**
+ * Root initializer.
+ */
+public interface InitRegistry {
+
+ /**
+ * Perform initialization on top of the data root.
+ */
+ void initAll(@Nonnull DataBroker broker, @Nonnull ReadContext ctx) throws InitFailedException;
+}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/ReaderRegistry.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/ReaderRegistry.java
index 9a1c99508..6436fd738 100644
--- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/ReaderRegistry.java
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/read/registry/ReaderRegistry.java
@@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
* Simple delegating reader suitable as a holder for all other root readers, providing readAll feature.
*/
@Beta
-public interface ReaderRegistry {
+public interface ReaderRegistry extends InitRegistry {
/**
* Performs read on all registered root readers and merges the results into a Multimap. Keys represent identifiers