Issue 112: change task to be id and not uri based

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2449 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-16 19:35:02 +00:00
parent a9e00bab79
commit 8c5f3bec4a
17 changed files with 184 additions and 182 deletions

View File

@ -29,7 +29,6 @@ import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -158,12 +157,15 @@ public interface VCloudAsyncClient {
@GET @GET
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/task/{taskId}")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> getTask(@Endpoint URI task); Future<? extends Task> getTask(@PathParam("taskId") String taskId);
@POST @POST
@Path("/action/cancel") @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
Future<Void> cancelTask(@Endpoint URI task); @Path("/task/{taskId}/action/cancel")
Future<Void> cancelTask(@PathParam("taskId") String taskId);
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)

View File

@ -23,7 +23,6 @@
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud;
import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
@ -81,9 +80,9 @@ public interface VCloudClient {
*/ */
Task suspendVApp(String vAppId); Task suspendVApp(String vAppId);
Task getTask(URI task); Task getTask(String taskId);
void cancelTask(URI task); void cancelTask(String taskId);
VApp getVApp(String appId); VApp getVApp(String appId);

View File

@ -23,9 +23,9 @@
*/ */
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain;
import java.net.URI;
import java.util.Date; import java.util.Date;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.TaskImpl; import org.jclouds.vcloud.domain.internal.TaskImpl;
@ -35,7 +35,10 @@ import com.google.inject.ImplementedBy;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(TaskImpl.class) @ImplementedBy(TaskImpl.class)
public interface Task extends Link, Comparable<Task> { public interface Task extends Comparable<Task> {
String getId();
URI getLocation();
TaskStatus getStatus(); TaskStatus getStatus();

View File

@ -29,7 +29,7 @@ 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; SUCCESS, FAILED, RUNNING, QUEUED, ERROR, CANCELLED, COMPLETED;
public String value() { public String value() {
return name().toLowerCase(); return name().toLowerCase();
} }

View File

@ -29,8 +29,6 @@ import java.net.URI;
import java.util.Date; import java.util.Date;
import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.rest.domain.internal.LinkImpl;
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;
@ -42,7 +40,9 @@ import com.google.inject.internal.Nullable;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class TaskImpl extends LinkImpl implements Task { public class TaskImpl implements Task {
private final String id;
private final URI location;
private final TaskStatus status; private final TaskStatus status;
private final Date startTime; private final Date startTime;
@Nullable @Nullable
@ -51,9 +51,11 @@ public class TaskImpl extends LinkImpl implements Task {
@Nullable @Nullable
private final NamedResource result; private final NamedResource result;
public TaskImpl(URI location, TaskStatus status, Date startTime, @Nullable Date endTime, public TaskImpl(String id, URI location, TaskStatus status, Date startTime,
NamedResource owner, @Nullable NamedResource result) { @Nullable Date endTime, NamedResource owner,
super(VCloudMediaType.TASK_XML, location); @Nullable NamedResource result) {
this.id = checkNotNull(id, "id");
this.location = checkNotNull(location, "location");
this.status = checkNotNull(status, "status"); this.status = checkNotNull(status, "status");
this.startTime = startTime; this.startTime = startTime;
this.endTime = endTime; this.endTime = endTime;
@ -82,17 +84,30 @@ public class TaskImpl extends LinkImpl implements Task {
} }
public int compareTo(Task o) { public int compareTo(Task o) {
return (this == o) ? 0 : getStartTime().compareTo(o.getStartTime()); return (this == o) ? 0 : getId().compareTo(o.getId());
}
public String getId() {
return id;
}
public URI getLocation() {
return location;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = 1;
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode()); result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result
+ ((location == null) ? 0 : location.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
result = prime * result + ((startTime == null) ? 0 : startTime.hashCode()); + ((this.result == null) ? 0 : this.result.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;
} }
@ -101,7 +116,7 @@ public class TaskImpl extends LinkImpl implements Task {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (!super.equals(obj)) if (obj == null)
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
@ -111,6 +126,16 @@ public class TaskImpl extends LinkImpl implements Task {
return false; return false;
} else if (!endTime.equals(other.endTime)) } else if (!endTime.equals(other.endTime))
return false; return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location))
return false;
if (owner == null) { if (owner == null) {
if (other.owner != null) if (other.owner != null)
return false; return false;
@ -136,7 +161,8 @@ public class TaskImpl extends LinkImpl implements Task {
@Override @Override
public String toString() { public String toString() {
return "TaskImpl [endTime=" + endTime + ", owner=" + owner + ", result=" + result return "TaskImpl [endTime=" + endTime + ", id=" + id + ", location="
+ location + ", owner=" + owner + ", result=" + result
+ ", startTime=" + startTime + ", status=" + status + "]"; + ", startTime=" + startTime + ", status=" + status + "]";
} }

View File

@ -23,17 +23,11 @@
*/ */
package org.jclouds.vcloud.predicates; package org.jclouds.vcloud.predicates;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TaskStatus;
@ -47,40 +41,25 @@ import com.google.inject.Inject;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class TaskSuccess implements Predicate<URI> { public class TaskSuccess implements Predicate<String> {
private final VCloudAsyncClient client; private final VCloudClient client;
@Inject(optional = true)
@Named("org.jclouds.vcloud.timeout")
private long taskTimeout = 30000;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject @Inject
public TaskSuccess(VCloudAsyncClient client) { public TaskSuccess(VCloudClient client) {
this.client = client; this.client = client;
} }
public boolean apply(URI taskUri) { public boolean apply(String taskId) {
logger.trace("looking for status on task %s", taskUri); logger.trace("looking for status on task %s", taskId);
Task task; Task task = client.getTask(taskId);
try { logger.trace("%s: looking for status %s: currently: %s", task,
task = client.getTask(taskUri).get(taskTimeout, TimeUnit.MILLISECONDS); TaskStatus.SUCCESS, task.getStatus());
logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task
.getStatus());
return task.getStatus() == TaskStatus.SUCCESS; return task.getStatus() == TaskStatus.SUCCESS;
} catch (InterruptedException e) {
logger.warn(e, "%s interrupted, returning false", taskUri);
} catch (ExecutionException e) {
throw new RuntimeException(e.getCause());
} catch (TimeoutException e) {
logger.warn(e, "%s timeout, returning false", taskUri);
}
return false;
} }
} }

View File

@ -32,7 +32,6 @@ import javax.inject.Inject;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.rest.util.Utils; import org.jclouds.rest.util.Utils;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
@ -47,7 +46,7 @@ import org.xml.sax.SAXException;
public class TaskHandler extends ParseSax.HandlerWithResult<Task> { public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
protected final DateService dateService; protected final DateService dateService;
private Link taskLink; private NamedResource taskLink;
private NamedResource owner; private NamedResource owner;
private NamedResource result; private NamedResource result;
private TaskStatus status; private TaskStatus status;
@ -72,7 +71,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
throws SAXException { throws SAXException {
if (qName.equalsIgnoreCase("Task")) { if (qName.equalsIgnoreCase("Task")) {
if (attributes.getIndex("href") != -1)// queued tasks may not have an href yet if (attributes.getIndex("href") != -1)// queued tasks may not have an href yet
taskLink = Utils.newLink(attributes); taskLink = Utils.newNamedResource(attributes);
status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status"))); status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
if (attributes.getIndex("startTime") != -1) if (attributes.getIndex("startTime") != -1)
startTime = parseDate(attributes, "startTime"); startTime = parseDate(attributes, "startTime");
@ -83,7 +82,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
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.newNamedLink(attributes); taskLink = Utils.newNamedResource(attributes);
} else if (qName.equals("Result")) { } else if (qName.equals("Result")) {
result = Utils.newNamedResource(attributes); result = Utils.newNamedResource(attributes);
} }
@ -111,7 +110,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("Task")) { if (qName.equalsIgnoreCase("Task")) {
this.task = new TaskImpl(taskLink.getLocation(), status, startTime, endTime, owner, result); this.task = new TaskImpl(taskLink.getId(), taskLink.getLocation(), status, startTime, endTime, owner, result);
taskLink = null; taskLink = null;
status = null; status = null;
startTime = null; startTime = null;

View File

@ -250,9 +250,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class); Method method = VCloudAsyncClient.class.getMethod("getTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, URI GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
.create("http://vcloud/task/1"));
assertRequestLineEquals(httpMethod, "GET http://vcloud/task/1 HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://vcloud/task/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
@ -266,9 +265,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class); Method method = VCloudAsyncClient.class.getMethod("cancelTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, URI GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
.create("http://vcloud/task/1"));
assertRequestLineEquals(httpMethod, "POST http://vcloud/task/1/action/cancel HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/task/1/action/cancel HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");

View File

@ -83,7 +83,7 @@ public class VCloudClientLiveTest {
assertNotNull(response.getLocation()); assertNotNull(response.getLocation());
assertNotNull(response.getTasks()); assertNotNull(response.getTasks());
for (Task t : response.getTasks()) { for (Task t : response.getTasks()) {
assertEquals(connection.getTask(t.getLocation()).getLocation(), t.getLocation()); assertEquals(connection.getTask(t.getId()).getLocation(), t.getLocation());
} }
} }

View File

@ -179,8 +179,8 @@ public class VCloudComputeClientLiveTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
private Predicate<URI> successTester(TaskSuccess success) { private Predicate<String> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS); return new RetryablePredicate<String>(success, 300, 10, TimeUnit.SECONDS);
} }
}).buildInjector(); }).buildInjector();

View File

@ -60,7 +60,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 Task expects = new TaskImpl("3299", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"),
dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), new NamedResourceImpl("1", dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), new NamedResourceImpl("1",
@ -81,7 +81,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 Task expects = new TaskImpl("d188849-78", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"), .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"),
TaskStatus.QUEUED, null, null, null, null TaskStatus.QUEUED, null, null, null, null
); );
@ -94,7 +94,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 Task expects = new TaskImpl("d188849-72", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-72"), .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-72"),
TaskStatus.RUNNING, dateService.iso8601SecondsDateParse("2001-01-01T05:00:00Z"), TaskStatus.RUNNING, dateService.iso8601SecondsDateParse("2001-01-01T05:00:00Z"),
null, new NamedResourceImpl("188849", "188849", VCloudMediaType.VDC_XML, URI null, new NamedResourceImpl("188849", "188849", VCloudMediaType.VDC_XML, URI

View File

@ -65,7 +65,7 @@ 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(URI Task task1 = new TaskImpl("3300", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"),
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:30:19.587Z"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:30:19.587Z"),
dateService.iso8601DateParse("2009-08-24T21:30:32.63Z"), new NamedResourceImpl("1", dateService.iso8601DateParse("2009-08-24T21:30:32.63Z"), new NamedResourceImpl("1",
@ -73,7 +73,7 @@ public class TasksListHandlerTest extends BaseHandlerTest {
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")));
Task task2 = new TaskImpl(URI Task task2 = new TaskImpl("3299", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"),
dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), new NamedResourceImpl("1", dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), new NamedResourceImpl("1",

View File

@ -26,7 +26,6 @@ package org.jclouds.vcloud.hostingdotcom.compute;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -53,12 +52,12 @@ public class HostingDotComVCloudComputeClient {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Predicate<URI> taskTester; private final Predicate<String> taskTester;
private final HostingDotComVCloudClient tmClient; private final HostingDotComVCloudClient tmClient;
@Inject @Inject
public HostingDotComVCloudComputeClient(HostingDotComVCloudClient tmClient, public HostingDotComVCloudComputeClient(HostingDotComVCloudClient tmClient,
Predicate<URI> successTester) { Predicate<String> successTester) {
this.tmClient = tmClient; this.tmClient = tmClient;
this.taskTester = successTester; this.taskTester = successTester;
} }
@ -127,7 +126,7 @@ public class HostingDotComVCloudComputeClient {
private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType, private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType,
VAppStatus expectedStatus) { VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getLocation())) { if (!taskTester.apply(deployTask.getId())) {
throw new TaskException(taskType, vApp, deployTask); throw new TaskException(taskType, vApp, deployTask);
} }

View File

@ -69,8 +69,8 @@ public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule
@Provides @Provides
@Singleton @Singleton
protected Predicate<URI> successTester(TaskSuccess success) { protected Predicate<String> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 600, 10, TimeUnit.SECONDS); return new RetryablePredicate<String>(success, 600, 10, TimeUnit.SECONDS);
} }
@Provides @Provides

View File

@ -28,7 +28,6 @@ import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Bui
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
@ -62,11 +61,11 @@ public class TerremarkVCloudComputeClient {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Predicate<URI> taskTester; private final Predicate<String> taskTester;
private final TerremarkVCloudClient tmClient; private final TerremarkVCloudClient tmClient;
@Inject @Inject
public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient, Predicate<URI> successTester) { public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient, Predicate<String> successTester) {
this.tmClient = tmClient; this.tmClient = tmClient;
this.taskTester = successTester; this.taskTester = successTester;
} }
@ -218,7 +217,7 @@ public class TerremarkVCloudComputeClient {
private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask, private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask,
String taskType, VAppStatus expectedStatus) { String taskType, VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getLocation())) { if (!taskTester.apply(deployTask.getId())) {
throw new TaskException(taskType, vApp, deployTask); throw new TaskException(taskType, vApp, deployTask);
} }

View File

@ -27,7 +27,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
@ -76,8 +75,8 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
@Provides @Provides
@Singleton @Singleton
protected Predicate<URI> successTester(TaskSuccess success) { protected Predicate<String> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 600, 10, TimeUnit.SECONDS); return new RetryablePredicate<String>(success, 600, 10, TimeUnit.SECONDS);
} }
@Provides @Provides

View File

@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -80,7 +79,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
private RetryablePredicate<InetSocketAddress> socketTester; private RetryablePredicate<InetSocketAddress> socketTester;
private RetryablePredicate<URI> successTester; private RetryablePredicate<String> successTester;
public static final String PREFIX = System.getProperty("user.name") + "-terremark"; public static final String PREFIX = System.getProperty("user.name") + "-terremark";
@ -134,12 +133,12 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
assertEquals(vApp.getStatus(), VAppStatus.CREATING); assertEquals(vApp.getStatus(), VAppStatus.CREATING);
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());
@ -150,7 +149,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk); verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.OFF); assertEquals(vApp.getStatus(), VAppStatus.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());
@ -190,7 +189,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
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());
@ -201,7 +200,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
// 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(), VAppStatus.OFF); assertEquals(vApp.getStatus(), VAppStatus.OFF);
@ -252,7 +251,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
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) {
} }
@ -276,7 +275,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
.getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make it longer then .getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make it longer then
// default internet // default internet
// service timeout // service timeout
successTester = new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), 300, 10, successTester = new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), 300, 10,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }