diff --git a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/search/ServerGroupKeyProcessor.groovy b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/search/ServerGroupKeyProcessor.groovy index f90fdbc41e1..0772028b97c 100644 --- a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/search/ServerGroupKeyProcessor.groovy +++ b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/search/ServerGroupKeyProcessor.groovy @@ -1,21 +1,20 @@ package com.netflix.spinnaker.clouddriver.aws.search +import com.netflix.spinnaker.cats.cache.Cache +import com.netflix.spinnaker.cats.cache.CacheData +import com.netflix.spinnaker.cats.cache.RelationshipCacheFilter import com.netflix.spinnaker.clouddriver.aws.data.Keys -import com.netflix.spinnaker.clouddriver.aws.model.AmazonServerGroup -import com.netflix.spinnaker.clouddriver.aws.provider.view.AmazonClusterProvider import com.netflix.spinnaker.clouddriver.cache.KeyProcessor -import com.netflix.spinnaker.clouddriver.model.view.ServerGroupViewModelPostProcessor import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component +import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.SERVER_GROUPS + @Component("AmazonServerGroupKeyProcessor") class ServerGroupKeyProcessor implements KeyProcessor { @Autowired - AmazonClusterProvider amazonClusterProvider - - @Autowired(required = false) - ServerGroupViewModelPostProcessor serverGroupViewModelPostProcessor + private final Cache cacheView @Override Boolean canProcess(String type) { @@ -30,6 +29,9 @@ class ServerGroupKeyProcessor implements KeyProcessor { String region = parsed['region'] String name = parsed['serverGroup'] - return amazonClusterProvider.getServerGroup(account, region, name) != null + String serverGroupKey = Keys.getServerGroupKey(name, account, region) + CacheData serverGroupData = cacheView.get(SERVER_GROUPS.ns, serverGroupKey, RelationshipCacheFilter.none()) + + return serverGroupData != null; } } diff --git a/clouddriver-core/src/main/groovy/com/netflix/spinnaker/clouddriver/cache/CatsSearchProvider.groovy b/clouddriver-core/src/main/groovy/com/netflix/spinnaker/clouddriver/cache/CatsSearchProvider.groovy index c8e1ad6aaac..5f414bf51c4 100644 --- a/clouddriver-core/src/main/groovy/com/netflix/spinnaker/clouddriver/cache/CatsSearchProvider.groovy +++ b/clouddriver-core/src/main/groovy/com/netflix/spinnaker/clouddriver/cache/CatsSearchProvider.groovy @@ -157,7 +157,7 @@ class CatsSearchProvider implements SearchProvider { resultSet } - private List findMatches(String q, List toQuery, Map filters) { + private List findMatches(String q, List cachesToQuery, Map filters) { if (!q && keyParsers) { // no keyword search so find sensible default value to set for searching @@ -173,22 +173,26 @@ class CatsSearchProvider implements SearchProvider { log.info("no query string specified, looked for sensible default and found: ${q}") } - log.info("Querying ${toQuery} for term: ${q}") + log.info("Querying ${cachesToQuery} for term: ${q}") String normalizedWord = q.toLowerCase() - List matches = new ArrayList() - toQuery.each { String cache -> - matches.addAll(cacheView.filterIdentifiers(cache, "*:${cache}:*${normalizedWord}*").findAll { String key -> - try { - - // if the key represented in the cache doesn't actually exist, don't process it - if (keyProcessors && !keyProcessors.any { it.canProcess(cache) && it.exists(key) }) { - log.warn("found ${cache} key that did not exist: ${key}") - return false; - } + List matches = cachesToQuery.collect { String cache -> + List keyProcessors = (this.keyProcessors ?: []).findAll { it.canProcess(cache) } + + // if the key represented in the cache doesn't actually exist, don't process it + Closure keyExists = { String key -> + boolean exists = keyProcessors.empty || keyProcessors.any { it.exists(key) } + if (!exists) { + log.warn("found ${cache} key that did not exist: ${key}") + } + return exists + } + Closure filtersMatch = { String key -> + try { if (!filters) { return true } + if (keyParsers) { KeyParser parser = keyParsers.find { it.cloudProvider == filters.cloudProvider && it.canParseType(cache) } if (parser) { @@ -205,8 +209,16 @@ class CatsSearchProvider implements SearchProvider { } catch (Exception e) { log.warn("Failed on $cache:$key", e) } - }) - } + } + + Collection identifiers = cacheView + .filterIdentifiers(cache, "*:${cache}:*${normalizedWord}*") + .findAll(keyExists) + .findAll(filtersMatch) + + return identifiers + }.flatten() + matches.sort { String a, String b -> def aKey = a.toLowerCase().substring(a.indexOf(':')) def bKey = b.toLowerCase().substring(b.indexOf(':'))