Issue 254: correct docs

This commit is contained in:
Adrian Cole 2010-05-20 20:05:14 -07:00
parent efc47969d9
commit 5af9bdd34f
16 changed files with 93 additions and 87 deletions

View File

@ -229,12 +229,12 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
} }
@Override @Override
public NodeMetadata execute(String handle) { public NodeMetadata execute(String id) {
String[] parts = parseHandle(handle); String[] parts = parseHandle(id);
String region = parts[0]; String region = parts[0];
String id = parts[1]; String instanceId = parts[1];
RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion( RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion(
client, region, id)); client, region, instanceId));
return runningInstanceToNodeMetadata.apply(runningInstance); return runningInstanceToNodeMetadata.apply(runningInstance);
} }
@ -250,11 +250,11 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
String[] parts = parseHandle(handle); String[] parts = parseHandle(id);
String region = parts[0]; String region = parts[0];
String id = parts[1]; String instanceId = parts[1];
client.rebootInstancesInRegion(region, id); client.rebootInstancesInRegion(region, instanceId);
return true; return true;
} }
@ -389,7 +389,9 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
.describeImagesInRegion(region, ownedBy(amiOwners))) { .describeImagesInRegion(region, ownedBy(amiOwners))) {
Image image = parser.apply(from); Image image = parser.apply(from);
if (image != null) if (image != null)
images.put(new RegionAndName(region, image.getProviderId()), image); images
.put(new RegionAndName(region, image.getProviderId()),
image);
else if (from.getImageType() == ImageType.MACHINE) else if (from.getImageType() == ImageType.MACHINE)
holder.logger.trace("<< image(%s) didn't parse", from.getId()); holder.logger.trace("<< image(%s) didn't parse", from.getId());
} }

View File

@ -59,12 +59,12 @@ public class EC2DestroyNodeStrategy implements DestroyNodeStrategy {
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
String[] parts = parseHandle(handle); String[] parts = parseHandle(id);
String region = parts[0]; String region = parts[0];
String id = parts[1]; String instanceId = parts[1];
ec2Client.getInstanceServices().terminateInstancesInRegion(region, id); ec2Client.getInstanceServices().terminateInstancesInRegion(region, instanceId);
return instanceStateTerminated.apply(Iterables.getOnlyElement(Iterables.concat(ec2Client return instanceStateTerminated.apply(Iterables.getOnlyElement(Iterables.concat(ec2Client
.getInstanceServices().describeInstancesInRegion(region, id)))); .getInstanceServices().describeInstancesInRegion(region, instanceId))));
} }
} }

View File

@ -64,9 +64,9 @@ public class EC2Utils {
return Iterables.concat(client.describeInstancesInRegion(region, id)); return Iterables.concat(client.describeInstancesInRegion(region, id));
} }
public static String[] parseHandle(String handle) { public static String[] parseHandle(String id) {
String[] parts = checkNotNull(handle, "handle").split("/"); String[] parts = checkNotNull(id, "id").split("/");
checkArgument(parts.length == 2, "handle syntax is region/id"); checkArgument(parts.length == 2, "id syntax is region/instanceid");
return parts; return parts;
} }

View File

@ -146,10 +146,10 @@ public interface ComputeService {
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException; Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException;
/** /**
* destroy the node, given its handle. If it is the only node in a tag set, the dependent * destroy the node, given its id. If it is the only node in a tag set, the dependent
* resources will also be destroyed. * resources will also be destroyed.
*/ */
void destroyNode(String handle); void destroyNode(String id);
/** /**
* nodes matching the filter are treated as a logical set. Using the delete command, you can save * nodes matching the filter are treated as a logical set. Using the delete command, you can save
@ -161,9 +161,9 @@ public interface ComputeService {
Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter); Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter);
/** /**
* reboot the node, given its handle. * reboot the node, given its id.
*/ */
void rebootNode(String handle); void rebootNode(String id);
/** /**
* nodes matching the filter are treated as a logical set. Using this command, you can save time * nodes matching the filter are treated as a logical set. Using this command, you can save time
@ -172,9 +172,9 @@ public interface ComputeService {
void rebootNodesMatching(Predicate<NodeMetadata> filter); void rebootNodesMatching(Predicate<NodeMetadata> filter);
/** /**
* Find a node by its handle. * Find a node by its id.
*/ */
NodeMetadata getNodeMetadata(String handle); NodeMetadata getNodeMetadata(String id);
/** /**
* get all nodes including details such as image and ip addresses even if it incurs extra * get all nodes including details such as image and ip addresses even if it incurs extra

View File

@ -37,12 +37,12 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 7374704415964898694L; private static final long serialVersionUID = 7374704415964898694L;
private final String handle; private final String id;
public ComputeMetadataImpl(ComputeType type, String id, String name, String handle, public ComputeMetadataImpl(ComputeType type, String providerId, String name, String id,
Location location, URI uri, Map<String, String> userMetadata) { Location location, URI uri, Map<String, String> userMetadata) {
super(type, id, name, location, uri, userMetadata); super(type, providerId, name, location, uri, userMetadata);
this.handle = checkNotNull(handle, "handle"); this.id = checkNotNull(id, "id");
} }
/** /**
@ -50,7 +50,7 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
*/ */
@Override @Override
public String getId() { public String getId() {
return handle; return id;
} }
} }

View File

@ -52,11 +52,11 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
private final Architecture architecture; private final Architecture architecture;
private final Credentials defaultCredentials; private final Credentials defaultCredentials;
public ImageImpl(String id, String name, String handle, Location location, URI uri, public ImageImpl(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, String description, String version, Map<String, String> userMetadata, String description, String version,
@Nullable OsFamily osFamily, String osDescription, Architecture architecture, @Nullable OsFamily osFamily, String osDescription, Architecture architecture,
Credentials defaultCredentials) { Credentials defaultCredentials) {
super(ComputeType.IMAGE, id, name, handle, location, uri, userMetadata); super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata);
this.version = checkNotNull(version, "version"); this.version = checkNotNull(version, "version");
this.osFamily = osFamily; this.osFamily = osFamily;
this.description = checkNotNull(description, "description"); this.description = checkNotNull(description, "description");
@ -115,9 +115,10 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
@Override @Override
public String toString() { public String toString() {
return "[id=" + getProviderId() + ", name=" + getName() + ", locationId=" + getLocation() return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName()
+ ", architecture=" + architecture + ", osDescription=" + osDescription + ", locationId=" + getLocation() + ", architecture=" + architecture
+ ", osFamily=" + osFamily + ", version=" + version + "]"; + ", osDescription=" + osDescription + ", osFamily=" + osFamily + ", version="
+ version + "]";
} }
@Override @Override

View File

@ -54,12 +54,12 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
private final String tag; private final String tag;
private final Image image; private final Image image;
public NodeMetadataImpl(String id, String name, String handle, Location location, URI uri, public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, @Nullable String tag, @Nullable Image image, Map<String, String> userMetadata, @Nullable String tag, @Nullable Image image,
NodeState state, Iterable<InetAddress> publicAddresses, NodeState state, Iterable<InetAddress> publicAddresses,
Iterable<InetAddress> privateAddresses, Map<String, String> extra, Iterable<InetAddress> privateAddresses, Map<String, String> extra,
@Nullable Credentials credentials) { @Nullable Credentials credentials) {
super(ComputeType.NODE, id, name, handle, location, uri, userMetadata); super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata);
this.tag = tag; this.tag = tag;
this.image = image; this.image = image;
this.state = checkNotNull(state, "state"); this.state = checkNotNull(state, "state");
@ -128,10 +128,11 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
@Override @Override
public String toString() { public String toString() {
return "[id=" + getProviderId() + ", tag=" + getTag() + ", name=" + getName() + ", location=" return "[id=" + getId() + ", providerId=" + getProviderId() + ", tag=" + getTag() + ", name="
+ getLocation() + ", uri=" + getUri() + ", image=" + getImage() + ", userMetadata=" + getName() + ", location=" + getLocation() + ", uri=" + getUri() + ", image="
+ getUserMetadata() + ", state=" + getState() + ", privateAddresses=" + getImage() + ", userMetadata=" + getUserMetadata() + ", state=" + getState()
+ privateAddresses + ", publicAddresses=" + publicAddresses + "]"; + ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses
+ "]";
} }
@Override @Override

View File

@ -48,10 +48,10 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
private final Set<Architecture> supportedArchitectures = Sets.newHashSet(); private final Set<Architecture> supportedArchitectures = Sets.newHashSet();
public SizeImpl(String id, String name, String handle, @Nullable Location location, URI uri, public SizeImpl(String providerId, String name, String id, @Nullable Location location, URI uri,
Map<String, String> userMetadata, double cores, int ram, int disk, Map<String, String> userMetadata, double cores, int ram, int disk,
Iterable<Architecture> supportedArchitectures) { Iterable<Architecture> supportedArchitectures) {
super(ComputeType.SIZE, id, name, handle, location, uri, userMetadata); super(ComputeType.SIZE, providerId, name, id, location, uri, userMetadata);
this.cores = cores; this.cores = cores;
this.ram = ram; this.ram = ram;
this.disk = disk; this.disk = disk;
@ -103,8 +103,9 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
*/ */
@Override @Override
public String toString() { public String toString() {
return "[id=" + getProviderId() + ", cores=" + cores + ", ram=" + ram + ", disk=" + disk return "[id=" + getId() + ", providerId=" + getProviderId() + ", cores=" + cores + ", ram="
+ ", supportedArchitectures=" + supportedArchitectures + "]"; + ram + ", disk=" + disk + ", supportedArchitectures=" + supportedArchitectures
+ "]";
} }
/** /**

View File

@ -147,7 +147,8 @@ public class BaseComputeService implements ComputeService {
checkNotNull(template.getLocation(), "location"); checkNotNull(template.getLocation(), "location");
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)",
count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template
.getImage().getProviderId(), template.getSize().getProviderId(), template.getOptions()); .getImage().getProviderId(), template.getSize().getProviderId(), template
.getOptions());
Set<NodeMetadata> nodes = Sets.newHashSet(); Set<NodeMetadata> nodes = Sets.newHashSet();
Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap(); Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count,
@ -182,11 +183,11 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void destroyNode(String handle) { public void destroyNode(String id) {
checkNotNull(handle, "handle"); checkNotNull(id, "id");
logger.debug(">> destroying node(%s)", handle); logger.debug(">> destroying node(%s)", id);
boolean successful = destroyNodeStrategy.execute(handle); boolean successful = destroyNodeStrategy.execute(id);
logger.debug("<< destroyed node(%s) success(%s)", handle, successful); logger.debug("<< destroyed node(%s) success(%s)", id, successful);
} }
/** /**
@ -278,20 +279,20 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public NodeMetadata getNodeMetadata(String handle) { public NodeMetadata getNodeMetadata(String id) {
checkNotNull(handle, "handle"); checkNotNull(id, "id");
return getNodeMetadataStrategy.execute(handle); return getNodeMetadataStrategy.execute(id);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void rebootNode(String handle) { public void rebootNode(String id) {
checkNotNull(handle, "handle"); checkNotNull(id, "id");
logger.debug(">> rebooting node(%s)", handle); logger.debug(">> rebooting node(%s)", id);
boolean successful = rebootNodeStrategy.execute(handle); boolean successful = rebootNodeStrategy.execute(id);
logger.debug("<< rebooted node(%s) success(%s)", handle, successful); logger.debug("<< rebooted node(%s) success(%s)", id, successful);
} }
/** /**

View File

@ -28,6 +28,6 @@ package org.jclouds.compute.strategy;
*/ */
public interface DestroyNodeStrategy { public interface DestroyNodeStrategy {
boolean execute(String handle); boolean execute(String id);
} }

View File

@ -28,6 +28,6 @@ import org.jclouds.compute.domain.NodeMetadata;
*/ */
public interface GetNodeMetadataStrategy { public interface GetNodeMetadataStrategy {
NodeMetadata execute(String handle); NodeMetadata execute(String id);
} }

View File

@ -27,6 +27,6 @@ package org.jclouds.compute.strategy;
*/ */
public interface RebootNodeStrategy { public interface RebootNodeStrategy {
boolean execute(String handle); boolean execute(String id);
} }

View File

@ -42,7 +42,7 @@ public class ResourceMetadataImpl<T extends Enum<T>> implements ResourceMetadata
private final T type; private final T type;
@Nullable @Nullable
private final String id; private final String providerId;
@Nullable @Nullable
private final String name; private final String name;
@Nullable @Nullable
@ -51,10 +51,10 @@ public class ResourceMetadataImpl<T extends Enum<T>> implements ResourceMetadata
private final URI uri; private final URI uri;
private final Map<String, String> userMetadata = Maps.newLinkedHashMap(); private final Map<String, String> userMetadata = Maps.newLinkedHashMap();
public ResourceMetadataImpl(T type, @Nullable String id, @Nullable String name, public ResourceMetadataImpl(T type, @Nullable String providerId, @Nullable String name,
@Nullable Location location, @Nullable URI uri, Map<String, String> userMetadata) { @Nullable Location location, @Nullable URI uri, Map<String, String> userMetadata) {
this.type = checkNotNull(type, "type"); this.type = checkNotNull(type, "type");
this.id = id; this.providerId = providerId;
this.name = name; this.name = name;
this.location = location; this.location = location;
this.uri = uri; this.uri = uri;
@ -84,7 +84,7 @@ public class ResourceMetadataImpl<T extends Enum<T>> implements ResourceMetadata
*/ */
@Override @Override
public String getProviderId() { public String getProviderId() {
return id; return providerId;
} }
/** /**
@ -121,7 +121,7 @@ public class ResourceMetadataImpl<T extends Enum<T>> implements ResourceMetadata
@Override @Override
public String toString() { public String toString() {
return "[type=" + type + ", id=" + id + ", name=" + name + ", location=" + location return "[type=" + type + ", providerId=" + providerId + ", name=" + name + ", location=" + location
+ ", uri=" + uri + ", userMetadata=" + userMetadata + "]"; + ", uri=" + uri + ", userMetadata=" + userMetadata + "]";
} }
@ -129,7 +129,7 @@ public class ResourceMetadataImpl<T extends Enum<T>> implements ResourceMetadata
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((providerId == null) ? 0 : providerId.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode());
@ -146,10 +146,10 @@ public class ResourceMetadataImpl<T extends Enum<T>> implements ResourceMetadata
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
ResourceMetadataImpl<?> other = (ResourceMetadataImpl<?>) obj; ResourceMetadataImpl<?> other = (ResourceMetadataImpl<?>) obj;
if (id == null) { if (providerId == null) {
if (other.id != null) if (other.providerId != null)
return false; return false;
} else if (!id.equals(other.id)) } else if (!providerId.equals(other.providerId))
return false; return false;
if (location == null) { if (location == null) {
if (other.location != null) if (other.location != null)

View File

@ -138,9 +138,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
new Long(handle))); new Long(id)));
client.getServerServices().power(server.getName(), PowerCommand.RESTART); client.getServerServices().power(server.getName(), PowerCommand.RESTART);
serverLatestJobCompleted.apply(server); serverLatestJobCompleted.apply(server);
client.getServerServices().power(server.getName(), PowerCommand.START); client.getServerServices().power(server.getName(), PowerCommand.START);
@ -186,9 +186,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
} }
@Override @Override
public NodeMetadata execute(String handle) { public NodeMetadata execute(String id) {
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
new Long(checkNotNull(handle, "handle")))); new Long(checkNotNull(id, "id"))));
return server == null ? null : serverToNodeMetadata.apply(server); return server == null ? null : serverToNodeMetadata.apply(server);
} }
} }
@ -206,9 +206,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
new Long(handle))); new Long(id)));
client.getServerServices().deleteByName(server.getName()); client.getServerServices().deleteByName(server.getName());
return serverLatestJobCompleted.apply(server); return serverLatestJobCompleted.apply(server);
} }

View File

@ -142,8 +142,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
int serverId = Integer.parseInt(handle); int serverId = Integer.parseInt(id);
// if false server wasn't around in the first place // if false server wasn't around in the first place
client.rebootServer(serverId, RebootType.HARD); client.rebootServer(serverId, RebootType.HARD);
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
@ -165,8 +165,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
int serverId = Integer.parseInt(handle); int serverId = Integer.parseInt(id);
// if false server wasn't around in the first place // if false server wasn't around in the first place
if (!client.deleteServer(serverId)) if (!client.deleteServer(serverId))
return false; return false;
@ -243,8 +243,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
} }
@Override @Override
public NodeMetadata execute(String handle) { public NodeMetadata execute(String id) {
int serverId = Integer.parseInt(handle); int serverId = Integer.parseInt(id);
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
return server == null ? null : serverToNodeMetadata.apply(server); return server == null ? null : serverToNodeMetadata.apply(server);
} }

View File

@ -140,8 +140,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
Long serverId = Long.parseLong(handle); Long serverId = Long.parseLong(id);
// if false server wasn't around in the first place // if false server wasn't around in the first place
return client.restartServer(serverId).getState() == RunningState.RUNNING; return client.restartServer(serverId).getState() == RunningState.RUNNING;
} }
@ -161,8 +161,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
@Override @Override
public boolean execute(String handle) { public boolean execute(String id) {
Long serverId = Long.parseLong(handle); Long serverId = Long.parseLong(id);
client.destroyServer(serverId); client.destroyServer(serverId);
return serverDestroyed.apply(client.getServer(serverId)); return serverDestroyed.apply(client.getServer(serverId));
} }
@ -247,8 +247,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
@Override @Override
public NodeMetadata execute(String handle) { public NodeMetadata execute(String id) {
long serverId = Long.parseLong(handle); long serverId = Long.parseLong(id);
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
return server == null ? null : serverToNodeMetadata.apply(server); return server == null ? null : serverToNodeMetadata.apply(server);
} }