Issue 899:NPE on cleanUpIncidentalResourcesOfDeadNodes

This commit is contained in:
Adrian Cole 2012-04-08 22:23:28 -06:00
parent 32aaa4981f
commit 27ca6445a4
2 changed files with 16 additions and 6 deletions

View File

@ -32,7 +32,6 @@ import static org.jclouds.compute.predicates.NodePredicates.all;
import static org.jclouds.concurrent.FutureIterables.awaitCompletion; import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
@ -82,6 +81,7 @@ import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.domain.LoginCredentials.Builder;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statement;
@ -225,9 +225,10 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void destroyNode(final String id) { public void destroyNode(String id) {
NodeMetadata destroyedNode = doDestroyNode(id); NodeMetadata destroyedNodeOrNull = doDestroyNode(id);
cleanUpIncidentalResourcesOfDeadNodes(Collections.singleton(destroyedNode)); if (destroyedNodeOrNull != null)
cleanUpIncidentalResourcesOfDeadNodes(ImmutableSet.of(destroyedNodeOrNull));
} }
/** /**
@ -236,7 +237,7 @@ public class BaseComputeService implements ComputeService {
@Override @Override
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) { public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> destroying nodes matching(%s)", filter); logger.debug(">> destroying nodes matching(%s)", filter);
Set<NodeMetadata> set = newLinkedHashSet(transformParallel(nodesMatchingFilterAndNotTerminated(filter), Set<NodeMetadata> set = newLinkedHashSet(filter(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, Future<NodeMetadata>>() { new Function<NodeMetadata, Future<NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping // TODO make an async interface instead of re-wrapping
@ -244,6 +245,7 @@ public class BaseComputeService implements ComputeService {
public Future<NodeMetadata> apply(final NodeMetadata from) { public Future<NodeMetadata> apply(final NodeMetadata from) {
return executor.submit(new Callable<NodeMetadata>() { return executor.submit(new Callable<NodeMetadata>() {
@Nullable
@Override @Override
public NodeMetadata call() throws Exception { public NodeMetadata call() throws Exception {
doDestroyNode(from.getId()); doDestroyNode(from.getId());
@ -257,13 +259,19 @@ public class BaseComputeService implements ComputeService {
}); });
} }
}, executor, null, logger, "destroyNodesMatching(" + filter + ")")); }, executor, null, logger, "destroyNodesMatching(" + filter + ")"), notNull()));
logger.debug("<< destroyed(%d)", set.size()); logger.debug("<< destroyed(%d)", set.size());
cleanUpIncidentalResourcesOfDeadNodes(set); cleanUpIncidentalResourcesOfDeadNodes(set);
return set; return set;
} }
/**
*
* @param id
* @return node that was deleted or null if it wasn't found
*/
@Nullable
protected NodeMetadata doDestroyNode(final String id) { protected NodeMetadata doDestroyNode(final String id) {
checkNotNull(id, "id"); checkNotNull(id, "id");
logger.debug(">> destroying node(%s)", id); logger.debug(">> destroying node(%s)", id);

View File

@ -19,6 +19,7 @@
package org.jclouds.compute.strategy; package org.jclouds.compute.strategy;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.javax.annotation.Nullable;
/** /**
* terminates the node * terminates the node
@ -31,6 +32,7 @@ public interface DestroyNodeStrategy {
* *
* @return null if the node wasn't found * @return null if the node wasn't found
*/ */
@Nullable
NodeMetadata destroyNode(String id); NodeMetadata destroyNode(String id);
} }