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
65ba26eca7
commit
624e4cb6af
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue