mirror of https://github.com/apache/jclouds.git
Issue 280: converged 0.8 and 1.0 tasks
This commit is contained in:
parent
345684c6f2
commit
c08fb5ddfd
|
@ -128,6 +128,7 @@ public class SimpleDateFormatDateService implements DateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Date iso8601DateParse(String toParse) {
|
public final Date iso8601DateParse(String toParse) {
|
||||||
|
toParse = trimTZ(toParse);
|
||||||
toParse = trimNanosToMillis(toParse);
|
toParse = trimNanosToMillis(toParse);
|
||||||
synchronized (iso8601SimpleDateFormat) {
|
synchronized (iso8601SimpleDateFormat) {
|
||||||
try {
|
try {
|
||||||
|
@ -141,7 +142,7 @@ public class SimpleDateFormatDateService implements DateService {
|
||||||
public static final Pattern NANOS_TO_MILLIS_PATTERN = Pattern
|
public static final Pattern NANOS_TO_MILLIS_PATTERN = Pattern
|
||||||
.compile(".*[0-9][0-9][0-9][0-9][0-9][0-9]");
|
.compile(".*[0-9][0-9][0-9][0-9][0-9][0-9]");
|
||||||
|
|
||||||
public static final Pattern TZ_PATTERN = Pattern.compile(".*[+][0-9][0-9]:[0-9][0-9]");
|
public static final Pattern TZ_PATTERN = Pattern.compile(".*[+-][0-9][0-9]:[0-9][0-9]");
|
||||||
|
|
||||||
private String trimNanosToMillis(String toParse) {
|
private String trimNanosToMillis(String toParse) {
|
||||||
if (NANOS_TO_MILLIS_PATTERN.matcher(toParse).matches())
|
if (NANOS_TO_MILLIS_PATTERN.matcher(toParse).matches())
|
||||||
|
|
|
@ -80,7 +80,7 @@ public abstract class CommonVCloudComputeClientImpl<T, A extends NamedResource>
|
||||||
A vApp = refreshVApp(id);
|
A vApp = refreshVApp(id);
|
||||||
logger.debug(">> resetting vApp(%s)", vApp.getName());
|
logger.debug(">> resetting vApp(%s)", vApp.getName());
|
||||||
Task task = client.resetVApp(vApp.getId());
|
Task task = client.resetVApp(vApp.getId());
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "resetVApp", vApp.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "resetVApp", vApp.getName(), task));
|
||||||
}
|
}
|
||||||
logger.debug("<< on vApp(%s)", vApp.getName());
|
logger.debug("<< on vApp(%s)", vApp.getName());
|
||||||
|
@ -106,7 +106,7 @@ public abstract class CommonVCloudComputeClientImpl<T, A extends NamedResource>
|
||||||
if (getStatus(vApp).compareTo(Status.RESOLVED) > 0) {
|
if (getStatus(vApp).compareTo(Status.RESOLVED) > 0) {
|
||||||
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), getStatus(vApp));
|
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), getStatus(vApp));
|
||||||
Task task = client.undeployVApp(vApp.getId());
|
Task task = client.undeployVApp(vApp.getId());
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
// TODO timeout
|
// TODO timeout
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task));
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public abstract class CommonVCloudComputeClientImpl<T, A extends NamedResource>
|
||||||
if (getStatus(vApp).compareTo(Status.OFF) > 0) {
|
if (getStatus(vApp).compareTo(Status.OFF) > 0) {
|
||||||
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), getStatus(vApp));
|
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), getStatus(vApp));
|
||||||
Task task = client.powerOffVApp(vApp.getId());
|
Task task = client.powerOffVApp(vApp.getId());
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
// TODO timeout
|
// TODO timeout
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,14 +75,14 @@ public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl<VAppT
|
||||||
|
|
||||||
Task task = client.deployVApp(vAppResponse.getId());
|
Task task = client.deployVApp(vAppResponse.getId());
|
||||||
if (options.shouldBlockOnDeploy()) {
|
if (options.shouldBlockOnDeploy()) {
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
|
||||||
}
|
}
|
||||||
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
|
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
|
||||||
|
|
||||||
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
|
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
|
||||||
task = client.powerOnVApp(vAppResponse.getId());
|
task = client.powerOnVApp(vAppResponse.getId());
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(), task));
|
||||||
}
|
}
|
||||||
logger.debug("<< on vApp(%s)", vAppResponse.getName());
|
logger.debug("<< on vApp(%s)", vAppResponse.getName());
|
||||||
|
|
|
@ -77,14 +77,14 @@ public class VCloudExpressComputeClientImpl extends
|
||||||
|
|
||||||
Task task = client.deployVApp(vAppResponse.getId());
|
Task task = client.deployVApp(vAppResponse.getId());
|
||||||
if (options.shouldBlockOnDeploy()) {
|
if (options.shouldBlockOnDeploy()) {
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
|
||||||
}
|
}
|
||||||
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
|
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
|
||||||
|
|
||||||
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
|
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
|
||||||
task = client.powerOnVApp(vAppResponse.getId());
|
task = client.powerOnVApp(vAppResponse.getId());
|
||||||
if (!taskTester.apply(task.getLocation())) {
|
if (!taskTester.apply(task.getId())) {
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(), task));
|
||||||
}
|
}
|
||||||
logger.debug("<< on vApp(%s)", vAppResponse.getName());
|
logger.debug("<< on vApp(%s)", vAppResponse.getName());
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class VCloudRebootNodeStrategy implements RebootNodeStrategy {
|
||||||
public NodeMetadata execute(String in) {
|
public NodeMetadata execute(String in) {
|
||||||
URI id = URI.create(checkNotNull(in, "node.id"));
|
URI id = URI.create(checkNotNull(in, "node.id"));
|
||||||
Task task = client.resetVApp(id);
|
Task task = client.resetVApp(id);
|
||||||
taskTester.apply(task.getLocation());
|
taskTester.apply(task.getId());
|
||||||
return getNode.execute(in);
|
return getNode.execute(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,47 +19,89 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.domain;
|
package org.jclouds.vcloud.domain;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.jclouds.vcloud.domain.internal.TaskImpl;
|
import org.jclouds.vcloud.domain.internal.TaskImpl;
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
import com.google.inject.ImplementedBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* Whenever the result of a request cannot be returned immediately, the server creates a Task
|
||||||
|
* object. Tasks owned by an object such as a vApp or vDC are contained in the Tasks element of the
|
||||||
|
* object’s XML representation. This element is read‐only.
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(TaskImpl.class)
|
@ImplementedBy(TaskImpl.class)
|
||||||
public interface Task extends Comparable<Task> {
|
public interface Task extends NamedResource {
|
||||||
|
/**
|
||||||
URI getLocation();
|
* The current status of the task.
|
||||||
|
*/
|
||||||
TaskStatus getStatus();
|
TaskStatus getStatus();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date and time when the task was started.
|
||||||
|
*/
|
||||||
Date getStartTime();
|
Date getStartTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date and time when the task completed. Does not appear for running tasks.
|
||||||
|
*/
|
||||||
Date getEndTime();
|
Date getEndTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* date and time at which the task expires. By default, tasks expire 24 hours after their start
|
||||||
|
* time. Expired tasks cannot be queried.
|
||||||
|
*/
|
||||||
Date getExpiryTime();
|
Date getExpiryTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A link to the vDC in which the task was started
|
* A link to the object that owns the task. For copy operations, the owner is the copy that is
|
||||||
|
* being created. For delete operations, the owner is the deleted object, so this element is not
|
||||||
|
* included. For all other operations, the owner is the object to which the request was made.
|
||||||
*/
|
*/
|
||||||
NamedResource getOwner();
|
NamedResource getOwner();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A link to the result of the task
|
* error message or related information returned by the task
|
||||||
*/
|
*/
|
||||||
NamedResource getResult();
|
@Nullable
|
||||||
|
|
||||||
Error getError();
|
Error getError();
|
||||||
|
|
||||||
@ImplementedBy(TaskImpl.ErrorImpl.class)
|
@ImplementedBy(TaskImpl.ErrorImpl.class)
|
||||||
static interface Error {
|
static interface Error {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return message describing the error
|
||||||
|
*/
|
||||||
String getMessage();
|
String getMessage();
|
||||||
|
|
||||||
String getMajorErrorCode();
|
/**
|
||||||
|
*
|
||||||
|
* @return matches the HTTP status code
|
||||||
|
*/
|
||||||
|
int getMajorErrorCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return error code specific to the failed operation or null if vcloud <0.9
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
String getMinorErrorCode();
|
String getMinorErrorCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return optional additional information about the source of the error
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
String getVendorSpecificErrorCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return stack trace of the error, if available. This attribute is returned only when a
|
||||||
|
* request is made by the system administrator.
|
||||||
|
*/
|
||||||
|
String getStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -25,11 +25,27 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public enum TaskStatus {
|
public enum TaskStatus {
|
||||||
SUCCESS, FAILED, RUNNING, QUEUED, ERROR, CANCELLED,
|
|
||||||
/**
|
/**
|
||||||
* invalid status, temporarily in.
|
* The task has completed and returned a value indicating success.
|
||||||
*/
|
*/
|
||||||
COMPLETED;
|
SUCCESS,
|
||||||
|
/**
|
||||||
|
* The task is running.
|
||||||
|
*/
|
||||||
|
RUNNING,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The task has been queued for execution.
|
||||||
|
*/
|
||||||
|
QUEUED,
|
||||||
|
/**
|
||||||
|
* The task has completed and returned a value indicating an error.
|
||||||
|
*/
|
||||||
|
ERROR,
|
||||||
|
/**
|
||||||
|
* not an official status, temporarily in.
|
||||||
|
*/
|
||||||
|
CANCELLED;
|
||||||
public String value() {
|
public String value() {
|
||||||
return name().toLowerCase();
|
return name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
@ -43,6 +59,10 @@ public enum TaskStatus {
|
||||||
if ("CANCELED".equals(status.toUpperCase())) {
|
if ("CANCELED".equals(status.toUpperCase())) {
|
||||||
// TODO: ecloud hack
|
// TODO: ecloud hack
|
||||||
status = "CANCELLED";
|
status = "CANCELLED";
|
||||||
|
} else if ("FAILED".equals(status.toUpperCase())) {
|
||||||
|
status = "ERROR";
|
||||||
|
} else if ("COMPLETED".equals(status.toUpperCase())) {
|
||||||
|
status = "SUCCESS";
|
||||||
}
|
}
|
||||||
return valueOf(checkNotNull(status, "status").toUpperCase());
|
return valueOf(checkNotNull(status, "status").toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.jclouds.vcloud.VCloudMediaType;
|
||||||
import org.jclouds.vcloud.domain.NamedResource;
|
import org.jclouds.vcloud.domain.NamedResource;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.TaskStatus;
|
import org.jclouds.vcloud.domain.TaskStatus;
|
||||||
|
@ -35,24 +36,31 @@ import com.google.inject.internal.Nullable;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TaskImpl implements Task {
|
public class TaskImpl extends NamedResourceImpl implements Task {
|
||||||
|
|
||||||
public static class ErrorImpl implements Error {
|
public static class ErrorImpl implements Error {
|
||||||
private final String message;
|
private final String message;
|
||||||
private final String majorErrorCode;
|
private final int majorErrorCode;
|
||||||
private final String minorErrorCode;
|
private final String minorErrorCode;
|
||||||
|
@Nullable
|
||||||
|
private final String vendorSpecificErrorCode;
|
||||||
|
@Nullable
|
||||||
|
private final String stackTrace;
|
||||||
|
|
||||||
public ErrorImpl(String message, String majorErrorCode, String minorErrorCode) {
|
public ErrorImpl(String message, int majorErrorCode, @Nullable String minorErrorCode,
|
||||||
this.message = message;
|
@Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) {
|
||||||
this.majorErrorCode = majorErrorCode;
|
this.message = checkNotNull(message, "message");
|
||||||
this.minorErrorCode = minorErrorCode;
|
this.majorErrorCode = checkNotNull(majorErrorCode, "majorErrorCode");
|
||||||
|
this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone
|
||||||
|
this.vendorSpecificErrorCode = vendorSpecificErrorCode;
|
||||||
|
this.stackTrace = stackTrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMajorErrorCode() {
|
public int getMajorErrorCode() {
|
||||||
return majorErrorCode;
|
return majorErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,13 +68,23 @@ public class TaskImpl implements Task {
|
||||||
return minorErrorCode;
|
return minorErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVendorSpecificErrorCode() {
|
||||||
|
return vendorSpecificErrorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStackTrace() {
|
||||||
|
return stackTrace;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((majorErrorCode == null) ? 0 : majorErrorCode.hashCode());
|
result = prime * result + majorErrorCode;
|
||||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||||
result = prime * result + ((minorErrorCode == null) ? 0 : minorErrorCode.hashCode());
|
result = prime * result + ((minorErrorCode == null) ? 0 : minorErrorCode.hashCode());
|
||||||
|
result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode());
|
||||||
|
result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +97,7 @@ public class TaskImpl implements Task {
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
ErrorImpl other = (ErrorImpl) obj;
|
ErrorImpl other = (ErrorImpl) obj;
|
||||||
if (majorErrorCode == null) {
|
if (majorErrorCode != other.majorErrorCode)
|
||||||
if (other.majorErrorCode != null)
|
|
||||||
return false;
|
|
||||||
} else if (!majorErrorCode.equals(other.majorErrorCode))
|
|
||||||
return false;
|
return false;
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
if (other.message != null)
|
if (other.message != null)
|
||||||
|
@ -94,17 +109,27 @@ public class TaskImpl implements Task {
|
||||||
return false;
|
return false;
|
||||||
} else if (!minorErrorCode.equals(other.minorErrorCode))
|
} else if (!minorErrorCode.equals(other.minorErrorCode))
|
||||||
return false;
|
return false;
|
||||||
|
if (stackTrace == null) {
|
||||||
|
if (other.stackTrace != null)
|
||||||
|
return false;
|
||||||
|
} else if (!stackTrace.equals(other.stackTrace))
|
||||||
|
return false;
|
||||||
|
if (vendorSpecificErrorCode == null) {
|
||||||
|
if (other.vendorSpecificErrorCode != null)
|
||||||
|
return false;
|
||||||
|
} else if (!vendorSpecificErrorCode.equals(other.vendorSpecificErrorCode))
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ErrorImpl [majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode="
|
return "[majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode=" + minorErrorCode
|
||||||
+ minorErrorCode + "]";
|
+ ", stackTrace=" + stackTrace + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final URI id;
|
|
||||||
private final TaskStatus status;
|
private final TaskStatus status;
|
||||||
private final Date startTime;
|
private final Date startTime;
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -113,19 +138,16 @@ public class TaskImpl implements Task {
|
||||||
private final Date expiryTime;
|
private final Date expiryTime;
|
||||||
private final NamedResource owner;
|
private final NamedResource owner;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final NamedResource result;
|
|
||||||
@Nullable
|
|
||||||
private final Error error;
|
private final Error error;
|
||||||
|
|
||||||
public TaskImpl(URI id, TaskStatus status, Date startTime, @Nullable Date endTime, @Nullable Date expiryTime,
|
public TaskImpl(URI id, TaskStatus status, Date startTime, @Nullable Date endTime, @Nullable Date expiryTime,
|
||||||
NamedResource owner, @Nullable NamedResource result, Error error) {
|
NamedResource owner, Error error) {
|
||||||
this.id = checkNotNull(id, "id");
|
super(null, VCloudMediaType.TASK_XML, id);
|
||||||
this.status = checkNotNull(status, "status");
|
this.status = checkNotNull(status, "status");
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
this.expiryTime = expiryTime;
|
this.expiryTime = expiryTime;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.result = result;
|
|
||||||
this.error = error;
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,26 +166,11 @@ public class TaskImpl implements Task {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NamedResource getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getEndTime() {
|
public Date getEndTime() {
|
||||||
return endTime;
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Task o) {
|
|
||||||
return (this == o) ? 0 : getLocation().compareTo(o.getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URI getLocation() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Error getError() {
|
public Error getError() {
|
||||||
return error;
|
return error;
|
||||||
|
@ -176,9 +183,7 @@ public class TaskImpl implements Task {
|
||||||
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
|
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
|
||||||
result = prime * result + ((error == null) ? 0 : error.hashCode());
|
result = prime * result + ((error == null) ? 0 : error.hashCode());
|
||||||
result = prime * result + ((expiryTime == null) ? 0 : expiryTime.hashCode());
|
result = prime * result + ((expiryTime == null) ? 0 : expiryTime.hashCode());
|
||||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
|
||||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
||||||
result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
|
|
||||||
result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
|
result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
|
||||||
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
||||||
return result;
|
return result;
|
||||||
|
@ -208,21 +213,11 @@ public class TaskImpl implements Task {
|
||||||
return false;
|
return false;
|
||||||
} else if (!expiryTime.equals(other.expiryTime))
|
} else if (!expiryTime.equals(other.expiryTime))
|
||||||
return false;
|
return false;
|
||||||
if (id == null) {
|
|
||||||
if (other.id != null)
|
|
||||||
return false;
|
|
||||||
} else if (!id.equals(other.id))
|
|
||||||
return false;
|
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
if (other.owner != null)
|
if (other.owner != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!owner.equals(other.owner))
|
} else if (!owner.equals(other.owner))
|
||||||
return false;
|
return false;
|
||||||
if (result == null) {
|
|
||||||
if (other.result != null)
|
|
||||||
return false;
|
|
||||||
} else if (!result.equals(other.result))
|
|
||||||
return false;
|
|
||||||
if (startTime == null) {
|
if (startTime == null) {
|
||||||
if (other.startTime != null)
|
if (other.startTime != null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -238,8 +233,8 @@ public class TaskImpl implements Task {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TaskImpl [endTime=" + endTime + ", error=" + error + ", id=" + id + ", owner=" + owner
|
return "TaskImpl [endTime=" + endTime + ", error=" + error + ", id=" + getName() + ", owner=" + owner
|
||||||
+ ", result=" + result + ", startTime=" + startTime + ", status=" + status + "]";
|
+ ", startTime=" + startTime + ", status=" + status + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getExpiryTime() {
|
public Date getExpiryTime() {
|
||||||
|
|
|
@ -55,10 +55,9 @@ public class TaskSuccess implements Predicate<URI> {
|
||||||
logger.trace("looking for status on task %s", taskId);
|
logger.trace("looking for status on task %s", taskId);
|
||||||
|
|
||||||
Task task = client.getTask(taskId);
|
Task task = client.getTask(taskId);
|
||||||
logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task
|
logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task.getStatus());
|
||||||
.getStatus());
|
|
||||||
if (task.getStatus() == TaskStatus.ERROR)
|
if (task.getStatus() == TaskStatus.ERROR)
|
||||||
throw new RuntimeException("error on task: " + task.getLocation() + " error: " + task.getError());
|
throw new RuntimeException("error on task: " + task.getId() + " error: " + task.getError());
|
||||||
return task.getStatus() == TaskStatus.SUCCESS;
|
return task.getStatus() == TaskStatus.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class Utils {
|
||||||
String uri = attributes.getValue(attributes.getIndex("href"));
|
String uri = attributes.getValue(attributes.getIndex("href"));
|
||||||
String type = attributes.getValue(attributes.getIndex("type"));
|
String type = attributes.getValue(attributes.getIndex("type"));
|
||||||
return new NamedResourceImpl(attributes.getValue(attributes.getIndex("name")), type != null ? type : defaultType,
|
return new NamedResourceImpl(attributes.getValue(attributes.getIndex("name")), type != null ? type : defaultType,
|
||||||
URI.create(uri));
|
URI.create(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NamedResource newNamedResource(Attributes attributes) {
|
public static NamedResource newNamedResource(Attributes attributes) {
|
||||||
|
@ -45,8 +45,18 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task.Error newError(Attributes attributes) {
|
public static Task.Error newError(Attributes attributes) {
|
||||||
return new ErrorImpl(attrOrNull(attributes, "message"), attrOrNull(attributes, "majorErrorCode"), attrOrNull(
|
String minorErrorCode = attrOrNull(attributes, "minorErrorCode");
|
||||||
attributes, "minorErrorCode"));
|
String vendorSpecificErrorCode = attrOrNull(attributes, "vendorSpecificErrorCode");
|
||||||
|
int errorCode;
|
||||||
|
// remove this logic when vcloud 0.8 is gone
|
||||||
|
try {
|
||||||
|
errorCode = Integer.parseInt(attrOrNull(attributes, "majorErrorCode"));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
errorCode = 500;
|
||||||
|
vendorSpecificErrorCode = attrOrNull(attributes, "majorErrorCode");
|
||||||
|
}
|
||||||
|
return new ErrorImpl(attrOrNull(attributes, "message"), errorCode, minorErrorCode, vendorSpecificErrorCode,
|
||||||
|
attrOrNull(attributes, "stackTrace"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String attrOrNull(Attributes attributes, String attr) {
|
public static String attrOrNull(Attributes attributes, String attr) {
|
||||||
|
|
|
@ -22,7 +22,6 @@ package org.jclouds.vcloud.xml;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
|
@ -45,7 +44,6 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||||
|
|
||||||
private NamedResource taskLink;
|
private NamedResource taskLink;
|
||||||
private NamedResource owner;
|
private NamedResource owner;
|
||||||
private NamedResource result;
|
|
||||||
private TaskStatus status;
|
private TaskStatus status;
|
||||||
private Date startTime;
|
private Date startTime;
|
||||||
private Date endTime;
|
private Date endTime;
|
||||||
|
@ -53,7 +51,6 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||||
private Task task;
|
private Task task;
|
||||||
private Error error;
|
private Error error;
|
||||||
|
|
||||||
@Resource
|
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -78,13 +75,12 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||||
endTime = parseDate(attributes, "endTime");
|
endTime = parseDate(attributes, "endTime");
|
||||||
if (attributes.getIndex("expiryTime") != -1)
|
if (attributes.getIndex("expiryTime") != -1)
|
||||||
expiryTime = parseDate(attributes, "expiryTime");
|
expiryTime = parseDate(attributes, "expiryTime");
|
||||||
} else if (qName.equals("Owner")) {
|
// TODO technically the old Result object should only be owner for copy and delete tasks
|
||||||
|
} else if (qName.equals("Owner") || qName.equals("Result")) {
|
||||||
owner = Utils.newNamedResource(attributes);
|
owner = Utils.newNamedResource(attributes);
|
||||||
} else if (qName.equals("Link") && attributes.getIndex("rel") != -1
|
} else if (qName.equals("Link") && attributes.getIndex("rel") != -1
|
||||||
&& attributes.getValue(attributes.getIndex("rel")).equals("self")) {
|
&& attributes.getValue(attributes.getIndex("rel")).equals("self")) {
|
||||||
taskLink = Utils.newNamedResource(attributes);
|
taskLink = Utils.newNamedResource(attributes);
|
||||||
} else if (qName.equals("Result")) {
|
|
||||||
result = Utils.newNamedResource(attributes);
|
|
||||||
} else if (qName.equals("Error")) {
|
} else if (qName.equals("Error")) {
|
||||||
error = Utils.newError(attributes);
|
error = Utils.newError(attributes);
|
||||||
}
|
}
|
||||||
|
@ -96,13 +92,9 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||||
return dateService.iso8601DateParse(toParse);
|
return dateService.iso8601DateParse(toParse);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (e.getCause() instanceof ParseException) {
|
if (e.getCause() instanceof ParseException) {
|
||||||
try {
|
if (!toParse.endsWith("Z"))
|
||||||
if (!toParse.endsWith("Z"))
|
toParse += "Z";
|
||||||
toParse += "Z";
|
return dateService.iso8601SecondsDateParse(toParse);
|
||||||
return dateService.iso8601SecondsDateParse(toParse);
|
|
||||||
} catch (RuntimeException ex) {
|
|
||||||
logger.error(e, "error parsing date");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.error(e, "error parsing date");
|
logger.error(e, "error parsing date");
|
||||||
}
|
}
|
||||||
|
@ -113,13 +105,12 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||||
@Override
|
@Override
|
||||||
public void endElement(String uri, String localName, String qName) {
|
public void endElement(String uri, String localName, String qName) {
|
||||||
if (qName.equalsIgnoreCase("Task")) {
|
if (qName.equalsIgnoreCase("Task")) {
|
||||||
this.task = new TaskImpl(taskLink.getId(), status, startTime, endTime, expiryTime, owner, result, error);
|
this.task = new TaskImpl(taskLink.getId(), status, startTime, endTime, expiryTime, owner, error);
|
||||||
taskLink = null;
|
taskLink = null;
|
||||||
status = null;
|
status = null;
|
||||||
startTime = null;
|
startTime = null;
|
||||||
endTime = null;
|
endTime = null;
|
||||||
owner = null;
|
owner = null;
|
||||||
result = null;
|
|
||||||
error = null;
|
error = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
||||||
assertNotNull(response.getTasks());
|
assertNotNull(response.getTasks());
|
||||||
if (response.getTasks().size() > 0) {
|
if (response.getTasks().size() > 0) {
|
||||||
Task task = response.getTasks().last();
|
Task task = response.getTasks().last();
|
||||||
assertEquals(connection.getTask(task.getLocation()).getLocation(), task.getLocation());
|
assertEquals(connection.getTask(task.getId()).getId(), task.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.jclouds.vcloud.VCloudExpressMediaType;
|
import org.jclouds.vcloud.VCloudMediaType;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.TaskStatus;
|
import org.jclouds.vcloud.domain.TaskStatus;
|
||||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||||
|
@ -51,20 +51,34 @@ public class TaskHandlerTest extends BaseHandlerTest {
|
||||||
dateService = injector.getInstance(DateService.class);
|
dateService = injector.getInstance(DateService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testApplyInputStream() {
|
public void test() {
|
||||||
InputStream is = getClass().getResourceAsStream("/express/task.xml");
|
InputStream is = getClass().getResourceAsStream("/task.xml");
|
||||||
|
|
||||||
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
|
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
|
||||||
|
|
||||||
|
Task expects = new TaskImpl(URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320"),
|
||||||
|
TaskStatus.RUNNING, dateService.iso8601DateParse("2010-08-23T02:09:52.443-04:00"), dateService
|
||||||
|
.iso8601DateParse("9999-12-31T23:59:59.999-05:00"), dateService
|
||||||
|
.iso8601DateParse("2010-11-21T02:09:52.443-05:00"), new NamedResourceImpl("vApp_acole_2",
|
||||||
|
VCloudMediaType.VAPP_XML, URI
|
||||||
|
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320"))
|
||||||
|
|
||||||
|
, null
|
||||||
|
|
||||||
|
);
|
||||||
|
assertEquals(result, expects);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTerremark() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/express/task.xml");
|
||||||
|
|
||||||
|
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
|
||||||
Task expects = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
|
Task expects = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
|
||||||
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService
|
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService
|
||||||
.iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("VDC Name",
|
.iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("Server1",
|
||||||
VCloudExpressMediaType.VDC_XML, URI
|
VCloudMediaType.VAPP_XML, URI
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null
|
||||||
new NamedResourceImpl("Server1", VCloudExpressMediaType.VAPP_XML, URI
|
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")
|
|
||||||
|
|
||||||
), null
|
|
||||||
|
|
||||||
);
|
);
|
||||||
assertEquals(result, expects);
|
assertEquals(result, expects);
|
||||||
|
@ -77,7 +91,7 @@ public class TaskHandlerTest extends BaseHandlerTest {
|
||||||
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
|
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
|
||||||
|
|
||||||
Task expects = new TaskImpl(URI.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"),
|
Task expects = new TaskImpl(URI.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"),
|
||||||
TaskStatus.QUEUED, null, null, null, null, null, null);
|
TaskStatus.QUEUED, null, null, null, null, null);
|
||||||
assertEquals(result, expects);
|
assertEquals(result, expects);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,8 +106,8 @@ public class TaskHandlerTest extends BaseHandlerTest {
|
||||||
.iso8601SecondsDateParse("2010-01-14T20:05:02Z"), dateService
|
.iso8601SecondsDateParse("2010-01-14T20:05:02Z"), dateService
|
||||||
.iso8601SecondsDateParse("2010-01-15T20:05:02Z"),
|
.iso8601SecondsDateParse("2010-01-15T20:05:02Z"),
|
||||||
|
|
||||||
new NamedResourceImpl("188849-96", VCloudExpressMediaType.VAPP_XML, URI
|
new NamedResourceImpl("188849-96", VCloudMediaType.VAPP_XML, URI
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96")), null, null);
|
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96")), null);
|
||||||
assertEquals(result, expects);
|
assertEquals(result, expects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,11 +118,10 @@ public class TaskHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
Task expects = new TaskImpl(URI.create("http://10.150.4.49/api/v0.8/task/23"), TaskStatus.ERROR, dateService
|
Task expects = new TaskImpl(URI.create("http://10.150.4.49/api/v0.8/task/23"), TaskStatus.ERROR, dateService
|
||||||
.iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService
|
.iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService
|
||||||
.iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new NamedResourceImpl("APIOrg",
|
.iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new NamedResourceImpl("testapp1",
|
||||||
VCloudExpressMediaType.ORG_XML, URI.create("http://10.150.4.49/api/v0.8/org/1")), new NamedResourceImpl(
|
VCloudMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), new TaskImpl.ErrorImpl(
|
||||||
"testapp1", VCloudExpressMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")),
|
"Error processing job", 500, " Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00",
|
||||||
new TaskImpl.ErrorImpl("Error processing job", "500",
|
null, null));
|
||||||
" Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00"));
|
|
||||||
assertEquals(result, expects);
|
assertEquals(result, expects);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,21 +59,17 @@ public class TasksListHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
TasksList result = factory.create(injector.getInstance(TasksListHandler.class)).parse(is);
|
TasksList result = factory.create(injector.getInstance(TasksListHandler.class)).parse(is);
|
||||||
assertEquals(result.getLocation(), URI
|
assertEquals(result.getLocation(), URI
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/1"));
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/1"));
|
||||||
Task task1 = new TaskImpl(
|
Task task1 = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"),
|
||||||
|
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:30:19.587Z"), dateService
|
||||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"), TaskStatus.SUCCESS, dateService
|
.iso8601DateParse("2009-08-24T21:30:32.63Z"), null, new NamedResourceImpl("Server1",
|
||||||
.iso8601DateParse("2009-08-24T21:30:19.587Z"), dateService.iso8601DateParse("2009-08-24T21:30:32.63Z"),
|
VCloudExpressMediaType.VAPP_XML, URI
|
||||||
null, new NamedResourceImpl("VDC Name", VCloudExpressMediaType.VDC_XML, URI
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null);
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), new NamedResourceImpl(
|
|
||||||
"Server1", VCloudExpressMediaType.VAPP_XML, URI
|
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null);
|
|
||||||
Task task2 = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
|
Task task2 = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
|
||||||
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService
|
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService
|
||||||
.iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("VDC Name",
|
.iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("Server1",
|
||||||
VCloudExpressMediaType.VDC_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
|
VCloudExpressMediaType.VAPP_XML, URI
|
||||||
new NamedResourceImpl("Server1", VCloudExpressMediaType.VAPP_XML, URI
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null);
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null);
|
|
||||||
assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2));
|
assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Task status="running" startTime="2010-08-23T02:09:52.443-04:00"
|
||||||
|
operation="Creating Virtual Application vApp_acole_2(607806320)"
|
||||||
|
expiryTime="2010-11-21T02:09:52.443-05:00" endTime="9999-12-31T23:59:59.999-05:00"
|
||||||
|
type="application/vnd.vmware.vcloud.task+xml"
|
||||||
|
href="https://vcenterprise.bluelock.com/api/v1.0/task/3cc08ir8oczbze3n1a3">
|
||||||
|
<Owner type="application/vnd.vmware.vcloud.vApp+xml" name="vApp_acole_2"
|
||||||
|
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320" />
|
||||||
|
</Task>
|
|
@ -233,7 +233,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
|
||||||
private void powerOffAndWait(VCloudExpressVApp vApp) {
|
private void powerOffAndWait(VCloudExpressVApp vApp) {
|
||||||
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
|
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
|
||||||
Task task = client.powerOffVApp(vApp.getId());
|
Task task = client.powerOffVApp(vApp.getId());
|
||||||
if (!taskTester.apply(task.getLocation()))
|
if (!taskTester.apply(task.getId()))
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
if (!taskTester.apply(lastTask.getLocation()))
|
if (!taskTester.apply(lastTask.getId()))
|
||||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), lastTask));
|
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), lastTask));
|
||||||
} catch (NoSuchElementException ex) {
|
} catch (NoSuchElementException ex) {
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ParseTaskFromLocationHeader implements Function<HttpResponse, Task>
|
||||||
if (location == null)
|
if (location == null)
|
||||||
location = from.getFirstHeaderOrNull("location");
|
location = from.getFirstHeaderOrNull("location");
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
return new TaskImpl(URI.create(location), TaskStatus.QUEUED, new Date(), null, null, null, null, null);
|
return new TaskImpl(URI.create(location), TaskStatus.QUEUED, new Date(), null, null, null, null);
|
||||||
} else {
|
} else {
|
||||||
throw new HttpResponseException("no uri in headers or content", null, from);
|
throw new HttpResponseException("no uri in headers or content", null, from);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ import org.jclouds.vcloud.domain.Catalog;
|
||||||
import org.jclouds.vcloud.domain.NamedResource;
|
import org.jclouds.vcloud.domain.NamedResource;
|
||||||
import org.jclouds.vcloud.domain.ResourceAllocation;
|
import org.jclouds.vcloud.domain.ResourceAllocation;
|
||||||
import org.jclouds.vcloud.domain.ResourceType;
|
import org.jclouds.vcloud.domain.ResourceType;
|
||||||
|
import org.jclouds.vcloud.domain.Status;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||||
import org.jclouds.vcloud.domain.Status;
|
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
||||||
import org.jclouds.vcloud.domain.VDC;
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
import org.jclouds.vcloud.options.CloneVAppOptions;
|
import org.jclouds.vcloud.options.CloneVAppOptions;
|
||||||
|
@ -185,19 +185,19 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
|
|
||||||
// check to see the result of calling deploy twice
|
// check to see the result of calling deploy twice
|
||||||
deployTask = tmClient.deployVApp(vApp.getId());
|
deployTask = tmClient.deployVApp(vApp.getId());
|
||||||
assertEquals(deployTask.getLocation(), deployTask.getLocation());
|
assertEquals(deployTask.getId(), deployTask.getId());
|
||||||
|
|
||||||
vApp = tmClient.getVApp(vApp.getId());
|
vApp = tmClient.getVApp(vApp.getId());
|
||||||
|
|
||||||
assertEquals(vApp.getStatus(), Status.RESOLVED);
|
assertEquals(vApp.getStatus(), Status.RESOLVED);
|
||||||
|
|
||||||
try {// per docs, this is not supported
|
try {// per docs, this is not supported
|
||||||
tmClient.cancelTask(deployTask.getLocation());
|
tmClient.cancelTask(deployTask.getId());
|
||||||
} catch (HttpResponseException e) {
|
} catch (HttpResponseException e) {
|
||||||
assertEquals(e.getResponse().getStatusCode(), 501);
|
assertEquals(e.getResponse().getStatusCode(), 501);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert successTester.apply(deployTask.getLocation());
|
assert successTester.apply(deployTask.getId());
|
||||||
System.out.printf("%d: done deploying vApp%n", System.currentTimeMillis());
|
System.out.printf("%d: done deploying vApp%n", System.currentTimeMillis());
|
||||||
|
|
||||||
vApp = tmClient.getVApp(vApp.getId());
|
vApp = tmClient.getVApp(vApp.getId());
|
||||||
|
@ -210,7 +210,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
|
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
|
||||||
assertEquals(vApp.getStatus(), Status.OFF);
|
assertEquals(vApp.getStatus(), Status.OFF);
|
||||||
|
|
||||||
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getId());
|
||||||
System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis());
|
System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis());
|
||||||
|
|
||||||
vApp = tmClient.getVApp(vApp.getId());
|
vApp = tmClient.getVApp(vApp.getId());
|
||||||
|
@ -240,7 +240,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testInstantiateAndPowerOn")
|
@Test(enabled = true, dependsOnMethods = "testInstantiateAndPowerOn")
|
||||||
public void testCloneVApp() throws IOException {
|
public void testCloneVApp() throws IOException {
|
||||||
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId());
|
||||||
System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis());
|
System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis());
|
||||||
|
|
||||||
StringBuffer name = new StringBuffer();
|
StringBuffer name = new StringBuffer();
|
||||||
|
@ -254,16 +254,16 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
Task task = tmClient.cloneVAppInVDC(vdc.getId(), vApp.getId(), newName, options);
|
Task task = tmClient.cloneVAppInVDC(vdc.getId(), vApp.getId(), newName, options);
|
||||||
|
|
||||||
// wait for the task to complete
|
// wait for the task to complete
|
||||||
assert successTester.apply(task.getLocation());
|
assert successTester.apply(task.getId());
|
||||||
System.out.printf("%d: done cloning vApp%n", System.currentTimeMillis());
|
System.out.printf("%d: done cloning vApp%n", System.currentTimeMillis());
|
||||||
|
|
||||||
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getId());
|
||||||
System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis());
|
System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis());
|
||||||
|
|
||||||
// refresh task to get the new vApp location
|
// refresh task to get the new vApp location
|
||||||
task = tmClient.getTask(task.getLocation());
|
task = tmClient.getTask(task.getId());
|
||||||
|
|
||||||
clone = tmClient.getVApp(task.getResult().getId());
|
clone = tmClient.getVApp(task.getOwner().getId());
|
||||||
assertEquals(clone.getStatus(), Status.ON);
|
assertEquals(clone.getStatus(), Status.ON);
|
||||||
|
|
||||||
assertEquals(clone.getName(), newName);
|
assertEquals(clone.getName(), newName);
|
||||||
|
@ -312,7 +312,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
assertEquals(e.getResponse().getStatusCode(), 501);
|
assertEquals(e.getResponse().getStatusCode(), 501);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert successTester.apply(tmClient.resetVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.resetVApp(vApp.getId()).getId());
|
||||||
|
|
||||||
vApp = tmClient.getVApp(vApp.getId());
|
vApp = tmClient.getVApp(vApp.getId());
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
// vApp = tmClient.getVApp(vApp.getId());
|
// vApp = tmClient.getVApp(vApp.getId());
|
||||||
// assertEquals(vApp.getStatus(), VAppStatus.ON);
|
// assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||||
|
|
||||||
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId());
|
||||||
|
|
||||||
vApp = tmClient.getVApp(vApp.getId());
|
vApp = tmClient.getVApp(vApp.getId());
|
||||||
assertEquals(vApp.getStatus(), Status.OFF);
|
assertEquals(vApp.getStatus(), Status.OFF);
|
||||||
|
@ -338,7 +338,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1)
|
Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1)
|
||||||
.addDisk(25 * 1048576).addDisk(25 * 1048576));
|
.addDisk(25 * 1048576).addDisk(25 * 1048576));
|
||||||
|
|
||||||
assert successTester.apply(task.getLocation());
|
assert successTester.apply(task.getId());
|
||||||
|
|
||||||
vApp = tmClient.getVApp(vApp.getId());
|
vApp = tmClient.getVApp(vApp.getId());
|
||||||
assertEquals(vApp.getName(), "eduardo");
|
assertEquals(vApp.getName(), "eduardo");
|
||||||
|
@ -346,11 +346,11 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(), 1536);
|
assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(), 1536);
|
||||||
assertEquals(size(filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))), 3);
|
assertEquals(size(filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))), 3);
|
||||||
|
|
||||||
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getId());
|
||||||
|
|
||||||
loopAndCheckPass();
|
loopAndCheckPass();
|
||||||
|
|
||||||
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId());
|
||||||
|
|
||||||
// extract the disks on the vApp sorted by addressOnParent
|
// extract the disks on the vApp sorted by addressOnParent
|
||||||
List<ResourceAllocation> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(),
|
List<ResourceAllocation> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(),
|
||||||
|
@ -359,14 +359,14 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
// delete the second disk
|
// delete the second disk
|
||||||
task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(disks.get(1).getAddressOnParent()));
|
task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(disks.get(1).getAddressOnParent()));
|
||||||
|
|
||||||
assert successTester.apply(task.getLocation());
|
assert successTester.apply(task.getId());
|
||||||
|
|
||||||
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getLocation());
|
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getId());
|
||||||
loopAndCheckPass();
|
loopAndCheckPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, int processorCount,
|
private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs,
|
||||||
long memory, long hardDisk) {
|
int processorCount, long memory, long hardDisk) {
|
||||||
assertEquals(vApp.getName(), serverName);
|
assertEquals(vApp.getName(), serverName);
|
||||||
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
|
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
|
||||||
assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(),
|
assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(),
|
||||||
|
@ -410,7 +410,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
tmClient.deleteInternetService(is.getId());
|
tmClient.deleteInternetService(is.getId());
|
||||||
if (vApp != null) {
|
if (vApp != null) {
|
||||||
try {
|
try {
|
||||||
successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation());
|
successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
}
|
}
|
||||||
if (clone != null) {
|
if (clone != null) {
|
||||||
try {
|
try {
|
||||||
successTester.apply(tmClient.powerOffVApp(clone.getId()).getLocation());
|
successTester.apply(tmClient.powerOffVApp(clone.getId()).getId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,9 @@ import java.util.Map;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.vcloud.domain.Status;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||||
import org.jclouds.vcloud.domain.Status;
|
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
||||||
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
|
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
|
||||||
import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
|
import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
|
||||||
|
@ -73,9 +73,9 @@ public class TerremarkVCloudComputeClientTest {
|
||||||
expect(vdc.getId()).andReturn(vdcURI);
|
expect(vdc.getId()).andReturn(vdcURI);
|
||||||
expect(template.getId()).andReturn(templateURI);
|
expect(template.getId()).andReturn(templateURI);
|
||||||
expect(
|
expect(
|
||||||
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
|
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
|
||||||
new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password"))).andReturn(
|
new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password")))
|
||||||
vApp);
|
.andReturn(vApp);
|
||||||
Task task = createMock(Task.class);
|
Task task = createMock(Task.class);
|
||||||
URI vappLocation = URI.create("vapp");
|
URI vappLocation = URI.create("vapp");
|
||||||
URI taskLocation = URI.create("task");
|
URI taskLocation = URI.create("task");
|
||||||
|
@ -83,7 +83,7 @@ public class TerremarkVCloudComputeClientTest {
|
||||||
expect(vApp.getId()).andReturn(vappLocation).atLeastOnce();
|
expect(vApp.getId()).andReturn(vappLocation).atLeastOnce();
|
||||||
expect(vApp.getName()).andReturn("name").atLeastOnce();
|
expect(vApp.getName()).andReturn("name").atLeastOnce();
|
||||||
expect(client.deployVApp(vappLocation)).andReturn(task);
|
expect(client.deployVApp(vappLocation)).andReturn(task);
|
||||||
expect(task.getLocation()).andReturn(taskLocation).atLeastOnce();
|
expect(task.getId()).andReturn(taskLocation).atLeastOnce();
|
||||||
Predicate<URI> successTester = createMock(Predicate.class);
|
Predicate<URI> successTester = createMock(Predicate.class);
|
||||||
expect(successTester.apply(taskLocation)).andReturn(true).atLeastOnce();
|
expect(successTester.apply(taskLocation)).andReturn(true).atLeastOnce();
|
||||||
expect(client.powerOnVApp(vappLocation)).andReturn(task);
|
expect(client.powerOnVApp(vappLocation)).andReturn(task);
|
||||||
|
@ -92,14 +92,14 @@ public class TerremarkVCloudComputeClientTest {
|
||||||
Map<Status, NodeState> vAppStatusToNodeState = createMock(Map.class);
|
Map<Status, NodeState> vAppStatusToNodeState = createMock(Map.class);
|
||||||
|
|
||||||
TerremarkVCloudComputeClient computeClient = new TerremarkVCloudComputeClient(client,
|
TerremarkVCloudComputeClient computeClient = new TerremarkVCloudComputeClient(client,
|
||||||
new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(), new Provider<String>() {
|
new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(), new Provider<String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get() {
|
public String get() {
|
||||||
return "password";
|
return "password";
|
||||||
}
|
}
|
||||||
|
|
||||||
}, successTester, vAppStatusToNodeState);
|
}, successTester, vAppStatusToNodeState);
|
||||||
|
|
||||||
replay(vdc);
|
replay(vdc);
|
||||||
replay(template);
|
replay(template);
|
||||||
|
@ -111,7 +111,7 @@ public class TerremarkVCloudComputeClientTest {
|
||||||
replay(vAppStatusToNodeState);
|
replay(vAppStatusToNodeState);
|
||||||
|
|
||||||
Map<String, String> response = computeClient.start(vdcURI, templateURI, "name",
|
Map<String, String> response = computeClient.start(vdcURI, templateURI, "name",
|
||||||
new TerremarkInstantiateVAppTemplateOptions());
|
new TerremarkInstantiateVAppTemplateOptions());
|
||||||
|
|
||||||
assertEquals(response.get("id"), "vapp");
|
assertEquals(response.get("id"), "vapp");
|
||||||
assertEquals(response.get("username"), "Administrator");
|
assertEquals(response.get("username"), "Administrator");
|
||||||
|
|
Loading…
Reference in New Issue