From 04c868333214c0e5bfce3926c43a4302615f2ac5 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Wed, 26 Oct 2016 12:18:11 +0200 Subject: Honeycomb-73 Extensible initializers framework Change-Id: Ib23453d4040d59a512686315995a5cf9e532cefc Signed-off-by: Maros Marsalek --- .../honeycomb/translate/spi/read/Initialized.java | 77 ++++++++++++++++++++++ .../translate/spi/read/InitializingCustomizer.java | 45 +++++++++++++ .../spi/read/InitializingListReaderCustomizer.java | 29 ++++++++ .../spi/read/InitializingReaderCustomizer.java | 27 ++++++++ .../translate/spi/read/ListReaderCustomizer.java | 12 ++-- .../translate/spi/read/ReaderCustomizer.java | 10 +-- 6 files changed, 189 insertions(+), 11 deletions(-) create mode 100644 infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/Initialized.java create mode 100644 infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingCustomizer.java create mode 100644 infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingListReaderCustomizer.java create mode 100644 infra/translate-spi/src/main/java/io/fd/honeycomb/translate/spi/read/InitializingReaderCustomizer.java (limited to 'infra/translate-spi') 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 { + + private final InstanceIdentifier id; + private final T data; + + private Initialized(final InstanceIdentifier id, final T data) { + this.id = id; + this.data = data; + } + + public InstanceIdentifier 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 Initialized create(@Nonnull final InstanceIdentifier 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. + *

+ * 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 { + + /** + * 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 init(@Nonnull InstanceIdentifier 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, K extends Identifier, B extends Builder> + extends ListReaderCustomizer, InitializingCustomizer { +} 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> + extends ReaderCustomizer, InitializingCustomizer { +} 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 Specific DataObject derived type (Identifiable), that is handled by this customizer + * @param Specific DataObject derived type (Identifiable), that is handled by this customizer * @param Specific Identifier for handled type (C) * @param Specific Builder for handled type (C) */ @Beta -public interface ListReaderCustomizer, K extends Identifier, B extends Builder> - extends ReaderCustomizer { +public interface ListReaderCustomizer, K extends Identifier, B extends Builder> + extends ReaderCustomizer { /** * Return list with IDs of all list nodes to be read. @@ -47,16 +47,16 @@ public interface ListReaderCustomizer, K * @throws ReadFailedException if the list of IDs could not be read */ @Nonnull - List getAllIds(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext context) throws + List getAllIds(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext context) throws ReadFailedException; /** * Merge read data into provided parent builder. */ - void merge(@Nonnull final Builder builder, @Nonnull final List readData); + void merge(@Nonnull final Builder builder, @Nonnull final List readData); @Override - default void merge(@Nonnull final Builder parentBuilder, @Nonnull final C readValue) { + default void merge(@Nonnull final Builder 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 Specific DataObject derived type (Identifiable), that is handled by this customizer + * @param Specific DataObject derived type (Identifiable), that is handled by this customizer * @param Specific Builder for handled type (C) */ @Beta -public interface ReaderCustomizer> { +public interface ReaderCustomizer> { /** * Creates new builder that will be used to build read value. */ @Nonnull - B getBuilder(@Nonnull final InstanceIdentifier id); + B getBuilder(@Nonnull final InstanceIdentifier id); /** * Adds current data (identified by id) to the provided builder. @@ -47,14 +47,14 @@ public interface ReaderCustomizer> { * @param ctx context for current read * @throws ReadFailedException if read was unsuccessful */ - void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final B builder, @Nonnull final ReadContext ctx) throws ReadFailedException; /** * Merge read data into provided parent builder. */ - void merge(@Nonnull final Builder parentBuilder, @Nonnull final C readValue); + void merge(@Nonnull final Builder parentBuilder, @Nonnull final O readValue); } -- cgit 1.2.3-korg