mirror of https://github.com/apache/jclouds.git
Added getNodes withDetails()
This commit is contained in:
parent
31d2b08b71
commit
4b8b0e8770
|
@ -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<? extends ComputeMetadata> execute() {
|
||||
public Iterable<? extends ComputeMetadata> execute(GetNodesOptions options) {
|
||||
Set<NodeMetadata> 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
|
||||
|
|
|
@ -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<String, ? extends ComputeMetadata> getNodes();
|
||||
|
||||
/**
|
||||
* all nodes available to the current user by id. If possible, the returned set will include
|
||||
* {@link NodeMetadata} objects.
|
||||
*/
|
||||
Map<String, ? extends ComputeMetadata> 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
|
||||
|
|
19
compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java
Normal file → Executable file
19
compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java
Normal file → Executable file
|
@ -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<?, ? extends ComputeMetadata> currentNodes = Maps.uniqueIndex(
|
||||
listNodesStrategy.execute(), METADATA_TO_ID);
|
||||
listNodesStrategy.execute(GetNodesOptions.NONE), METADATA_TO_ID);
|
||||
for (Entry<?, Exception> 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<String, ? extends ComputeMetadata> getNodes() {
|
||||
logger.debug(">> listing servers");
|
||||
ImmutableMap<String, ? extends ComputeMetadata> 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<String, ? extends ComputeMetadata> getNodes(GetNodesOptions options) {
|
||||
logger.debug(">> listing servers");
|
||||
if(options == null){
|
||||
options = GetNodesOptions.NONE;
|
||||
}
|
||||
ImmutableMap<String, ? extends ComputeMetadata> 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<String, ? extends NodeMetadata> doGetNodesWithTag(final String tag) {
|
||||
Iterable<? extends NodeMetadata> nodes = Iterables.filter(Iterables.transform(
|
||||
listNodesStrategy.execute(), new Function<ComputeMetadata, NodeMetadata>() {
|
||||
listNodesStrategy.execute(GetNodesOptions.NONE), new Function<ComputeMetadata, NodeMetadata>() {
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(ComputeMetadata from) {
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
4
compute/src/main/java/org/jclouds/compute/strategy/ListNodesStrategy.java
Normal file → Executable file
4
compute/src/main/java/org/jclouds/compute/strategy/ListNodesStrategy.java
Normal file → Executable file
|
@ -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<? extends ComputeMetadata> execute();
|
||||
|
||||
Iterable<? extends ComputeMetadata> execute(GetNodesOptions options);
|
||||
}
|
3
compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java
Normal file → Executable file
3
compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java
Normal file → Executable file
|
@ -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<String> names = Sets.newHashSet();
|
||||
int nodeIndex = new SecureRandom().nextInt(8096);
|
||||
Map<String, ? extends ComputeMetadata> 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)) {
|
||||
|
|
15
compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java
Normal file → Executable file
15
compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java
Normal file → Executable file
|
@ -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<String, ? extends ComputeMetadata> 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<String, ? extends Image> image : client.getImages().entrySet()) {
|
||||
assertEquals(image.getKey(), image.getValue().getId());
|
||||
|
|
3
gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java
Normal file → Executable file
3
gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java
Normal file → Executable file
|
@ -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<? extends ComputeMetadata> execute() {
|
||||
public Iterable<? extends ComputeMetadata> execute(GetNodesOptions options) {
|
||||
return Iterables.transform(client.getServerServices().getServerList(),
|
||||
serverToNodeMetadata);
|
||||
}
|
||||
|
|
|
@ -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<? extends ComputeMetadata> execute() {
|
||||
public Iterable<? extends ComputeMetadata> execute(GetNodesOptions options) {
|
||||
return Iterables.transform(client.listServers(ListOptions.Builder.withDetails()),
|
||||
serverToNodeMetadata);
|
||||
}
|
||||
|
|
|
@ -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<? extends ComputeMetadata> execute() {
|
||||
public Iterable<? extends ComputeMetadata> execute(GetNodesOptions options) {
|
||||
return Iterables.transform(client.getServerList(), serverToNodeMetadata);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<? extends ComputeMetadata> execute() {
|
||||
public Iterable<? extends ComputeMetadata> execute(GetNodesOptions options) {
|
||||
Set<ComputeMetadata> nodes = Sets.newHashSet();
|
||||
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) {
|
||||
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
|
||||
|
|
Loading…
Reference in New Issue