mirror of https://github.com/apache/jclouds.git
first attempt at fixing/refactoring destroyNodesWithTag for EC2
This commit is contained in:
parent
7ccc18c0f8
commit
bb52dfd9a2
|
@ -18,15 +18,21 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.compute;
|
package org.jclouds.aws.ec2.compute;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.aws.ec2.EC2Client;
|
import org.jclouds.aws.ec2.EC2Client;
|
||||||
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromNodeOrDefault;
|
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromNodeOrDefault;
|
||||||
|
@ -41,6 +47,7 @@ import org.jclouds.compute.domain.NodeState;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -110,15 +117,14 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
@Override
|
@Override
|
||||||
public void destroyNodesWithTag(String tag) {
|
public void destroyNodesWithTag(String tag) {
|
||||||
super.destroyNodesWithTag(tag);
|
super.destroyNodesWithTag(tag);
|
||||||
Iterable<? extends NodeMetadata> nodes = Iterables.filter(listNodesWithTag(tag),
|
Set<String> regions = Sets.newHashSet(Iterables.transform(listNodesWithTag(tag),
|
||||||
new Predicate<NodeMetadata>() {
|
new Function<NodeMetadata, String>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(NodeMetadata input) {
|
public String apply(@Nullable NodeMetadata nodeMetadata) {
|
||||||
return input.getState() == NodeState.TERMINATED;
|
return getRegionFromNodeOrDefault.apply(nodeMetadata);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
if (Iterables.size(nodes) > 0) {
|
for(String region : regions) {
|
||||||
String region = getRegionFromNodeOrDefault.apply(Iterables.get(nodes, 0));
|
|
||||||
deleteKeyPair(region, tag);
|
deleteKeyPair(region, tag);
|
||||||
deleteSecurityGroup(region, tag);
|
deleteSecurityGroup(region, tag);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue