From 9779f4b3ffe24bb2338630c66169da92c880ffbb Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 3 Nov 2017 13:33:53 +0100 Subject: HONEYCOMB-359 - Wildcarded writers Adds option to specify subtree writer that can handle whole subtree of nodes without having whole subtree specified. Its checking if node is children at runtime, rather than having pre-computed tree Change-Id: Ic46f2bd6de84f0dd14865825399f5a90a1f80859 Signed-off-by: Jan Srnicek --- ...stractSubtreeManagerRegistryBuilderBuilder.java | 38 ++++++++++++++++++++-- .../util/write/AbstractGenericWriter.java | 9 ++--- .../translate/util/write/BindingBrokerWriter.java | 9 ++--- 3 files changed, 45 insertions(+), 11 deletions(-) (limited to 'infra/translate-utils/src') diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java index fe2f1178f..181d71727 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java @@ -21,13 +21,14 @@ import com.google.common.collect.ImmutableMap; import io.fd.honeycomb.translate.ModifiableSubtreeManagerRegistryBuilder; import io.fd.honeycomb.translate.SubtreeManager; import io.fd.honeycomb.translate.SubtreeManagerRegistryBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import javax.annotation.Nonnull; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public abstract class AbstractSubtreeManagerRegistryBuilderBuilder, R> implements ModifiableSubtreeManagerRegistryBuilder, SubtreeManagerRegistryBuilder { @@ -64,6 +65,12 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder wildcardedSubtreeAdd(@Nonnull S handler) { + add(getWildcardedSubtreeHandler(handler)); + return this; + } + private void checkWriterNotPresentYet(final InstanceIdentifier targetType) { Preconditions.checkArgument(!handlersMap.containsKey(targetType), "Writer for type: %s already present: %s", targetType, handlersMap.get(targetType)); @@ -109,6 +116,12 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder wildcardedSubtreeAddBefore(@Nonnull final S handler, + @Nonnull final InstanceIdentifier relatedType) { + return addBefore(getWildcardedSubtreeHandler(handler), relatedType); + } + @Override public AbstractSubtreeManagerRegistryBuilderBuilder subtreeAddBefore( @Nonnull final Set> handledChildren, @@ -117,9 +130,17 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder wildcardedSubtreeAddBefore(@Nonnull final S handler, + @Nonnull final Collection> relatedTypes) { + return addBefore(getWildcardedSubtreeHandler(handler), relatedTypes); + } + protected abstract S getSubtreeHandler(@Nonnull final Set> handledChildren, @Nonnull final S handler); + protected abstract S getWildcardedSubtreeHandler(@Nonnull final S handler); + /** * Add handler with relationship: to be executed after handler handling relatedType. */ @@ -162,6 +183,12 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder wildcardedSubtreeAddAfter(@Nonnull final S handler, + @Nonnull final InstanceIdentifier relatedType) { + return addAfter(getWildcardedSubtreeHandler(handler), relatedType); + } + @Override public AbstractSubtreeManagerRegistryBuilderBuilder subtreeAddAfter( @Nonnull final Set> handledChildren, @@ -170,6 +197,11 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder wildcardedSubtreeAddAfter(@Nonnull S handler, @Nonnull Collection> relatedTypes) { + return addAfter(getWildcardedSubtreeHandler(handler), relatedTypes); + } + protected ImmutableMap, S> getMappedHandlers() { final ImmutableMap.Builder, S> builder = ImmutableMap.builder(); // Iterate writer types according to their relationships from graph diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java index e2ea11535..4f1b696cf 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/AbstractGenericWriter.java @@ -16,19 +16,20 @@ package io.fd.honeycomb.translate.util.write; -import static com.google.common.base.Preconditions.checkArgument; - import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.translate.write.Writer; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkArgument; + public abstract class AbstractGenericWriter implements Writer { private static final Logger LOG = LoggerFactory.getLogger(AbstractGenericWriter.class); diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java index 7b68376ba..60a81a77a 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/BindingBrokerWriter.java @@ -16,20 +16,21 @@ package io.fd.honeycomb.translate.util.write; -import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; - import com.google.common.util.concurrent.CheckedFuture; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.translate.write.Writer; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; + /** * Simple DataBroker backed writer allowing to delegate writes to different brokers. */ -- cgit 1.2.3-korg