Issue 328: added blacklist for node commands using property jclouds.compute.blacklist.nodes with comma separated node names; note that this is only implemented in vcloud right now

This commit is contained in:
Adrian Cole 2010-08-08 13:10:45 -07:00
parent 1bb15418fe
commit 664644534a
2 changed files with 44 additions and 15 deletions

View File

@ -35,6 +35,11 @@ public interface ComputeServiceConstants {
public static final String PROPERTY_TIMEOUT_NODE_RUNNING = "jclouds.compute.timeout.node-running"; public static final String PROPERTY_TIMEOUT_NODE_RUNNING = "jclouds.compute.timeout.node-running";
public static final String PROPERTY_TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete"; public static final String PROPERTY_TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete";
public static final String PROPERTY_TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open"; public static final String PROPERTY_TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open";
/**
* comma-separated nodes that we shouldn't attempt to list as they are dead
* in the provider for some reason.
*/
public static final String PROPERTY_BLACKLIST_NODES = "jclouds.compute.blacklist.nodes";
@Singleton @Singleton
static class Timeouts { static class Timeouts {

View File

@ -18,10 +18,13 @@
*/ */
package org.jclouds.vcloud.compute.strategy; package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.compute.reference.ComputeServiceConstants.COMPUTE_LOGGER;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_BLACKLIST_NODES;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -29,7 +32,6 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.internal.ComputeMetadataImpl; import org.jclouds.compute.domain.internal.ComputeMetadataImpl;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -38,11 +40,16 @@ import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.functions.FindLocationForResource; import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata; import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.internal.util.ImmutableSet;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -50,16 +57,26 @@ import com.google.common.collect.Sets;
@Singleton @Singleton
public class VCloudListNodesStrategy implements ListNodesStrategy { public class VCloudListNodesStrategy implements ListNodesStrategy {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
protected final VCloudGetNodeMetadata getNodeMetadata; protected final VCloudGetNodeMetadata getNodeMetadata;
protected final VCloudClient client; protected final VCloudClient client;
protected final FindLocationForResource findLocationForResourceInVDC; protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@Inject(optional = true)
void setBlackList(@Named(PROPERTY_BLACKLIST_NODES) String blackListNodes) {
if (blackListNodes != null && !"".equals(blackListNodes))
this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes));
}
private final Supplier<Map<String, NamedResource>> orgNameToEndpoint;
@Inject @Inject
protected VCloudListNodesStrategy(VCloudClient client, VCloudGetNodeMetadata getNodeMetadata, protected VCloudListNodesStrategy(VCloudClient client, @Org Supplier<Map<String, NamedResource>> orgNameToEndpoint,
FindLocationForResource findLocationForResourceInVDC) { VCloudGetNodeMetadata getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
this.client = client; this.client = client;
this.orgNameToEndpoint = orgNameToEndpoint;
this.getNodeMetadata = getNodeMetadata; this.getNodeMetadata = getNodeMetadata;
this.findLocationForResourceInVDC = findLocationForResourceInVDC; this.findLocationForResourceInVDC = findLocationForResourceInVDC;
} }
@ -67,30 +84,37 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
@Override @Override
public Iterable<ComputeMetadata> list() { public Iterable<ComputeMetadata> list() {
Set<ComputeMetadata> nodes = Sets.newHashSet(); Set<ComputeMetadata> nodes = Sets.newHashSet();
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) { for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) { for (NamedResource vdc : client.getOrganizationNamed(org).getVDCs().values()) {
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) { for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
nodes.add(convertVAppToComputeMetadata(vdc, resource)); if (validVApp(resource)) {
nodes.add(convertVAppToComputeMetadata(vdc, resource));
}
} }
} }
} }
return nodes; return nodes;
} }
private boolean validVApp(NamedResource resource) {
return resource.getType().equals(VCloudMediaType.VAPP_XML) && !blackListVAppNames.contains(resource.getName());
}
private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) { private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) {
Location location = findLocationForResourceInVDC.apply(vdc); Location location = findLocationForResourceInVDC.apply(vdc);
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId(), resource.getName(), resource.getId(), return new ComputeMetadataImpl(ComputeType.NODE, resource.getId(), resource.getName(), resource.getId(),
location, null, ImmutableMap.<String, String> of()); location, null, ImmutableMap.<String, String> of());
} }
@Override @Override
public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) { public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
Set<NodeMetadata> nodes = Sets.newHashSet(); Set<NodeMetadata> nodes = Sets.newHashSet();
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) { for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) { for (NamedResource vdc : client.getOrganizationNamed(org).getVDCs().values()) {
if (resource.getType().equals(VCloudMediaType.VAPP_XML) for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
&& filter.apply(convertVAppToComputeMetadata(vdc, resource))) { if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource); addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
}
} }
} }
} }