mirror of https://github.com/apache/jclouds.git
Better predicate signature for node operations
This commit is contained in:
parent
34b54ad163
commit
d98348d503
|
@ -103,7 +103,7 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
Iterable<? extends RunningInstance> instances = pollRunningInstances();
|
||||
Iterable<? extends NodeMetadata> nodes = filter(transform(filter(instances, notNull()),
|
||||
runningInstanceToNodeMetadata), and(notNull(), filter));
|
||||
|
|
|
@ -103,7 +103,7 @@ public interface ComputeService {
|
|||
/**
|
||||
* @return all nodes with one of the provided ids available to the current user.
|
||||
*/
|
||||
Set<? extends NodeMetadata> listNodesByIds(Iterable<String> ids);
|
||||
Set<? extends ComputeMetadata> listNodesByIds(Iterable<String> ids);
|
||||
|
||||
/**
|
||||
* The list locations command returns all the valid locations for nodes. A location has a scope,
|
||||
|
@ -197,7 +197,7 @@ public interface ComputeService {
|
|||
* @throws NoSuchElementException
|
||||
* if no nodes matched the predicate specified
|
||||
*/
|
||||
Set<? extends NodeMetadata> resumeNodesMatching(Predicate<NodeMetadata> filter);
|
||||
Set<? extends NodeMetadata> resumeNodesMatching(Predicate<? super NodeMetadata> filter);
|
||||
|
||||
/**
|
||||
* suspend the node, given its id. This will result in
|
||||
|
@ -227,7 +227,7 @@ public interface ComputeService {
|
|||
* @throws NoSuchElementException
|
||||
* if no nodes matched the predicate specified
|
||||
*/
|
||||
Set<? extends NodeMetadata> suspendNodesMatching(Predicate<NodeMetadata> filter);
|
||||
Set<? extends NodeMetadata> suspendNodesMatching(Predicate<? super NodeMetadata> filter);
|
||||
|
||||
/**
|
||||
* destroy the node, given its id. If it is the only node in a tag set, the dependent resources
|
||||
|
@ -242,7 +242,7 @@ public interface ComputeService {
|
|||
*
|
||||
* @return list of nodes destroyed
|
||||
*/
|
||||
Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter);
|
||||
Set<? extends NodeMetadata> destroyNodesMatching(Predicate<? super NodeMetadata> filter);
|
||||
|
||||
/**
|
||||
* reboot the node, given its id.
|
||||
|
@ -258,7 +258,7 @@ public interface ComputeService {
|
|||
* @throws NoSuchElementException
|
||||
* if no nodes matched the predicate specified
|
||||
*/
|
||||
Set<? extends NodeMetadata> rebootNodesMatching(Predicate<NodeMetadata> filter);
|
||||
Set<? extends NodeMetadata> rebootNodesMatching(Predicate<? super NodeMetadata> filter);
|
||||
|
||||
/**
|
||||
* Find a node by its id.
|
||||
|
@ -272,27 +272,27 @@ public interface ComputeService {
|
|||
* @param filter
|
||||
* how to select the nodes you are interested in details on.
|
||||
*/
|
||||
Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter);
|
||||
Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<? super NodeMetadata> filter);
|
||||
|
||||
/**
|
||||
*
|
||||
* @see ComputeService#runScriptOnNodesMatching(Predicate, Statement, RunScriptOptions)
|
||||
*/
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, String runScript)
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter, String runScript)
|
||||
throws RunScriptOnNodesException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see ComputeService#runScriptOnNodesMatching(Predicate, Statement, RunScriptOptions)
|
||||
*/
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter,
|
||||
Statement runScript) throws RunScriptOnNodesException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see ComputeService#runScriptOnNodesMatching(Predicate, Statement, RunScriptOptions)
|
||||
*/
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, String runScript,
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter, String runScript,
|
||||
RunScriptOptions options) throws RunScriptOnNodesException;
|
||||
|
||||
/**
|
||||
|
@ -313,7 +313,7 @@ public interface ComputeService {
|
|||
* @see org.jclouds.compute.predicates.NodePredicates#runningInGroup(String)
|
||||
* @see org.jclouds.scriptbuilder.domain.Statements
|
||||
*/
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
||||
Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter,
|
||||
Statement runScript, RunScriptOptions options) throws RunScriptOnNodesException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -256,7 +256,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
logger.debug(">> destroying nodes matching(%s)", filter);
|
||||
Set<NodeMetadata> destroyNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
|
||||
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
|
||||
|
@ -317,7 +317,7 @@ public class BaseComputeService implements ComputeService {
|
|||
// no-op; to be overridden
|
||||
}
|
||||
|
||||
Iterable<? extends NodeMetadata> nodesMatchingFilterAndNotTerminated(Predicate<NodeMetadata> filter) {
|
||||
Iterable<? extends NodeMetadata> nodesMatchingFilterAndNotTerminated(Predicate<? super NodeMetadata> filter) {
|
||||
return filter(detailsOnAllNodes(), and(checkNotNull(filter, "filter"), not(TERMINATED)));
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* if none found
|
||||
*/
|
||||
Iterable<? extends NodeMetadata> nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(
|
||||
Predicate<NodeMetadata> filter) {
|
||||
Predicate<? super NodeMetadata> filter) {
|
||||
Iterable<? extends NodeMetadata> nodes = nodesMatchingFilterAndNotTerminated(filter);
|
||||
if (Iterables.isEmpty(nodes))
|
||||
throw new NoSuchElementException("no nodes matched filter: " + filter);
|
||||
|
@ -360,7 +360,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<? super NodeMetadata> filter) {
|
||||
checkNotNull(filter, "filter");
|
||||
logger.trace(">> listing node details matching(%s)", filter);
|
||||
Set<? extends NodeMetadata> set = newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter));
|
||||
|
@ -434,7 +434,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> rebootNodesMatching(Predicate<NodeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> rebootNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
logger.debug(">> rebooting nodes matching(%s)", filter);
|
||||
Set<NodeMetadata> rebootNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
|
||||
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
|
||||
|
@ -475,7 +475,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> resumeNodesMatching(Predicate<NodeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> resumeNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
logger.debug(">> resuming nodes matching(%s)", filter);
|
||||
Set<NodeMetadata> resumeNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
|
||||
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
|
||||
|
@ -516,7 +516,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> suspendNodesMatching(Predicate<NodeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> suspendNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
logger.debug(">> suspending nodes matching(%s)", filter);
|
||||
Set<NodeMetadata> suspendNodes = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
|
||||
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
|
||||
|
@ -545,7 +545,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, String runScript)
|
||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter, String runScript)
|
||||
throws RunScriptOnNodesException {
|
||||
return runScriptOnNodesMatching(filter, Statements.literal(checkNotNull(runScript, "runScript")));
|
||||
}
|
||||
|
@ -554,13 +554,13 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, Statement runScript)
|
||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter, Statement runScript)
|
||||
throws RunScriptOnNodesException {
|
||||
return runScriptOnNodesMatching(filter, runScript, RunScriptOptions.NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
||||
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter,
|
||||
String runScript, RunScriptOptions options) throws RunScriptOnNodesException {
|
||||
return runScriptOnNodesMatching(filter, Statements.literal(checkNotNull(runScript, "runScript")), options);
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ public class BaseComputeService implements ComputeService {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, Statement runScript,
|
||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<? super NodeMetadata> filter, Statement runScript,
|
||||
RunScriptOptions options) throws RunScriptOnNodesException {
|
||||
|
||||
checkNotNull(filter, "filter");
|
||||
|
|
|
@ -25,7 +25,7 @@ public interface ListNodesStrategy {
|
|||
|
||||
Iterable<? extends ComputeMetadata> listNodes();
|
||||
|
||||
Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter);
|
||||
Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<? super NodeMetadata> filter);
|
||||
|
||||
Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids);
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeW
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
return filter(transform(client.listNodes(), nodeMetadataAdapter), filter);
|
||||
}
|
||||
|
||||
|
|
|
@ -644,7 +644,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
}));
|
||||
|
||||
SortedSet<? extends NodeMetadata> listedNodes = ImmutableSortedSet.copyOf(client.listNodesByIds(nodeIds));
|
||||
SortedSet<? extends ComputeMetadata> listedNodes = ImmutableSortedSet.copyOf(client.listNodesByIds(nodeIds));
|
||||
// newTreeSet is here because elementsEqual cares about ordering.
|
||||
assertTrue(Iterables.elementsEqual(nodes, listedNodes),
|
||||
"nodes and listNodesByIds should be identical: was " + listedNodes + " but should be " + nodes);
|
||||
|
|
|
@ -136,7 +136,7 @@ public final class GoogleComputeEngineService extends BaseComputeService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<? super NodeMetadata> filter) {
|
||||
// GCE 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
|
||||
|
|
Loading…
Reference in New Issue