Cleanup extraneous resources

This was not being called as doDestroyNode returns once node deleted.

Change based on similar code on gce compute provider
This commit is contained in:
Duncan Grant 2017-08-24 13:11:47 +01:00 committed by Andrea Turli
parent b38ce8d7b3
commit 4e66420997
1 changed files with 27 additions and 0 deletions

View File

@ -16,9 +16,12 @@
*/
package org.jclouds.azurecompute.arm.compute;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Sets.newHashSet;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.all;
import java.util.Map;
import java.util.Map.Entry;
@ -124,4 +127,28 @@ public class AzureComputeService extends BaseComputeService {
cleanupResources.deleteResourceGroupIfEmpty(resourceGroup);
}
}
@Override
public void destroyNode(String id) {
// Azure ARM does not return TERMINATED nodes, so in practice no node will never reach the TERMINATED
// state, and the deleted nodes will never be returned.
// In order to be able to clean up the resources associated to the deleted nodes, we have to retrieve
// the details of the nodes before deleting them.
NodeMetadata nodeMetadataBeforeDelete = getNodeMetadata(id);
super.destroyNode(id);
//Node metadata is null after deletion but we still need to clean up incidental resources
cleanUpIncidentalResourcesOfDeadNodes(ImmutableSet.of(nodeMetadataBeforeDelete));
}
@Override
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<? super NodeMetadata> filter) {
// Azure ARM does not return TERMINATED nodes, so in practice no node will never reach the TERMINATED
// state, and the deleted nodes will never be returned.
// In order to be able to clean up the resources associated to the deleted nodes, we have to retrieve
// the details of the nodes before deleting them.
Set<? extends NodeMetadata> nodes = newHashSet(filter(listNodesDetailsMatching(all()), filter));
super.destroyNodesMatching(filter); // This returns an empty list (a list of null elements) in Azure ARM, as the api does not return deleted nodes
cleanUpIncidentalResourcesOfDeadNodes(nodes);
return nodes;
}
}