mirror of https://github.com/apache/jclouds.git
Issue 955:introduce NodeMetadata/Image.backendStatus
This commit is contained in:
parent
7203286a90
commit
9bf92e0403
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.tools.ant.taskdefs.compute;
|
||||
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.buildComputeMap;
|
||||
import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.createTemplateFromElement;
|
||||
|
@ -253,8 +254,7 @@ public class ComputeTask extends Task {
|
|||
NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) : computeService
|
||||
.getNodeMetadata(node.getId());
|
||||
log(String.format(" node id=%s, name=%s, group=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, hardware=%s",
|
||||
metadata.getProviderId(), metadata.getName(), metadata.getGroup(), metadata.getLocation(), metadata
|
||||
.getState(), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()),
|
||||
metadata.getProviderId(), metadata.getName(), metadata.getGroup(), metadata.getLocation(), formatStatus(metadata), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()),
|
||||
ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getHardware()));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,15 +18,26 @@
|
|||
*/
|
||||
package org.jclouds.compute.domain;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface ComputeMetadataIncludingStatus<S extends Enum<S>> extends ComputeMetadata {
|
||||
|
||||
/**
|
||||
* status of the resource
|
||||
* portable status of the resource
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public S getStatus();
|
||||
|
||||
/**
|
||||
* status of the resource, as supplied literally from the backend api.
|
||||
*
|
||||
* @return status or null, if the backend api has no concept of status
|
||||
* @since 1.5
|
||||
*/
|
||||
@Nullable
|
||||
public String getBackendStatus();
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
public class ImageBuilder extends ComputeMetadataBuilder {
|
||||
private OperatingSystem operatingSystem;
|
||||
private Status status;
|
||||
private String backendStatus;
|
||||
private String version;
|
||||
private String description;
|
||||
private LoginCredentials defaultLoginCredentials;
|
||||
|
@ -53,6 +54,11 @@ public class ImageBuilder extends ComputeMetadataBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ImageBuilder backendStatus(@Nullable String backendStatus) {
|
||||
this.backendStatus = backendStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImageBuilder version(@Nullable String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
|
@ -110,14 +116,14 @@ public class ImageBuilder extends ComputeMetadataBuilder {
|
|||
@Override
|
||||
public Image build() {
|
||||
return new ImageImpl(providerId, name, id, location, uri, userMetadata, tags, operatingSystem, status,
|
||||
description, version, defaultLoginCredentials);
|
||||
backendStatus, description, version, defaultLoginCredentials);
|
||||
}
|
||||
|
||||
public static ImageBuilder fromImage(Image image) {
|
||||
return new ImageBuilder().providerId(image.getProviderId()).name(image.getName()).id(image.getId())
|
||||
.location(image.getLocation()).uri(image.getUri()).userMetadata(image.getUserMetadata())
|
||||
.tags(image.getTags()).version(image.getVersion()).description(image.getDescription())
|
||||
.operatingSystem(image.getOperatingSystem()).status(image.getStatus())
|
||||
return new ImageBuilder().providerId(image.getProviderId()).name(image.getName()).id(image.getId()).location(
|
||||
image.getLocation()).uri(image.getUri()).userMetadata(image.getUserMetadata()).tags(image.getTags())
|
||||
.version(image.getVersion()).description(image.getDescription()).operatingSystem(
|
||||
image.getOperatingSystem()).status(image.getStatus()).backendStatus(image.getBackendStatus())
|
||||
.defaultCredentials(image.getDefaultCredentials());
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.google.common.collect.Sets;
|
|||
*/
|
||||
public class NodeMetadataBuilder extends ComputeMetadataBuilder {
|
||||
private Status status;
|
||||
private String backendStatus;
|
||||
private Set<String> publicAddresses = Sets.newLinkedHashSet();
|
||||
private Set<String> privateAddresses = Sets.newLinkedHashSet();
|
||||
@Nullable
|
||||
|
@ -68,6 +69,11 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder backendStatus(@Nullable String backendStatus) {
|
||||
this.backendStatus = backendStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h3>Note</h3>
|
||||
* will be removed in jclouds 1.6!
|
||||
|
@ -162,15 +168,16 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
|
|||
@Override
|
||||
public NodeMetadata build() {
|
||||
return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, tags, group, hardware, imageId,
|
||||
os, status, loginPort, publicAddresses, privateAddresses, credentials, hostname);
|
||||
os, status, backendStatus, loginPort, publicAddresses, privateAddresses, credentials, hostname);
|
||||
}
|
||||
|
||||
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) {
|
||||
return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location(
|
||||
node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group(
|
||||
node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem(
|
||||
node.getOperatingSystem()).status(node.getStatus()).loginPort(node.getLoginPort()).publicAddresses(
|
||||
node.getPublicAddresses()).privateAddresses(node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname());
|
||||
node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort(
|
||||
node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses(
|
||||
node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname());
|
||||
}
|
||||
|
||||
}
|
|
@ -84,8 +84,12 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
|
|||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
ComputeMetadataImpl that = ComputeMetadataImpl.class.cast(o);
|
||||
return super.equals(that) &&
|
||||
equal(this.id, that.id);
|
||||
return super.equals(that) && equal(this.id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), id);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.compute.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -31,6 +32,9 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -41,17 +45,19 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
|
|||
|
||||
private final OperatingSystem operatingSystem;
|
||||
private final Status status;
|
||||
private final String backendStatus;
|
||||
private final String version;
|
||||
private final String description;
|
||||
private final LoginCredentials defaultCredentials;
|
||||
|
||||
|
||||
public ImageImpl(String providerId, String name, String id, Location location, URI uri,
|
||||
Map<String, String> userMetadata, Set<String> tags, OperatingSystem operatingSystem, Image.Status status, String description,
|
||||
@Nullable String version, @Nullable LoginCredentials defaultCredentials) {
|
||||
Map<String, String> userMetadata, Set<String> tags, OperatingSystem operatingSystem, Image.Status status,
|
||||
@Nullable String backendStatus, String description, @Nullable String version,
|
||||
@Nullable LoginCredentials defaultCredentials) {
|
||||
super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata, tags);
|
||||
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
|
||||
this.status = checkNotNull(status, "status");
|
||||
this.backendStatus = backendStatus;
|
||||
this.version = version;
|
||||
this.description = checkNotNull(description, "description");
|
||||
this.defaultCredentials = defaultCredentials;
|
||||
|
@ -73,6 +79,14 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
|
|||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getBackendStatus() {
|
||||
return backendStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -107,57 +121,14 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
|
|||
.getPassword() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", name=" + getName() + ", operatingSystem=" + operatingSystem + ", description="
|
||||
+ description + ", version=" + version + ", location=" + getLocation() + ", loginUser="
|
||||
+ ((defaultCredentials != null) ? defaultCredentials.identity : null) + ", userMetadata="
|
||||
+ getUserMetadata() + ", tags=" + tags + "]";
|
||||
// equals and toString from super are sufficient to establish identity equivalence
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper("").add("id", getId()).add("providerId", getProviderId()).add("name", getName())
|
||||
.add("os", getOperatingSystem()).add("description", getDescription()).add("version", getVersion()).add(
|
||||
"location", getLocation()).add("status", formatStatus(this)).add("loginUser",
|
||||
((defaultCredentials != null) ? defaultCredentials.identity : null)).add("tags", getTags())
|
||||
.add("userMetadata", getUserMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((defaultCredentials == null) ? 0 : defaultCredentials.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
|
||||
result = prime * result + ((version == null) ? 0 : version.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ImageImpl other = (ImageImpl) obj;
|
||||
if (defaultCredentials == null) {
|
||||
if (other.defaultCredentials != null)
|
||||
return false;
|
||||
} else if (!defaultCredentials.equals(other.defaultCredentials))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (operatingSystem == null) {
|
||||
if (other.operatingSystem != null)
|
||||
return false;
|
||||
} else if (!operatingSystem.equals(other.operatingSystem))
|
||||
return false;
|
||||
if (version == null) {
|
||||
if (other.version != null)
|
||||
return false;
|
||||
} else if (!version.equals(other.version))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.compute.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -32,6 +33,8 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +47,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
private static final long serialVersionUID = 7924307572338157887L;
|
||||
|
||||
private final Status status;
|
||||
private final String backendStatus;
|
||||
private final int loginPort;
|
||||
private final Set<String> publicAddresses;
|
||||
private final Set<String> privateAddresses;
|
||||
|
@ -62,15 +66,16 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
|
||||
public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
|
||||
Map<String, String> userMetadata, Set<String> tags, @Nullable String group, @Nullable Hardware hardware,
|
||||
@Nullable String imageId, @Nullable OperatingSystem os, Status status, int loginPort,
|
||||
Iterable<String> publicAddresses, Iterable<String> privateAddresses, @Nullable LoginCredentials credentials,
|
||||
String hostname) {
|
||||
@Nullable String imageId, @Nullable OperatingSystem os, Status status, @Nullable String backendStatus,
|
||||
int loginPort, Iterable<String> publicAddresses, Iterable<String> privateAddresses,
|
||||
@Nullable LoginCredentials credentials, String hostname) {
|
||||
super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata, tags);
|
||||
this.group = group;
|
||||
this.hardware = hardware;
|
||||
this.imageId = imageId;
|
||||
this.os = os;
|
||||
this.status = checkNotNull(status, "status");
|
||||
this.backendStatus = backendStatus;
|
||||
this.loginPort = loginPort;
|
||||
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
|
||||
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||
|
@ -144,6 +149,14 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getBackendStatus() {
|
||||
return backendStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -176,78 +189,16 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
return hostname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", providerId=" + getProviderId() + ", group=" + getGroup() + ", name=" + getName()
|
||||
+ ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os="
|
||||
+ getOperatingSystem() + ", status=" + getStatus() + ", loginPort=" + getLoginPort() + ", hostname="
|
||||
+ getHostname() + ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses
|
||||
+ ", hardware=" + getHardware() + ", loginUser=" + ((credentials != null) ? credentials.identity : null)
|
||||
+ ", userMetadata=" + getUserMetadata() + ", tags=" + tags + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + loginPort;
|
||||
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
|
||||
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
|
||||
result = prime * result + ((group == null) ? 0 : group.hashCode());
|
||||
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
|
||||
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
|
||||
result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
|
||||
result = prime * result + ((os == null) ? 0 : os.hashCode());
|
||||
return result;
|
||||
}
|
||||
// equals and toString from super are sufficient to establish identity equivalence
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
NodeMetadataImpl other = (NodeMetadataImpl) obj;
|
||||
if (loginPort != other.loginPort)
|
||||
return false;
|
||||
if (privateAddresses == null) {
|
||||
if (other.privateAddresses != null)
|
||||
return false;
|
||||
} else if (!privateAddresses.equals(other.privateAddresses))
|
||||
return false;
|
||||
if (publicAddresses == null) {
|
||||
if (other.publicAddresses != null)
|
||||
return false;
|
||||
} else if (!publicAddresses.equals(other.publicAddresses))
|
||||
return false;
|
||||
if (hostname == null) {
|
||||
if (other.hostname != null)
|
||||
return false;
|
||||
} else if (!hostname.equals(other.hostname))
|
||||
return false;
|
||||
if (group == null) {
|
||||
if (other.group != null)
|
||||
return false;
|
||||
} else if (!group.equals(other.group))
|
||||
return false;
|
||||
if (imageId == null) {
|
||||
if (other.imageId != null)
|
||||
return false;
|
||||
} else if (!imageId.equals(other.imageId))
|
||||
return false;
|
||||
if (hardware == null) {
|
||||
if (other.hardware != null)
|
||||
return false;
|
||||
} else if (!hardware.equals(other.hardware))
|
||||
return false;
|
||||
if (os == null) {
|
||||
if (other.os != null)
|
||||
return false;
|
||||
} else if (!os.equals(other.os))
|
||||
return false;
|
||||
return true;
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper("").add("id", getId()).add("providerId", getProviderId()).add("group", getGroup())
|
||||
.add("name", getName()).add("location", getLocation()).add("uri", getUri()).add("imageId", getImageId())
|
||||
.add("os", getOperatingSystem()).add("status", formatStatus(this)).add("loginPort", getLoginPort()).add(
|
||||
"hostname", getHostname()).add("privateAddresses", getPrivateAddresses()).add(
|
||||
"publicAddresses", getPublicAddresses()).add("hardware", getHardware()).add("loginUser",
|
||||
((credentials != null) ? credentials.identity : null)).add("tags", getTags()).add(
|
||||
"userMetadata", getUserMetadata());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import static com.google.common.collect.Sets.newLinkedHashSet;
|
|||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.all;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
|
||||
import static org.jclouds.concurrent.FutureIterables.transformParallel;
|
||||
|
||||
|
@ -578,7 +579,7 @@ public class BaseComputeService implements ComputeService {
|
|||
throw new NoSuchElementException(id);
|
||||
if (node.getStatus() != Status.RUNNING)
|
||||
throw new IllegalStateException("node " + id
|
||||
+ " needs to be running before executing a script on it. current state: " + node.getStatus());
|
||||
+ " needs to be running before executing a script on it. current state: " + formatStatus(node));
|
||||
initAdminAccess.visit(runScript);
|
||||
node = updateNodeWithCredentialsIfPresent(node, options);
|
||||
ExecResponse response = runScriptOnNodeFactory.create(node, runScript, options).init().call();
|
||||
|
@ -597,7 +598,7 @@ public class BaseComputeService implements ComputeService {
|
|||
throw new NoSuchElementException(id);
|
||||
if (node.getStatus() != Status.RUNNING)
|
||||
throw new IllegalStateException("node " + id
|
||||
+ " needs to be running before executing a script on it. current state: " + node.getStatus());
|
||||
+ " needs to be running before executing a script on it. current state: " + formatStatus(node));
|
||||
initAdminAccess.visit(runScript);
|
||||
final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options);
|
||||
ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node1, runScript, options);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.compute.predicates.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -66,10 +67,10 @@ public abstract class RefreshAndDoubleCheckOnFailUnlessStatusInvalid<S extends E
|
|||
public boolean checkStatus(C resource) {
|
||||
if (resource == null)
|
||||
return false;
|
||||
logger.trace("%s: looking for resource state %s: currently: %s", resource.getId(), intended, resource.getStatus());
|
||||
logger.trace("%s: looking for resource state %s: currently: %s", resource.getId(), intended, formatStatus(resource));
|
||||
if (invalids.contains(resource.getStatus()))
|
||||
throw new IllegalStateException("resource " + resource.getId() + " in location " + resource.getLocation()
|
||||
+ " is in invalid status " + resource.getStatus());
|
||||
+ " is in invalid status " + formatStatus(resource));
|
||||
return resource.getStatus() == intended;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.compute.predicates.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -57,8 +58,7 @@ public abstract class TrueIfNullOrDeletedRefreshAndDoubleCheckOnFalse<S extends
|
|||
public boolean checkStatus(C resource) {
|
||||
if (resource == null)
|
||||
return true;
|
||||
logger.trace("%s: looking for resource status %s: currently: %s", resource.getId(), deletedStatus, resource
|
||||
.getStatus());
|
||||
logger.trace("%s: looking for resource status %s: currently: %s", resource.getId(), deletedStatus, formatStatus(resource));
|
||||
return resource.getStatus() == deletedStatus;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Throwables.getRootCause;
|
||||
import static java.lang.String.format;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -141,12 +142,12 @@ public class CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap implements Cal
|
|||
throw new IllegalStateException(
|
||||
format(
|
||||
"node(%s) didn't achieve the status running, so we couldn't customize; aborting prematurely after %d seconds with final status: %s",
|
||||
originalId, timeWaited / 1000, node.get().getStatus()));
|
||||
originalId, timeWaited / 1000, formatStatus(node.get())));
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
format(
|
||||
"node(%s) didn't achieve the status running within %d seconds, so we couldn't customize; final status: %s",
|
||||
originalId, timeouts.nodeRunning / 1000, node.get().getStatus()));
|
||||
originalId, timeouts.nodeRunning / 1000, formatStatus(node.get())));
|
||||
}
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.compute.strategy.impl;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -127,7 +128,8 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeW
|
|||
}
|
||||
|
||||
private void checkStateAvailable(NodeMetadata node) {
|
||||
checkState(node != null && node.getStatus() != Status.TERMINATED, "node %s terminated or unavailable!", node);
|
||||
checkState(node != null && node.getStatus() != Status.TERMINATED,
|
||||
"node %s terminated or unavailable! current status: %s", node, formatStatus(node));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
import static org.jclouds.concurrent.Futures.compose;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -79,7 +80,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
|
|||
logger.debug(">> adding node location(%s) name(%s) image(%s) hardware(%s)", template.getLocation().getId(),
|
||||
name, template.getImage().getProviderId(), template.getHardware().getProviderId());
|
||||
node = addNodeWithGroupStrategy.createNodeWithGroupEncodedIntoName(group, name, template);
|
||||
logger.debug("<< %s node(%s)", node.getStatus(), node.getId());
|
||||
logger.debug("<< %s node(%s)", formatStatus(node), node.getId());
|
||||
return new AtomicReference<NodeMetadata>(node);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.compute.stub.config;
|
||||
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -211,7 +213,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
|
|||
if (node.getStatus() == Status.RUNNING)
|
||||
return;
|
||||
if (node.getStatus() != Status.SUSPENDED)
|
||||
throw new IllegalStateException("to resume a node, it must be in suspended status, not: " + node.getStatus());
|
||||
throw new IllegalStateException("to resume a node, it must be in suspended status, not: " + formatStatus(node));
|
||||
setStateOnNode(Status.PENDING, node);
|
||||
setStateOnNodeAfterDelay(Status.RUNNING, node, 50);
|
||||
}
|
||||
|
@ -224,7 +226,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
|
|||
if (node.getStatus() == Status.SUSPENDED)
|
||||
return;
|
||||
if (node.getStatus() != Status.RUNNING)
|
||||
throw new IllegalStateException("to suspend a node, it must be in running status, not: " + node.getStatus());
|
||||
throw new IllegalStateException("to suspend a node, it must be in running status, not: " + formatStatus(node));
|
||||
setStateOnNode(Status.PENDING, node);
|
||||
setStateOnNodeAfterDelay(Status.SUSPENDED, node, 50);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.ComputeMetadataIncludingStatus;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
|
@ -58,6 +59,16 @@ import com.google.common.reflect.TypeToken;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class ComputeServiceUtils {
|
||||
|
||||
/**
|
||||
* status as a string which optionally includes the backend status
|
||||
*/
|
||||
public static String formatStatus(ComputeMetadataIncludingStatus<?> resource) {
|
||||
if (resource.getBackendStatus() == null)
|
||||
return resource.getStatus().toString();
|
||||
return String.format("%s[%s]", resource.getStatus(), resource.getBackendStatus());
|
||||
}
|
||||
|
||||
public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("(.+)-[0-9a-f]+");
|
||||
|
||||
/**
|
||||
|
|
|
@ -134,6 +134,7 @@ public class AtomicNodePredicatesTest {
|
|||
@Test
|
||||
public void testNodeRunningReturnsTrueWhenRunning() {
|
||||
expect(node.getStatus()).andReturn(Status.RUNNING).atLeastOnce();
|
||||
expect(node.getBackendStatus()).andReturn(null).atLeastOnce();
|
||||
replay(node);
|
||||
replay(computeService);
|
||||
|
||||
|
@ -146,6 +147,7 @@ public class AtomicNodePredicatesTest {
|
|||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testNodeRunningFailsOnTerminated() {
|
||||
expect(node.getStatus()).andReturn(Status.TERMINATED).atLeastOnce();
|
||||
expect(node.getBackendStatus()).andReturn(null).atLeastOnce();
|
||||
replay(node);
|
||||
replay(computeService);
|
||||
|
||||
|
@ -158,6 +160,7 @@ public class AtomicNodePredicatesTest {
|
|||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testNodeRunningFailsOnError() {
|
||||
expect(node.getStatus()).andReturn(Status.ERROR).atLeastOnce();
|
||||
expect(node.getBackendStatus()).andReturn(null).atLeastOnce();
|
||||
replay(node);
|
||||
replay(computeService);
|
||||
|
||||
|
|
|
@ -18,14 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.compute.util;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsValuesOfEmptyString;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseVersionOrReturnEmptyString;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.ComputeMetadataIncludingStatus;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
|
@ -45,8 +53,31 @@ import com.google.inject.Guice;
|
|||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
@Test(groups = "unit", testName = "ComputeServiceUtilsTest")
|
||||
public class ComputeServiceUtilsTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testFormatStatusWithBackendStatus() {
|
||||
ComputeMetadataIncludingStatus<Image.Status> resource = createMock(ComputeMetadataIncludingStatus.class);
|
||||
expect(resource.getStatus()).andReturn(Image.Status.PENDING);
|
||||
expect(resource.getBackendStatus()).andReturn("queued").anyTimes();
|
||||
replay(resource);
|
||||
assertEquals(formatStatus(resource), "PENDING[queued]");
|
||||
verify(resource);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testFormatStatusWithoutBackendStatus() {
|
||||
ComputeMetadataIncludingStatus<Image.Status> resource = createMock(ComputeMetadataIncludingStatus.class);
|
||||
expect(resource.getStatus()).andReturn(Image.Status.PENDING);
|
||||
expect(resource.getBackendStatus()).andReturn(null).anyTimes();
|
||||
replay(resource);
|
||||
assertEquals(formatStatus(resource), "PENDING");
|
||||
verify(resource);
|
||||
}
|
||||
|
||||
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
|
||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||
.getInstance(Json.class));
|
||||
|
|
Loading…
Reference in New Issue