diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-11-03 13:33:53 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-11-03 12:58:01 +0000 |
commit | 9779f4b3ffe24bb2338630c66169da92c880ffbb (patch) | |
tree | fac37c53b70b7bbfcea00f180554b3a0dfddd59c /infra/translate-utils | |
parent | 054eb07de938df56000a8fc5cb41cb77f84bf2b5 (diff) |
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 <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-utils')
3 files changed, 45 insertions, 11 deletions
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<S extends SubtreeManager<? extends DataObject>, R> implements ModifiableSubtreeManagerRegistryBuilder<S>, SubtreeManagerRegistryBuilder<R> { @@ -64,6 +65,12 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder<S extends Sub return this; } + @Override + public ModifiableSubtreeManagerRegistryBuilder<S> 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)); @@ -110,6 +117,12 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder<S extends Sub } @Override + public ModifiableSubtreeManagerRegistryBuilder<S> wildcardedSubtreeAddBefore(@Nonnull final S handler, + @Nonnull final InstanceIdentifier<?> relatedType) { + return addBefore(getWildcardedSubtreeHandler(handler), relatedType); + } + + @Override public AbstractSubtreeManagerRegistryBuilderBuilder<S, R> subtreeAddBefore( @Nonnull final Set<InstanceIdentifier<?>> handledChildren, @Nonnull final S handler, @@ -117,9 +130,17 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder<S extends Sub return addBefore(getSubtreeHandler(handledChildren, handler), relatedTypes); } + @Override + public ModifiableSubtreeManagerRegistryBuilder<S> wildcardedSubtreeAddBefore(@Nonnull final S handler, + @Nonnull final Collection<InstanceIdentifier<?>> relatedTypes) { + return addBefore(getWildcardedSubtreeHandler(handler), relatedTypes); + } + protected abstract S getSubtreeHandler(@Nonnull final Set<InstanceIdentifier<?>> handledChildren, @Nonnull final S handler); + protected abstract S getWildcardedSubtreeHandler(@Nonnull final S handler); + /** * Add handler with relationship: to be executed after handler handling relatedType. */ @@ -163,6 +184,12 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder<S extends Sub } @Override + public ModifiableSubtreeManagerRegistryBuilder<S> wildcardedSubtreeAddAfter(@Nonnull final S handler, + @Nonnull final InstanceIdentifier<?> relatedType) { + return addAfter(getWildcardedSubtreeHandler(handler), relatedType); + } + + @Override public AbstractSubtreeManagerRegistryBuilderBuilder<S, R> subtreeAddAfter( @Nonnull final Set<InstanceIdentifier<?>> handledChildren, @Nonnull final S handler, @@ -170,6 +197,11 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder<S extends Sub return addAfter(getSubtreeHandler(handledChildren, handler), relatedTypes); } + @Override + public ModifiableSubtreeManagerRegistryBuilder<S> wildcardedSubtreeAddAfter(@Nonnull S handler, @Nonnull Collection<InstanceIdentifier<?>> relatedTypes) { + return addAfter(getWildcardedSubtreeHandler(handler), relatedTypes); + } + protected ImmutableMap<InstanceIdentifier<?>, S> getMappedHandlers() { final ImmutableMap.Builder<InstanceIdentifier<?>, 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<D extends DataObject> implements Writer<D> { 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. */ |