JCLOUDS-1307: Invalidate SG on removal even if already externally deleted

This commit is contained in:
Svetoslav Neykov 2017-06-09 12:41:16 +03:00
parent 65ba26eca7
commit 624e4cb6af
No known key found for this signature in database
GPG Key ID: 979090BE59D0A896
2 changed files with 16 additions and 14 deletions

View File

@ -23,6 +23,7 @@ import static com.google.common.collect.Iterables.transform;
import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.ruleCidrMatches;
import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.ruleGroupMatches;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
@ -150,6 +151,7 @@ public class CloudStackSecurityGroupExtension implements SecurityGroupExtension
api.getSecurityGroupApi().getSecurityGroup(id);
if (group == null) {
invalidateCache(id);
return false;
}
@ -159,15 +161,17 @@ public class CloudStackSecurityGroupExtension implements SecurityGroupExtension
api.getSecurityGroupApi().deleteSecurityGroup(id);
// TODO find something better here maybe - hard to map zones to groups
for (Location location : locations.get()) {
groupCreator.invalidate(ZoneSecurityGroupNamePortsCidrs.builder()
.zone(location.getId())
.name(group.getName())
.build());
invalidateCache(id);
return true;
}
return true;
private void invalidateCache(String id) {
for (Map.Entry<ZoneAndName, org.jclouds.cloudstack.domain.SecurityGroup> sg : groupCreator.asMap().entrySet()) {
if (id.equals(sg.getValue().getId())) {
groupCreator.invalidate(sg.getKey());
break;
}
}
}
@Override

View File

@ -172,17 +172,15 @@ public class EC2SecurityGroupExtension implements SecurityGroupExtension {
String region = parts[0];
String groupName = parts[1];
boolean deleted = false;
if (!client.getSecurityGroupApi().get().describeSecurityGroupsInRegion(region, groupName).isEmpty()) {
client.getSecurityGroupApi().get().deleteSecurityGroupInRegion(region, groupName);
// TODO: test this clear happens
deleted = true;
}
groupCreator.invalidate(new RegionNameAndIngressRules(region, groupName, null, false, null));
return true;
return deleted;
}
return false;
}
@Override
public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());