From 3bd0a6a0bcd1cec006500c60de20eb0904697263 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 21 Mar 2017 13:38:21 +0100 Subject: HONEYCOMB-348: include dump params in entity key Change-Id: I18b2ea3c897c467740f19bf346d13240aac458ac Signed-off-by: Marek Gradzki --- .../translate/util/read/cache/CacheKeyFactory.java | 7 ++++--- .../translate/util/read/cache/DumpCacheManager.java | 6 +++--- .../cache/TypeAwareIdentifierCacheKeyFactory.java | 21 +++++++++++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'infra/translate-utils/src/main') diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java index bf4659e89..0f045e5f7 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/CacheKeyFactory.java @@ -17,18 +17,19 @@ package io.fd.honeycomb.translate.util.read.cache; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Provides keys for provided {@code InstanceIdentifier} */ -public interface CacheKeyFactory { +public interface CacheKeyFactory { /** - * Construct key accordingly to provided {@code InstanceIdentifier} + * Construct key accordingly to provided {@code InstanceIdentifier} and dumpParams */ @Nonnull - String createKey(@Nonnull final InstanceIdentifier actualContextIdentifier); + String createKey(@Nonnull final InstanceIdentifier actualContextIdentifier, @Nullable final U dumpParams); /** * Returns type of data, for which is this factory creating keys diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java index adcd32e0c..d3cfd415a 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java @@ -42,7 +42,7 @@ public final class DumpCacheManager { private final EntityDumpExecutor dumpExecutor; private final EntityDumpPostProcessingFunction postProcessor; - private final CacheKeyFactory cacheKeyFactory; + private final CacheKeyFactory cacheKeyFactory; private final Class acceptOnly; private DumpCacheManager(DumpCacheManagerBuilder builder) { @@ -66,7 +66,7 @@ public final class DumpCacheManager { @Nonnull final ModificationCache cache, final U dumpParams) throws ReadFailedException { - final String entityKey = this.cacheKeyFactory.createKey(identifier); + final String entityKey = this.cacheKeyFactory.createKey(identifier, dumpParams); // this key binding to every log has its logic ,because every customizer have its own cache manager and if // there is need for debugging/fixing some complex call with a lot of data,you can get lost in those logs LOG.debug("Loading dump for KEY[{}]", entityKey); @@ -120,7 +120,7 @@ public final class DumpCacheManager { /** * Key providing unique(type-aware) keys. */ - public DumpCacheManagerBuilder withCacheKeyFactory(@Nonnull final CacheKeyFactory cacheKeyFactory) { + public DumpCacheManagerBuilder withCacheKeyFactory(@Nonnull final CacheKeyFactory cacheKeyFactory) { this.cacheKeyFactory = cacheKeyFactory; return this; } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java index ba4e7e493..3cefedb95 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactory.java @@ -20,11 +20,13 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem; +import com.google.common.annotations.VisibleForTesting; import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -32,9 +34,11 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Factory providing cache keys to easier switching between scopes of caching */ -public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory { +public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory { private static final String KEY_PARTS_SEPARATOR = "|"; + @VisibleForTesting + protected static final String NO_PARAMS_KEY = "NO_PARAMS"; // should be Set>>, but that's not possible for wildcards private final Set> additionalKeyTypes; @@ -78,14 +82,15 @@ public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory } @Override - public String createKey(@Nonnull final InstanceIdentifier actualContextIdentifier) { + public String createKey(@Nonnull final InstanceIdentifier actualContextIdentifier, @Nullable final U dumpParams) { checkNotNull(actualContextIdentifier, "Cannot construct key for null InstanceIdentifier"); // easiest case when only simple key is needed if (additionalKeyTypes.isEmpty()) { return String - .join(KEY_PARTS_SEPARATOR, type.getTypeName(), actualContextIdentifier.getTargetType().toString()); + .join(KEY_PARTS_SEPARATOR, type.getTypeName(), params(dumpParams), + actualContextIdentifier.getTargetType().toString()); } checkArgument(isUniqueKeyConstructable(actualContextIdentifier), @@ -95,7 +100,15 @@ public final class TypeAwareIdentifierCacheKeyFactory implements CacheKeyFactory // joins unique key in form : type | additional keys | actual context return String .join(KEY_PARTS_SEPARATOR, type.getTypeName(), additionalKeys(actualContextIdentifier), - actualContextIdentifier.getTargetType().toString()); + params(dumpParams), actualContextIdentifier.getTargetType().toString()); + } + + private String params(final U dumpParams) { + if (dumpParams == null) { + return NO_PARAMS_KEY; + } else { + return String.valueOf(dumpParams.hashCode()); + } } @Override -- cgit 1.2.3-korg