diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index db55ad0b88..8177ef098a 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -63,6 +63,7 @@ import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.predicates.RunScriptRunning; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -124,7 +125,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { } @Override - public Iterable execute() { + public Iterable execute(GetNodesOptions options) { Set nodes = Sets.newHashSet(); for (Region region : ImmutableSet.of(Region.US_EAST_1, Region.US_WEST_1, Region.EU_WEST_1)) { Iterables.addAll(nodes, Iterables.transform(Iterables.concat(client diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java old mode 100644 new mode 100755 index 90a609d5dd..0a89b1848b --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -27,6 +27,7 @@ import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.domain.Location; import org.jclouds.ssh.ExecResponse; @@ -77,6 +78,12 @@ public interface ComputeService { */ Map getNodes(); + /** + * all nodes available to the current user by id. If possible, the returned set will include + * {@link NodeMetadata} objects. + */ + Map getNodes(GetNodesOptions options); + /** * The get locations command returns all the valid locations for nodes. A location has a scope, * which is typically region or zone. A region is a general area, like eu-west, where a zone is diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java old mode 100644 new mode 100755 index c649aa30cd..945b6832d8 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -53,6 +53,7 @@ import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -172,7 +173,7 @@ public class BaseComputeService implements ComputeService { "starting nodes"); if (exceptions.size() > 0 && template.getOptions().shouldDestroyOnError()) { ImmutableMap currentNodes = Maps.uniqueIndex( - listNodesStrategy.execute(), METADATA_TO_ID); + listNodesStrategy.execute(GetNodesOptions.NONE), METADATA_TO_ID); for (Entry entry : exceptions.entrySet()) { logger.error(entry.getValue(), "<< error applying nodes(%s) [%s] destroying ", entry .getKey(), entry.getValue().getMessage()); @@ -221,18 +222,28 @@ public class BaseComputeService implements ComputeService { public Map getNodes() { logger.debug(">> listing servers"); ImmutableMap map = Maps.uniqueIndex(listNodesStrategy - .execute(), METADATA_TO_ID); + .execute(GetNodesOptions.NONE), METADATA_TO_ID); + logger.debug("<< list(%d)", map.size()); + return map; + } + @Override + public Map getNodes(GetNodesOptions options) { + logger.debug(">> listing servers"); + if(options == null){ + options = GetNodesOptions.NONE; + } + ImmutableMap map = Maps.uniqueIndex(listNodesStrategy + .execute(options), METADATA_TO_ID); logger.debug("<< list(%d)", map.size()); return map; } - /** * If the result of {@link ListNodesStrategy#execute} is a set of nodes, then return them. * Otherwise iteratively call {@link #getNodeMetadata} */ protected Map doGetNodesWithTag(final String tag) { Iterable nodes = Iterables.filter(Iterables.transform( - listNodesStrategy.execute(), new Function() { + listNodesStrategy.execute(GetNodesOptions.NONE), new Function() { @Override public NodeMetadata apply(ComputeMetadata from) { diff --git a/compute/src/main/java/org/jclouds/compute/options/GetNodesOptions.java b/compute/src/main/java/org/jclouds/compute/options/GetNodesOptions.java new file mode 100755 index 0000000000..8af03190dd --- /dev/null +++ b/compute/src/main/java/org/jclouds/compute/options/GetNodesOptions.java @@ -0,0 +1,82 @@ +package org.jclouds.compute.options; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Ivan Meredith + */ +public class GetNodesOptions implements Cloneable { + public static final ImmutableGetNodesOptions NONE = new ImmutableGetNodesOptions( + new GetNodesOptions()); + + private boolean detailed; + + public GetNodesOptions() { + } + + GetNodesOptions(boolean detailed) { + this.detailed = detailed; + } + + public static class ImmutableGetNodesOptions extends GetNodesOptions { + private final GetNodesOptions delegate; + + + + public ImmutableGetNodesOptions(GetNodesOptions delegate) { + this.delegate = delegate; + } + + @Override + public boolean isDetailed() { + return delegate.isDetailed(); + } + + + @Override + public GetNodesOptions clone() { + return delegate.clone(); + } + + @Override + public String toString() { + return delegate.toString(); + } + + } + + public boolean isDetailed() { + return detailed; + } + /** + * populate each result with detailed such as metadata even if it incurs extra requests to the + * service. + */ + public GetNodesOptions withDetails() { + this.detailed = true; + return this; + } + + public static class Builder { + + + /** + * @see GetNodesOptions#withDetails() + */ + public static GetNodesOptions withDetails() { + GetNodesOptions options = new GetNodesOptions(); + return options.withDetails(); + } + } + + @Override + public GetNodesOptions clone() { + return new GetNodesOptions(detailed); + } + + @Override + public String toString() { + return "[detailed=" + detailed + "]"; + } +} diff --git a/compute/src/main/java/org/jclouds/compute/strategy/ListNodesStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/ListNodesStrategy.java old mode 100644 new mode 100755 index 662ecc59e1..d2f05abc55 --- a/compute/src/main/java/org/jclouds/compute/strategy/ListNodesStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/ListNodesStrategy.java @@ -20,6 +20,7 @@ package org.jclouds.compute.strategy; import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.options.GetNodesOptions; /** * @@ -27,6 +28,5 @@ import org.jclouds.compute.domain.ComputeMetadata; */ public interface ListNodesStrategy { - Iterable execute(); - + Iterable execute(GetNodesOptions options); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java old mode 100644 new mode 100755 index 618e0103cc..de01f86e72 --- a/compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java @@ -37,6 +37,7 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; import org.jclouds.compute.internal.BaseComputeService; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; @@ -107,7 +108,7 @@ public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetS Set names = Sets.newHashSet(); int nodeIndex = new SecureRandom().nextInt(8096); Map currentNodes = Maps.uniqueIndex(listNodesStrategy - .execute(), BaseComputeService.METADATA_TO_NAME); + .execute(GetNodesOptions.NONE), BaseComputeService.METADATA_TO_NAME); while (names.size() < count) { String name = String.format(nodeNamingConvention, tag, nodeIndex++); if (!currentNodes.containsKey(name)) { diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java old mode 100644 new mode 100755 index 1b91be358e..14cfbd2266 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -44,6 +44,7 @@ import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; @@ -302,6 +303,20 @@ public abstract class BaseComputeServiceLiveTest { } } + public void testGetNodesWithDetails() throws Exception { + for (Entry node : client.getNodes(new GetNodesOptions().withDetails()).entrySet()) { + assertEquals(node.getKey(), node.getValue().getId()); + assert node.getValue().getId() != null; + assert node.getValue().getLocationId() != null; + assertEquals(node.getValue().getType(), ComputeType.NODE); + assert node.getValue() instanceof NodeMetadata; + NodeMetadata nodeMetadata = (NodeMetadata)node.getValue(); + assertNotNull(nodeMetadata.getName()); + assertNotNull(nodeMetadata.getPublicAddresses()); + assert nodeMetadata.getPublicAddresses().size() > 1; + assertNotNull(nodeMetadata.getPrivateAddresses()); + } + } public void testListImages() throws Exception { for (Entry image : client.getImages().entrySet()) { assertEquals(image.getKey(), image.getValue().getId()); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java old mode 100644 new mode 100755 index 515599cfc5..b4545d0c2b --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java @@ -52,6 +52,7 @@ import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.predicates.RunScriptRunning; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.*; @@ -212,7 +213,7 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { } @Override - public Iterable execute() { + public Iterable execute(GetNodesOptions options) { return Iterables.transform(client.getServerServices().getServerList(), serverToNodeMetadata); } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 2875e2338b..11ad843233 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -52,6 +52,7 @@ import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.predicates.RunScriptRunning; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; @@ -206,7 +207,7 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext } @Override - public Iterable execute() { + public Iterable execute(GetNodesOptions options) { return Iterables.transform(client.listServers(ListOptions.Builder.withDetails()), serverToNodeMetadata); } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 1a96846c71..83f7aeebb9 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -54,6 +54,7 @@ import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.predicates.RunScriptRunning; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; @@ -213,7 +214,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo } @Override - public Iterable execute() { + public Iterable execute(GetNodesOptions options) { return Iterables.transform(client.getServerList(), serverToNodeMetadata); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index cc86c4a24e..5765973b54 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -53,6 +53,7 @@ import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; +import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.predicates.RunScriptRunning; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; @@ -222,7 +223,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { } @Override - public Iterable execute() { + public Iterable execute(GetNodesOptions options) { Set nodes = Sets.newHashSet(); for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) { for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {