diff --git a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/Cache.java b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/Cache.java index aa17b9fc06f..82f1f39b751 100644 --- a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/Cache.java +++ b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/Cache.java @@ -23,11 +23,6 @@ /** Cache provides view access to data keyed by type and identifier. */ public interface Cache { - enum StoreType { - REDIS, - IN_MEMORY, - SQL - } /** * Gets a single item from the cache by type and id @@ -122,10 +117,18 @@ Collection getAll( */ Collection getAll(String type, String... identifiers); + /** Returns whether or not the three {@code getAllByApplication} methods are supported */ + default boolean supportsGetAllByApplication() { + return false; + } + /** * Retrieves all items for the specified type associated with the provided application. Requires a * storeType with secondary indexes and support in the type's caching agent. * + *

Clients should check {@link #supportsGetAllByApplication()} to check if this method is + * supported before calling it. + * * @param type the type for which to retrieve items * @param application the application name * @return the matching items, keyed by type @@ -138,6 +141,9 @@ default Map> getAllByApplication(String type, Stri * Retrieves all items for the specified type associated with the provided application. Requires a * storeType with secondary indexes and support in the type's caching agent. * + *

Clients should check {@link #supportsGetAllByApplication()} to check if this method is + * supported before calling it. + * * @param type the type for which to retrieve items * @param application the application name * @param cacheFilter the cacheFilter to govern which relationships to fetch @@ -152,6 +158,9 @@ default Map> getAllByApplication( * Retrieves all items for the specified type associated with the provided application. Requires a * storeType with secondary indexes and support in the type's caching agent. * + *

Clients should check {@link #supportsGetAllByApplication()} to check if this method is + * supported before calling it. + * * @param types collection of types for which to retrieve items * @param application the application name * @param cacheFilters cacheFilters to govern which relationships to fetch, as type to filter @@ -161,13 +170,4 @@ default Map> getAllByApplication( Collection types, String application, Map cacheFilters) { throw new UnsupportedCacheMethodException("Method only implemented for StoreType.SQL"); } - - /** - * Get backing store type for Cache implementation - * - * @return the backing StoreType - */ - default StoreType storeType() { - return StoreType.REDIS; - } } diff --git a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/CompositeCache.java b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/CompositeCache.java index a79bfd60f3e..fcf6e100ead 100644 --- a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/CompositeCache.java +++ b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/cache/CompositeCache.java @@ -17,7 +17,6 @@ package com.netflix.spinnaker.cats.cache; import java.util.*; -import java.util.stream.Collectors; /** A cache that provides a unified view of multiples, merging items from each cache together. */ public class CompositeCache implements Cache { @@ -28,8 +27,9 @@ public CompositeCache(Collection caches) { this.caches = caches; } - public Set getStoreTypes() { - return caches.stream().map(c -> ((Cache) c).storeType()).collect(Collectors.toSet()); + @Override + public boolean supportsGetAllByApplication() { + return caches.stream().allMatch(Cache::supportsGetAllByApplication); } @Override diff --git a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/mem/InMemoryCache.java b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/mem/InMemoryCache.java index 6b15224f41c..290a55fa4d1 100644 --- a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/mem/InMemoryCache.java +++ b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/mem/InMemoryCache.java @@ -39,11 +39,6 @@ public class InMemoryCache implements WriteableCache { private ConcurrentMap> typeMap = new ConcurrentHashMap<>(); - @Override - public StoreType storeType() { - return StoreType.IN_MEMORY; - } - @Override public void merge(String type, CacheData cacheData) { merge(getOrCreate(type, cacheData.getId()), cacheData); diff --git a/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/SqlProviderCache.kt b/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/SqlProviderCache.kt index 288ab4d550b..0a9fdfb12ca 100644 --- a/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/SqlProviderCache.kt +++ b/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/SqlProviderCache.kt @@ -1,8 +1,6 @@ package com.netflix.spinnaker.cats.sql import com.netflix.spinnaker.cats.agent.CacheResult -import com.netflix.spinnaker.cats.cache.Cache.StoreType -import com.netflix.spinnaker.cats.cache.Cache.StoreType.SQL import com.netflix.spinnaker.cats.cache.CacheData import com.netflix.spinnaker.cats.cache.CacheFilter import com.netflix.spinnaker.cats.cache.DefaultCacheData @@ -30,8 +28,6 @@ class SqlProviderCache(private val backingStore: WriteableCache) : ProviderCache } } - override fun storeType(): StoreType = SQL - /** * Filters the supplied list of identifiers to only those that exist in the cache. * @@ -82,6 +78,10 @@ class SqlProviderCache(private val backingStore: WriteableCache) : ProviderCache return backingStore.getAll(type, identifiers, cacheFilter) } + override fun supportsGetAllByApplication(): Boolean { + return true + } + override fun getAllByApplication(type: String, application: String): Map> { return getAllByApplication(type, application, null) } diff --git a/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/cache/SqlCache.kt b/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/cache/SqlCache.kt index 423bc1ae84b..d1c8aece19e 100644 --- a/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/cache/SqlCache.kt +++ b/cats/cats-sql/src/main/kotlin/com/netflix/spinnaker/cats/sql/cache/SqlCache.kt @@ -1,8 +1,6 @@ package com.netflix.spinnaker.cats.sql.cache import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.cats.cache.Cache.StoreType -import com.netflix.spinnaker.cats.cache.Cache.StoreType.SQL import com.netflix.spinnaker.cats.cache.CacheData import com.netflix.spinnaker.cats.cache.CacheFilter import com.netflix.spinnaker.cats.cache.DefaultCacheData @@ -76,8 +74,6 @@ class SqlCache( log.info("Configured for $name") } - override fun storeType(): StoreType = SQL - /** * Only evicts cache records but not relationship rows */ @@ -267,6 +263,10 @@ class SqlCache( return getAll(type, ids) } + override fun supportsGetAllByApplication(): Boolean { + return true + } + override fun getAllByApplication( type: String, application: String, diff --git a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/view/AmazonClusterProvider.groovy b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/view/AmazonClusterProvider.groovy index 214d814138b..3e91769dea0 100644 --- a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/view/AmazonClusterProvider.groovy +++ b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/view/AmazonClusterProvider.groovy @@ -21,7 +21,6 @@ import com.netflix.frigga.ami.AppVersion import com.netflix.spinnaker.cats.cache.Cache import com.netflix.spinnaker.cats.cache.CacheData import com.netflix.spinnaker.cats.cache.CacheFilter -import com.netflix.spinnaker.cats.cache.CompositeCache import com.netflix.spinnaker.cats.cache.RelationshipCacheFilter import com.netflix.spinnaker.clouddriver.aws.AmazonCloudProvider import com.netflix.spinnaker.clouddriver.aws.data.Keys @@ -34,7 +33,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component -import static com.netflix.spinnaker.cats.cache.Cache.StoreType.SQL import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.* @Component @@ -259,12 +257,7 @@ class AmazonClusterProvider implements ClusterProvider, ServerGro Collection clusters - // TODO: remove special casing for sql vs. redis; possibly via dropping redis support in the future - if ((includeDetails && sqlEnabled) && - ((cacheView instanceof CompositeCache && - (cacheView as CompositeCache).getStoreTypes().every { (it == SQL) }) || - (cacheView.storeType() == SQL)) - ) { + if (includeDetails && cacheView.supportsGetAllByApplication()) { clusters = allClustersByApplication(applicationName) } else { clusters = translateClusters(resolveRelationshipData(application, CLUSTERS.ns), includeDetails)