protected void cleanUpIncidentalResourcesOfDeadNodes()

in aliyun-ecs/src/main/java/org/jclouds/aliyun/ecs/compute/ECSComputeService.java [103:143]


   protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
      for (NodeMetadata deadNode : deadNodes) {
         RegionAndId regionAndId = RegionAndId.fromSlashEncoded(deadNode.getId());
         Set<String> tags = deadNode.getTags();
         String vSwitchId = extractVSwitchId(tags);
         VSwitch vSwitch = context.unwrapApi(ECSComputeServiceApi.class).vSwitchApi().list(deadNode.getLocation().getId(), ListVSwitchesOptions.Builder.vSwitchId(vSwitchId)).first().orNull();
         String vpcId = vSwitch.vpcId();

         try {
            cleanupResources.cleanupNode(regionAndId);
         } catch (Exception ex) {
            logger.warn(ex, "Error cleaning up resources for node %s", deadNode);
         }

         List<SecurityGroup> securityGroups = cleanupResources.findOrphanedSecurityGroups(regionAndId.regionId(), deadNode.getGroup());
         for (SecurityGroup securityGroup : securityGroups) {
            logger.debug(">> destroying security group %s ...", securityGroup.id());
            if (cleanupResources.cleanupSecurityGroupIfOrphaned(regionAndId.regionId(), securityGroup.id())) {
               logger.debug(">> security group: (%s) has been deleted.", securityGroup.id());
            } else {
               logger.warn(">> security group: (%s) has not been deleted.", securityGroup.id());
            }
         }

         // FIXME not sure it is correct to always delete vSwitch and VPC_PREFIX
         logger.debug(">> destroying vSwitch %s ...", vSwitchId);
         if (cleanupResources.cleanupVSwitchIfOrphaned(regionAndId.regionId(), vSwitchId)) {
            logger.debug(">> vSwitch: (%s) has been deleted.", vSwitchId);
         } else {
            logger.warn(">> vSwitch: (%s) has not been deleted.", vSwitchId);
         }

         logger.debug(">> destroying vpc %s ...", vpcId);
         try {
            cleanupResources.cleanupVPCIfOrphaned(regionAndId.regionId(), vpcId);
            logger.debug(">> VPC_PREFIX: (%s) has been deleted.", vpcId);
         } catch (IllegalArgumentException e) {
            logger.warn(">> VPC_PREFIX: (%s) has not been deleted.", vpcId);
         }
      }
   }