You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2017/08/25 07:19:50 UTC

jclouds-labs git commit: Cleanup extraneous resources

Repository: jclouds-labs
Updated Branches:
  refs/heads/master 515f9b5f1 -> 3a63007f4


Cleanup extraneous resources

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

Change based on similar code on gce compute provider


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/3a63007f
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/3a63007f
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/3a63007f

Branch: refs/heads/master
Commit: 3a63007f4c6e55bd34ad16c32c71798e7fa4c35d
Parents: 515f9b5
Author: Duncan Grant <du...@cloudsoftcorp.com>
Authored: Thu Aug 24 13:11:47 2017 +0100
Committer: Andrea Turli <an...@gmail.com>
Committed: Fri Aug 25 09:09:44 2017 +0200

----------------------------------------------------------------------
 .../arm/compute/AzureComputeService.java        | 27 ++++++++++++++++++++
 1 file changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3a63007f/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeService.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeService.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeService.java
index dcb9c44..e82110a 100644
--- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeService.java
+++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeService.java
@@ -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;
+   }
 }