mirror of https://github.com/apache/jclouds.git
JCLOUDS-1307: Invalidate SG on removal even if already externally deleted
This commit is contained in:
parent
502d749680
commit
a2863b2a3c
|
@ -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,17 +161,19 @@ 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;
|
||||
}
|
||||
|
||||
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
|
||||
public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
|
||||
checkNotNull(group, "group");
|
||||
|
|
|
@ -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
|
||||
groupCreator.invalidate(new RegionNameAndIngressRules(region, groupName, null, false, null));
|
||||
return true;
|
||||
deleted = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
groupCreator.invalidate(new RegionNameAndIngressRules(region, groupName, null, false, null));
|
||||
return deleted;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
|
||||
String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
|
||||
|
|
Loading…
Reference in New Issue