diff --git a/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java b/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java index 1d26a9716b..2d4105f514 100755 --- a/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java +++ b/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java @@ -128,6 +128,7 @@ public class SimpleDateFormatDateService implements DateService { } public final Date iso8601DateParse(String toParse) { + toParse = trimTZ(toParse); toParse = trimNanosToMillis(toParse); synchronized (iso8601SimpleDateFormat) { try { @@ -141,7 +142,7 @@ public class SimpleDateFormatDateService implements DateService { public static final Pattern NANOS_TO_MILLIS_PATTERN = Pattern .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) { if (NANOS_TO_MILLIS_PATTERN.matcher(toParse).matches()) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java index c061da6120..a14a4be243 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/CommonVCloudComputeClientImpl.java @@ -80,7 +80,7 @@ public abstract class CommonVCloudComputeClientImpl A vApp = refreshVApp(id); logger.debug(">> resetting vApp(%s)", vApp.getName()); 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)); } logger.debug("<< on vApp(%s)", vApp.getName()); @@ -106,7 +106,7 @@ public abstract class CommonVCloudComputeClientImpl if (getStatus(vApp).compareTo(Status.RESOLVED) > 0) { logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), getStatus(vApp)); Task task = client.undeployVApp(vApp.getId()); - if (!taskTester.apply(task.getLocation())) { + if (!taskTester.apply(task.getId())) { // TODO timeout throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task)); } @@ -120,7 +120,7 @@ public abstract class CommonVCloudComputeClientImpl if (getStatus(vApp).compareTo(Status.OFF) > 0) { logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), getStatus(vApp)); Task task = client.powerOffVApp(vApp.getId()); - if (!taskTester.apply(task.getLocation())) { + if (!taskTester.apply(task.getId())) { // TODO timeout throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task)); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java index becb98aef3..f27078fbdd 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudComputeClientImpl.java @@ -75,14 +75,14 @@ public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl> powering vApp(%s)", vAppResponse.getName()); 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)); } logger.debug("<< on vApp(%s)", vAppResponse.getName()); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java index 37899441bb..07497447d3 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudExpressComputeClientImpl.java @@ -77,14 +77,14 @@ public class VCloudExpressComputeClientImpl extends Task task = client.deployVApp(vAppResponse.getId()); 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)); } logger.debug("<< deployed vApp(%s)", vAppResponse.getName()); logger.debug(">> powering vApp(%s)", vAppResponse.getName()); 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)); } logger.debug("<< on vApp(%s)", vAppResponse.getName()); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java index 1288e09a35..0b022fe131 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java @@ -55,7 +55,7 @@ public class VCloudRebootNodeStrategy implements RebootNodeStrategy { public NodeMetadata execute(String in) { URI id = URI.create(checkNotNull(in, "node.id")); Task task = client.resetVApp(id); - taskTester.apply(task.getLocation()); + taskTester.apply(task.getId()); return getNode.execute(in); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java index 8d47e05094..bc68374415 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java @@ -19,47 +19,89 @@ package org.jclouds.vcloud.domain; -import java.net.URI; import java.util.Date; +import javax.annotation.Nullable; + import org.jclouds.vcloud.domain.internal.TaskImpl; 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) -public interface Task extends Comparable { - - URI getLocation(); - +public interface Task extends NamedResource { + /** + * The current status of the task. + */ TaskStatus getStatus(); + /** + * date and time when the task was started. + */ Date getStartTime(); + /** + * date and time when the task completed. Does not appear for running tasks. + */ 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(); /** - * 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(); /** - * A link to the result of the task + * error message or related information returned by the task */ - NamedResource getResult(); - + @Nullable Error getError(); @ImplementedBy(TaskImpl.ErrorImpl.class) static interface Error { + /** + * + * @return message describing the error + */ 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(); + + /** + * + * @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(); } + } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java index d4a679a347..a88478fc93 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TaskStatus.java @@ -25,11 +25,27 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Adrian Cole */ 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() { return name().toLowerCase(); } @@ -43,6 +59,10 @@ public enum TaskStatus { if ("CANCELED".equals(status.toUpperCase())) { // TODO: ecloud hack status = "CANCELLED"; + } else if ("FAILED".equals(status.toUpperCase())) { + status = "ERROR"; + } else if ("COMPLETED".equals(status.toUpperCase())) { + status = "SUCCESS"; } return valueOf(checkNotNull(status, "status").toUpperCase()); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java index a44a87b3d4..79f16404cd 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Date; +import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TaskStatus; @@ -35,24 +36,31 @@ import com.google.inject.internal.Nullable; * @author Adrian Cole * */ -public class TaskImpl implements Task { +public class TaskImpl extends NamedResourceImpl implements Task { public static class ErrorImpl implements Error { private final String message; - private final String majorErrorCode; + private final int majorErrorCode; private final String minorErrorCode; + @Nullable + private final String vendorSpecificErrorCode; + @Nullable + private final String stackTrace; - public ErrorImpl(String message, String majorErrorCode, String minorErrorCode) { - this.message = message; - this.majorErrorCode = majorErrorCode; - this.minorErrorCode = minorErrorCode; + public ErrorImpl(String message, int majorErrorCode, @Nullable String minorErrorCode, + @Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) { + this.message = checkNotNull(message, "message"); + this.majorErrorCode = checkNotNull(majorErrorCode, "majorErrorCode"); + this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone + this.vendorSpecificErrorCode = vendorSpecificErrorCode; + this.stackTrace = stackTrace; } public String getMessage() { return message; } - public String getMajorErrorCode() { + public int getMajorErrorCode() { return majorErrorCode; } @@ -60,13 +68,23 @@ public class TaskImpl implements Task { return minorErrorCode; } + public String getVendorSpecificErrorCode() { + return vendorSpecificErrorCode; + } + + public String getStackTrace() { + return stackTrace; + } + @Override public int hashCode() { final int prime = 31; 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 + ((minorErrorCode == null) ? 0 : minorErrorCode.hashCode()); + result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode()); + result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.hashCode()); return result; } @@ -79,10 +97,7 @@ public class TaskImpl implements Task { if (getClass() != obj.getClass()) return false; ErrorImpl other = (ErrorImpl) obj; - if (majorErrorCode == null) { - if (other.majorErrorCode != null) - return false; - } else if (!majorErrorCode.equals(other.majorErrorCode)) + if (majorErrorCode != other.majorErrorCode) return false; if (message == null) { if (other.message != null) @@ -94,17 +109,27 @@ public class TaskImpl implements Task { return false; } else if (!minorErrorCode.equals(other.minorErrorCode)) 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; } @Override public String toString() { - return "ErrorImpl [majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode=" - + minorErrorCode + "]"; + return "[majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode=" + minorErrorCode + + ", stackTrace=" + stackTrace + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]"; } + } - private final URI id; private final TaskStatus status; private final Date startTime; @Nullable @@ -113,19 +138,16 @@ public class TaskImpl implements Task { private final Date expiryTime; private final NamedResource owner; @Nullable - private final NamedResource result; - @Nullable private final Error error; public TaskImpl(URI id, TaskStatus status, Date startTime, @Nullable Date endTime, @Nullable Date expiryTime, - NamedResource owner, @Nullable NamedResource result, Error error) { - this.id = checkNotNull(id, "id"); + NamedResource owner, Error error) { + super(null, VCloudMediaType.TASK_XML, id); this.status = checkNotNull(status, "status"); this.startTime = startTime; this.endTime = endTime; this.expiryTime = expiryTime; this.owner = owner; - this.result = result; this.error = error; } @@ -144,26 +166,11 @@ public class TaskImpl implements Task { return owner; } - @Override - public NamedResource getResult() { - return result; - } - @Override public Date getEndTime() { return endTime; } - @Override - public int compareTo(Task o) { - return (this == o) ? 0 : getLocation().compareTo(o.getLocation()); - } - - @Override - public URI getLocation() { - return id; - } - @Override public Error getError() { return error; @@ -176,9 +183,7 @@ public class TaskImpl implements Task { result = prime * result + ((endTime == null) ? 0 : endTime.hashCode()); result = prime * result + ((error == null) ? 0 : error.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 + ((this.result == null) ? 0 : this.result.hashCode()); result = prime * result + ((startTime == null) ? 0 : startTime.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); return result; @@ -208,21 +213,11 @@ public class TaskImpl implements Task { return false; } else if (!expiryTime.equals(other.expiryTime)) return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; if (owner == null) { if (other.owner != null) return false; } else if (!owner.equals(other.owner)) return false; - if (result == null) { - if (other.result != null) - return false; - } else if (!result.equals(other.result)) - return false; if (startTime == null) { if (other.startTime != null) return false; @@ -238,8 +233,8 @@ public class TaskImpl implements Task { @Override public String toString() { - return "TaskImpl [endTime=" + endTime + ", error=" + error + ", id=" + id + ", owner=" + owner - + ", result=" + result + ", startTime=" + startTime + ", status=" + status + "]"; + return "TaskImpl [endTime=" + endTime + ", error=" + error + ", id=" + getName() + ", owner=" + owner + + ", startTime=" + startTime + ", status=" + status + "]"; } public Date getExpiryTime() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java b/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java index 3572a597a7..6fb5edee8f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java @@ -55,10 +55,9 @@ public class TaskSuccess implements Predicate { logger.trace("looking for status on task %s", taskId); Task task = client.getTask(taskId); - logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task - .getStatus()); + logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task.getStatus()); 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; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java index 9d9cbbb395..9ee575b608 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java @@ -37,7 +37,7 @@ public class Utils { String uri = attributes.getValue(attributes.getIndex("href")); String type = attributes.getValue(attributes.getIndex("type")); return new NamedResourceImpl(attributes.getValue(attributes.getIndex("name")), type != null ? type : defaultType, - URI.create(uri)); + URI.create(uri)); } public static NamedResource newNamedResource(Attributes attributes) { @@ -45,8 +45,18 @@ public class Utils { } public static Task.Error newError(Attributes attributes) { - return new ErrorImpl(attrOrNull(attributes, "message"), attrOrNull(attributes, "majorErrorCode"), attrOrNull( - attributes, "minorErrorCode")); + String minorErrorCode = attrOrNull(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) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java index 972cf38877..5a15743964 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java @@ -22,7 +22,6 @@ package org.jclouds.vcloud.xml; import java.text.ParseException; import java.util.Date; -import javax.annotation.Resource; import javax.inject.Inject; import org.jclouds.date.DateService; @@ -45,7 +44,6 @@ public class TaskHandler extends ParseSax.HandlerWithResult { private NamedResource taskLink; private NamedResource owner; - private NamedResource result; private TaskStatus status; private Date startTime; private Date endTime; @@ -53,7 +51,6 @@ public class TaskHandler extends ParseSax.HandlerWithResult { private Task task; private Error error; - @Resource protected Logger logger = Logger.NULL; @Inject @@ -78,13 +75,12 @@ public class TaskHandler extends ParseSax.HandlerWithResult { endTime = parseDate(attributes, "endTime"); if (attributes.getIndex("expiryTime") != -1) 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); } else if (qName.equals("Link") && attributes.getIndex("rel") != -1 && attributes.getValue(attributes.getIndex("rel")).equals("self")) { taskLink = Utils.newNamedResource(attributes); - } else if (qName.equals("Result")) { - result = Utils.newNamedResource(attributes); } else if (qName.equals("Error")) { error = Utils.newError(attributes); } @@ -96,13 +92,9 @@ public class TaskHandler extends ParseSax.HandlerWithResult { return dateService.iso8601DateParse(toParse); } catch (RuntimeException e) { if (e.getCause() instanceof ParseException) { - try { - if (!toParse.endsWith("Z")) - toParse += "Z"; - return dateService.iso8601SecondsDateParse(toParse); - } catch (RuntimeException ex) { - logger.error(e, "error parsing date"); - } + if (!toParse.endsWith("Z")) + toParse += "Z"; + return dateService.iso8601SecondsDateParse(toParse); } else { logger.error(e, "error parsing date"); } @@ -113,13 +105,12 @@ public class TaskHandler extends ParseSax.HandlerWithResult { @Override public void endElement(String uri, String localName, String qName) { 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; status = null; startTime = null; endTime = null; owner = null; - result = null; error = null; } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java index 2af04662a0..f9587ddf5f 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/CommonVCloudClientLiveTest.java @@ -172,7 +172,7 @@ public abstract class CommonVCloudClientLiveTest 0) { Task task = response.getTasks().last(); - assertEquals(connection.getTask(task.getLocation()).getLocation(), task.getLocation()); + assertEquals(connection.getTask(task.getId()).getId(), task.getId()); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java index 41bc2d58be..3624411572 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java @@ -26,7 +26,7 @@ import java.net.URI; import org.jclouds.date.DateService; 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.TaskStatus; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; @@ -51,20 +51,34 @@ public class TaskHandlerTest extends BaseHandlerTest { dateService = injector.getInstance(DateService.class); } - public void testApplyInputStream() { - InputStream is = getClass().getResourceAsStream("/express/task.xml"); + public void test() { + InputStream is = getClass().getResourceAsStream("/task.xml"); 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"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService - .iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("VDC Name", - VCloudExpressMediaType.VDC_XML, URI - .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 + .iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("Server1", + VCloudMediaType.VAPP_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null ); assertEquals(result, expects); @@ -77,7 +91,7 @@ public class TaskHandlerTest extends BaseHandlerTest { 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"), - TaskStatus.QUEUED, null, null, null, null, null, null); + TaskStatus.QUEUED, null, null, null, null, null); assertEquals(result, expects); } @@ -92,8 +106,8 @@ public class TaskHandlerTest extends BaseHandlerTest { .iso8601SecondsDateParse("2010-01-14T20:05:02Z"), dateService .iso8601SecondsDateParse("2010-01-15T20:05:02Z"), - new NamedResourceImpl("188849-96", VCloudExpressMediaType.VAPP_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96")), null, null); + new NamedResourceImpl("188849-96", VCloudMediaType.VAPP_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96")), null); 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 .iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService - .iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new NamedResourceImpl("APIOrg", - VCloudExpressMediaType.ORG_XML, URI.create("http://10.150.4.49/api/v0.8/org/1")), new NamedResourceImpl( - "testapp1", VCloudExpressMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), - new TaskImpl.ErrorImpl("Error processing job", "500", - " Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00")); + .iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new NamedResourceImpl("testapp1", + VCloudMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), new TaskImpl.ErrorImpl( + "Error processing job", 500, " Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00", + null, null)); assertEquals(result, expects); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java index 846d1e1068..2758efb1b0 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java @@ -59,21 +59,17 @@ public class TasksListHandlerTest extends BaseHandlerTest { TasksList result = factory.create(injector.getInstance(TasksListHandler.class)).parse(is); assertEquals(result.getLocation(), URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/1")); - 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.iso8601DateParse("2009-08-24T21:30:32.63Z"), - null, new NamedResourceImpl("VDC Name", VCloudExpressMediaType.VDC_XML, URI - .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); + .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/1")); + 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 + .iso8601DateParse("2009-08-24T21:30:32.63Z"), null, 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"), - TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService - .iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("VDC Name", - VCloudExpressMediaType.VDC_XML, URI.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); + TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService + .iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("Server1", + VCloudExpressMediaType.VAPP_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null); assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2)); } diff --git a/vcloud/core/src/test/resources/task.xml b/vcloud/core/src/test/resources/task.xml new file mode 100644 index 0000000000..20fde3f84f --- /dev/null +++ b/vcloud/core/src/test/resources/task.xml @@ -0,0 +1,9 @@ + + + + diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index fe92ff7564..0b442afbc1 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -233,7 +233,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl private void powerOffAndWait(VCloudExpressVApp vApp) { logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus()); 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)); } @@ -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)); } catch (NoSuchElementException ex) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java index 03793fa65b..26f6d1fd15 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java @@ -45,7 +45,7 @@ public class ParseTaskFromLocationHeader implements Function if (location == null) location = from.getFirstHeaderOrNull("location"); 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 { throw new HttpResponseException("no uri in headers or content", null, from); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java index bd3fb4d8dd..7467621d9f 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java @@ -53,9 +53,9 @@ import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceType; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VCloudExpressVApp; -import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VDC; 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 deployTask = tmClient.deployVApp(vApp.getId()); - assertEquals(deployTask.getLocation(), deployTask.getLocation()); + assertEquals(deployTask.getId(), deployTask.getId()); vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getStatus(), Status.RESOLVED); try {// per docs, this is not supported - tmClient.cancelTask(deployTask.getLocation()); + tmClient.cancelTask(deployTask.getId()); } catch (HttpResponseException e) { 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()); vApp = tmClient.getVApp(vApp.getId()); @@ -210,7 +210,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk); 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()); vApp = tmClient.getVApp(vApp.getId()); @@ -240,7 +240,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes @Test(enabled = true, dependsOnMethods = "testInstantiateAndPowerOn") 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()); StringBuffer name = new StringBuffer(); @@ -254,16 +254,16 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes Task task = tmClient.cloneVAppInVDC(vdc.getId(), vApp.getId(), newName, options); // 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()); - 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()); // 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.getName(), newName); @@ -312,7 +312,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes 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()); @@ -324,7 +324,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes // vApp = tmClient.getVApp(vApp.getId()); // 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()); 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) .addDisk(25 * 1048576).addDisk(25 * 1048576)); - assert successTester.apply(task.getLocation()); + assert successTester.apply(task.getId()); vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getName(), "eduardo"); @@ -346,11 +346,11 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(), 1536); 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(); - 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 List disks = Lists.newArrayList(filter(vApp.getResourceAllocations(), @@ -359,14 +359,14 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes // delete the second disk 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(); } - private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, int processorCount, - long memory, long hardDisk) { + private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, + int processorCount, long memory, long hardDisk) { assertEquals(vApp.getName(), serverName); assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(), @@ -410,7 +410,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes tmClient.deleteInternetService(is.getId()); if (vApp != null) { try { - successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation()); + successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId()); } catch (Exception e) { } @@ -418,7 +418,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes } if (clone != null) { try { - successTester.apply(tmClient.powerOffVApp(clone.getId()).getLocation()); + successTester.apply(tmClient.powerOffVApp(clone.getId()).getId()); } catch (Exception e) { } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java index 8026674746..ceddae9c1e 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientTest.java @@ -33,9 +33,9 @@ import java.util.Map; import javax.inject.Provider; import org.jclouds.compute.domain.NodeState; +import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VCloudExpressVApp; -import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials; @@ -73,9 +73,9 @@ public class TerremarkVCloudComputeClientTest { expect(vdc.getId()).andReturn(vdcURI); expect(template.getId()).andReturn(templateURI); expect( - client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name", - new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password"))).andReturn( - vApp); + client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name", + new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password"))) + .andReturn(vApp); Task task = createMock(Task.class); URI vappLocation = URI.create("vapp"); URI taskLocation = URI.create("task"); @@ -83,7 +83,7 @@ public class TerremarkVCloudComputeClientTest { expect(vApp.getId()).andReturn(vappLocation).atLeastOnce(); expect(vApp.getName()).andReturn("name").atLeastOnce(); expect(client.deployVApp(vappLocation)).andReturn(task); - expect(task.getLocation()).andReturn(taskLocation).atLeastOnce(); + expect(task.getId()).andReturn(taskLocation).atLeastOnce(); Predicate successTester = createMock(Predicate.class); expect(successTester.apply(taskLocation)).andReturn(true).atLeastOnce(); expect(client.powerOnVApp(vappLocation)).andReturn(task); @@ -92,14 +92,14 @@ public class TerremarkVCloudComputeClientTest { Map vAppStatusToNodeState = createMock(Map.class); TerremarkVCloudComputeClient computeClient = new TerremarkVCloudComputeClient(client, - new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(), new Provider() { + new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(), new Provider() { - @Override - public String get() { - return "password"; - } + @Override + public String get() { + return "password"; + } - }, successTester, vAppStatusToNodeState); + }, successTester, vAppStatusToNodeState); replay(vdc); replay(template); @@ -111,7 +111,7 @@ public class TerremarkVCloudComputeClientTest { replay(vAppStatusToNodeState); Map response = computeClient.start(vdcURI, templateURI, "name", - new TerremarkInstantiateVAppTemplateOptions()); + new TerremarkInstantiateVAppTemplateOptions()); assertEquals(response.get("id"), "vapp"); assertEquals(response.get("username"), "Administrator");