diff --git a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgent.groovy b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgent.groovy index fb912b265c1..23c9231ad79 100644 --- a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgent.groovy +++ b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgent.groovy @@ -82,9 +82,9 @@ class AmazonApplicationLoadBalancerCachingAgent extends AbstractAmazonLoadBalanc @Override Optional> getCacheKeyPatterns() { - return [ + return Optional.of([ (LOAD_BALANCERS.ns): Keys.getLoadBalancerKey('*', account.name, region, 'vpc-????????', '*') - ] + ]) } @Override diff --git a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgent.groovy b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgent.groovy index ee423947b19..49a26f7dfa7 100644 --- a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgent.groovy +++ b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgent.groovy @@ -17,7 +17,12 @@ package com.netflix.spinnaker.clouddriver.aws.provider.agent import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing -import com.amazonaws.services.elasticloadbalancing.model.* +import com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancerAttributesRequest +import com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest +import com.amazonaws.services.elasticloadbalancing.model.DescribeTagsRequest +import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerAttributes +import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription +import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerNotFoundException import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.ObjectMapper import com.netflix.spectator.api.Registry @@ -32,9 +37,10 @@ import com.netflix.spinnaker.clouddriver.aws.edda.EddaApi import com.netflix.spinnaker.clouddriver.aws.security.AmazonClientProvider import com.netflix.spinnaker.clouddriver.aws.security.NetflixAmazonCredentials import com.netflix.spinnaker.clouddriver.cache.OnDemandAgent -import com.netflix.spinnaker.clouddriver.model.LoadBalancer -import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.* +import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.INSTANCES +import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.LOAD_BALANCERS +import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.ON_DEMAND class AmazonLoadBalancerCachingAgent extends AbstractAmazonLoadBalancerCachingAgent { @@ -55,9 +61,9 @@ class AmazonLoadBalancerCachingAgent extends AbstractAmazonLoadBalancerCachingAg @Override Optional> getCacheKeyPatterns() { - return [ + return Optional.of([ (LOAD_BALANCERS.ns): Keys.getLoadBalancerKey('*', account.name, region, 'vpc-????????', null) - ] + ]) } @Override diff --git a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgent.groovy b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgent.groovy index 36c163210bb..b57f13b7347 100644 --- a/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgent.groovy +++ b/clouddriver-aws/src/main/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgent.groovy @@ -141,9 +141,9 @@ class ClusterCachingAgent implements CachingAgent, OnDemandAgent, AccountAware, @Override Optional> getCacheKeyPatterns() { - return [ + return Optional.of([ (SERVER_GROUPS.ns): Keys.getServerGroupKey('*', '*', account.name, region) - ] + ]) } static class AmazonClients { diff --git a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgentSpec.groovy b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgentSpec.groovy index 6b329a25500..0303ad46d34 100644 --- a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgentSpec.groovy +++ b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonApplicationLoadBalancerCachingAgentSpec.groovy @@ -112,6 +112,20 @@ class AmazonApplicationLoadBalancerCachingAgentSpec extends Specification { [taggify(".*", "ciao")] | [taggify("hello", ".*")] | buildCacheKeys([]) } + void "should get correct cache key pattern"() { + given: + def agent = getAgent() + + when: + def cacheKeyPatterns = agent.getCacheKeyPatterns() + + then: + cacheKeyPatterns.isPresent() + cacheKeyPatterns.get() == [ + loadBalancers: buildCacheKey("*:vpc-????????:*") + ] + } + private static final Map> filterableLBs() { return [ (new LoadBalancer().withLoadBalancerName("test-hello-tag-value").withLoadBalancerArn(buildELBArn("test-hello-tag-value"))) : diff --git a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgentSpec.groovy b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgentSpec.groovy index c2b41bea7c8..059d9ce4c74 100644 --- a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgentSpec.groovy +++ b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonLoadBalancerCachingAgentSpec.groovy @@ -95,6 +95,20 @@ class AmazonLoadBalancerCachingAgentSpec extends Specification { [taggify(".*", "ciao")] | [taggify("hello", ".*")] | buildCacheKeys([]) } + void "should get correct cache key pattern"() { + given: + def agent = getAgent() + + when: + def cacheKeyPatterns = agent.getCacheKeyPatterns() + + then: + cacheKeyPatterns.isPresent() + cacheKeyPatterns.get() == [ + loadBalancers: buildCacheKey("*:vpc-????????") + ] + } + private static final Map> filterableLBs() { return [ (new LoadBalancerDescription().withLoadBalancerName("test-hello-tag-value")): diff --git a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonSecurityGroupCachingAgentSpec.groovy b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonSecurityGroupCachingAgentSpec.groovy index 8377b68eb9c..d00050a3b18 100644 --- a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonSecurityGroupCachingAgentSpec.groovy +++ b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/AmazonSecurityGroupCachingAgentSpec.groovy @@ -98,4 +98,18 @@ class AmazonSecurityGroupCachingAgentSpec extends Specification { cache.cacheResults[SECURITY_GROUPS.ns] == existingCacheData } + + void "should get correct cache key pattern"() { + given: + def agent = getAgent() + + when: + def cacheKeyPatterns = agent.getCacheKeyPatterns() + + then: + cacheKeyPatterns.isPresent() + cacheKeyPatterns.get() == [ + (SECURITY_GROUPS.ns): "aws:securityGroups:*:*:region:account:*" + ] + } } diff --git a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgentSpec.groovy b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgentSpec.groovy index 6dc21576eec..fbc7699c625 100644 --- a/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgentSpec.groovy +++ b/clouddriver-aws/src/test/groovy/com/netflix/spinnaker/clouddriver/aws/provider/agent/ClusterCachingAgentSpec.groovy @@ -37,6 +37,8 @@ import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.SERVER_GROUPS + class ClusterCachingAgentSpec extends Specification { static String region = 'region' static String accountName = 'accountName' @@ -216,6 +218,20 @@ class ClusterCachingAgentSpec extends Specification { [taggify(".*", "ciao")] | [taggify("hello", ".*")] | [] } + void "should get correct cache key pattern"() { + given: + def agent = getAgent() + + when: + def cacheKeyPatterns = agent.getCacheKeyPatterns() + + then: + cacheKeyPatterns.isPresent() + cacheKeyPatterns.get() == [ + (SERVER_GROUPS.ns): "aws:serverGroups:*:accountName:region:*" + ] + } + private static final List filterableASGs = [ new AutoScalingGroup() .withAutoScalingGroupName("test-hello-tag-value")