From 65ba26eca7d63b6b7cef70386f00425438318825 Mon Sep 17 00:00:00 2001 From: Svetoslav Neykov Date: Fri, 9 Jun 2017 12:41:16 +0300 Subject: [PATCH] JCLOUDS-1307: Invalidate SG on removal even if already externally deleted --- .../extensions/AWSEC2SecurityGroupExtension.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java index db1e8f24b4..6c10493d8d 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java @@ -24,6 +24,7 @@ import static com.google.common.collect.Iterables.transform; import javax.inject.Inject; import javax.inject.Named; +import java.util.Map; import java.util.Set; import com.google.common.base.Function; @@ -105,12 +106,17 @@ public class AWSEC2SecurityGroupExtension extends EC2SecurityGroupExtension { if (group != null) { client.getSecurityGroupApi().get().deleteSecurityGroupInRegionById(region, groupId); - // TODO: test this clear happens groupCreator.invalidate(new RegionNameAndIngressRules(region, group.getName(), null, false, null)); return true; + } else { + for (Map.Entry cachedSg : groupCreator.asMap().entrySet()) { + if (groupId.equals(cachedSg.getValue())) { + groupCreator.invalidate(cachedSg.getKey()); + break; + } + } + return false; } - - return false; } @Override