in dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServer.java [67:136]
public Boolean apply(final String serverId) {
final ServerApi serverApi = api.getServerApi();
Server server = serverApi.getServer(serverId);
if (server == null) {
return true;
}
if (server.state().isFailed()) {
rollbackOperation(format("Server(%s) not deleted as it is in state(%s).", serverId, server.state()));
}
if (!server.state().isNormal()) {
return false;
}
String networkDomainId = server.networkInfo().networkDomainId();
final String internalIp = server.networkInfo().primaryNic().privateIpv4();
// delete nat rules associated to the server, if any
final NetworkApi networkApi = api.getNetworkApi();
List<NatRule> natRulesToBeDeleted = networkApi.listNatRules(networkDomainId).concat()
.filter(new Predicate<NatRule>() {
@Override
public boolean apply(NatRule natRule) {
return natRule.internalIp().equals(internalIp);
}
}).toList();
for (final NatRule natRule : natRulesToBeDeleted) {
attemptDeleteNatRule(serverId, networkApi, natRule);
Optional<PublicIpBlock> optionalPublicIpBlock = networkApi.listPublicIPv4AddressBlocks(networkDomainId)
.concat().firstMatch(new Predicate<PublicIpBlock>() {
@Override
public boolean apply(PublicIpBlock input) {
return input.baseIp().equals(natRule.externalIp());
}
});
if (optionalPublicIpBlock.isPresent()) {
attemptDeletePublicIpBlock(serverId, networkApi, optionalPublicIpBlock.get());
}
}
List<FirewallRule> firewallRulesToBeDeleted = networkApi.listFirewallRules(networkDomainId).concat()
.filter(new Predicate<FirewallRule>() {
@Override
public boolean apply(FirewallRule firewallRule) {
return firewallRule.name().equals(generateFirewallRuleName(serverId));
}
}).toList();
for (FirewallRule firewallRule : firewallRulesToBeDeleted) {
attemptDeleteFirewallRule(serverId, networkApi, firewallRule);
}
serverApi.powerOffServer(serverId);
String message = format("Server(%s) not terminated within %d ms.", serverId, timeouts.nodeTerminated);
if (!serverStoppedPredicate.apply(serverId)) {
throw new IllegalStateException(message);
}
serverApi.deleteServer(serverId);
String deleteFailureMessage = format("Server(%s) not deleted within %d ms.", serverId, timeouts.nodeTerminated);
if (!serverDeletedPredicate.apply(serverId)) {
throw new IllegalStateException(deleteFailureMessage);
}
return true;
}