nacx commented on this pull request. Thanks, @trevorflanagan! Just some minor comments!
> +import static java.lang.String.format; +import static org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.generateFirewallRuleName; +import static org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForServerState; + +@Singleton +public class CleanupServer implements Function<String, Boolean> { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final DimensionDataCloudControlApi api; + private final Timeouts timeouts; + + @Inject + public CleanupServer(final DimensionDataCloudControlApi api, final Timeouts timeouts) { Remove the public modifier > + 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) { + if (natRule.state().isNormal()) { + networkApi.deleteNatRule(natRule.id()); Surround with a try/catch and log a warning, for a best-effort cleanup? Otherwise, it will stop deleting stuff here if this call fails. (Apply the same criteria to the other cleanup calls). > + } + + @Override + 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()) { Just return false if it is not normal and continue the rest of the method "outside" the conditional. It is easier to read. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/jclouds/jclouds-labs/pull/422#pullrequestreview-80498909