From 3623918de520adac0a7f19ebe71dcb46e2096164 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 7 Feb 2012 18:48:01 +0000 Subject: [PATCH 01/26] Java SimpleDateFormat cannot handle valid ISO8601 time zone strings, fixed --- .../org/jclouds/date/internal/DateUtils.java | 25 ++++++++-- .../internal/SimpleDateFormatDateService.java | 47 ++++++++++++------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/jclouds/date/internal/DateUtils.java b/core/src/main/java/org/jclouds/date/internal/DateUtils.java index 0135d86c5a..02220e6379 100644 --- a/core/src/main/java/org/jclouds/date/internal/DateUtils.java +++ b/core/src/main/java/org/jclouds/date/internal/DateUtils.java @@ -27,14 +27,15 @@ import java.util.regex.Pattern; */ public class DateUtils { - public static final Pattern MILLIS_PATTERN = Pattern.compile("(.*\\.[0-9][0-9][0-9])[0-9]*Z?"); + public static final Pattern MILLIS_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]Z?"); + // This regexp will match all TZ forms that are valid is ISO 8601 + public static final Pattern TZ_PATTERN = Pattern.compile("(.*)([+-][0-9][0-9](:?[0-9][0-9])?|Z)"); public static String trimToMillis(String toParse) { Matcher matcher = MILLIS_PATTERN.matcher(toParse); if (matcher.find()) { - toParse = matcher.group(1) + 'Z'; + toParse = matcher.group(1); } return toParse; } @@ -44,11 +45,25 @@ public class DateUtils { public static String trimTZ(String toParse) { Matcher matcher = TZ_PATTERN.matcher(toParse); if (matcher.find()) { - toParse = matcher.group(1) + 'Z'; + toParse = matcher.group(1); } + // TODO explain why this check is here if (toParse.length() == 25 && SECOND_PATTERN.matcher(toParse).matches()) - toParse = toParse.substring(0, toParse.length() - 6) + 'Z'; + toParse = toParse.substring(0, toParse.length() - 6); return toParse; } + public static String findTZ(String toParse) { + Matcher matcher = TZ_PATTERN.matcher(toParse); + if (matcher.find()) { + // Remove ':' from the TZ string, as SimpleDateFormat can't handle it + String tz = matcher.group(2).replace(":", ""); + // Append '00; if we only have a two digit TZ, as SimpleDateFormat + if (tz.length() == 2) tz += "00"; + return tz; + } else { + return ""; + } + } + } \ No newline at end of file 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 1b3ac583ca..69d0f62fc0 100644 --- a/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java +++ b/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java @@ -17,8 +17,7 @@ * under the License. */ package org.jclouds.date.internal; -import static org.jclouds.date.internal.DateUtils.trimToMillis; -import static org.jclouds.date.internal.DateUtils.trimTZ; +import static org.jclouds.date.internal.DateUtils.*; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -42,20 +41,16 @@ public class SimpleDateFormatDateService implements DateService { * guard against the lack of thread safety. */ // @GuardedBy("this") - private static final SimpleDateFormat iso8601SecondsSimpleDateFormat = new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); + private static final SimpleDateFormat iso8601SecondsSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US); // @GuardedBy("this") - private static final SimpleDateFormat iso8601SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", - Locale.US); + private static final SimpleDateFormat iso8601SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); // @GuardedBy("this") - private static final SimpleDateFormat rfc822SimpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", - Locale.US); + private static final SimpleDateFormat rfc822SimpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); // @GuardedBy("this") - private static final SimpleDateFormat cSimpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss '+0000' yyyy", - Locale.US); + private static final SimpleDateFormat cSimpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss '+0000' yyyy", Locale.US); static { iso8601SimpleDateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); @@ -64,83 +59,99 @@ public class SimpleDateFormatDateService implements DateService { cSimpleDateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); } + @Override public final Date fromSeconds(long seconds) { return new Date(seconds * 1000); } + @Override public final String cDateFormat(Date date) { synchronized (cSimpleDateFormat) { return cSimpleDateFormat.format(date); } } + @Override public final String cDateFormat() { return cDateFormat(new Date()); } + @Override public final Date cDateParse(String toParse) { synchronized (cSimpleDateFormat) { try { return cSimpleDateFormat.parse(toParse); - } catch (ParseException e) { - throw new RuntimeException(e); + } catch (ParseException pe) { + throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe); } } } + @Override public final String rfc822DateFormat(Date date) { synchronized (rfc822SimpleDateFormat) { return rfc822SimpleDateFormat.format(date); } } + @Override public final String rfc822DateFormat() { return rfc822DateFormat(new Date()); } + @Override public final Date rfc822DateParse(String toParse) { synchronized (rfc822SimpleDateFormat) { try { return rfc822SimpleDateFormat.parse(toParse); - } catch (ParseException e) { - throw new RuntimeException(e); + } catch (ParseException pe) { + throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe); } } } + @Override public final String iso8601SecondsDateFormat() { return iso8601SecondsDateFormat(new Date()); } + @Override public final String iso8601DateFormat(Date date) { synchronized (iso8601SimpleDateFormat) { return iso8601SimpleDateFormat.format(date); } } + @Override public final String iso8601DateFormat() { return iso8601DateFormat(new Date()); } + @Override public final Date iso8601DateParse(String toParse) { + String tz = findTZ(toParse); toParse = trimTZ(toParse); toParse = trimToMillis(toParse); + toParse += tz; // Usable TZ added back synchronized (iso8601SimpleDateFormat) { try { return iso8601SimpleDateFormat.parse(toParse); - } catch (ParseException e) { - throw new RuntimeException(e); + } catch (ParseException pe) { + throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe); } } } + @Override public final Date iso8601SecondsDateParse(String toParse) { + String tz = findTZ(toParse); toParse = trimTZ(toParse); + toParse += tz; // Usable TZ added back synchronized (iso8601SecondsSimpleDateFormat) { try { return iso8601SecondsSimpleDateFormat.parse(toParse); - } catch (ParseException e) { - throw new RuntimeException(e); + } catch (ParseException pe) { + throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe); } } } From 78fb8bd919acdf795fa106fc67e55641d94dcb74 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 7 Feb 2012 11:35:33 +0000 Subject: [PATCH 02/26] Created new TaskClient and updated domain objects and tests accordingly --- .../v1_5/VCloudDirectorAsyncClient.java | 8 +- .../director/v1_5/VCloudDirectorClient.java | 7 + .../v1_5/VCloudDirectorMediaType.java | 11 +- .../VCloudDirectorRestClientModule.java | 3 + .../vcloud/director/v1_5/domain/Task.java | 141 ++++++++++++++++-- .../director/v1_5/domain/TasksList.java | 81 +++++++++- .../v1_5/features/OrgAsyncClient.java | 1 - .../v1_5/features/TaskAsyncClient.java | 75 ++++++++++ .../director/v1_5/features/TaskClient.java | 56 +++++++ .../v1_5/features/TaskClientExpectTest.java | 123 +++++++++++++++ ...aseVCloudDirectorRestClientExpectTest.java | 36 +++-- .../src/test/resources/taskslist.xml | 51 +++++++ 12 files changed, 563 insertions(+), 30 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java create mode 100644 labs/vcloud-director/src/test/resources/taskslist.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java index 11d9fa44e7..806e8af011 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java @@ -22,13 +22,13 @@ import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import com.google.inject.Provides; /** * Provides asynchronous access to VCloudDirector via their REST API. - *

* * @see VCloudDirectorClient * @author Adrian Cole @@ -47,6 +47,12 @@ public interface VCloudDirectorAsyncClient { @Delegate OrgAsyncClient getOrgClient(); + /** + * @return asynchronous access to Task features + */ + @Delegate + TaskAsyncClient getTaskClient(); + /** * @return asynchronous access to Network features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index ac5d56f44c..9a6cada8a8 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -25,6 +25,7 @@ import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient; +import org.jclouds.vcloud.director.v1_5.features.TaskClient; import com.google.inject.Provides; @@ -49,6 +50,12 @@ public interface VCloudDirectorClient { */ @Delegate OrgClient getOrgClient(); + + /** + * @return synchronous access to Task features + */ + @Delegate + TaskClient getTaskClient(); /** * @return synchronous access to Network features diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index d50ec22299..d31433ca72 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -18,16 +18,13 @@ */ package org.jclouds.vcloud.director.v1_5; -import javax.ws.rs.core.MediaType; - /** - * Resource Types used in VCloud + * Resource Types used in VCloud. * - *
* The object type, specified as a MIME content type, of the object that the link references. This * attribute is present only for links to objects. It is not present for links to actions. * - * @see MediaType + * @see javax.ws.rs.core.MediaType; */ public interface VCloudDirectorMediaType { public final static String NS = "http://www.vmware.com/vcloud/v1.5"; @@ -43,5 +40,9 @@ public interface VCloudDirectorMediaType { public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml"; public static final String ORG_NETWORK_XML = "application/vnd.vmware.vcloud.orgNetwork+xml"; + + public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml"; + + public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml"; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 41a31f0e34..49e2865065 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -46,6 +46,8 @@ import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient; +import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword; import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose; import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; @@ -75,6 +77,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// .put(OrgClient.class, OrgAsyncClient.class) .put(NetworkClient.class, NetworkAsyncClient.class) + .put(TaskClient.class, TaskAsyncClient.class) .build(); public VCloudDirectorRestClientModule() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index de82e172fc..8e3ebce260 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -59,7 +59,10 @@ public class Task extends EntityType { public static class Builder extends EntityType.Builder { private Error error; - private Org org; + private Reference org; + private Reference owner; + private Reference user; + private Object params; private Integer progress; private String status; private String operation; @@ -79,11 +82,35 @@ public class Task extends EntityType { /** * @see Task#getOrg() */ - public Builder org(Org org) { + public Builder org(Reference org) { this.org = org; return this; } + /** + * @see Task#getOwner() + */ + public Builder owner(Reference owner) { + this.owner = owner; + return this; + } + + /** + * @see Task#getUser() + */ + public Builder user(Reference user) { + this.user = user; + return this; + } + + /** + * @see Task#getParams() + */ + public Builder params(Object params) { + this.params = params; + return this; + } + /** * @see Task#getProgress() */ @@ -143,8 +170,16 @@ public class Task extends EntityType { @Override public Task build() { Task task = new Task(href, name); + task.setDescription(description); + task.setTasksInProgress(tasksInProgress); + task.setId(id); + task.setType(type); + task.setLinks(links); task.setError(error); task.setOrg(org); + task.setOwner(owner); + task.setUser(user); + task.setParams(params); task.setProgress(progress); task.setStatus(status); task.setOperation(operation); @@ -250,28 +285,31 @@ public class Task extends EntityType { @XmlElement(namespace = NS, name = "Error") private Error error; @XmlElement(namespace = NS, name = "Organization") - private Org org; + private Reference org; @XmlElement(namespace = NS, name = "Progress") private Integer progress; @XmlElement(namespace = NS, name = "Owner") - private Entity owner; + private Reference owner; @XmlElement(namespace = NS, name = "User") - private Entity user; + private Reference user; @XmlElement(namespace = NS, name = "Params") private Object params; - @XmlAttribute(namespace = NS, name = "status") + @XmlAttribute private String status; - @XmlAttribute(namespace = NS, name = "operation") + @XmlAttribute private String operation; - @XmlAttribute(namespace = NS, name = "operationName") + @XmlAttribute private String operationName; - @XmlAttribute(namespace = NS, name = "startTime") + @XmlAttribute private Date startTime; - @XmlAttribute(namespace = NS, name = "endTime") + @XmlAttribute private Date endTime; - @XmlAttribute(namespace = NS, name = "expiryTime") + @XmlAttribute private Date expiryTime; + /** + * Represents an error information if the task failed. + */ public Error getError() { return error; } @@ -280,14 +318,56 @@ public class Task extends EntityType { this.error = error; } - public Org getOrg() { + /** + * The organization that started the task. + */ + public Reference getOrg() { return org; } - public void setOrg(Org org) { + public void setOrg(Reference org) { this.org = org; } + /** + * Reference to the owner of the task. + */ + public Reference getOwner() { + return owner; + } + + public void setOwner(Reference owner) { + this.owner = owner; + } + + /** + * The user who started the task. + */ + public Reference getUser() { + return user; + } + + public void setUser(Reference user) { + this.user = user; + } + + /** + * The parameters with which this task has been run. + */ + public Object getParams() { + return params; + } + + public void setParams(Object params) { + this.params = params; + } + + /** + * The progress of a long running asynchronous task. + * + * The value is between 0 - 100. Not all tasks have progress, the value is not + * present for task which progress is not available. + */ public Integer getProgress() { return progress; } @@ -296,6 +376,20 @@ public class Task extends EntityType { this.progress = progress; } + /** + * The execution status of the task. + * + * One of: + *

+ */ public String getStatus() { return status; } @@ -304,6 +398,9 @@ public class Task extends EntityType { this.status = status; } + /** + * The display name of the operation that is tracked by this task. + */ public String getOperation() { return operation; } @@ -312,6 +409,9 @@ public class Task extends EntityType { this.operation = operation; } + /** + * The name of the operation that is tracked by this task. + */ public String getOperationName() { return operationName; } @@ -320,6 +420,11 @@ public class Task extends EntityType { this.operationName = operationName; } + /** + * The date and time the system started executing the task. + * + * May not be present if the task hasn't been executed yet. + */ public Date getStartTime() { return startTime; } @@ -328,6 +433,11 @@ public class Task extends EntityType { this.startTime = startTime; } + /** + * The date and time that processing of the task was completed. + * + * May not be present if the task is still being executed. + */ public Date getEndTime() { return endTime; } @@ -336,6 +446,11 @@ public class Task extends EntityType { this.endTime = endTime; } + /** + * The date and time at which the task resource will be destroyed and no longer available for retrieval. + * + * May not be present if the task has not been executed or is still being executed. + */ public Date getExpiryTime() { return expiryTime; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java index ca930800ed..8fe0ef32aa 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java @@ -28,6 +28,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.domain.Org.Builder; + import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -81,8 +83,85 @@ public class TasksList extends EntityType { return taskslist; } + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + public Builder fromTasksList(TasksList in) { - return tasks(in.getTasks()); + return fromEntityType(in).tasks(in.getTasks()); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java index 92a88593dc..7bf2dff7bc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java @@ -38,7 +38,6 @@ import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import com.google.common.util.concurrent.ListenableFuture; /** - * @see OrgClient * @author Adrian Cole */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java new file mode 100644 index 0000000000..c1a2e78002 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.TasksList; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see TaskClient + * @author grkvlt@apache.org + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface TaskAsyncClient { + + /** + * @see TaskClient#getTaskList(URI) + */ + @GET + @Path("/tasksList/{id}") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTaskList(@PathParam("id") String orgId); + + /** + * @see TaskClient#getTask(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTask(@EndpointParam URI taskHref); + + /** + * @see TaskClient#cancelTask(URI) + */ + @POST + @Path("/action/cancel") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + void cancelTask(@EndpointParam URI taskHref); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java new file mode 100644 index 0000000000..e0cfc81698 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.TasksList; + +/** + * Provides synchronous access to {@link Task} objects. + * + * @see TaskAsyncClient + * @author grkvlt@apache.org + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface TaskClient { + + /** + * Retrieves a list of tasks. + * + * @param orgId the unique id for the organization + * @return a list of tasks + */ + TasksList getTaskList(String orgId); + + /** + * Retrieves a task. + * + * @return the task or null if not found + */ + Task getTask(URI taskHref); + + /** + * Cancels a task. + */ + void cancelTask(URI taskHref); +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java new file mode 100644 index 0000000000..3bfa7aa6a3 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -0,0 +1,123 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + *(Link.builder().regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless(Link.builder().required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import static org.testng.Assert.*; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.TasksList; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Iterables; + +/** + * Test the {@link TaskClient} by observing its side effects. + * + * @author grkvlt@apache.org + */ +@Test(groups = "unit", singleThreaded = true, testName = "TaskClientExpectTest") +public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + @Test + public void testTaskListForValidOrg() { + HttpRequest orgListRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create("http://localhost/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse orgListResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/taskslist.xml", VCloudDirectorMediaType.TASKSLIST_XML + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); + + String orgId =Iterables.getLast(Splitter.on("/").split(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0").getPath())); + + assertEquals(client.getTaskClient().getTaskList(orgId), TasksList.builder() + .name("Tasks Lists") + .type("application/vnd.vmware.vcloud.tasksList+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .task(Task.builder() + .type("application/vnd.vmware.vcloud.task+xml") + .name("task") + .id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .status("success") + .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") + .operationName("catalogCreateCatalog") + .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build()) + .task(Task.builder() + .type("application/vnd.vmware.vcloud.task+xml") + .name("task") + .id("urn:vcloud:task:bd22e745-9c2a-4f82-a954-0e35b6f76ba5") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/bd22e745-9c2a-4f82-a954-0e35b6f76ba5")) + .status("success") + .operation("Enabled User (967d317c-4273-4a95-b8a4-bf63b78e9c69)") + .operationName("jobEnable") + .startTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-06T17:30:38.507-04:00")) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adrian@jclouds.org") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/8c360b93-ed25-4c9a-8e24-d48cd9966d93")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build()) + .build() + ); + } +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 244ede2323..6dde723dae 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -20,13 +20,16 @@ package org.jclouds.vcloud.director.v1_5.internal; import java.net.URI; +import org.jclouds.date.DateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.testng.annotations.BeforeTest; import com.google.common.collect.ImmutableMultimap; +import com.google.inject.Guice; /** * Base class for writing KeyStone Rest Client Expect tests @@ -40,16 +43,31 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect public static final String password = "password"; public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ="; - protected HttpRequest loginRequest = HttpRequest.builder().method("POST").endpoint( - URI.create("http://localhost/api/sessions")).headers( - ImmutableMultimap. builder().put("Accept", "*/*").put("Authorization", - "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=").build()).build(); + protected DateService dateService; - protected HttpResponse sessionResponse = HttpResponse.builder().statusCode(200).headers( - ImmutableMultimap. builder().put("x-vcloud-authorization", token).put("Set-Cookie", - String.format("vcloud-token=%s; Secure; Path=/", token)).build()).payload( - payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + ";version=1.5")) - .build(); + @BeforeTest + protected void setUpInjector() { + dateService = Guice.createInjector().getInstance(DateService.class); + assert dateService != null; + } + + protected HttpRequest loginRequest = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("http://localhost/api/sessions")) + .headers(ImmutableMultimap.builder() + .put("Accept", "*/*") + .put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=") + .build()) + .build(); + + protected HttpResponse sessionResponse = HttpResponse.builder() + .statusCode(200) + .headers(ImmutableMultimap. builder() + .put("x-vcloud-authorization", token) + .put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)) + .build()) + .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + ";version=1.5")) + .build(); public BaseVCloudDirectorRestClientExpectTest() { provider = "vcloud-director"; diff --git a/labs/vcloud-director/src/test/resources/taskslist.xml b/labs/vcloud-director/src/test/resources/taskslist.xml new file mode 100644 index 0000000000..094e7f7e33 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/taskslist.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + \ No newline at end of file From 9153d887af49b85bdadb5453aae2cc5d387e86fd Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 8 Feb 2012 13:32:25 +0000 Subject: [PATCH 03/26] Fixing equals method on domain objects --- .../vcloud/director/v1_5/domain/Entity.java | 4 +- .../director/v1_5/domain/EntityType.java | 4 +- .../vcloud/director/v1_5/domain/Error.java | 41 +++++++++++-------- .../vcloud/director/v1_5/domain/Link.java | 4 +- .../vcloud/director/v1_5/domain/Metadata.java | 6 ++- .../director/v1_5/domain/MetadataEntry.java | 11 ++--- .../vcloud/director/v1_5/domain/Org.java | 4 +- .../vcloud/director/v1_5/domain/Task.java | 7 +++- .../director/v1_5/domain/TasksList.java | 3 +- 9 files changed, 52 insertions(+), 32 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java index e9e5c3611d..4410fb0649 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java @@ -147,7 +147,9 @@ public class Entity extends EntityType { @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; Entity that = Entity.class.cast(o); return super.equals(that); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java index c14f0cf31d..16d17fcc0c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java @@ -224,7 +224,9 @@ public class EntityType> extends ResourceType { @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; EntityType that = EntityType.class.cast(o); return super.equals(that) && diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java index 4820cd3471..0a337b7a67 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java @@ -18,9 +18,14 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -107,17 +112,17 @@ public class Error { public Builder fromError(Error in) { return message(in.getMessage()) - .majorErrorCode(in.getMajorErrorCode()) - .minorErrorCode(in.getMinorErrorCode()) - .vendorSpecificErrorCode(in.getVendorSpecificErrorCode()) - .stackTrace(in.getStackTrace()); + .majorErrorCode(in.getMajorErrorCode()) + .minorErrorCode(in.getMinorErrorCode()) + .vendorSpecificErrorCode(in.getVendorSpecificErrorCode()) + .stackTrace(in.getStackTrace()); } } @XmlAttribute private String message; @XmlAttribute - private int majorErrorCode; + private Integer majorErrorCode; @XmlAttribute private String minorErrorCode; @XmlAttribute @@ -125,9 +130,9 @@ public class Error { @XmlAttribute private String stackTrace; - private Error(String message, int majorErrorCode, String minorErrorCode) { + private Error(String message, Integer majorErrorCode, String minorErrorCode) { this.message = checkNotNull(message, "message"); - this.majorErrorCode = majorErrorCode; + this.majorErrorCode = checkNotNull(majorErrorCode, "majorErrorCode"); this.minorErrorCode = checkNotNull(minorErrorCode, "minorErrorCode"); } @@ -145,7 +150,7 @@ public class Error { /** * The class of the error. Matches the HTTP status code. */ - public int getMajorErrorCode() { + public Integer getMajorErrorCode() { return majorErrorCode; } @@ -182,10 +187,11 @@ public class Error { this.stackTrace = stackTrace; } - -@Override + @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; Error that = (Error) o; return equal(this.message, that.message) && @@ -197,15 +203,14 @@ public class Error { @Override public int hashCode() { - return super.hashCode() + Objects.hashCode(message, majorErrorCode, minorErrorCode, vendorSpecificErrorCode, stackTrace); + return Objects.hashCode(message, majorErrorCode, minorErrorCode, vendorSpecificErrorCode, stackTrace); } @Override public String toString() { return Objects.toStringHelper("") - .add("message", message) - .add("majorErrorCode", majorErrorCode) - .add("minorErrorCode", minorErrorCode) + .add("message", message).add("majorErrorCode", majorErrorCode).add("minorErrorCode", minorErrorCode) + .add("vendorSpecificErrorCode", vendorSpecificErrorCode).add("stackTrace", stackTrace) .toString(); } } \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index 274545149f..cbbfbf5a5a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -159,7 +159,9 @@ public class Link extends ReferenceType { @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; Link that = (Link) o; return super.equals(that) && equal(this.rel, that.rel); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java index 26936df2f0..f8b9213852 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java @@ -50,6 +50,7 @@ public class Metadata extends ResourceType{ return new Builder(); } + @Override public Builder toBuilder() { return new Builder().fromMetadataList(this); } @@ -74,6 +75,7 @@ public class Metadata extends ResourceType{ return this; } + @Override public Metadata build() { Metadata metadata = new Metadata(href, metadataEntries); metadata.setType(type); @@ -140,7 +142,9 @@ public class Metadata extends ResourceType{ @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; Metadata that = Metadata.class.cast(o); return super.equals(that) && equal(metadata, that.metadata); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index ce4cf0aeb3..3353b207d4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -49,6 +49,7 @@ public class MetadataEntry extends ResourceType { return new Builder(); } + @Override public Builder toBuilder() { return new Builder().fromMetadata(this); } @@ -73,6 +74,7 @@ public class MetadataEntry extends ResourceType { return this; } + @Override public MetadataEntry build() { MetadataEntry metadataEntry = new MetadataEntry(href, key, value); metadataEntry.setType(type); @@ -132,13 +134,12 @@ public class MetadataEntry extends ResourceType { this.value = checkNotNull(value, "value"); } - @XmlElement(namespace = NS, name = "K") + @XmlElement(namespace = NS, name = "Key") private String key; @XmlElement(namespace = NS, name = "Value") private String value; /** - * * @return key of the entry */ public String getKey() { @@ -146,17 +147,17 @@ public class MetadataEntry extends ResourceType { } /** - * * @return value of the entry */ public String getValue() { return value; } - @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; MetadataEntry that = MetadataEntry.class.cast(o); return super.equals(that) && equal(key, that.key); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index 2e7f63568c..97dd7c0c41 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -183,7 +183,9 @@ public class Org extends EntityType { @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; Org that = Org.class.cast(o); return super.equals(that) && equal(fullName, that.fullName); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index 8e3ebce260..9c880ce9aa 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -461,10 +461,13 @@ public class Task extends EntityType { @Override public boolean equals(Object o) { - if (!super.equals(o)) + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) return false; Task that = Task.class.cast(o); - return super.equals(that) && equal(this.error, that.error) && equal(this.org, that.org) && + return super.equals(that) && + equal(this.error, that.error) && equal(this.org, that.org) && equal(this.progress, that.progress) && equal(this.status, that.status) && equal(this.operation, that.operation) && equal(this.operationName, that.operationName) && equal(this.startTime, that.startTime) && equal(this.endTime, that.endTime) && diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java index 8fe0ef32aa..c9e13f17df 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java @@ -28,9 +28,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import org.jclouds.vcloud.director.v1_5.domain.Org.Builder; - import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; From c771b2ac877619251cb87a3b7c4fc24011518ef8 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 8 Feb 2012 13:33:01 +0000 Subject: [PATCH 04/26] Remove unused annotations --- .../java/org/jclouds/functions/ExceptionToValueOrPropagate.java | 1 - .../src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java b/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java index 7e175c1d35..081fb11d33 100644 --- a/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java +++ b/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java @@ -44,7 +44,6 @@ public class ExceptionToValueOrPropagate implements Func this.value = value; } - @SuppressWarnings("unchecked") @Override public T apply(Exception from) { checkNotNull(from, "exception"); diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java b/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java index bf8f63f97f..3ad6a2d4d6 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java +++ b/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java @@ -418,7 +418,6 @@ public abstract class BaseRestClientExpectTest { protected String identity = "identity"; protected String credential = "credential"; - @SuppressWarnings("unchecked") private RestContextSpec makeContextSpec() { if (getClass().isAnnotationPresent(RegisterContext.class)) return (RestContextSpec) contextSpec(provider, "http://mock", "1", "", "", "userfoo", null, getClass() From 412dd45ce1a1076981a8f124f5719d4f863cf70f Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 8 Feb 2012 13:40:41 +0000 Subject: [PATCH 05/26] Added annotation for throwing exception with Error object on 4xx status codes, and implemented in TaskClient --- .../v1_5/VCloudDirectorException.java | 48 ++++++++++ .../v1_5/VCloudDirectorMediaType.java | 4 + .../v1_5/features/TaskAsyncClient.java | 8 +- .../ThrowVCloudErrorOn4xxOrNull.java | 61 +++++++++++++ .../v1_5/features/TaskClientExpectTest.java | 88 +++++++++++++++++-- ...aseVCloudDirectorRestClientExpectTest.java | 42 +++++++-- .../src/test/resources/task/error400.xml | 2 + .../src/test/resources/task/error403.xml | 2 + .../test/resources/{ => task}/taskslist.xml | 0 9 files changed, 236 insertions(+), 19 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java create mode 100644 labs/vcloud-director/src/test/resources/task/error400.xml create mode 100644 labs/vcloud-director/src/test/resources/task/error403.xml rename labs/vcloud-director/src/test/resources/{ => task}/taskslist.xml (100%) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java new file mode 100644 index 0000000000..620128e13a --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5; + +import org.jclouds.vcloud.director.v1_5.domain.Error; +import org.jclouds.vcloud.director.v1_5.domain.Task; + +/** + * @author grkvlt@apache.org + */ +public class VCloudDirectorException extends RuntimeException { + + /** The serialVersionUID. */ + private static final long serialVersionUID = -3200853408568729058L; + + private final Error error; + + public VCloudDirectorException(Error error) { + super("Error: " + error.getMessage()); + this.error = error; + } + + public VCloudDirectorException(Task task) { + super("Task error: " + task.getError().getMessage()); + this.error = task.getError(); + } + + public Error getError() { + return error; + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index d31433ca72..4d9e4c434f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -29,8 +29,12 @@ package org.jclouds.vcloud.director.v1_5; public interface VCloudDirectorMediaType { public final static String NS = "http://www.vmware.com/vcloud/v1.5"; + public final static String ANY = "*/*"; + public final static String SESSION_XML = "application/vnd.vmware.vcloud.session+xml"; + public final static String ERROR_XML = "application/vnd.vmware.vcloud.error+xml"; + public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml"; public final static String METADATA_XML = "application/vnd.vmware.vcloud.metadata+xml"; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java index c1a2e78002..870c74abdb 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java @@ -30,10 +30,10 @@ import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xxOrNull; import com.google.common.util.concurrent.ListenableFuture; @@ -51,7 +51,7 @@ public interface TaskAsyncClient { @Path("/tasksList/{id}") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) ListenableFuture getTaskList(@PathParam("id") String orgId); /** @@ -60,7 +60,7 @@ public interface TaskAsyncClient { @GET @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) ListenableFuture getTask(@EndpointParam URI taskHref); /** @@ -70,6 +70,6 @@ public interface TaskAsyncClient { @Path("/action/cancel") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) void cancelTask(@EndpointParam URI taskHref); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java new file mode 100644 index 0000000000..da4e6504c5 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.functions; + +import java.io.IOException; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.xml.bind.JAXB; + +import org.jclouds.http.HttpResponseException; +import org.jclouds.io.InputSuppliers; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; +import org.jclouds.vcloud.director.v1_5.domain.Error; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * @author grkvlt@apache.org + */ +@Singleton +public class ThrowVCloudErrorOn4xxOrNull implements Function { + @Inject + private ThrowVCloudErrorOn4xxOrNull() { } + + @Override + public Object apply(Exception from) { + Iterable throwables = Iterables.filter(Throwables.getCausalChain(from), HttpResponseException.class); + if (Iterables.size(throwables) == 1) { + HttpResponseException exception = Iterables.getOnlyElement(throwables); + if (exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) { + try { + Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class); + throw new VCloudDirectorException(error); + } catch (IOException e) { + Throwables.propagate(e); + } + } + } + return null; // TODO is this correct? + } + +} \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java index 3bfa7aa6a3..7028e323b6 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -25,16 +25,16 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; -import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Iterables; /** * Test the {@link TaskClient} by observing its side effects. @@ -48,7 +48,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest public void testTaskListForValidOrg() { HttpRequest orgListRequest = HttpRequest.builder() .method("GET") - .endpoint(URI.create("http://localhost/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .endpoint(URI.create(endpoint + "/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) @@ -57,14 +57,14 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest HttpResponse orgListResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/taskslist.xml", VCloudDirectorMediaType.TASKSLIST_XML + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKSLIST_XML + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); - String orgId =Iterables.getLast(Splitter.on("/").split(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0").getPath())); + String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build()); - assertEquals(client.getTaskClient().getTaskList(orgId), TasksList.builder() + TasksList expected = TasksList.builder() .name("Tasks Lists") .type("application/vnd.vmware.vcloud.tasksList+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) @@ -117,7 +117,79 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build()) .build()) - .build() - ); + .build(); + + assertEquals(client.getTaskClient().getTaskList(orgId), expected); + } + + @Test + public void testTaskListForInvalidOrgId() { + HttpRequest orgListRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/tasksList/NOTAUUID")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse orgListResponse = HttpResponse.builder() + .statusCode(400) + .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR_XML + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); + + String orgId = "NOTAUUID"; + + Error expected = Error.builder() + .message("validation error on field 'id': String value has invalid format or length") + .majorErrorCode(400) + .minorErrorCode("BAD_REQUEST") + .build(); + try { + client.getTaskClient().getTaskList(orgId); + fail("Should give HTTP 400 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testTaskListForNotFoundOrgId() { + HttpRequest orgListRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/tasksList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse orgListResponse = HttpResponse.builder() + .statusCode(403) + .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR_XML + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); + + String orgId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + + Error expected = Error.builder() + .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + try { + client.getTaskClient().getTaskList(orgId); + fail("Should give HTTP 400 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 6dde723dae..6429cdf5ab 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -26,9 +26,13 @@ import org.jclouds.http.HttpResponse; import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.testng.annotations.BeforeTest; +import com.google.common.base.Function; +import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Iterables; import com.google.inject.Guice; /** @@ -42,6 +46,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect public static final String org = "JClouds"; public static final String password = "password"; public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ="; + public static final String endpoint = "http://localhost/api"; protected DateService dateService; @@ -51,6 +56,14 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect assert dateService != null; } + protected static final Function, String> getUuidFromReference = new Function, String>() { + @Override + public String apply(ReferenceType input) { + String uuid = Iterables.getLast(Splitter.on("/").split(input.getHref().getPath())); + return uuid; + } + }; + protected HttpRequest loginRequest = HttpRequest.builder() .method("POST") .endpoint(URI.create("http://localhost/api/sessions")) @@ -75,17 +88,32 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect credential = password; } + protected HttpRequest getStandardRequest(String method, String command) { + return getStandardRequest(method, URI.create(endpoint + command)); + } + protected HttpRequest getStandardRequest(String method, URI uri) { - return HttpRequest.builder().method(method).endpoint(uri).headers( - ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("x-vcloud-authorization",token) - .build()).build(); + return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); + } + + protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) { + return HttpRequest.builder() + .method(method) + .endpoint(uri) + .headers(ImmutableMultimap. builder() + .put("Accept", mediaType) + .put("x-vcloud-authorization", token) + .build()) + .build(); } protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) { - return HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType+";version=1.5")).build(); + return getStandardPayloadResponse(200, relativeFilePath, mediaType); } + protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) { + return HttpResponse.builder() + .statusCode(statusCode) + .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType+";version=1.5")).build(); + } } diff --git a/labs/vcloud-director/src/test/resources/task/error400.xml b/labs/vcloud-director/src/test/resources/task/error400.xml new file mode 100644 index 0000000000..9ad5bd1ad9 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/task/error400.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/task/error403.xml b/labs/vcloud-director/src/test/resources/task/error403.xml new file mode 100644 index 0000000000..417556d341 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/task/error403.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/taskslist.xml b/labs/vcloud-director/src/test/resources/task/taskslist.xml similarity index 100% rename from labs/vcloud-director/src/test/resources/taskslist.xml rename to labs/vcloud-director/src/test/resources/task/taskslist.xml From 69c4bd62e61747e118ca8b19485c50b82bef2881 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 12:56:11 +0000 Subject: [PATCH 06/26] Implemented 4xx Error annotation in OrgClient --- .../v1_5/features/OrgAsyncClient.java | 24 ++--- .../director/v1_5/features/OrgClient.java | 7 +- .../v1_5/features/OrgClientExpectTest.java | 100 ++++++++++++++++-- .../src/test/resources/org/error400.xml | 2 + .../test/resources/org/error403-catalog.xml | 2 + .../src/test/resources/org/error403-fake.xml | 2 + 6 files changed, 111 insertions(+), 26 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/org/error400.xml create mode 100644 labs/vcloud-director/src/test/resources/org/error403-catalog.xml create mode 100644 labs/vcloud-director/src/test/resources/org/error403-fake.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java index 7bf2dff7bc..8541fc2638 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java @@ -18,22 +18,20 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; -import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xxOrNull; import com.google.common.util.concurrent.ListenableFuture; @@ -48,7 +46,7 @@ public interface OrgAsyncClient { * @see OrgClient#getOrgList */ @GET - @Path("/org/") + @Path("/org") @Consumes @JAXBResponseParser ListenableFuture getOrgList(); @@ -57,27 +55,29 @@ public interface OrgAsyncClient { * @see OrgClient#getOrg */ @GET + @Path("/org/{id}") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getOrg(@EndpointParam URI uri); + @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + ListenableFuture getOrg(@PathParam("id") String orgId); /** * @see OrgClient#getMetadata */ @GET - @Path("/metadata/") + @Path("/org/{id}/metadata") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getMetadata(@EndpointParam URI orgRef); + @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + ListenableFuture getMetadata(@PathParam("id") String orgId); /** * @see OrgClient#getMetadataEntry */ @GET + @Path("/org/{id}/metadata/{key}") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getMetadataEntry(@EndpointParam URI metaDataRef); + @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + ListenableFuture getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java index d5078f52c4..88efcf1709 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -50,19 +49,19 @@ public interface OrgClient { * * @return the org or null if not found */ - Org getOrg(URI orgHref); + Org getOrg(String orgId); /** * Retrieves an list of the organization's metadata * * @return a list of metadata */ - Metadata getMetadata(URI orgRef); + Metadata getMetadata(String orgId); /** * Retrieves a metadata * * @return the metadata or null if not found */ - MetadataEntry getMetadataEntry(URI metaDataRef); + MetadataEntry getMetadataEntry(String orgId, String key); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java index c8c407e86e..9112b295f3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -18,12 +18,14 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.*; import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; @@ -44,7 +46,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest public void testWhenResponseIs2xxLoginReturnsValidOrgList() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", URI.create("http://localhost/api/org/")), + getStandardRequest("GET", "/org"), getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORGLIST_XML+";version=1.5")); OrgList expected = OrgList.builder() @@ -63,7 +65,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", orgRef), + getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"), getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG_XML+";version=1.5")); Org expected = Org @@ -115,16 +117,91 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - assertEquals(client.getOrgClient().getOrg(orgRef), expected); + String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + assertEquals(client.getOrgClient().getOrg(orgId), expected); + } + + @Test + public void testWhenResponseIs400ForInvalidOrgId() { + URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", "/org/NOTAUUID"), + getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR_XML)); + + Error expected = Error.builder() + .message("validation error on field 'id': String value has invalid format or length") + .majorErrorCode(400) + .minorErrorCode("BAD_REQUEST") + .build(); + + String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + try { + client.getOrgClient().getOrg(orgId); + fail("Should give HTTP 400 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testWhenResponseIs403ForCatalogIdUsedAsOrgId() { + URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"), + getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR_XML)); + + Error expected = Error.builder() + .message("No access to entity "com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c".") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + try { + client.getOrgClient().getOrg(orgId); + fail("Should give HTTP 403 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testWhenResponseIs403ForFakeOrgId() { + URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"), + getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR_XML)); + + Error expected = Error.builder() + .message("No access to entity "com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee".") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + try { + client.getOrgClient().getOrg(orgId); + fail("Should give HTTP 403 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } } @Test public void testWhenResponseIs2xxLoginReturnsValidMetadataList() { URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); - URI metaRef = URI.create(orgRef.toASCIIString()+"/metadata/"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metaRef), + getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"), getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA_XML+";version=1.5")); Metadata expected = Metadata.builder() @@ -137,20 +214,23 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - assertEquals(client.getOrgClient().getMetadata(orgRef), expected); + String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + assertEquals(client.getOrgClient().getMetadata(orgId), expected); } @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadata() { - URI metadataRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"); + URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataRef), + getStandardRequest("GET", "i/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATAENTRY_XML+";version=1.5")); MetadataEntry expected = MetadataEntry.builder() + .key("KEY") .build(); - assertEquals(client.getOrgClient().getMetadataEntry(metadataRef), expected); + String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + assertEquals(client.getOrgClient().getMetadataEntry(orgId, "KEY"), expected); } } diff --git a/labs/vcloud-director/src/test/resources/org/error400.xml b/labs/vcloud-director/src/test/resources/org/error400.xml new file mode 100644 index 0000000000..9ad5bd1ad9 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/error400.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/error403-catalog.xml b/labs/vcloud-director/src/test/resources/org/error403-catalog.xml new file mode 100644 index 0000000000..b37a321662 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/error403-catalog.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/error403-fake.xml b/labs/vcloud-director/src/test/resources/org/error403-fake.xml new file mode 100644 index 0000000000..417556d341 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/error403-fake.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file From aab725d9eba690f2d7379cbc450624f4b51bbe4a Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 8 Feb 2012 18:50:59 +0000 Subject: [PATCH 07/26] Tidy up domain objects, using media type enum --- .../v1_5/VCloudDirectorConstants.java | 31 ++++++++++++++++ .../v1_5/VCloudDirectorMediaType.java | 37 +++++++++---------- .../director/v1_5/domain/EntityType.java | 33 +++++++++++------ .../vcloud/director/v1_5/domain/Error.java | 9 +---- .../vcloud/director/v1_5/domain/Link.java | 4 +- .../vcloud/director/v1_5/domain/Metadata.java | 10 ++--- .../director/v1_5/domain/MetadataEntry.java | 12 +++--- .../vcloud/director/v1_5/domain/Org.java | 6 +-- .../vcloud/director/v1_5/domain/OrgList.java | 10 ++--- .../director/v1_5/domain/ReferenceType.java | 16 +++++++- .../vcloud/director/v1_5/domain/Resource.java | 2 +- .../director/v1_5/domain/ResourceType.java | 32 +++++++++++----- .../vcloud/director/v1_5/domain/Session.java | 6 +-- .../v1_5/domain/SessionWithToken.java | 4 +- .../vcloud/director/v1_5/domain/Task.java | 24 ++++++------ .../director/v1_5/domain/TasksInProgress.java | 10 ++--- .../director/v1_5/domain/TasksList.java | 6 +-- 17 files changed, 154 insertions(+), 98 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java new file mode 100644 index 0000000000..fa71a182f3 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java @@ -0,0 +1,31 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5; + +/** + * Constants used by VCloudDirector clients + * + * @author grkvlt@apache.org + */ +public class VCloudDirectorConstants { + + /** The XML namespace used by the clients. */ + public static final String XMLNS = "http://www.vmware.com/vcloud/v1.5"; + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 4d9e4c434f..e103f2413d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -26,27 +26,24 @@ package org.jclouds.vcloud.director.v1_5; * * @see javax.ws.rs.core.MediaType; */ -public interface VCloudDirectorMediaType { - public final static String NS = "http://www.vmware.com/vcloud/v1.5"; +public enum VCloudDirectorMediaType { + ANY("*/*"), + SESSION("application/vnd.vmware.vcloud.session+xml"), + ERROR("application/vnd.vmware.vcloud.error+xml"), + ORG_LIST("application/vnd.vmware.vcloud.orgList+xml"), + METADATA("application/vnd.vmware.vcloud.metadata+xml"), + METADATA_ENTRY("*/*"), // TODO + ORG("application/vnd.vmware.vcloud.org+xml"), + TASKS_LIST("application/vnd.vmware.vcloud.tasksList+xml"), + TASK("application/vnd.vmware.vcloud.task+xml"); - public final static String ANY = "*/*"; + private final String mediaType; - public final static String SESSION_XML = "application/vnd.vmware.vcloud.session+xml"; - - public final static String ERROR_XML = "application/vnd.vmware.vcloud.error+xml"; - - public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml"; - - public final static String METADATA_XML = "application/vnd.vmware.vcloud.metadata+xml"; - - public static final String METADATAENTRY_XML = "TODO"; // TODO - - public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml"; - - public static final String ORG_NETWORK_XML = "application/vnd.vmware.vcloud.orgNetwork+xml"; - - public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml"; - - public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml"; + private VCloudDirectorMediaType(String mediaType) { + this.mediaType = mediaType; + } + public String getMediaType() { + return mediaType; + } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java index 16d17fcc0c..af1f468ff6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java @@ -18,9 +18,9 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlElement; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** @@ -143,7 +145,6 @@ public class EntityType> extends ResourceType { /** * {@inheritDoc} */ - @SuppressWarnings("unchecked") @Override public Builder fromResourceType(ResourceType in) { return Builder.class.cast(super.fromResourceType(in)); @@ -156,9 +157,9 @@ public class EntityType> extends ResourceType { } } - @XmlElement(namespace = NS, name = "Description") + @XmlElement(namespace = XMLNS, name = "Description") private String description; - @XmlElement(namespace = NS, name = "TasksInProgress") + @XmlElement(namespace = XMLNS, name = "TasksInProgress") private TasksInProgress tasksInProgress; @XmlAttribute private String id; @@ -211,12 +212,20 @@ public class EntityType> extends ResourceType { } /** - * Contains the name of the the entity. + * Returns the unique UUID string for this entity. * - * The object type, specified as a MIME content type, of the object that the link references. - * This attribute is present only for links to objects. It is not present for links to actions. - * - * @return type definition, type, expressed as an HTTP Content-Type + * Once we have an entity, the {@link #getId()} field is better suited to retrieving the + * id than {@link #getHref()}. + * + * @see ReferenceType#getUuid() + */ + @Override + public String getUuid() { + return Iterables.getLast(Splitter.on(":").split(id)); + } + + /** + * Contains the name of the the entity. */ public String getName() { return name; @@ -231,7 +240,7 @@ public class EntityType> extends ResourceType { EntityType that = EntityType.class.cast(o); return super.equals(that) && equal(this.id, that.id) && equal(this.description, that.description) && - equal(this.tasksInProgress, that.tasksInProgress); + equal(this.tasksInProgress, that.tasksInProgress) && equal(this.name, that.name); } @Override diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java index 0a337b7a67..7bb5a94d8e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java @@ -20,12 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -43,7 +38,7 @@ import com.google.common.base.Objects; * * @author grkvlt@apache.org */ -@XmlRootElement(namespace = NS, name = "Error") +@XmlRootElement(namespace = XMLNS, name = "Error") @XmlAccessorType(XmlAccessType.FIELD) public class Error { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index cbbfbf5a5a..ed4d5de848 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -18,8 +18,8 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; import java.net.URI; import java.util.Map; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java index f8b9213852..913cc8f165 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java @@ -18,9 +18,9 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -42,7 +42,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "Metadata") +@XmlRootElement(namespace = XMLNS, name = "Metadata") public class Metadata extends ResourceType{ @SuppressWarnings("unchecked") @@ -133,7 +133,7 @@ public class Metadata extends ResourceType{ this.metadata = ImmutableSet.copyOf(metadataEntries); } - @XmlElement(namespace = NS, name = "MetadataEntry") + @XmlElement(namespace = XMLNS, name = "MetadataEntry") private Set metadata = Sets.newLinkedHashSet(); public Set getMetadata() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index 3353b207d4..3c798eb179 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -18,9 +18,9 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -41,7 +41,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "TODO") +@XmlRootElement(namespace = XMLNS, name = "MetadataEntry") public class MetadataEntry extends ResourceType { @SuppressWarnings("unchecked") @@ -134,9 +134,9 @@ public class MetadataEntry extends ResourceType { this.value = checkNotNull(value, "value"); } - @XmlElement(namespace = NS, name = "Key") + @XmlElement(namespace = XMLNS, name = "Key") private String key; - @XmlElement(namespace = NS, name = "Value") + @XmlElement(namespace = XMLNS, name = "Value") private String value; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index 97dd7c0c41..d86e10a573 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -43,7 +43,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = NS, name = "Org") +@XmlRootElement(namespace = XMLNS, name = "Org") public class Org extends EntityType { @SuppressWarnings("unchecked") @@ -170,7 +170,7 @@ public class Org extends EntityType { this.fullName = fullName; } - @XmlElement(namespace = NS, name = "FullName") + @XmlElement(namespace = XMLNS, name = "FullName") private String fullName; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java index 5351747da1..bd407f0ebb 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java @@ -18,9 +18,9 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.util.Set; @@ -36,7 +36,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = NS, name = "OrgList") +@XmlRootElement(namespace = XMLNS, name = "OrgList") public class OrgList { public static Builder builder() { @@ -84,7 +84,7 @@ public class OrgList { this.orgs = ImmutableSet.copyOf(orgs); } - @XmlElement(namespace = NS, name = "Org") + @XmlElement(namespace = XMLNS, name = "Org") private Set orgs = Sets.newLinkedHashSet(); public Set getOrgs() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java index 24bdc3b47c..b1e59ce4d4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java @@ -28,7 +28,9 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import com.google.common.base.Objects; +import com.google.common.base.Splitter; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Iterables; /** * A reference to a resource. @@ -42,7 +44,7 @@ import com.google.common.base.Objects.ToStringHelper; * @author grkvlt@apache.org */ @XmlAccessorType(XmlAccessType.FIELD) -public class ReferenceType> { +public class ReferenceType> implements URISupplier { public static > Builder builder() { return new Builder(); @@ -156,6 +158,15 @@ public class ReferenceType> { this.id = id; } + /** + * Returns the unique UUID string for this reference. + * + * @see ResourceType#getUuid() + */ + public String getUuid() { + return Iterables.getLast(Splitter.on("/").split(href.getPath())); + } + /** * Contains the name of the the entity. * @@ -189,8 +200,9 @@ public class ReferenceType> { } /** - * @see #getHref() + * @see URISupplier#getURI() */ + @Override public URI getURI() { return getHref(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java index b380e200e0..64fa11e8fe 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java @@ -18,7 +18,7 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.*; import java.net.URI; import java.util.Set; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java index 15df502eb9..67c6a47dcc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -31,7 +31,9 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import com.google.common.base.Objects; +import com.google.common.base.Splitter; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** @@ -46,7 +48,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @XmlAccessorType(XmlAccessType.FIELD) -public class ResourceType> { +public class ResourceType> implements URISupplier { public static > Builder builder() { return new Builder(); @@ -110,7 +112,7 @@ public class ResourceType> { private URI href; @XmlAttribute private String type; - @XmlElement(namespace = NS, name = "Link") + @XmlElement(namespace = XMLNS, name = "Link") private Set links = Sets.newLinkedHashSet(); protected ResourceType(URI href) { @@ -138,6 +140,23 @@ public class ResourceType> { return href; } + /** + * @see URISupplier#getURI() + */ + @Override + public URI getURI() { + return getHref(); + } + + /** + * Returns the unique UUID string for this resource. + * + * @see ReferenceType#getUuid() + */ + public String getUuid() { + return Iterables.getLast(Splitter.on("/").split(href.getPath())); + } + /** * Contains the type of the the entity. * @@ -169,13 +188,6 @@ public class ResourceType> { this.links.add(checkNotNull(link, "link")); } - /** - * @see #getHref() - */ - public URI getURI() { - return getHref(); - } - @Override public boolean equals(Object o) { if (this == o) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java index 8778581e99..42dc3ef44f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -42,7 +42,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = NS, name = "Session") +@XmlRootElement(namespace = XMLNS, name = "Session") @XmlAccessorType(XmlAccessType.FIELD) public class Session { @@ -120,7 +120,7 @@ public class Session { this.links = ImmutableSet.copyOf(links); } - @XmlElement(namespace = NS, name = "Link") + @XmlElement(namespace = XMLNS, name = "Link") private Set links = Sets.newLinkedHashSet(); @XmlAttribute private String user; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SessionWithToken.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SessionWithToken.java index a9575e50ca..aaaf682c6f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SessionWithToken.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SessionWithToken.java @@ -43,7 +43,7 @@ public class SessionWithToken { protected String token; /** - * @see SessionWithToken#getType + * @see SessionWithToken#getSession() */ public Builder session(Session session) { this.session = session; @@ -51,7 +51,7 @@ public class SessionWithToken { } /** - * @see SessionWithToken#getHref + * @see SessionWithToken#getToken() */ public Builder token(String token) { this.token = token; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index 9c880ce9aa..5b4bee8ed8 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -7,20 +7,20 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICEXMLNSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIOXMLNS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Date; @@ -43,7 +43,7 @@ import com.google.common.collect.Sets; * * @author grkvlt@apache.org */ -@XmlRootElement(namespace = NS, name = "Task") +@XmlRootElement(namespace = XMLNS, name = "Task") public class Task extends EntityType { @SuppressWarnings("unchecked") @@ -282,17 +282,17 @@ public class Task extends EntityType { super(href, name); } - @XmlElement(namespace = NS, name = "Error") + @XmlElement(namespace = XMLNS, name = "Error") private Error error; - @XmlElement(namespace = NS, name = "Organization") + @XmlElement(namespace = XMLNS, name = "Organization") private Reference org; - @XmlElement(namespace = NS, name = "Progress") + @XmlElement(namespace = XMLNS, name = "Progress") private Integer progress; - @XmlElement(namespace = NS, name = "Owner") + @XmlElement(namespace = XMLNS, name = "Owner") private Reference owner; - @XmlElement(namespace = NS, name = "User") + @XmlElement(namespace = XMLNS, name = "User") private Reference user; - @XmlElement(namespace = NS, name = "Params") + @XmlElement(namespace = XMLNS, name = "Params") private Object params; @XmlAttribute private String status; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java index d220381781..6d21e17952 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java @@ -7,11 +7,11 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICEXMLNSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIOXMLNS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.util.Collection; import java.util.Set; @@ -37,7 +37,7 @@ import com.google.common.collect.Sets; /** * @author grkvlt@apache.org */ -@XmlRootElement(namespace = NS, name = "TasksInProgress") +@XmlRootElement(namespace = XMLNS, name = "TasksInProgress") @XmlAccessorType(XmlAccessType.FIELD) public class TasksInProgress { @@ -86,7 +86,7 @@ public class TasksInProgress { this.tasks = ImmutableSet.copyOf(tasks); } - @XmlElement(namespace = NS, name = "Task") + @XmlElement(namespace = XMLNS, name = "Task") private Set tasks = Sets.newLinkedHashSet(); public Set getTasks() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java index c9e13f17df..a34ca958bc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -38,7 +38,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = NS, name = "TasksList") +@XmlRootElement(namespace = XMLNS, name = "TasksList") public class TasksList extends EntityType { @SuppressWarnings("unchecked") @@ -173,7 +173,7 @@ public class TasksList extends EntityType { this.tasks = ImmutableSet.copyOf(tasks); } - @XmlElement(namespace = NS, name = "Task") + @XmlElement(namespace = XMLNS, name = "Task") private Set tasks = Sets.newLinkedHashSet(); public Set getTasks() { From 73a2593f8b989de92d51782a7d2fe44d334d1647 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 8 Feb 2012 18:51:18 +0000 Subject: [PATCH 08/26] Tidy --- .../vcloud/director/v1_5/VCloudDirectorContextBuilder.java | 1 - .../vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java index bd974278a3..95aeea6d6e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java @@ -27,7 +27,6 @@ import org.jclouds.rest.RestContextBuilder; import com.google.inject.Module; /** - * * @author Adrian Cole */ public class VCloudDirectorContextBuilder extends RestContextBuilder { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java index bc5fd100ed..05e724c3c1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java @@ -27,11 +27,12 @@ import java.util.Properties; import org.jclouds.PropertiesBuilder; /** - * Builds properties used in VCloudDirector Clients + * Builds properties used in VCloudDirector clients * * @author Adrian Cole */ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { + @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); From d29bd2eec8325c48711125c9e941690c8afc5458 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 13:04:12 +0000 Subject: [PATCH 09/26] Completed TaskClient and tidied up OrgClient. Note two types of API call here, one using traditional REST semantics and the other taking ReferenceTypes and extracting URIs from them. --- .../director/v1_5/domain/URISupplier.java | 35 ++++ .../v1_5/features/OrgAsyncClient.java | 48 ++++- .../director/v1_5/features/OrgClient.java | 8 +- .../v1_5/features/TaskAsyncClient.java | 40 +++- .../director/v1_5/features/TaskClient.java | 10 +- .../v1_5/functions/ReferenceToEndpoint.java | 40 ++++ ...OrNull.java => ThrowVCloudErrorOn4xx.java} | 23 +-- .../v1_5/features/OrgClientExpectTest.java | 152 +++++++++++++-- .../v1_5/features/TaskClientExpectTest.java | 178 ++++++++++++++++-- ...aseVCloudDirectorRestClientExpectTest.java | 15 +- .../v1_5/login/SessionClientExpectTest.java | 4 +- .../src/test/resources/task/task.xml | 6 + 12 files changed, 491 insertions(+), 68 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/URISupplier.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReferenceToEndpoint.java rename labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/{ThrowVCloudErrorOn4xxOrNull.java => ThrowVCloudErrorOn4xx.java} (69%) create mode 100644 labs/vcloud-director/src/test/resources/task/task.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/URISupplier.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/URISupplier.java new file mode 100644 index 0000000000..4cd978d6f8 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/URISupplier.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import java.net.URI; + +/** + * @author grkvlt@apache.org + */ +public interface URISupplier { + + /** + * This returns the {@link URI} for a particular {@link ReferenceType} or {@link ResourceType} object. + * + * @see ResourceType#getHref() + * @see ReferenceType#getHref() + */ + public URI getURI(); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java index 8541fc2638..e110a6ff18 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java @@ -23,6 +23,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; @@ -30,8 +31,10 @@ import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; -import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xxOrNull; +import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import com.google.common.util.concurrent.ListenableFuture; @@ -43,7 +46,7 @@ import com.google.common.util.concurrent.ListenableFuture; public interface OrgAsyncClient { /** - * @see OrgClient#getOrgList + * @see OrgClient#getOrgList() */ @GET @Path("/org") @@ -52,32 +55,61 @@ public interface OrgAsyncClient { ListenableFuture getOrgList(); /** - * @see OrgClient#getOrg + * @see OrgClient#getOrg(String) */ @GET @Path("/org/{id}") @Consumes @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getOrg(@PathParam("id") String orgId); + + /** + * @see OrgClient#getOrg(ReferenceType) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getOrg(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef); /** - * @see OrgClient#getMetadata + * @see OrgClient#getMetadata(String) */ @GET @Path("/org/{id}/metadata") @Consumes @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getMetadata(@PathParam("id") String orgId); + + /** + * @see OrgClient#getMetadata(ReferenceType) + */ + @GET + @Path("/metadata") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef); /** - * @see OrgClient#getMetadataEntry + * @see OrgClient#getMetadataEntry(String, String) */ @GET @Path("/org/{id}/metadata/{key}") @Consumes @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key); + + /** + * @see OrgClient#getMetadataEntry(ReferenceType, String) + */ + @GET + @Path("/metadata/{key}") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java index 88efcf1709..d72d99c17f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java @@ -25,13 +25,13 @@ import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; /** * Provides synchronous access to Org. *

* * @see OrgAsyncClient - * @see * @author Adrian Cole */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @@ -50,6 +50,8 @@ public interface OrgClient { * @return the org or null if not found */ Org getOrg(String orgId); + + Org getOrg(ReferenceType orgRef); /** * Retrieves an list of the organization's metadata @@ -58,10 +60,14 @@ public interface OrgClient { */ Metadata getMetadata(String orgId); + Metadata getMetadata(ReferenceType orgRef); + /** * Retrieves a metadata * * @return the metadata or null if not found */ MetadataEntry getMetadataEntry(String orgId, String key); + + MetadataEntry getMetadataEntry(ReferenceType orgRef, String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java index 870c74abdb..833b918640 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java @@ -18,8 +18,6 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -30,10 +28,12 @@ import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; -import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xxOrNull; +import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import com.google.common.util.concurrent.ListenableFuture; @@ -45,23 +45,43 @@ import com.google.common.util.concurrent.ListenableFuture; public interface TaskAsyncClient { /** - * @see TaskClient#getTaskList(URI) + * @see TaskClient#getTaskList(String) */ @GET @Path("/tasksList/{id}") @Consumes @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) + @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getTaskList(@PathParam("id") String orgId); /** - * @see TaskClient#getTask(URI) + * @see TaskClient#getTask(String id) + */ + @GET + @Path("/task/{id}") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getTask(@PathParam("id") String taskId); + + /** + * @see TaskClient#getTask(ReferenceType) */ @GET @Consumes @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) - ListenableFuture getTask(@EndpointParam URI taskHref); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType taskRef); + + /** + * @see TaskClient#cancelTask(URI) + */ + @POST + @Path("/task/{id}/action/cancel") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture cancelTask(@PathParam("id") String taskId); /** * @see TaskClient#cancelTask(URI) @@ -70,6 +90,6 @@ public interface TaskAsyncClient { @Path("/action/cancel") @Consumes @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class) - void cancelTask(@EndpointParam URI taskHref); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture cancelTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType taskRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java index e0cfc81698..be8734c722 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java @@ -18,10 +18,10 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; @@ -47,10 +47,14 @@ public interface TaskClient { * * @return the task or null if not found */ - Task getTask(URI taskHref); + Task getTask(String taskId); + + Task getTask(ReferenceType taskRef); /** * Cancels a task. */ - void cancelTask(URI taskHref); + void cancelTask(String taskId); + + void cancelTask(ReferenceType taskRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReferenceToEndpoint.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReferenceToEndpoint.java new file mode 100644 index 0000000000..f1f33bd35b --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ReferenceToEndpoint.java @@ -0,0 +1,40 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.functions; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; + +import com.google.common.base.Function; +import com.google.common.base.Preconditions; + +/** + * @author grkvlt@apache.org + */ +public class ReferenceToEndpoint implements Function { + + @Override + public URI apply(Object input) { + Preconditions.checkNotNull(input); + Preconditions.checkArgument(input instanceof ReferenceType); + ReferenceType reference = (ReferenceType) input; + return reference.getURI(); + }; +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xx.java similarity index 69% rename from labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java rename to labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xx.java index da4e6504c5..9de694e36b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xxOrNull.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/ThrowVCloudErrorOn4xx.java @@ -37,25 +37,22 @@ import com.google.common.collect.Iterables; * @author grkvlt@apache.org */ @Singleton -public class ThrowVCloudErrorOn4xxOrNull implements Function { +public class ThrowVCloudErrorOn4xx implements Function { @Inject - private ThrowVCloudErrorOn4xxOrNull() { } + private ThrowVCloudErrorOn4xx() { } @Override public Object apply(Exception from) { Iterable throwables = Iterables.filter(Throwables.getCausalChain(from), HttpResponseException.class); - if (Iterables.size(throwables) == 1) { - HttpResponseException exception = Iterables.getOnlyElement(throwables); - if (exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) { - try { - Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class); - throw new VCloudDirectorException(error); - } catch (IOException e) { - Throwables.propagate(e); - } + HttpResponseException exception = Iterables.getFirst(throwables, null); + if (exception != null && exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) { + try { + Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class); + throw new VCloudDirectorException(error); + } catch (IOException e) { + Throwables.propagate(e); } } - return null; // TODO is this correct? + throw Throwables.propagate(from); } - } \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java index 9112b295f3..ff368206b4 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -35,6 +35,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; +import com.google.common.collect.Iterables; + /** * Allows us to test a client via its side effects. * @@ -42,12 +44,12 @@ import org.testng.annotations.Test; */ @Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest") public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + @Test public void testWhenResponseIs2xxLoginReturnsValidOrgList() { - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org"), - getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORGLIST_XML+";version=1.5")); + getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); OrgList expected = OrgList.builder() .org(Reference.builder() @@ -60,13 +62,139 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest assertEquals(client.getOrgClient().getOrgList(), expected); } + @Test + public void testWhenResponseIs2xxLoginReturnsValidOrgFromListByReference() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", "/org"), + getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); + Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs()); + + client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", org.getHref()), + getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); + + Org expected = Org + .builder() + .name("JClouds") + .description("") + .fullName("JClouds") + .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.vdc+xml") + .name("Cluster01-JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.tasksList+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("Public") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.controlAccess+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("ilsolation01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("internet01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()) + .build(); + + assertEquals(client.getOrgClient().getOrg(org), expected); + } + + @Test + public void testWhenResponseIs2xxLoginReturnsValidOrgFromListById() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", "/org"), + getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); + Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs()); + client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", "/org/" + org.getUuid()), + getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); + + Org expected = Org + .builder() + .name("JClouds") + .description("") + .fullName("JClouds") + .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.vdc+xml") + .name("Cluster01-JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.tasksList+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("Public") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.controlAccess+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("ilsolation01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("internet01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()) + .build(); + + assertEquals(org.getUuid(), "6f312e42-cd2b-488d-a2bb-97519cd57ed0"); + assertEquals(client.getOrgClient().getOrg(org.getUuid()), expected); + } + @Test public void testWhenResponseIs2xxLoginReturnsValidOrg() { URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"), - getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG_XML+";version=1.5")); + getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); Org expected = Org .builder() @@ -74,7 +202,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .description("") .fullName("JClouds") .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") - .type(VCloudDirectorMediaType.ORG_XML) + .type("application/vnd.vmware.vcloud.org+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .link(Link.builder() .rel("down") @@ -127,7 +255,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/NOTAUUID"), - getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR_XML)); + getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR)); Error expected = Error.builder() .message("validation error on field 'id': String value has invalid format or length") @@ -152,10 +280,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"), - getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR_XML)); + getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR)); Error expected = Error.builder() - .message("No access to entity "com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c".") + .message("No access to entity \"com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c\".") .majorErrorCode(403) .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); @@ -177,10 +305,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"), - getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR_XML)); + getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR)); Error expected = Error.builder() - .message("No access to entity "com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee".") + .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".") .majorErrorCode(403) .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); @@ -202,7 +330,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"), - getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA_XML+";version=1.5")); + getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA)); Metadata expected = Metadata.builder() .type("application/vnd.vmware.vcloud.metadata+xml") @@ -223,8 +351,8 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "i/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), - getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATAENTRY_XML+";version=1.5")); + getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), + getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY)); MetadataEntry expected = MetadataEntry.builder() .key("KEY") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java index 7028e323b6..de37593c98 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -46,7 +46,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test public void testTaskListForValidOrg() { - HttpRequest orgListRequest = HttpRequest.builder() + HttpRequest taskRequest = HttpRequest.builder() .method("GET") .endpoint(URI.create(endpoint + "/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .headers(ImmutableMultimap. builder() @@ -55,12 +55,12 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse orgListResponse = HttpResponse.builder() + HttpResponse taskResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKSLIST_XML + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST.getMediaType() + ";version=1.5")) .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build()); @@ -124,7 +124,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test public void testTaskListForInvalidOrgId() { - HttpRequest orgListRequest = HttpRequest.builder() + HttpRequest taskRequest = HttpRequest.builder() .method("GET") .endpoint(URI.create(endpoint + "/tasksList/NOTAUUID")) .headers(ImmutableMultimap. builder() @@ -133,12 +133,12 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse orgListResponse = HttpResponse.builder() + HttpResponse taskResponse = HttpResponse.builder() .statusCode(400) - .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR_XML + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5")) .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); String orgId = "NOTAUUID"; @@ -159,7 +159,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test public void testTaskListForNotFoundOrgId() { - HttpRequest orgListRequest = HttpRequest.builder() + HttpRequest taskRequest = HttpRequest.builder() .method("GET") .endpoint(URI.create(endpoint + "/tasksList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")) .headers(ImmutableMultimap. builder() @@ -168,12 +168,12 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse orgListResponse = HttpResponse.builder() + HttpResponse taskResponse = HttpResponse.builder() .statusCode(403) - .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR_XML + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5")) .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); String orgId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -192,4 +192,158 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest fail("Should have thrown a VCloudDirectorException"); } } + + @Test + public void testGetTaskForTaskId() { + HttpRequest taskRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse taskResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); + + String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b"; + + Task expected = Task.builder() + .type("application/vnd.vmware.vcloud.task+xml") + .name("task") + .id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .status("success") + .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") + .operationName("catalogCreateCatalog") + .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + + assertEquals(client.getTaskClient().getTask(taskId), expected); + } + + @Test + public void testGetTaskForTaskRef() { + HttpRequest taskRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse taskResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); + + Reference taskRef = Reference.builder() + .type("application/vnd.vmware.vcloud.task+xml") + .name("task") + .href(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .build(); + + Task expected = Task.builder() + .type("application/vnd.vmware.vcloud.task+xml") + .name("task") + .id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .status("success") + .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") + .operationName("catalogCreateCatalog") + .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + + assertEquals(client.getTaskClient().getTask(taskRef), expected); + } + + @Test + public void testCancelTaskByTaskId() { + HttpRequest taskRequest = HttpRequest.builder() + .method("POST") + .endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse taskResponse = HttpResponse.builder() + .statusCode(200) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); + + String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b"; + + client.getTaskClient().cancelTask(taskId); + } + + @Test + public void testCancelTaskByTaskRef() { + HttpRequest taskRequest = HttpRequest.builder() + .method("POST") + .endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse taskResponse = HttpResponse.builder() + .statusCode(200) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); + + Reference taskRef = Reference.builder() + .type("application/vnd.vmware.vcloud.task+xml") + .name("task") + .href(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .build(); + + client.getTaskClient().cancelTask(taskRef); + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 6429cdf5ab..55a21c418d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -27,6 +27,7 @@ import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; import com.google.common.base.Function; @@ -50,7 +51,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect protected DateService dateService; - @BeforeTest + @BeforeClass protected void setUpInjector() { dateService = Guice.createInjector().getInstance(DateService.class); assert dateService != null; @@ -79,7 +80,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect .put("x-vcloud-authorization", token) .put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)) .build()) - .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() + ";version=1.5")) .build(); public BaseVCloudDirectorRestClientExpectTest() { @@ -96,24 +97,24 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); } - protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) { + protected HttpRequest getStandardRequest(String method, URI uri, VCloudDirectorMediaType mediaType) { return HttpRequest.builder() .method(method) .endpoint(uri) .headers(ImmutableMultimap. builder() - .put("Accept", mediaType) + .put("Accept", mediaType.getMediaType()) .put("x-vcloud-authorization", token) .build()) .build(); } - protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) { + protected HttpResponse getStandardPayloadResponse(String relativeFilePath, VCloudDirectorMediaType mediaType) { return getStandardPayloadResponse(200, relativeFilePath, mediaType); } - protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) { + protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, VCloudDirectorMediaType mediaType) { return HttpResponse.builder() .statusCode(statusCode) - .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType+";version=1.5")).build(); + .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType.getMediaType()+";version=1.5")).build(); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java index 879db3a1ef..3f82809586 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java @@ -72,7 +72,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest builder().put("x-vcloud-authorization", token).put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)).build()) .payload( - payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() + ";version=1.5")).build() ); @@ -97,7 +97,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest + + + + + From 97320fcc001d429339a0c6f13f6cf12ac866f7b9 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 13:12:18 +0000 Subject: [PATCH 10/26] No enum for media types, after all... --- .../v1_5/VCloudDirectorMediaType.java | 36 ++++++++++--------- .../vcloud/director/v1_5/domain/Error.java | 4 +++ .../vcloud/director/v1_5/domain/Metadata.java | 6 +++- .../director/v1_5/domain/MetadataEntry.java | 4 +++ .../vcloud/director/v1_5/domain/Org.java | 4 +++ .../vcloud/director/v1_5/domain/OrgList.java | 4 +++ .../vcloud/director/v1_5/domain/Session.java | 4 +++ .../vcloud/director/v1_5/domain/Task.java | 4 +++ .../director/v1_5/domain/TasksList.java | 4 +++ .../v1_5/features/TaskClientExpectTest.java | 10 +++--- ...aseVCloudDirectorRestClientExpectTest.java | 13 ++++--- .../v1_5/login/SessionClientExpectTest.java | 6 ++-- 12 files changed, 65 insertions(+), 34 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index e103f2413d..2748cfa4a1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -26,24 +26,26 @@ package org.jclouds.vcloud.director.v1_5; * * @see javax.ws.rs.core.MediaType; */ -public enum VCloudDirectorMediaType { - ANY("*/*"), - SESSION("application/vnd.vmware.vcloud.session+xml"), - ERROR("application/vnd.vmware.vcloud.error+xml"), - ORG_LIST("application/vnd.vmware.vcloud.orgList+xml"), - METADATA("application/vnd.vmware.vcloud.metadata+xml"), - METADATA_ENTRY("*/*"), // TODO - ORG("application/vnd.vmware.vcloud.org+xml"), - TASKS_LIST("application/vnd.vmware.vcloud.tasksList+xml"), - TASK("application/vnd.vmware.vcloud.task+xml"); +public class VCloudDirectorMediaType { - private final String mediaType; + public static final String ANY = "*/*"; - private VCloudDirectorMediaType(String mediaType) { - this.mediaType = mediaType; - } + public static final String SESSION = "application/vnd.vmware.vcloud.session+xml"; + + public static final String ERROR = "application/vnd.vmware.vcloud.error+xml"; + + public static final String ORG_LIST = "application/vnd.vmware.vcloud.orgList+xml"; + + public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml"; + + public static final String METADATA_ENTRY = "*/*"; // TODO + + public static final String ORG = "application/vnd.vmware.vcloud.org+xml"; + + public static final String TASKS_LIST = "application/vnd.vmware.vcloud.tasksList+xml"; + + public static final String TASK = "application/vnd.vmware.vcloud.task+xml"; + + public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml"; - public String getMediaType() { - return mediaType; - } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java index 7bb5a94d8e..22b31a6cbf 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java @@ -27,6 +27,8 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; /** @@ -41,6 +43,8 @@ import com.google.common.base.Objects; @XmlRootElement(namespace = XMLNS, name = "Error") @XmlAccessorType(XmlAccessType.FIELD) public class Error { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.ERROR; public static Builder builder() { return new Builder(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java index 913cc8f165..90b38cd312 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java @@ -28,6 +28,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; @@ -43,7 +45,9 @@ import com.google.common.collect.Sets; * @author danikov */ @XmlRootElement(namespace = XMLNS, name = "Metadata") -public class Metadata extends ResourceType{ +public class Metadata extends ResourceType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA; @SuppressWarnings("unchecked") public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index 3c798eb179..d46e5d26c4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -28,6 +28,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Sets; @@ -43,6 +45,8 @@ import com.google.common.collect.Sets; */ @XmlRootElement(namespace = XMLNS, name = "MetadataEntry") public class MetadataEntry extends ResourceType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY; @SuppressWarnings("unchecked") public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index d86e10a573..ff7f257071 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -28,6 +28,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Sets; @@ -45,6 +47,8 @@ import com.google.common.collect.Sets; */ @XmlRootElement(namespace = XMLNS, name = "Org") public class Org extends EntityType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG; @SuppressWarnings("unchecked") public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java index bd407f0ebb..20492aca2b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java @@ -27,6 +27,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -38,6 +40,8 @@ import com.google.common.collect.Sets; */ @XmlRootElement(namespace = XMLNS, name = "OrgList") public class OrgList { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG_LIST; public static Builder builder() { return new Builder(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java index 42dc3ef44f..1ec2a852fb 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java @@ -31,6 +31,8 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -45,6 +47,8 @@ import com.google.common.collect.Sets; @XmlRootElement(namespace = XMLNS, name = "Session") @XmlAccessorType(XmlAccessType.FIELD) public class Session { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.SESSION; public static Builder builder() { return new Builder(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index 5b4bee8ed8..e2b246616d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Sets; @@ -45,6 +47,8 @@ import com.google.common.collect.Sets; */ @XmlRootElement(namespace = XMLNS, name = "Task") public class Task extends EntityType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASK; @SuppressWarnings("unchecked") public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java index a34ca958bc..5ae39756cf 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java @@ -28,6 +28,8 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; @@ -40,6 +42,8 @@ import com.google.common.collect.Sets; */ @XmlRootElement(namespace = XMLNS, name = "TasksList") public class TasksList extends EntityType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASKS_LIST; @SuppressWarnings("unchecked") public static Builder builder() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java index de37593c98..2082fa2651 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -57,7 +57,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest HttpResponse taskResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST.getMediaType() + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); @@ -135,7 +135,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest HttpResponse taskResponse = HttpResponse.builder() .statusCode(400) - .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); @@ -170,7 +170,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest HttpResponse taskResponse = HttpResponse.builder() .statusCode(403) - .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); @@ -206,7 +206,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest HttpResponse taskResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); @@ -257,7 +257,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest HttpResponse taskResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 55a21c418d..560d348311 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -28,7 +28,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeTest; import com.google.common.base.Function; import com.google.common.base.Splitter; @@ -80,7 +79,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect .put("x-vcloud-authorization", token) .put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)) .build()) - .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")) .build(); public BaseVCloudDirectorRestClientExpectTest() { @@ -97,24 +96,24 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); } - protected HttpRequest getStandardRequest(String method, URI uri, VCloudDirectorMediaType mediaType) { + protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) { return HttpRequest.builder() .method(method) .endpoint(uri) .headers(ImmutableMultimap. builder() - .put("Accept", mediaType.getMediaType()) + .put("Accept", mediaType) .put("x-vcloud-authorization", token) .build()) .build(); } - protected HttpResponse getStandardPayloadResponse(String relativeFilePath, VCloudDirectorMediaType mediaType) { + protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) { return getStandardPayloadResponse(200, relativeFilePath, mediaType); } - protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, VCloudDirectorMediaType mediaType) { + protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) { return HttpResponse.builder() .statusCode(statusCode) - .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType.getMediaType()+";version=1.5")).build(); + .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType + ";version=1.5")).build(); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java index 3f82809586..89055a05f5 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java @@ -72,8 +72,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest builder().put("x-vcloud-authorization", token).put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)).build()) .payload( - payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() - + ";version=1.5")).build() + payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")).build() ); @@ -97,8 +96,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest Date: Thu, 9 Feb 2012 01:08:21 +0000 Subject: [PATCH 11/26] Fix search and replace over-zealousness --- .../main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java | 2 +- .../jclouds/vcloud/director/v1_5/domain/TasksInProgress.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index e2b246616d..342474312e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -7,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICEXMLNSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java index 6d21e17952..2881f74c85 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java @@ -7,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICEXMLNSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an From 64e698d4ff405a5964129547522028e24fee2a1d Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 13:21:55 +0000 Subject: [PATCH 12/26] Remove client methods which rely on parsing URIs and add new function for tasksList operation --- .../v1_5/VCloudDirectorPropertiesBuilder.java | 2 +- .../VCloudDirectorRestClientModule.java | 4 +- .../v1_5/features/OrgAsyncClient.java | 33 +-- .../director/v1_5/features/OrgClient.java | 28 +- .../v1_5/features/TaskAsyncClient.java | 27 +- .../director/v1_5/features/TaskClient.java | 18 +- .../OrgReferenceToTaskListEndpoint.java | 60 +++++ .../v1_5/features/OrgClientExpectTest.java | 253 ++++++------------ .../v1_5/features/TaskClientExpectTest.java | 148 ++++------ ...aseVCloudDirectorRestClientExpectTest.java | 12 +- 10 files changed, 235 insertions(+), 350 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java index 05e724c3c1..0e0b74745a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java @@ -36,7 +36,7 @@ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost/api"); + properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api"); properties.setProperty(PROPERTY_SESSION_INTERVAL, 30*60 + ""); properties.setProperty(PROPERTY_API_VERSION, "1.5"); return properties; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 49e2865065..9c868d7f6e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -88,8 +88,8 @@ public class VCloudDirectorRestClientModule extends RestClientModule getOrgList(); - /** - * @see OrgClient#getOrg(String) - */ - @GET - @Path("/org/{id}") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getOrg(@PathParam("id") String orgId); - /** * @see OrgClient#getOrg(ReferenceType) */ @@ -73,16 +63,6 @@ public interface OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getOrg(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef); - /** - * @see OrgClient#getMetadata(String) - */ - @GET - @Path("/org/{id}/metadata") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadata(@PathParam("id") String orgId); - /** * @see OrgClient#getMetadata(ReferenceType) */ @@ -93,16 +73,6 @@ public interface OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef); - /** - * @see OrgClient#getMetadataEntry(String, String) - */ - @GET - @Path("/org/{id}/metadata/{key}") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key); - /** * @see OrgClient#getMetadataEntry(ReferenceType, String) */ @@ -111,5 +81,6 @@ public interface OrgAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, @PathParam("key") String key); + ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, + @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java index d72d99c17f..e52ac68748 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java @@ -39,6 +39,10 @@ public interface OrgClient { /** * Retrieves a list of organizations. + * + *

+    * GET /org
+    * 
* * @return a list of organizations */ @@ -46,28 +50,36 @@ public interface OrgClient { /** * Retrieves an organization. + * + *
+    * GET /org/{id}
+    * 
* * @return the org or null if not found */ - Org getOrg(String orgId); - Org getOrg(ReferenceType orgRef); + // FIXME throws exception on not found currently /** * Retrieves an list of the organization's metadata + * + *
+    * GET /org/{id}/metadata
+    * 
* * @return a list of metadata */ - Metadata getMetadata(String orgId); - Metadata getMetadata(ReferenceType orgRef); /** - * Retrieves a metadata + * Retrieves a metadata entry. + * + *
+    * GET /org/{id}/metadata{key}
+    * 
* - * @return the metadata or null if not found + * @return the metadata entry or null if not found */ - MetadataEntry getMetadataEntry(String orgId, String key); - MetadataEntry getMetadataEntry(ReferenceType orgRef, String key); + // FIXME throws exception on not found currently } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java index 833b918640..41050aee94 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java @@ -22,7 +22,6 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; @@ -32,6 +31,7 @@ import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.OrgReferenceToTaskListEndpoint; import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -45,24 +45,13 @@ import com.google.common.util.concurrent.ListenableFuture; public interface TaskAsyncClient { /** - * @see TaskClient#getTaskList(String) + * @see TaskClient#getTaskList(ReferenceType) */ @GET - @Path("/tasksList/{id}") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getTaskList(@PathParam("id") String orgId); - - /** - * @see TaskClient#getTask(String id) - */ - @GET - @Path("/task/{id}") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getTask(@PathParam("id") String taskId); + ListenableFuture getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) ReferenceType orgRef); /** * @see TaskClient#getTask(ReferenceType) @@ -73,16 +62,6 @@ public interface TaskAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType taskRef); - /** - * @see TaskClient#cancelTask(URI) - */ - @POST - @Path("/task/{id}/action/cancel") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture cancelTask(@PathParam("id") String taskId); - /** * @see TaskClient#cancelTask(URI) */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java index be8734c722..9682316877 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java @@ -36,25 +36,33 @@ public interface TaskClient { /** * Retrieves a list of tasks. + * + *
+    * GET /tasksList/{id}
+    * 
* * @param orgId the unique id for the organization * @return a list of tasks */ - TasksList getTaskList(String orgId); + TasksList getTaskList(ReferenceType orgRef); /** * Retrieves a task. + * + *
+    * GET /task/{id}
+    * 
* * @return the task or null if not found */ - Task getTask(String taskId); - Task getTask(ReferenceType taskRef); /** * Cancels a task. + * + *
+    * POST /task/{id}/action/cancel
+    * 
*/ - void cancelTask(String taskId); - void cancelTask(ReferenceType taskRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java new file mode 100644 index 0000000000..42b7e07dee --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.functions; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.Org; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.features.OrgClient; + +import com.google.common.base.Function; +import com.google.common.base.Preconditions; + +/** + * @author grkvlt@apache.org + */ +@Singleton +public class OrgReferenceToTaskListEndpoint implements Function { + private final OrgClient client; + + @Inject + public OrgReferenceToTaskListEndpoint(OrgClient client) { + this.client = client; + } + + @Override + public URI apply(Object input) { + Preconditions.checkNotNull(input); + Preconditions.checkArgument(input instanceof ReferenceType); + ReferenceType reference = (ReferenceType) input; + Org org = client.getOrg(reference); + for (Link link : org.getLinks()) { + if (link.getType().equals(VCloudDirectorMediaType.TASKS_LIST)) { + return link.getHref(); + } + } + throw new RuntimeException(String.format("Could not find a link of type %s", VCloudDirectorMediaType.TASKS_LIST)); + }; +} \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java index ff368206b4..b7c3dc7f6d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -67,191 +67,36 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org"), getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); + Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs()); client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", org.getHref()), getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); - Org expected = Org - .builder() - .name("JClouds") - .description("") - .fullName("JClouds") - .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") - .type("application/vnd.vmware.vcloud.org+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.vdc+xml") - .name("Cluster01-JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.tasksList+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("Public") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.controlAccess+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.orgNetwork+xml") - .name("ilsolation01-Jclouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.orgNetwork+xml") - .name("internet01-Jclouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) - .build()) - .build(); + Org expected = org(); assertEquals(client.getOrgClient().getOrg(org), expected); } - @Test - public void testWhenResponseIs2xxLoginReturnsValidOrgFromListById() { - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/org"), - getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); - Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs()); - client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/org/" + org.getUuid()), - getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); - - Org expected = Org - .builder() - .name("JClouds") - .description("") - .fullName("JClouds") - .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") - .type("application/vnd.vmware.vcloud.org+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.vdc+xml") - .name("Cluster01-JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.tasksList+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("Public") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.controlAccess+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.orgNetwork+xml") - .name("ilsolation01-Jclouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.orgNetwork+xml") - .name("internet01-Jclouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) - .build()) - .build(); - - assertEquals(org.getUuid(), "6f312e42-cd2b-488d-a2bb-97519cd57ed0"); - assertEquals(client.getOrgClient().getOrg(org.getUuid()), expected); - } - @Test public void testWhenResponseIs2xxLoginReturnsValidOrg() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); + URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"), getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); - Org expected = Org - .builder() - .name("JClouds") - .description("") - .fullName("JClouds") - .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") - .type("application/vnd.vmware.vcloud.org+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.vdc+xml") - .name("Cluster01-JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.tasksList+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("Public") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.controlAccess+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.orgNetwork+xml") - .name("ilsolation01-Jclouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.orgNetwork+xml") - .name("internet01-Jclouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) - .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) - .build()) - .build(); + Org expected = org(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); - assertEquals(client.getOrgClient().getOrg(orgId), expected); + Reference orgRef = Reference.builder().href(orgUri).build(); + + assertEquals(client.getOrgClient().getOrg(orgRef), expected); } @Test public void testWhenResponseIs400ForInvalidOrgId() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID"); + URI orgUri = URI.create(endpoint + "/org/NOTAUUID"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/NOTAUUID"), @@ -263,9 +108,9 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("BAD_REQUEST") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + Reference orgRef = Reference.builder().href(orgUri).build(); try { - client.getOrgClient().getOrg(orgId); + client.getOrgClient().getOrg(orgRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -276,7 +121,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test public void testWhenResponseIs403ForCatalogIdUsedAsOrgId() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"); + URI orgUri = URI.create(endpoint + "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"), @@ -288,9 +133,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + Reference orgRef = Reference.builder().href(orgUri).build(); + try { - client.getOrgClient().getOrg(orgId); + client.getOrgClient().getOrg(orgRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -301,7 +147,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test public void testWhenResponseIs403ForFakeOrgId() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); + URI orgUri = URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"), @@ -313,9 +159,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + Reference orgRef = Reference.builder().href(orgUri).build(); + try { - client.getOrgClient().getOrg(orgId); + client.getOrgClient().getOrg(orgRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -326,7 +173,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test public void testWhenResponseIs2xxLoginReturnsValidMetadataList() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); + URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"), @@ -342,13 +189,14 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); - assertEquals(client.getOrgClient().getMetadata(orgId), expected); + Reference orgRef = Reference.builder().href(orgUri).build(); + + assertEquals(client.getOrgClient().getMetadata(orgRef), expected); } @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadata() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); + URI orgUri = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), @@ -358,7 +206,58 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .key("KEY") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); - assertEquals(client.getOrgClient().getMetadataEntry(orgId, "KEY"), expected); + Reference orgRef = Reference.builder().href(orgUri).build(); + + assertEquals(client.getOrgClient().getMetadataEntry(orgRef, "KEY"), expected); + } + + public static Org org() { + return Org.builder() + .name("JClouds") + .description("") + .fullName("JClouds") + .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.vdc+xml") + .name("Cluster01-JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.tasksList+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("Public") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.controlAccess+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("ilsolation01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("internet01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()) + .build(); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java index 2082fa2651..fae7bebf13 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -59,11 +59,23 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .statusCode(200) .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5")) .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); - - String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build()); + HttpRequest orgRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse orgResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/org/org.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse); + TasksList expected = TasksList.builder() .name("Tasks Lists") .type("application/vnd.vmware.vcloud.tasksList+xml") @@ -119,7 +131,9 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - assertEquals(client.getTaskClient().getTaskList(orgId), expected); + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build(); + + assertEquals(client.getTaskClient().getTaskList(orgRef), expected); } @Test @@ -133,22 +147,34 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse taskResponse = HttpResponse.builder() - .statusCode(400) - .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) - .build(); + HttpResponse taskResponse = HttpResponse.builder().build(); + + HttpRequest orgRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/org/NOTAUUID")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); + HttpResponse orgResponse = HttpResponse.builder() + .statusCode(400) + .payload(payloadFromResourceWithContentType("/org/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) + .build(); - String orgId = "NOTAUUID"; + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse); Error expected = Error.builder() .message("validation error on field 'id': String value has invalid format or length") .majorErrorCode(400) .minorErrorCode("BAD_REQUEST") .build(); + + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID")).build(); + try { - client.getTaskClient().getTaskList(orgId); + client.getTaskClient().getTaskList(orgRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -168,14 +194,23 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse taskResponse = HttpResponse.builder() - .statusCode(403) - .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) + HttpResponse taskResponse = HttpResponse.builder().build(); + + HttpRequest orgRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); + HttpResponse orgResponse = HttpResponse.builder() + .statusCode(403) + .payload(payloadFromResourceWithContentType("/org/error403-fake.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) + .build(); - String orgId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse); Error expected = Error.builder() .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".") @@ -183,9 +218,11 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build(); + try { - client.getTaskClient().getTaskList(orgId); - fail("Should give HTTP 400 error"); + client.getTaskClient().getTaskList(orgRef); + fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); } catch (Exception e) { @@ -193,57 +230,6 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest } } - @Test - public void testGetTaskForTaskId() { - HttpRequest taskRequest = HttpRequest.builder() - .method("GET") - .endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) - .headers(ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("x-vcloud-authorization", token) - .build()) - .build(); - - HttpResponse taskResponse = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) - .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); - - String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b"; - - Task expected = Task.builder() - .type("application/vnd.vmware.vcloud.task+xml") - .name("task") - .id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") - .href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) - .status("success") - .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") - .operationName("catalogCreateCatalog") - .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) - .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) - .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) - .owner(Reference.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("QunyingTestCatalog") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) - .build()) - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .org(Reference.builder() - .type("application/vnd.vmware.vcloud.org+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .build(); - - assertEquals(client.getTaskClient().getTask(taskId), expected); - } - @Test public void testGetTaskForTaskRef() { HttpRequest taskRequest = HttpRequest.builder() @@ -299,28 +285,6 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest assertEquals(client.getTaskClient().getTask(taskRef), expected); } - @Test - public void testCancelTaskByTaskId() { - HttpRequest taskRequest = HttpRequest.builder() - .method("POST") - .endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")) - .headers(ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("x-vcloud-authorization", token) - .build()) - .build(); - - HttpResponse taskResponse = HttpResponse.builder() - .statusCode(200) - .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); - - String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b"; - - client.getTaskClient().cancelTask(taskId); - } - @Test public void testCancelTaskByTaskRef() { HttpRequest taskRequest = HttpRequest.builder() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 560d348311..ff01e2a85a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -46,7 +46,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect public static final String org = "JClouds"; public static final String password = "password"; public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ="; - public static final String endpoint = "http://localhost/api"; + public static final String endpoint = "https://vcloudbeta.bluelock.com/api"; protected DateService dateService; @@ -56,17 +56,9 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect assert dateService != null; } - protected static final Function, String> getUuidFromReference = new Function, String>() { - @Override - public String apply(ReferenceType input) { - String uuid = Iterables.getLast(Splitter.on("/").split(input.getHref().getPath())); - return uuid; - } - }; - protected HttpRequest loginRequest = HttpRequest.builder() .method("POST") - .endpoint(URI.create("http://localhost/api/sessions")) + .endpoint(URI.create(endpoint + "/sessions")) .headers(ImmutableMultimap.builder() .put("Accept", "*/*") .put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=") From 8185b280419950b1656b6a23a43542bf728db0f2 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 01:47:27 +0000 Subject: [PATCH 13/26] Changed namespace identifier to VCLOUD_1_5_NS --- .../director/v1_5/VCloudDirectorConstants.java | 2 +- .../vcloud/director/v1_5/domain/EntityType.java | 17 ++--------------- .../vcloud/director/v1_5/domain/Error.java | 2 +- .../vcloud/director/v1_5/domain/Metadata.java | 4 ++-- .../director/v1_5/domain/MetadataEntry.java | 6 +++--- .../vcloud/director/v1_5/domain/Org.java | 4 ++-- .../vcloud/director/v1_5/domain/OrgList.java | 4 ++-- .../director/v1_5/domain/ReferenceType.java | 9 --------- .../director/v1_5/domain/ResourceType.java | 11 +---------- .../vcloud/director/v1_5/domain/Session.java | 4 ++-- .../vcloud/director/v1_5/domain/Task.java | 14 +++++++------- .../director/v1_5/domain/TasksInProgress.java | 4 ++-- .../vcloud/director/v1_5/domain/TasksList.java | 4 ++-- 13 files changed, 27 insertions(+), 58 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java index fa71a182f3..c094600788 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java @@ -26,6 +26,6 @@ package org.jclouds.vcloud.director.v1_5; public class VCloudDirectorConstants { /** The XML namespace used by the clients. */ - public static final String XMLNS = "http://www.vmware.com/vcloud/v1.5"; + public static final String VCLOUD_1_5_NS = "http://www.vmware.com/vcloud/v1.5"; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java index af1f468ff6..0568885c8f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java @@ -157,9 +157,9 @@ public class EntityType> extends ResourceType { } } - @XmlElement(namespace = XMLNS, name = "Description") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Description") private String description; - @XmlElement(namespace = XMLNS, name = "TasksInProgress") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "TasksInProgress") private TasksInProgress tasksInProgress; @XmlAttribute private String id; @@ -211,19 +211,6 @@ public class EntityType> extends ResourceType { this.id = id; } - /** - * Returns the unique UUID string for this entity. - * - * Once we have an entity, the {@link #getId()} field is better suited to retrieving the - * id than {@link #getHref()}. - * - * @see ReferenceType#getUuid() - */ - @Override - public String getUuid() { - return Iterables.getLast(Splitter.on(":").split(id)); - } - /** * Contains the name of the the entity. */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java index 22b31a6cbf..97a8c6b2d6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java @@ -40,7 +40,7 @@ import com.google.common.base.Objects; * * @author grkvlt@apache.org */ -@XmlRootElement(namespace = XMLNS, name = "Error") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Error") @XmlAccessorType(XmlAccessType.FIELD) public class Error { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java index 90b38cd312..14ce1b3065 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java @@ -44,7 +44,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = XMLNS, name = "Metadata") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Metadata") public class Metadata extends ResourceType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA; @@ -137,7 +137,7 @@ public class Metadata extends ResourceType { this.metadata = ImmutableSet.copyOf(metadataEntries); } - @XmlElement(namespace = XMLNS, name = "MetadataEntry") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "MetadataEntry") private Set metadata = Sets.newLinkedHashSet(); public Set getMetadata() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index d46e5d26c4..202b8dd9a5 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -43,7 +43,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = XMLNS, name = "MetadataEntry") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "MetadataEntry") public class MetadataEntry extends ResourceType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY; @@ -138,9 +138,9 @@ public class MetadataEntry extends ResourceType { this.value = checkNotNull(value, "value"); } - @XmlElement(namespace = XMLNS, name = "Key") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Key") private String key; - @XmlElement(namespace = XMLNS, name = "Value") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Value") private String value; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index ff7f257071..5fb59b9753 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -45,7 +45,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = XMLNS, name = "Org") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Org") public class Org extends EntityType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG; @@ -174,7 +174,7 @@ public class Org extends EntityType { this.fullName = fullName; } - @XmlElement(namespace = XMLNS, name = "FullName") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "FullName") private String fullName; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java index 20492aca2b..bc9f6abd98 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java @@ -38,7 +38,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = XMLNS, name = "OrgList") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "OrgList") public class OrgList { public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG_LIST; @@ -88,7 +88,7 @@ public class OrgList { this.orgs = ImmutableSet.copyOf(orgs); } - @XmlElement(namespace = XMLNS, name = "Org") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Org") private Set orgs = Sets.newLinkedHashSet(); public Set getOrgs() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java index b1e59ce4d4..8e3f022ba9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java @@ -158,15 +158,6 @@ public class ReferenceType> implements URISupplier { this.id = id; } - /** - * Returns the unique UUID string for this reference. - * - * @see ResourceType#getUuid() - */ - public String getUuid() { - return Iterables.getLast(Splitter.on("/").split(href.getPath())); - } - /** * Contains the name of the the entity. * diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java index 67c6a47dcc..c12cef9699 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java @@ -112,7 +112,7 @@ public class ResourceType> implements URISupplier { private URI href; @XmlAttribute private String type; - @XmlElement(namespace = XMLNS, name = "Link") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Link") private Set links = Sets.newLinkedHashSet(); protected ResourceType(URI href) { @@ -148,15 +148,6 @@ public class ResourceType> implements URISupplier { return getHref(); } - /** - * Returns the unique UUID string for this resource. - * - * @see ReferenceType#getUuid() - */ - public String getUuid() { - return Iterables.getLast(Splitter.on("/").split(href.getPath())); - } - /** * Contains the type of the the entity. * diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java index 1ec2a852fb..ea3d7192b9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java @@ -44,7 +44,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = XMLNS, name = "Session") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Session") @XmlAccessorType(XmlAccessType.FIELD) public class Session { @@ -124,7 +124,7 @@ public class Session { this.links = ImmutableSet.copyOf(links); } - @XmlElement(namespace = XMLNS, name = "Link") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Link") private Set links = Sets.newLinkedHashSet(); @XmlAttribute private String user; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index 342474312e..11d79f6143 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -45,7 +45,7 @@ import com.google.common.collect.Sets; * * @author grkvlt@apache.org */ -@XmlRootElement(namespace = XMLNS, name = "Task") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Task") public class Task extends EntityType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASK; @@ -286,17 +286,17 @@ public class Task extends EntityType { super(href, name); } - @XmlElement(namespace = XMLNS, name = "Error") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Error") private Error error; - @XmlElement(namespace = XMLNS, name = "Organization") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Organization") private Reference org; - @XmlElement(namespace = XMLNS, name = "Progress") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Progress") private Integer progress; - @XmlElement(namespace = XMLNS, name = "Owner") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Owner") private Reference owner; - @XmlElement(namespace = XMLNS, name = "User") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "User") private Reference user; - @XmlElement(namespace = XMLNS, name = "Params") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Params") private Object params; @XmlAttribute private String status; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java index 2881f74c85..c377a98dfb 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksInProgress.java @@ -37,7 +37,7 @@ import com.google.common.collect.Sets; /** * @author grkvlt@apache.org */ -@XmlRootElement(namespace = XMLNS, name = "TasksInProgress") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "TasksInProgress") @XmlAccessorType(XmlAccessType.FIELD) public class TasksInProgress { @@ -86,7 +86,7 @@ public class TasksInProgress { this.tasks = ImmutableSet.copyOf(tasks); } - @XmlElement(namespace = XMLNS, name = "Task") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Task") private Set tasks = Sets.newLinkedHashSet(); public Set getTasks() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java index 5ae39756cf..7ffd1550d5 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TasksList.java @@ -40,7 +40,7 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -@XmlRootElement(namespace = XMLNS, name = "TasksList") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "TasksList") public class TasksList extends EntityType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASKS_LIST; @@ -177,7 +177,7 @@ public class TasksList extends EntityType { this.tasks = ImmutableSet.copyOf(tasks); } - @XmlElement(namespace = XMLNS, name = "Task") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Task") private Set tasks = Sets.newLinkedHashSet(); public Set getTasks() { From 3f8bf7e746d0abba8484a3e7322d2a89fb439322 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 03:16:47 +0000 Subject: [PATCH 14/26] Formatting --- .../org/jclouds/vcloud/director/v1_5/domain/ResourceType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java index c12cef9699..1b190760c6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java @@ -167,7 +167,7 @@ public class ResourceType> implements URISupplier { /** * Set of optional links to an entity or operation associated with this object. */ - public SetgetLinks() { + public Set getLinks() { return links; } From 28b7309b0310c560ab35f1e544b2459ef02587a2 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 13:28:35 +0000 Subject: [PATCH 15/26] Tidyup --- .../director/v1_5/domain/EntityType.java | 2 -- .../director/v1_5/domain/IpAddresses.java | 6 ++-- .../vcloud/director/v1_5/domain/IpRange.java | 10 +++--- .../vcloud/director/v1_5/domain/IpRanges.java | 6 ++-- .../vcloud/director/v1_5/domain/IpScope.java | 20 +++++------ .../v1_5/domain/NetworkConfiguration.java | 18 +++++----- .../director/v1_5/domain/NetworkFeatures.java | 6 ++-- .../director/v1_5/domain/NetworkService.java | 6 ++-- .../director/v1_5/domain/OrgNetwork.java | 22 ++++++------ .../director/v1_5/domain/ReferenceType.java | 2 -- .../director/v1_5/domain/ResourceType.java | 3 +- .../director/v1_5/domain/RouterInfo.java | 6 ++-- .../v1_5/domain/SyslogServerSettings.java | 8 ++--- .../features/NetworkClientExpectTest.java | 35 +++++++++++-------- 14 files changed, 74 insertions(+), 76 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java index 0568885c8f..6a9c68def2 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/EntityType.java @@ -30,8 +30,6 @@ import javax.xml.bind.annotation.XmlElement; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpAddresses.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpAddresses.java index c7dfa043a0..b023b5a6fb 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpAddresses.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpAddresses.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.util.Set; @@ -36,7 +36,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "IpAddresses") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "IpAddresses") public class IpAddresses { public static Builder builder() { @@ -83,7 +83,7 @@ public class IpAddresses { this.ipAddresses = ImmutableSet.copyOf(orgs); } - @XmlElement(namespace = NS, name = "IpAddress") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IpAddress") private Set ipAddresses = Sets.newLinkedHashSet(); public Set getIpAddresses() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRange.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRange.java index efffaee687..0274573425 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRange.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRange.java @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.vcloud.director.v1_5.domain; +package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -31,7 +31,7 @@ import com.google.common.base.Objects; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "IpRange") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "IpRange") public class IpRange { public static Builder builder() { @@ -82,9 +82,9 @@ public class IpRange { } - @XmlElement(namespace = NS, name = "StartAddress") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "StartAddress") private String startAddress; - @XmlElement(namespace = NS, name = "EndAddress") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "EndAddress") private String endAddress; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRanges.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRanges.java index da637355ac..c46beb5991 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRanges.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpRanges.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.util.Set; @@ -36,7 +36,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "IpRanges") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "IpRanges") public class IpRanges { public static Builder builder() { @@ -83,7 +83,7 @@ public class IpRanges { this.ipRanges = ImmutableSet.copyOf(ipRanges); } - @XmlElement(namespace = NS, name = "IpRange") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IpRange") private Set ipRanges = Sets.newLinkedHashSet(); public Set getIpRanges() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpScope.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpScope.java index 763082741b..ce847727a0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpScope.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/IpScope.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -33,7 +33,7 @@ import com.google.common.base.Objects; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "IpScope") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "IpScope") @XmlAccessorType(XmlAccessType.FIELD) public class IpScope { @@ -151,21 +151,21 @@ public class IpScope { this.isInherited = isInherited; } - @XmlElement(namespace = NS, name = "IsInherited") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IsInherited") private boolean isInherited; - @XmlElement(namespace = NS, name = "Gateway") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Gateway") private String gateway; - @XmlElement(namespace = NS, name = "Netmask") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Netmask") private String netmask; - @XmlElement(namespace = NS, name = "Dns1") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Dns1") private String dns1; - @XmlElement(namespace = NS, name = "Dns2") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Dns2") private String dns2; - @XmlElement(namespace = NS, name = "DnsSuffix") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "DnsSuffix") private String dnsSuffix; - @XmlElement(namespace = NS, name = "IpRanges") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IpRanges") private IpRanges ipRanges; - @XmlElement(namespace = NS, name = "AllocatedIpAddresses") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "AllocatedIpAddresses") private IpAddresses allocatedIpAddresses; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java index 694c1fd815..3146845319 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -33,7 +33,7 @@ import com.google.common.base.Objects; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "NetworkConfiguration") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "NetworkConfiguration") @XmlAccessorType(XmlAccessType.FIELD) public class NetworkConfiguration{ @@ -138,19 +138,19 @@ public class NetworkConfiguration{ this.fenceMode = fenceMode; } - @XmlElement(namespace = NS, name = "IpScope") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IpScope") private IpScope ipScope; - @XmlElement(namespace = NS, name = "ParentNetwork") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "ParentNetwork") private ReferenceType parentNetwork; - @XmlElement(namespace = NS, name = "FenceMode") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "FenceMode") private String fenceMode; - @XmlElement(namespace = NS, name = "RetainNetInfoAcrossDeployments") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "RetainNetInfoAcrossDeployments") private boolean retainNetInfoAcrossDeployments = false; - @XmlElement(namespace = NS, name = "Features") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Features") private NetworkFeatures features; - @XmlElement(namespace = NS, name = "SyslogServerSettings") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "SyslogServerSettings") private SyslogServerSettings syslogServerSettings; - @XmlElement(namespace = NS, name = "RouterInfo") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "RouterInfo") private RouterInfo routerInfo; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkFeatures.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkFeatures.java index b8a6d47897..036ee7f159 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkFeatures.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkFeatures.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.util.Set; @@ -36,7 +36,7 @@ import com.google.common.collect.Sets; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "Features") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Features") public class NetworkFeatures { public static Builder builder() { @@ -82,7 +82,7 @@ public class NetworkFeatures { // For JAXB and builder use } - @XmlElement(namespace = NS, name = "NetworkService") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "NetworkService") private Set services = Sets.newLinkedHashSet(); /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkService.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkService.java index 6fcbff73ac..3787b740ac 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkService.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkService.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -31,7 +31,7 @@ import com.google.common.base.Objects; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "NetworkService") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "NetworkService") public class NetworkService { public static Builder builder() { @@ -69,7 +69,7 @@ public class NetworkService { // For JAXB and builder use } - @XmlElement(namespace = NS, name = "IsEnabled") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IsEnabled") private boolean isEnabled; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java index 9133bf4f03..f2e72fac77 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java @@ -18,9 +18,9 @@ */ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Set; @@ -28,13 +28,11 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import org.jclouds.ovf.Network; - import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Sets; -@XmlRootElement(namespace = NS, name = "OrgNetwork") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "OrgNetwork") public class OrgNetwork extends EntityType { @SuppressWarnings("unchecked") @@ -54,7 +52,7 @@ public class OrgNetwork extends EntityType { private IpAddresses allowedExternalIpAddresses; /** - * @see Network#getConfiguration() + * @see OrgNetwork#getConfiguration() */ public Builder configuration(NetworkConfiguration networkConfiguration) { this.networkConfiguration = networkConfiguration; @@ -62,7 +60,7 @@ public class OrgNetwork extends EntityType { } /** - * @see Network#getNetworkPool() + * @see OrgNetwork#getNetworkPool() */ public Builder networkPool(ReferenceType networkPool) { this.networkPool = networkPool; @@ -70,7 +68,7 @@ public class OrgNetwork extends EntityType { } /** - * @see Network#getAllowedExternalIpAddresses() + * @see OrgNetwork#getAllowedExternalIpAddresses() */ public Builder allowedExternalIpAddresses(IpAddresses allowedExternalIpAddresses) { this.allowedExternalIpAddresses = allowedExternalIpAddresses; @@ -183,11 +181,11 @@ public class OrgNetwork extends EntityType { super(href, name); } - @XmlElement(namespace = NS, name = "Configuration") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Configuration") private NetworkConfiguration networkConfiguration; - @XmlElement(namespace = NS, name = "NetworkPool") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "NetworkPool") private ReferenceType networkPool; - @XmlElement(namespace = NS, name = "AllowedExternalIpAddresses") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "AllowedExternalIpAddresses") private IpAddresses allowedExternalIpAddresses; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java index 8e3f022ba9..e9444d8ef7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ReferenceType.java @@ -28,9 +28,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import com.google.common.base.Objects; -import com.google.common.base.Splitter; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.Iterables; /** * A reference to a resource. diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java index 1b190760c6..abeb7bf3b4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java @@ -31,7 +31,6 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import com.google.common.base.Objects; -import com.google.common.base.Splitter; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -202,4 +201,4 @@ public class ResourceType> implements URISupplier { protected ToStringHelper string() { return Objects.toStringHelper("").add("href", href).add("links", links).add("type", type); } -} \ No newline at end of file +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RouterInfo.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RouterInfo.java index 99151515a8..13afc7fced 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RouterInfo.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RouterInfo.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -31,7 +31,7 @@ import com.google.common.base.Objects; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "RouterInfo") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "RouterInfo") public class RouterInfo { public static Builder builder() { return new Builder(); @@ -71,7 +71,7 @@ public class RouterInfo { } - @XmlElement(namespace = NS, name = "ExternalIp") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "ExternalIp") private String externalIp; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SyslogServerSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SyslogServerSettings.java index 5217ad1252..9f21d7446c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SyslogServerSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SyslogServerSettings.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -34,7 +34,7 @@ import com.google.common.base.Objects; * * @author danikov */ -@XmlRootElement(namespace = NS, name = "SyslogServerSettings") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "SyslogServerSettings") @XmlAccessorType(XmlAccessType.FIELD) public class SyslogServerSettings { @@ -83,9 +83,9 @@ public class SyslogServerSettings { // For JAXB and builder use } - @XmlElement(namespace = NS, name = "SyslogServerIp1") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "SyslogServerIp1") private String syslogServerIp1; - @XmlElement(namespace = NS, name = "SyslogServerIp2") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "SyslogServerIp2") private String syslogServerIp2; /** diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java index a5c3732c7c..5d2f897f85 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.*; import java.net.URI; @@ -33,6 +33,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.SyslogServerSettings; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -51,13 +52,13 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", networkRef), - getStandardPayloadResponse("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK_XML)); + getStandardPayloadResponse("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK)); OrgNetwork expected = OrgNetwork .builder() .name("internet01-Jclouds") .id("urn:vcloud:network:55a677cf-ab3f-48ae-b880-fab90421980c") - .type(VCloudDirectorMediaType.ORG_NETWORK_XML) + .type(VCloudDirectorMediaType.ORG_NETWORK) .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) .link(Link.builder() .rel("up") @@ -96,12 +97,12 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT @Test public void testWhenResponseIs2xxLoginReturnsValidMetadata() { - URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"); - URI metaRef = URI.create(orgRef.toASCIIString()+"/metadata/"); + URI orgUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c"); + URI metaUri = URI.create(orgUri.toASCIIString() + "/metadata/"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metaRef), - getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA_XML)); + getStandardRequest("GET", metaUri), + getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA)); Metadata expected = Metadata.builder() .type("application/vnd.vmware.vcloud.metadata+xml") @@ -113,21 +114,25 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT .build()) .build(); - assertEquals(client.getOrgClient().getMetadata(orgRef), expected); + // TODO change network client to use ReferenceType params + Reference orgRef = Reference.builder().href(orgUri).build(); + + assertEquals(client.getNetworkClient().getMetadata(orgUri), expected); } @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { - URI metadataRef = URI.create( - "https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"); + URI metadataUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataRef), - getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATAENTRY_XML)); + getStandardRequest("GET", metadataUri), + getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY)); - MetadataEntry expected = MetadataEntry.builder() - .build(); + MetadataEntry expected = MetadataEntry.builder().build(); - assertEquals(client.getOrgClient().getMetadataEntry(metadataRef), expected); + // TODO change network client to use ReferenceType params + Reference orgRef = Reference.builder().href(metadataUri).build(); + + assertEquals(client.getNetworkClient().getMetadataEntry(metadataUri), expected); } } From b2cc1f6b388bd597ac9f15dcc17ee5cc794a2ee6 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 18:27:26 +0000 Subject: [PATCH 16/26] Updating ISO8601 time zone parsing and tests --- .../features/GlobalHostClientExpectTest.java | 32 +++++++++---------- .../parse/ListAlertsResponseTest.java | 2 +- .../parse/ListStoragePoolsResponseTest.java | 2 +- .../org/jclouds/date/internal/DateUtils.java | 13 ++++++-- .../internal/SimpleDateFormatDateService.java | 23 +++++++++---- .../org/jclouds/date/DateServiceTest.java | 19 ++++++----- .../jclouds/date/internal/DateUtilsTest.java | 2 +- .../jclouds/date/joda/JodaDateService.java | 30 +++++++++++++---- .../date/joda/JodaDateServiceTest.java | 20 ++++++++++++ 9 files changed, 98 insertions(+), 45 deletions(-) diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java index 512b6c80a4..877313075c 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java @@ -65,21 +65,21 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Set actual = requestSendsResponse(request, response).listHosts(); - Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); - Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC"); + Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); + Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); Host host1 = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); - Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); - lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC"); - created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); + Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00"); + lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00"); + created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00"); Host host2 = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); - lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); - created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 35, 51, "UTC"); + lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); + created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 35, 51, "GMT+02:00"); Host host3 = Host.builder().id(3).name("s-1-VM").state(Host.State.UP).type(Host.Type.SECONDARY_STORAGE_VM).ipAddress("10.26.26.81").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").lastPinged(lastPinged).managementServerId(223098941760041L).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); - lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); - created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 36, 46, "UTC"); + lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); + created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 36, 46, "GMT+02:00"); Host host4 = Host.builder().id(4).name("v-2-VM").state(Host.State.UP).type(Host.Type.CONSOLE_PROXY).ipAddress("10.26.26.96").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").lastPinged(lastPinged).managementServerId(223098941760041L).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Set expected = ImmutableSet.of(host1, host2, host3, host4); @@ -111,8 +111,8 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe .payload(payloadFromResource("/addhostresponse.json")) .statusCode(200).build(); - Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); - Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC"); + Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); + Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); Host expected = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).addHost(1, "http://example.com", "XenServer", "fred", "sekrit", @@ -132,8 +132,8 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe .payload(payloadFromResource("/updatehostresponse.json")) .statusCode(200).build(); - Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); - Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC"); + Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); + Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); Host expected = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).updateHost(1, UpdateHostOptions.Builder.allocationState(AllocationState.ENABLED).hostTags(Collections.emptySet()).osCategoryId(5)); @@ -223,9 +223,9 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe .payload(payloadFromResource("/addsecondarystorageresponse.json")) .statusCode(200).build(); - Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); - Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC"); - Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); + Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00"); + Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00"); + Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00"); Host expected = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).addSecondaryStorage("nfs://10.26.26.165/mnt/nfs/cs_sec", AddSecondaryStorageOptions.Builder.zoneId(1)); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAlertsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAlertsResponseTest.java index 6e4b1f3ac1..190767770b 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAlertsResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAlertsResponseTest.java @@ -62,7 +62,7 @@ public class ListAlertsResponseTest extends BaseSetParserTest { @Override @SelectJson("alert") public Set expected() { - Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+02:00")); c.set(Calendar.YEAR, 2011); c.set(Calendar.MONTH, Calendar.DECEMBER); c.set(Calendar.DAY_OF_MONTH, 4); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java index dd6adfded0..2220086a54 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java @@ -45,7 +45,7 @@ public class ListStoragePoolsResponseTest extends BaseItemParserTest expected() { - Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+02:00")); c.set(Calendar.YEAR, 2011); c.set(Calendar.MONTH, Calendar.NOVEMBER); c.set(Calendar.DAY_OF_MONTH, 26); diff --git a/core/src/main/java/org/jclouds/date/internal/DateUtils.java b/core/src/main/java/org/jclouds/date/internal/DateUtils.java index 02220e6379..cf68658f2c 100644 --- a/core/src/main/java/org/jclouds/date/internal/DateUtils.java +++ b/core/src/main/java/org/jclouds/date/internal/DateUtils.java @@ -27,15 +27,19 @@ import java.util.regex.Pattern; */ public class DateUtils { - public static final Pattern MILLIS_PATTERN = Pattern.compile("(.*\\.[0-9][0-9][0-9])[0-9]*"); + public static final String TZ_REGEX = "([+-][0-9][0-9](:?[0-9][0-9])?|Z)"; + + public static final Pattern MILLIS_PATTERN = Pattern.compile("(.*\\.[0-9][0-9][0-9])[0-9]*" + TZ_REGEX + "?"); // This regexp will match all TZ forms that are valid is ISO 8601 - public static final Pattern TZ_PATTERN = Pattern.compile("(.*)([+-][0-9][0-9](:?[0-9][0-9])?|Z)"); + public static final Pattern TZ_PATTERN = Pattern.compile("(.*)" + TZ_REGEX + "$"); public static String trimToMillis(String toParse) { Matcher matcher = MILLIS_PATTERN.matcher(toParse); if (matcher.find()) { toParse = matcher.group(1); + if (matcher.group(2) != null) + toParse += matcher.group(2); } return toParse; } @@ -60,9 +64,12 @@ public class DateUtils { String tz = matcher.group(2).replace(":", ""); // Append '00; if we only have a two digit TZ, as SimpleDateFormat if (tz.length() == 2) tz += "00"; + // Replace Z with +0000 + if (tz.equals("Z")) return "+0000"; return tz; } else { - return ""; + // Return +0000 if no time zone + return "+0000"; } } 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 69d0f62fc0..7df24289fb 100644 --- a/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java +++ b/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java @@ -50,7 +50,7 @@ public class SimpleDateFormatDateService implements DateService { private static final SimpleDateFormat rfc822SimpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); // @GuardedBy("this") - private static final SimpleDateFormat cSimpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss '+0000' yyyy", Locale.US); + private static final SimpleDateFormat cSimpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US); static { iso8601SimpleDateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); @@ -118,7 +118,12 @@ public class SimpleDateFormatDateService implements DateService { @Override public final String iso8601DateFormat(Date date) { synchronized (iso8601SimpleDateFormat) { - return iso8601SimpleDateFormat.format(date); + String parsed = iso8601SimpleDateFormat.format(date); + String tz = findTZ(parsed); + if (tz.equals("+0000")) { + parsed = trimTZ(parsed) + "Z"; + } + return parsed; } } @@ -130,9 +135,9 @@ public class SimpleDateFormatDateService implements DateService { @Override public final Date iso8601DateParse(String toParse) { String tz = findTZ(toParse); - toParse = trimTZ(toParse); toParse = trimToMillis(toParse); - toParse += tz; // Usable TZ added back + toParse = trimTZ(toParse); + toParse += tz; synchronized (iso8601SimpleDateFormat) { try { return iso8601SimpleDateFormat.parse(toParse); @@ -145,8 +150,9 @@ public class SimpleDateFormatDateService implements DateService { @Override public final Date iso8601SecondsDateParse(String toParse) { String tz = findTZ(toParse); + toParse = trimToMillis(toParse); toParse = trimTZ(toParse); - toParse += tz; // Usable TZ added back + toParse += tz; synchronized (iso8601SecondsSimpleDateFormat) { try { return iso8601SecondsSimpleDateFormat.parse(toParse); @@ -159,7 +165,12 @@ public class SimpleDateFormatDateService implements DateService { @Override public String iso8601SecondsDateFormat(Date date) { synchronized (iso8601SecondsSimpleDateFormat) { - return iso8601SecondsSimpleDateFormat.format(date); + String parsed = iso8601SecondsSimpleDateFormat.format(date); + String tz = findTZ(parsed); + if (tz.equals("+0000")) { + parsed = trimTZ(parsed) + "Z"; + } + return parsed; } } diff --git a/core/src/test/java/org/jclouds/date/DateServiceTest.java b/core/src/test/java/org/jclouds/date/DateServiceTest.java index bed5edb802..72d1f2ec85 100644 --- a/core/src/test/java/org/jclouds/date/DateServiceTest.java +++ b/core/src/test/java/org/jclouds/date/DateServiceTest.java @@ -82,17 +82,17 @@ public class DateServiceTest extends PerformanceTest { // Constant time test values, each TestData item must contain matching // times! testData = new TestData[] { - new TestData("2009-03-12T02:00:07.000Z", "2009-03-12T02:00:07-04:00", "2009-03-12T02:00:07Z", + new TestData("2009-03-12T02:00:07.000Z", "2009-03-12T06:00:07+0400", "2009-03-12T02:00:07Z", "Thu, 12 Mar 2009 02:00:07 GMT", "Thu Mar 12 02:00:07 +0000 2009", new Date(1236823207000l)), - new TestData("2009-03-12T02:00:07.000Z", "2009-03-12T02:00:07+04:00", "2009-03-12T02:00:07Z", + new TestData("2009-03-12T02:00:07.000Z", "2009-03-12T06:00:07+0400", "2009-03-12T02:00:07Z", "Thu, 12 Mar 2009 02:00:07 GMT", "Thu Mar 12 02:00:07 +0000 2009", new Date(1236823207000l)), - new TestData("2009-03-14T04:00:07.000Z", "2009-03-14T04:00:07Z+04:00", "2009-03-14T04:00:07Z", + new TestData("2009-03-14T04:00:07.000Z", "2009-03-14T08:00:07+0400", "2009-03-14T04:00:07Z", "Sat, 14 Mar 2009 04:00:07 GMT", "Thu Mar 14 04:00:07 +0000 2009", new Date(1237003207000l)), - new TestData("2009-03-16T06:00:07.000Z", "2009-03-16T06:00:07Z+04:00", "2009-03-16T06:00:07Z", + new TestData("2009-03-16T06:00:07.000Z", "2009-03-16T10:00:07+0400", "2009-03-16T06:00:07Z", "Mon, 16 Mar 2009 06:00:07 GMT", "Thu Mar 16 06:00:07 +0000 2009", new Date(1237183207000l)), - new TestData("2009-03-18T08:00:07.000Z", "2009-03-18T08:00:07Z+04:00", "2009-03-18T08:00:07Z", + new TestData("2009-03-18T08:00:07.000Z", "2009-03-18T12:00:07+0400", "2009-03-18T08:00:07Z", "Wed, 18 Mar 2009 08:00:07 GMT", "Thu Mar 18 08:00:07 +0000 2009", new Date(1237363207000l)), - new TestData("2009-03-20T10:00:07.000Z", "2009-03-20T10:00:07Z+04:00", "2009-03-20T10:00:07Z", + new TestData("2009-03-20T10:00:07.000Z", "2009-03-20T14:00:07+0400", "2009-03-20T10:00:07Z", "Fri, 20 Mar 2009 10:00:07 GMT", "Thu Mar 20 10:00:07 +0000 2009", new Date(1237543207000l)) }; } @@ -160,13 +160,12 @@ public class DateServiceTest extends PerformanceTest { void testFromSeconds() throws ExecutionException, InterruptedException { long seconds = 1254008225; Date date = dateService.fromSeconds(seconds); - assertEquals(dateService.rfc822DateFormat(date), "Sat, 26 Sep 2009 23:37:05 GMT"); + assertEquals(dateService.iso8601SecondsDateFormat(date), "2009-09-26T23:37:05Z"); } @Test - void testTzWithExtraZ() throws ExecutionException, InterruptedException { - assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T06:14:13-04:00").getTime(), 1306390453000l); - assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T06:14:13-04:00Z").getTime(), 1306390453000l); + void testTz() throws ExecutionException, InterruptedException { + assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T02:14:13-04:00").getTime(), 1306390453000l); } @Test diff --git a/core/src/test/java/org/jclouds/date/internal/DateUtilsTest.java b/core/src/test/java/org/jclouds/date/internal/DateUtilsTest.java index caf89178c3..7f7db19426 100644 --- a/core/src/test/java/org/jclouds/date/internal/DateUtilsTest.java +++ b/core/src/test/java/org/jclouds/date/internal/DateUtilsTest.java @@ -42,7 +42,7 @@ public class DateUtilsTest { // TODO: this test is failing on my jvm which is in IST @Test(enabled = false) public void testTrimsToMillisNoTimezone() { - assertEquals("NO_MILLIS", DateUtils.trimToMillis("NO_MILLISZ")); + assertEquals("NO_MILLIS", DateUtils.trimToMillis("NO_MILLIS")); assertEquals("NO_MILLIS.1", DateUtils.trimToMillis("NO_MILLIS.1")); assertEquals("NO_MILLIS.12", DateUtils.trimToMillis("NO_MILLIS.12")); assertEquals("NO_MILLIS.123", DateUtils.trimToMillis("NO_MILLIS.123")); diff --git a/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java b/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java index d8f39dd620..15a7c4317f 100644 --- a/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java +++ b/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java @@ -18,6 +18,7 @@ */ package org.jclouds.date.joda; +import static org.jclouds.date.internal.DateUtils.*; import static org.jclouds.date.internal.DateUtils.trimToMillis; import static org.jclouds.date.internal.DateUtils.trimTZ; @@ -41,16 +42,16 @@ import org.joda.time.format.DateTimeFormatter; public class JodaDateService implements DateService { private static final DateTimeFormatter rfc822DateFormatter = DateTimeFormat.forPattern( - "EEE, dd MMM yyyy HH:mm:ss 'GMT'").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); + "EEE, dd MMM yyyy HH:mm:ss z").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); private static final DateTimeFormatter cDateFormatter = DateTimeFormat - .forPattern("EEE MMM dd HH:mm:ss '+0000' yyyy").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); + .forPattern("EEE MMM dd HH:mm:ss Z yyyy").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); private static final DateTimeFormatter iso8601SecondsDateFormatter = DateTimeFormat.forPattern( - "yyyy-MM-dd'T'HH:mm:ss'Z'").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); + "yyyy-MM-dd'T'HH:mm:ssZ").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); private static final DateTimeFormatter iso8601DateFormatter = DateTimeFormat.forPattern( - "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); + "yyyy-MM-dd'T'HH:mm:ss.SSSZ").withLocale(Locale.US).withZone(DateTimeZone.forID("GMT")); public final Date fromSeconds(long seconds) { return new Date(seconds * 1000); @@ -81,7 +82,12 @@ public class JodaDateService implements DateService { } public final String iso8601SecondsDateFormat(Date dateTime) { - return iso8601SecondsDateFormatter.print(new DateTime(dateTime)); + String parsed = iso8601SecondsDateFormatter.print(new DateTime(dateTime)); + String tz = findTZ(parsed); + if (tz.equals("+0000")) { + parsed = trimTZ(parsed) + "Z"; + } + return parsed; } public final String iso8601SecondsDateFormat() { @@ -89,7 +95,12 @@ public class JodaDateService implements DateService { } public final String iso8601DateFormat(Date date) { - return iso8601DateFormatter.print(new DateTime(date)); + String parsed = iso8601DateFormatter.print(new DateTime(date)); + String tz = findTZ(parsed); + if (tz.equals("+0000")) { + parsed = trimTZ(parsed) + "Z"; + } + return parsed; } public final String iso8601DateFormat() { @@ -97,13 +108,18 @@ public class JodaDateService implements DateService { } public final Date iso8601DateParse(String toParse) { - toParse = trimTZ(toParse); + String tz = findTZ(toParse); toParse = trimToMillis(toParse); + toParse = trimTZ(toParse); + toParse += tz; return iso8601DateFormatter.parseDateTime(toParse).toDate(); } public final Date iso8601SecondsDateParse(String toParse) { + String tz = findTZ(toParse); + toParse = trimToMillis(toParse); toParse = trimTZ(toParse); + toParse += tz; return iso8601SecondsDateFormatter.parseDateTime(toParse).toDate(); } } \ No newline at end of file diff --git a/drivers/joda/src/test/java/org/jclouds/date/joda/JodaDateServiceTest.java b/drivers/joda/src/test/java/org/jclouds/date/joda/JodaDateServiceTest.java index b943eea19a..4ed87639d4 100644 --- a/drivers/joda/src/test/java/org/jclouds/date/joda/JodaDateServiceTest.java +++ b/drivers/joda/src/test/java/org/jclouds/date/joda/JodaDateServiceTest.java @@ -18,6 +18,11 @@ */ package org.jclouds.date.joda; +import static org.testng.Assert.*; + +import java.util.Date; +import java.util.concurrent.ExecutionException; + import org.jclouds.date.DateService; import org.jclouds.date.DateServiceTest; import org.jclouds.date.joda.config.JodaDateServiceModule; @@ -49,4 +54,19 @@ public class JodaDateServiceTest extends DateServiceTest { assert dateService instanceof JodaDateService; } + /* FIXME Joda routines cannot parse or correctly format the 'z' format specifier, e.g. 'GMT' used in RFC822 pattern. */ + + @Override + @Test + public void testRfc822DateFormat() throws ExecutionException, InterruptedException { + String dsString = dateService.rfc822DateFormat(testData[0].date); + assertEquals(dsString, testData[0].rfc822DateString.replace("GMT", "+00:00")); + } + + @Override + @Test(enabled = false) + public void testRfc822DateParse() throws ExecutionException, InterruptedException { + Date dsDate = dateService.rfc822DateParse(testData[0].rfc822DateString); + assertEquals(dsDate, testData[0].date); + } } \ No newline at end of file From 8da728488a9ce7915d18486ce383d84e0c531f4e Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 13:30:08 +0000 Subject: [PATCH 17/26] mergewithnext --- .../v1_5/VCloudDirectorMediaType.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 2748cfa4a1..dfb97c51cc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -28,24 +28,34 @@ package org.jclouds.vcloud.director.v1_5; */ public class VCloudDirectorMediaType { - public static final String ANY = "*/*"; + public static final String ANY = "*/*"; - public static final String SESSION = "application/vnd.vmware.vcloud.session+xml"; + public static final String SESSION = "application/vnd.vmware.vcloud.session+xml"; - public static final String ERROR = "application/vnd.vmware.vcloud.error+xml"; + public static final String ERROR = "application/vnd.vmware.vcloud.error+xml"; - public static final String ORG_LIST = "application/vnd.vmware.vcloud.orgList+xml"; + public static final String ORG_LIST = "application/vnd.vmware.vcloud.orgList+xml"; - public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml"; + public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml"; - public static final String METADATA_ENTRY = "*/*"; // TODO + public static final String METADATA_ENTRY = "*/*"; // TODO - public static final String ORG = "application/vnd.vmware.vcloud.org+xml"; + public static final String ORG = "application/vnd.vmware.vcloud.org+xml"; - public static final String TASKS_LIST = "application/vnd.vmware.vcloud.tasksList+xml"; + public static final String TASKS_LIST = "application/vnd.vmware.vcloud.tasksList+xml"; - public static final String TASK = "application/vnd.vmware.vcloud.task+xml"; + public static final String TASK = "application/vnd.vmware.vcloud.task+xml"; - public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml"; + public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml"; + + public static final String CATALOG = "application/vnd.vmware.vcloud.catalog+xml"; + + public static final String CATALOG_ITEM = "application/vnd.vmware.vcloud.catalogItem+xml"; + + public static final String CATALOG_ITEMS = "application/vnd.vmware.vcloud.catalogItems+xml"; + + public static final String CATALOGS_LIST = "application/vnd.vmware.vcloud.catalogsList+xml"; + + public static final String PROPERTY = "application/vnd.vmware.vcloud.property+xml"; } From c8148751ffd281964dccbfa8dc306840dfb34047 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 03:17:17 +0000 Subject: [PATCH 18/26] Added CatalogClient domain objects --- .../vcloud/director/v1_5/domain/Catalog.java | 239 ++++++++++++++++++ .../director/v1_5/domain/CatalogItem.java | 220 ++++++++++++++++ .../director/v1_5/domain/CatalogItems.java | 113 +++++++++ .../director/v1_5/domain/CatalogsList.java | 113 +++++++++ .../vcloud/director/v1_5/domain/Property.java | 126 +++++++++ 5 files changed, 811 insertions(+) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItems.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Property.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java new file mode 100644 index 0000000000..ee6cc24be7 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java @@ -0,0 +1,239 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + +import com.google.common.collect.Sets; + +/** + * Container for references to VappTemplate and Media objects. + * + *
+ * <complexType name="CatalogType" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Catalog") +public class Catalog extends EntityType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG; + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromCatalog(this); + } + + public static class Builder extends EntityType.Builder { + + private Entity owner; + private CatalogItems catalogItems; + private Boolean isPublished; + + /** + * @see Catalog#getOwner() + */ + public Builder owner(Entity owner) { + this.owner = owner; + return this; + } + + /** + * @see Catalog#getCatalogItems() + */ + public Builder catalogItems(CatalogItems catalogItems) { + this.catalogItems = catalogItems; + return this; + } + + /** + * @see Catalog#isPublished() + */ + public Builder isPublished(Boolean isPublished) { + this.isPublished = isPublished; + return this; + } + + /** + * @see Catalog#isPublished() + */ + public Builder published() { + this.isPublished = Boolean.TRUE; + return this; + } + + @Override + public Catalog build() { + Catalog catalog = new Catalog(href, name); + catalog.setOwner(owner); + catalog.setCatalogItems(catalogItems); + catalog.setIsPublished(isPublished); + catalog.setDescription(description); + catalog.setId(id); + catalog.setType(type); + catalog.setLinks(links); + catalog.setTasksInProgress(tasksInProgress); + return catalog; + } + + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + + public Builder fromCatalog(Catalog in) { + return fromEntityType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); + } + } + + private Catalog() { + // For JAXB and builder use + } + + private Catalog(URI href, String name) { + super(href, name); + } + + @XmlElement(name = "Owner") + private Entity owner; + @XmlElement(name = "CatalogItems") + private CatalogItems catalogItems; + @XmlElement(name = "IsPublished") + private Boolean isPublished; + + /** + * Gets the value of the owner property. + */ + public Entity getOwner() { + return owner; + } + + public void setOwner(Entity value) { + this.owner = value; + } + + /** + * Gets the value of the catalogItems property. + */ + public CatalogItems getCatalogItems() { + return catalogItems; + } + + public void setCatalogItems(CatalogItems value) { + this.catalogItems = value; + } + + /** + * Gets the value of the isPublished property. + */ + public Boolean isPublished() { + return isPublished; + } + + public void setIsPublished(Boolean value) { + this.isPublished = value; + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java new file mode 100644 index 0000000000..f098177137 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java @@ -0,0 +1,220 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +/** + * + * Contains a reference to a VappTemplate or Media object and related metadata. + * + *
+ * <complexType name="CatalogItemType" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Catalog") +public class CatalogItem extends EntityType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG_ITEM; + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromCatalogItem(this); + } + + public static class Builder extends EntityType.Builder { + + private Reference entity; + private List properties = Lists.newArrayList(); + + /** + * @see CatalogItem#getEntity() + */ + public Builder entity(Reference entity) { + this.entity = entity; + return this; + } + + /** + * @see CatalogItem#getProperties() + */ + public Builder properties(List properties) { + this.properties = Lists.newArrayList(checkNotNull(properties, "properties")); + return this; + } + + /** + * @see CatalogItem#getProperties() + */ + public Builder property(Property property) { + this.properties.add(checkNotNull(property, "property")); + return this; + } + + @Override + public CatalogItem build() { + CatalogItem catalog = new CatalogItem(href, name, entity); + catalog.setProperties(properties); + catalog.setDescription(description); + catalog.setId(id); + catalog.setType(type); + catalog.setLinks(links); + catalog.setTasksInProgress(tasksInProgress); + return catalog; + } + + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + + public Builder fromCatalogItem(CatalogItem in) { + return fromEntityType(in).entity(in.getEntity()).properties(in.getProperties()); + } + } + + private CatalogItem() { + // For JAXB and builder use + } + + private CatalogItem(URI href, String name, Reference entity) { + super(href, name); + this.entity = entity; + this.setProperties(properties); + } + + @XmlElement(name = "Entity", required = true) + private Reference entity; + @XmlElement(name = "Property") + private List properties = Lists.newArrayList(); + + /** + * Gets the value of the entity property. + */ + public Reference getEntity() { + return entity; + } + + /** + * Gets the value of the properties property. + */ + public List getProperties() { + return this.properties; + } + + public void setProperties(List properties) { + this.properties = Lists.newArrayList(checkNotNull(properties, "properties")); + } + + public void addProperty(Property property) { + this.properties.add(checkNotNull(property, "property")); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItems.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItems.java new file mode 100644 index 0000000000..7feb6c4e33 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItems.java @@ -0,0 +1,113 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.util.Collection; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + +import com.google.common.collect.Lists; + +/** + * Represents a list of catalog item references. + * + *
+ * <complexType name="CatalogItemsType" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogItems") +public class CatalogItems { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG_ITEMS; + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(); + } + + public static class Builder { + + private List catalogItems = Lists.newArrayList(); + + /** + * @see CatalogItems#getCatalogItems() + */ + public Builder items(List catalogItems) { + this.catalogItems = Lists.newArrayList(checkNotNull(catalogItems, "catalogItems")); + return this; + } + + /** + * @see CatalogItems#getCatalogItems() + */ + public Builder item(Reference catalogItem) { + this.catalogItems.add(checkNotNull(catalogItem, "catalogItem")); + return this; + } + + public CatalogItems build() { + return new CatalogItems(catalogItems); + } + + public Builder fromCatalogItems(CatalogItems in) { + return items(in.getCatalogItems()); + } + } + + private CatalogItems() { + // For JAXB and builder use + } + + private CatalogItems(Collection tasks) { + this.catalogItems = Lists.newArrayList(checkNotNull(catalogItems, "catalogItems")); + } + + @XmlElement(name = "CatalogItem") + private List catalogItems = Lists.newArrayList(); + + /** + * Gets the value of the catalogItems property. + */ + public List getCatalogItems() { + return this.catalogItems; + } + + public void setCatalogItems(List catalogItems) { + this.catalogItems = Lists.newArrayList(checkNotNull(catalogItems, "catalogItems")); + } + + public void addCatalogItem(Reference catalogItem) { + this.catalogItems.add(checkNotNull(catalogItem, "catalogItem")); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java new file mode 100644 index 0000000000..bb51299197 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java @@ -0,0 +1,113 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.util.Collection; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + +import com.google.common.collect.Lists; + +/** + * Container for ReferenceType elements that reference catalogs. + * + *
+ * <complexType name="CatalogsListType" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogsList") +public class CatalogsList { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG_ITEMS; + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(); + } + + public static class Builder { + + private List catalogReferences = Lists.newArrayList(); + + /** + * @see CatalogsList#getCatalogItems() + */ + public Builder catalogs(List catalogReferences) { + this.catalogReferences = Lists.newArrayList(checkNotNull(catalogReferences, "catalogReferences")); + return this; + } + + /** + * @see CatalogsList#getCatalogItems() + */ + public Builder catalog(Reference catalog) { + this.catalogReferences.add(checkNotNull(catalog, "catalog")); + return this; + } + + public CatalogsList build() { + return new CatalogsList(catalogReferences); + } + + public Builder fromCatalogsList(CatalogsList in) { + return catalogs(in.getCatalogsList()); + } + } + + private CatalogsList() { + // For JAXB and builder use + } + + private CatalogsList(Collection tasks) { + this.catalogReferences = Lists.newArrayList(checkNotNull(catalogReferences, "catalogReferences")); + } + + @XmlElement(name = "CatalogReference") + private List catalogReferences = Lists.newArrayList(); + + /** + * Gets the value of the catalogReferences property. + */ + public List getCatalogsList() { + return this.catalogReferences; + } + + public void setCatalogsList(List catalogReferences) { + this.catalogReferences = Lists.newArrayList(checkNotNull(catalogReferences, "catalogReferences")); + } + + public void addCatalog(Reference catalog) { + this.catalogReferences.add(checkNotNull(catalog, "catalog")); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Property.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Property.java new file mode 100644 index 0000000000..768ebedf8e --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Property.java @@ -0,0 +1,126 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; + +/** + * Contains key/value pair as property. + * + *
+ * <complexType name="PropertyType" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Property") +public class Property { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.PROPERTY; + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(); + } + + public static class Builder { + + private String value; + private String key; + + /** + * @see Property#getKey() + */ + public Builder key(String key) { + this.key = key; + return this; + } + + /** + * @see Property#getValue() + */ + public Builder value(String value) { + this.value = value; + return this; + } + + /** + * @see Property#getKey() + * @see Property#getValue() + */ + public Builder property(String key, String value) { + this.key = key; + this.value = value; + return this; + } + + public Property build() { + Property property = new Property(key); + property.setValue(value); + return property; + } + + public Builder fromProperty(Property in) { + return property(in.getKey(), in.getValue()); + } + } + + private Property() { + // For JAXB and builder use + } + + private Property(String key) { + this.key = key; + } + + @XmlValue + private String value; + @XmlAttribute(required = true) + private String key; + + /** + * Gets the value of the value property. + */ + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the key property. + */ + public String getKey() { + return key; + } +} From fbe68686d36c13a274a36f40273e8c7ea90faa32 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 03:27:13 +0000 Subject: [PATCH 19/26] Initial commit for CatalogClient with all operations defined and the client bound --- .../v1_5/VCloudDirectorAsyncClient.java | 1 + .../director/v1_5/VCloudDirectorClient.java | 12 +- .../v1_5/VCloudDirectorClient.java.orig | 65 ++++ .../v1_5/features/CatalogAsyncClient.java | 189 ++++++++++++ .../director/v1_5/features/CatalogClient.java | 190 ++++++++++++ .../features/CatalogClientExpectTest.java | 277 ++++++++++++++++++ 6 files changed, 732 insertions(+), 2 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java index 806e8af011..afac3ebc0a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java @@ -20,6 +20,7 @@ package org.jclouds.vcloud.director.v1_5; import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Session; +import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index 9a6cada8a8..4ac6d277b0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Session; +import org.jclouds.vcloud.director.v1_5.features.CatalogClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; @@ -46,13 +47,13 @@ public interface VCloudDirectorClient { Session getCurrentSession(); /** - * @return synchronous access to Org features + * @return synchronous access to {@link Org} features */ @Delegate OrgClient getOrgClient(); /** - * @return synchronous access to Task features + * @return synchronous access to {@link Task} features */ @Delegate TaskClient getTaskClient(); @@ -62,4 +63,11 @@ public interface VCloudDirectorClient { */ @Delegate NetworkClient getNetworkClient(); + + /** + * @return synchronous access to {@link Catalog} features + */ + @Delegate + CatalogClient getCatalogClient(); + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig new file mode 100644 index 0000000000..291eacb99e --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.vcloud.director.v1_5.domain.Session; +import org.jclouds.vcloud.director.v1_5.features.CatalogClient; +import org.jclouds.vcloud.director.v1_5.features.NetworkClient; +import org.jclouds.vcloud.director.v1_5.features.OrgClient; +import org.jclouds.vcloud.director.v1_5.features.TaskClient; + +import com.google.inject.Provides; + +/** + * Provides synchronous access to VCloudDirector. + * + * @see VCloudDirectorAsyncClient + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface VCloudDirectorClient { + + /** + * @return the current login session + */ + @Provides + Session getCurrentSession(); + + /** + * @return synchronous access to Org features + */ + @Delegate + OrgClient getOrgClient(); + + /** + * @return synchronous access to Task features + */ + @Delegate + TaskClient getTaskClient(); + + /** + * @return synchronous access to Network features + */ + @Delegate + NetworkClient getNetworkClient(); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java new file mode 100644 index 0000000000..d9837471ba --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java @@ -0,0 +1,189 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Catalog; +import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see CatalogClient + * @author grkvlt@apache.org + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface CatalogAsyncClient { + + /** + * Retrieves a catalog. + */ + @GET + @Consumes + @Produces(VCloudDirectorMediaType.CATALOG) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalog(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef); + + /** + * Creates a catalog item in a catalog. + */ + @POST + @Path("/catalogItems") + @Consumes(VCloudDirectorMediaType.CATALOG_ITEM) + @Produces(VCloudDirectorMediaType.CATALOG_ITEM) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture addCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef, + @PayloadParam("catalogItem") CatalogItem catalogItem); + + /** + * Returns the metadata associated with the catalog. + */ + @GET + @Path("/metadata") + @Consumes + @Produces(VCloudDirectorMediaType.METADATA) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalogMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef); + + /** + * Returns the metadata associated with the catalog for the specified key. + */ + @GET + @Path("/metadata/{key}") + @Consumes + @Produces(VCloudDirectorMediaType.METADATA_ENTRY) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalogMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef, + @PathParam("key") String key); + + /** + * Retrieves a catalog item. + */ + @GET + @Consumes + @Produces(VCloudDirectorMediaType.CATALOG_ITEM) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef); + + /** + * Modifies a catalog item. + */ + @PUT + @Consumes(VCloudDirectorMediaType.CATALOG_ITEM) + @Produces(VCloudDirectorMediaType.CATALOG_ITEM) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + @PayloadParam("catalogItem") CatalogItem catalogItem); + + /** + * Deletes a catalog item. + */ + @DELETE + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef); + + /** + * Returns the metadata associated with the catalog item. + */ + @GET + @Path("/metadata") + @Consumes + @Produces(VCloudDirectorMediaType.METADATA) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalogItemMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef); + + /** + * Merges the metadata for a catalog item with the information provided. + */ + @POST + @Path("/metadata") + @Consumes(VCloudDirectorMediaType.METADATA) + @Produces(VCloudDirectorMediaType.TASK) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture mergeCatalogItemMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + @PayloadParam("catalogItemMetadata") Metadata catalogItemMetadata); + + /** + * Returns the metadata associated with the catalog item for the specified key. + */ + @GET + @Path("/metadata/{key}") + @Consumes + @Produces(VCloudDirectorMediaType.METADATA_ENTRY) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + @PathParam("key") String key); + + /** + * Sets the metadata for the particular key for the catalog item to the value provided. + */ + @PUT + @Path("/metadata/{key}") + @Consumes /* (VCloudDirectorMediaType.METADATA_VALUE) */ + @Produces(VCloudDirectorMediaType.TASK) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture setCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + @PathParam("key") String key, @PayloadParam("metadataValue") /* MetadataValue */ Object metadataValue); + + /** + * Deletes the metadata for the particular key for the catalog item. + */ + @DELETE + @Path("/metadata/{key}") + @Consumes + @Produces(VCloudDirectorMediaType.TASK) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + @PathParam("key") String key); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java new file mode 100644 index 0000000000..41f77828cf --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java @@ -0,0 +1,190 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.Catalog; +import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.Task; + +/** + * Provides synchronous access to {@link Catalog} objects. + * + * @see CatalogAsyncClient + * @author grkvlt@apache.org + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface CatalogClient { + + /** + * Retrieves a catalog. + * + *
+    * GET /catalog/{id}
+    * 
+ * + * @param catalogRef the reference for the catalog + * @return a catalog + */ + Catalog getCatalog(ReferenceType catalogRef); + + /** + * Creates a catalog item in a catalog. + * + *
+    * POST /catalog/{id}/catalogItems
+    * 
+ * + * @param catalogRef the reference for the catalog + * @param item the catalog item to create + * @return the created catalog item + */ + CatalogItem addCatalogItem(ReferenceType catalogRef, CatalogItem item); + + /** + * Returns the metadata associated with the catalog. + * + *
+    * GET /catalog/{id}/metadata
+    * 
+ * + * @param catalogRef the reference for the catalog + * @return the catalog metadata + */ + Metadata getCatalogMetadata(ReferenceType catalogRef); + + /** + * Returns the metadata associated with the catalog for the specified key. + * + *
+    * GET /catalog/{id}/metadata/{key}
+    * 
+ * + * @param catalogRef the reference for the catalog + * @param key the metadata entry key + * @return the catalog metadata entry + */ + MetadataEntry getCatalogMetadataEntry(ReferenceType catalogRef, String key); + + /** + * Retrieves a catalog item. + * + *
+    * GET /catalogItem/{id}
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @return the catalog item + */ + CatalogItem getCatalogItem(ReferenceType catalogItemRef); + + /** + * Modifies a catalog item. + * + *
+    * PUT /catalogItem/{id}
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @param catalogItem the catalog item + * @return the updated catalog item + */ + CatalogItem updateCatalogItem(ReferenceType catalogItemRef, CatalogItem catalogItem); + + /** + * Deletes a catalog item. + * + *
+    * DELETE /catalogItem/{id}
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + */ + void deleteCatalogItem(ReferenceType catalogItemRef); + + /** + * Returns the metadata associated with the catalog item. + * + *
+    * GET /catalogItem/{id}/metadata
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @return the catalog item metadata + */ + Metadata getCatalogItemMetadata(ReferenceType catalogItemRef); + + /** + * Merges the metadata for a catalog item with the information provided. + * + *
+    * POST /catalogItem/{id}/metadata
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @param catalogItemMetadata the metadata for the catalog item + * @return a task for the merge operation + */ + Task mergeCatalogItemMetadata(ReferenceType catalogItemRef, Metadata catalogItemMetadata); + + /** + * Returns the metadata associated with the catalog item for the specified key. + * + *
+    * GET /catalog/{id}/metadata/{key}
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @param key the metadata entry key + * @return the catalog item metadata entry + */ + MetadataEntry getCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key); + + /** + * Sets the metadata for the particular key for the catalog item to the value provided. + * + *
+    * PUT /catalog/{id}/metadata/{key}
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @param key the metadata entry key + * @param value the metadata value + * @return a task for the set operation + */ + Task setCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key, /* MetadataValue */ Object value); + + /** + * Deletes the metadata for the particular key for the catalog item. + * + *
+    * DELETE /catalog/{id}/metadata/{key}
+    * 
+ * + * @param catalogItemRef the reference for the catalog item + * @param key the metadata entry key + * @return a task for the delete operation + */ + Task deleteCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key); +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java new file mode 100644 index 0000000000..ffbcc5bc2c --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java @@ -0,0 +1,277 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + *(Link.builder().regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless(Link.builder().required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import static org.testng.Assert.*; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Error; +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.Catalog; +import org.jclouds.vcloud.director.v1_5.domain.CatalogsList; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * Test the {@link CatalogClient} by observing its side effects. + * + * @author grkvlt@apache.org + */ +@Test(groups = "unit", singleThreaded = true, testName = "CatalogClientExpectTest") +public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + @Test + public void testCatalogListForValidOrg() { + HttpRequest catalogRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse catalogResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/catalog/catalogslist.xml", VCloudDirectorMediaType.CATALOGS_LIST + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + + CatalogsList expected = CatalogsList.builder() + .name("Catalogs Lists") + .type("application/vnd.vmware.vcloud.catalogsList+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .catalog(Catalog.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("catalog") + .id("urn:vcloud:catalog:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .status("success") + .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") + .operationName("catalogCreateCatalog") + .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build()) + .catalog(Catalog.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("catalog") + .id("urn:vcloud:catalog:bd22e745-9c2a-4f82-a954-0e35b6f76ba5") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/bd22e745-9c2a-4f82-a954-0e35b6f76ba5")) + .status("success") + .operation("Enabled User (967d317c-4273-4a95-b8a4-bf63b78e9c69)") + .operationName("jobEnable") + .startTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-06T17:30:38.507-04:00")) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adrian@jclouds.org") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/8c360b93-ed25-4c9a-8e24-d48cd9966d93")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build()) + .build(); + + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build(); + + assertEquals(client.getCatalogClient().getCatalogList(orgRef), expected); + } + + @Test + public void testCatalogListForInvalidOrgId() { + HttpRequest catalogRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalogsList/NOTAUUID")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse catalogResponse = HttpResponse.builder() + .statusCode(400) + .payload(payloadFromResourceWithContentType("/catalog/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + + Error expected = Error.builder() + .message("validation error on field 'id': String value has invalid format or length") + .majorErrorCode(400) + .minorErrorCode("BAD_REQUEST") + .build(); + + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID")).build(); + + try { + client.getCatalogClient().getCatalogList(orgRef); + fail("Should give HTTP 400 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testCatalogListForNotFoundOrgId() { + HttpRequest catalogRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalogsList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse catalogResponse = HttpResponse.builder() + .statusCode(403) + .payload(payloadFromResourceWithContentType("/catalog/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + + Error expected = Error.builder() + .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build(); + + try { + client.getCatalogClient().getCatalogList(orgRef); + fail("Should give HTTP 400 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testGetCatalogForCatalogRef() { + HttpRequest catalogRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse catalogResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.catalog + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + + Reference catalogRef = Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("catalog") + .href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .build(); + + Catalog expected = Catalog.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("catalog") + .id("urn:vcloud:catalog:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .status("success") + .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") + .operationName("catalogCreateCatalog") + .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + + assertEquals(client.getCatalogClient().getCatalog(catalogRef), expected); + } + + @Test + public void testCancelCatalogByCatalogRef() { + HttpRequest catalogRequest = HttpRequest.builder() + .method("POST") + .endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse catalogResponse = HttpResponse.builder() + .statusCode(200) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + + Reference catalogRef = Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("catalog") + .href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .build(); + + client.getCatalogClient().cancelCatalog(catalogRef); + } +} From d983eb38269e721da3570a07a0997cc6c5fd2a77 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 13:25:15 +0000 Subject: [PATCH 20/26] Added IsEnabled property to Org --- .../vcloud/director/v1_5/domain/Org.java | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index 5fb59b9753..ad304dba98 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -63,6 +63,7 @@ public class Org extends EntityType { public static class Builder extends EntityType.Builder { private String fullName; + private Boolean isEnabled; /** * @see Org#getFullName() @@ -72,6 +73,30 @@ public class Org extends EntityType { return this; } + /** + * @see Org#isEnabled() + */ + public Builder isEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + return this; + } + + /** + * @see Org#isEnabled() + */ + public Builder enabled() { + this.isEnabled = Boolean.TRUE; + return this; + } + + /** + * @see Org#isEnabled() + */ + public Builder disabled() { + this.isEnabled = Boolean.FALSE; + return this; + } + @Override public Org build() { Org org = new Org(href, name, fullName); @@ -80,6 +105,7 @@ public class Org extends EntityType { org.setType(type); org.setLinks(links); org.setTasksInProgress(tasksInProgress); + org.setIsEnabled(isEnabled); return org; } @@ -174,17 +200,29 @@ public class Org extends EntityType { this.fullName = fullName; } - @XmlElement(namespace = VCLOUD_1_5_NS, name = "FullName") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "FullName", required = true) private String fullName; + @XmlElement(namespace = VCLOUD_1_5_NS, name = "IsEnabled") + private Boolean isEnabled; /** - * - * @return fullName of the org + * Full name of the organization. */ public String getFullName() { return fullName; } + /** + * Full name of the organization. + */ + public Boolean isEnabled() { + return isEnabled; + } + + public void isEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + } + @Override public boolean equals(Object o) { if (this == o) @@ -192,16 +230,16 @@ public class Org extends EntityType { if (o == null || getClass() != o.getClass()) return false; Org that = Org.class.cast(o); - return super.equals(that) && equal(fullName, that.fullName); + return super.equals(that) && equal(fullName, that.fullName) && equal(this.isEnabled, that.isEnabled); } @Override public int hashCode() { - return super.hashCode() + Objects.hashCode(fullName); + return super.hashCode() + Objects.hashCode(fullName, isEnabled); } @Override public ToStringHelper string() { - return super.string().add("fullName", fullName); + return super.string().add("fullName", fullName).add("isEnabled", isEnabled); } } From 86e15398aa27c672d2182716e9a47bd5651d7d10 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 9 Feb 2012 15:07:04 +0000 Subject: [PATCH 21/26] Updated Metadata and associated domain objects --- .../v1_5/VCloudDirectorMediaType.java | 4 +- .../vcloud/director/v1_5/domain/Metadata.java | 27 ++- .../director/v1_5/domain/MetadataEntry.java | 42 +++-- .../director/v1_5/domain/MetadataValue.java | 168 ++++++++++++++++++ 4 files changed, 219 insertions(+), 22 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index dfb97c51cc..8a24111ebc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -38,7 +38,9 @@ public class VCloudDirectorMediaType { public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml"; - public static final String METADATA_ENTRY = "*/*"; // TODO + public static final String METADATA_ENTRY = "*/*"; // No media type (?) + + public static final String METADATA_VALUE = "application/vnd.vmware.vcloud.metadata.value+xml";; public static final String ORG = "application/vnd.vmware.vcloud.org+xml"; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java index 14ce1b3065..baee875246 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java @@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry.Builder; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -56,7 +57,7 @@ public class Metadata extends ResourceType { @Override public Builder toBuilder() { - return new Builder().fromMetadataList(this); + return new Builder().fromMetadata(this); } public static class Builder extends ResourceType.Builder { @@ -123,8 +124,16 @@ public class Metadata extends ResourceType { return this; } - public Builder fromMetadataList(Metadata in) { - return metadata(in.getMetadata()); + public Builder fromMetadata(Metadata in) { + return fromResourceType(in).metadata(in.getMetadata()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResourceType(ResourceType in) { + return Builder.class.cast(super.fromResourceType(in)); } } @@ -134,14 +143,14 @@ public class Metadata extends ResourceType { private Metadata(URI href, Set metadataEntries) { super(href); - this.metadata = ImmutableSet.copyOf(metadataEntries); + this.metadataEntries = ImmutableSet.copyOf(metadataEntries); } @XmlElement(namespace = VCLOUD_1_5_NS, name = "MetadataEntry") - private Set metadata = Sets.newLinkedHashSet(); + private Set metadataEntries = Sets.newLinkedHashSet(); public Set getMetadata() { - return ImmutableSet.copyOf(metadata); + return ImmutableSet.copyOf(metadataEntries); } @Override @@ -151,17 +160,17 @@ public class Metadata extends ResourceType { if (o == null || getClass() != o.getClass()) return false; Metadata that = Metadata.class.cast(o); - return super.equals(that) && equal(metadata, that.metadata); + return super.equals(that) && equal(this.metadataEntries, that.metadataEntries); } @Override public int hashCode() { - return super.hashCode() + Objects.hashCode(metadata); + return super.hashCode() + Objects.hashCode(metadataEntries); } @Override public ToStringHelper string() { - return super.string().add("metadata", metadata); + return super.string().add("metadataEntries", metadataEntries); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index 202b8dd9a5..82b28c77d4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Link.Builder; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -55,15 +56,15 @@ public class MetadataEntry extends ResourceType { @Override public Builder toBuilder() { - return new Builder().fromMetadata(this); + return new Builder().fromMetadataEntry(this); } public static class Builder extends ResourceType.Builder { private String key; - private String value; + private MetadataValue value; /** - * @see MetadataEntry#getKey + * @see MetadataEntry#getKey() */ public Builder key(String key) { this.key = key; @@ -71,9 +72,19 @@ public class MetadataEntry extends ResourceType { } /** - * @see MetadataEntry#getValue + * @see MetadataEntry#getValue() */ - public Builder value(String value) { + public Builder value(MetadataValue value) { + this.value = value; + return this; + } + + /** + * @see MetadataEntry#getKey() + * @see MetadataEntry#getValue() + */ + public Builder entry(String key, MetadataValue value) { + this.key = key; this.value = value; return this; } @@ -122,17 +133,24 @@ public class MetadataEntry extends ResourceType { return this; } - public Builder fromMetadata(MetadataEntry in) { - return key(in.getKey()).value(in.getValue()); + public Builder fromMetadataEntry(MetadataEntry in) { + return fromResourceType(in).entry(key, value); } + /** + * {@inheritDoc} + */ + @Override + public Builder fromResourceType(ResourceType in) { + return Builder.class.cast(super.fromResourceType(in)); + } } private MetadataEntry() { // For JAXB and builder use } - private MetadataEntry(URI href, String key, String value) { + private MetadataEntry(URI href, String key, MetadataValue value) { super(href); this.key = checkNotNull(key, "key"); this.value = checkNotNull(value, "value"); @@ -141,7 +159,7 @@ public class MetadataEntry extends ResourceType { @XmlElement(namespace = VCLOUD_1_5_NS, name = "Key") private String key; @XmlElement(namespace = VCLOUD_1_5_NS, name = "Value") - private String value; + private MetadataValue value; /** * @return key of the entry @@ -153,7 +171,7 @@ public class MetadataEntry extends ResourceType { /** * @return value of the entry */ - public String getValue() { + public MetadataValue getValue() { return value; } @@ -164,12 +182,12 @@ public class MetadataEntry extends ResourceType { if (o == null || getClass() != o.getClass()) return false; MetadataEntry that = MetadataEntry.class.cast(o); - return super.equals(that) && equal(key, that.key); + return super.equals(that) && equal(key, that.key) && equal(this.value, that.value); } @Override public int hashCode() { - return super.hashCode() + Objects.hashCode(key); + return super.hashCode() + Objects.hashCode(key, value); } @Override diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java new file mode 100644 index 0000000000..7ca328eb35 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java @@ -0,0 +1,168 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue.Builder; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Sets; + +/** + * Represents a metadata entry + * + *
+ * <xs:complexType name="MetadataType">
+ * 
+ * + * @author danikov + */ +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "MetadataValue") +public class MetadataValue extends ResourceType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY; + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromMetadataValue(this); + } + + public static class Builder extends ResourceType.Builder { + private String value; + + /** + * @see MetadataValue#getValue + */ + public Builder value(String value) { + this.value = value; + return this; + } + + @Override + public MetadataValue build() { + MetadataValue metadataValue = new MetadataValue(href, value); + metadataValue.setType(type); + metadataValue.setLinks(links); + return metadataValue; + } + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + public Builder fromMetadataValue(MetadataValue in) { + return fromResourceType(in).value(value); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResourceType(ResourceType in) { + return Builder.class.cast(super.fromResourceType(in)); + } + } + + private MetadataValue() { + // For JAXB and builder use + } + + private MetadataValue(URI href, String value) { + super(href); + this.value = checkNotNull(value, "value"); + } + + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Value", required = true) + private String value; + + /** + * The value. + */ + public String getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + MetadataValue that = MetadataValue.class.cast(o); + return super.equals(that) && equal(this.value, that.value); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(value); + } + + @Override + public ToStringHelper string() { + return super.string().add("value", value); + } +} From 33cd3c5716e6fde71cf44e0221233fd664a4a5bd Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 12:09:35 +0000 Subject: [PATCH 22/26] Deleted extraneous patching leftover --- .../v1_5/VCloudDirectorClient.java.orig | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig deleted file mode 100644 index 291eacb99e..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java.orig +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.vcloud.director.v1_5; - -import java.util.concurrent.TimeUnit; - -import org.jclouds.concurrent.Timeout; -import org.jclouds.rest.annotations.Delegate; -import org.jclouds.vcloud.director.v1_5.domain.Session; -import org.jclouds.vcloud.director.v1_5.features.CatalogClient; -import org.jclouds.vcloud.director.v1_5.features.NetworkClient; -import org.jclouds.vcloud.director.v1_5.features.OrgClient; -import org.jclouds.vcloud.director.v1_5.features.TaskClient; - -import com.google.inject.Provides; - -/** - * Provides synchronous access to VCloudDirector. - * - * @see VCloudDirectorAsyncClient - * @author Adrian Cole - */ -@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) -public interface VCloudDirectorClient { - - /** - * @return the current login session - */ - @Provides - Session getCurrentSession(); - - /** - * @return synchronous access to Org features - */ - @Delegate - OrgClient getOrgClient(); - - /** - * @return synchronous access to Task features - */ - @Delegate - TaskClient getTaskClient(); - - /** - * @return synchronous access to Network features - */ - @Delegate - NetworkClient getNetworkClient(); -} From ca5409866100c568734e6ef23e436676f7b0591b Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 13:35:48 +0000 Subject: [PATCH 23/26] Updates to CatalogClient --- .../v1_5/VCloudDirectorAsyncClient.java | 6 +++++ .../VCloudDirectorRestClientModule.java | 5 +++- .../v1_5/features/CatalogAsyncClient.java | 24 +++++++------------ .../director/v1_5/features/CatalogClient.java | 3 ++- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java index afac3ebc0a..9eb3e15dc4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java @@ -59,4 +59,10 @@ public interface VCloudDirectorAsyncClient { */ @Delegate NetworkAsyncClient getNetworkClient(); + + /** + * @return asynchronous access to Catalog features + */ + @Delegate + CatalogAsyncClient getCatalogClient(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 9c868d7f6e..522137d648 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -42,6 +42,8 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.annotations.Login; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; +import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.CatalogClient; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; @@ -75,8 +77,9 @@ import com.google.inject.name.Named; public class VCloudDirectorRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// - .put(OrgClient.class, OrgAsyncClient.class) + .put(CatalogClient.class, CatalogAsyncClient.class) .put(NetworkClient.class, NetworkAsyncClient.class) + .put(OrgClient.class, OrgAsyncClient.class) .put(TaskClient.class, TaskAsyncClient.class) .build(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java index d9837471ba..e3b8815d23 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java @@ -27,17 +27,18 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; -import org.jclouds.rest.annotations.Payload; -import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; @@ -58,7 +59,6 @@ public interface CatalogAsyncClient { */ @GET @Consumes - @Produces(VCloudDirectorMediaType.CATALOG) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getCatalog(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef); @@ -73,15 +73,14 @@ public interface CatalogAsyncClient { @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture addCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef, - @PayloadParam("catalogItem") CatalogItem catalogItem); - + @BinderParam(BindToXMLPayload.class) CatalogItem catalogItem); + /** * Returns the metadata associated with the catalog. */ @GET @Path("/metadata") @Consumes - @Produces(VCloudDirectorMediaType.METADATA) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getCatalogMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef); @@ -92,7 +91,6 @@ public interface CatalogAsyncClient { @GET @Path("/metadata/{key}") @Consumes - @Produces(VCloudDirectorMediaType.METADATA_ENTRY) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getCatalogMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef, @@ -103,7 +101,6 @@ public interface CatalogAsyncClient { */ @GET @Consumes - @Produces(VCloudDirectorMediaType.CATALOG_ITEM) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef); @@ -117,7 +114,7 @@ public interface CatalogAsyncClient { @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture updateCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, - @PayloadParam("catalogItem") CatalogItem catalogItem); + @BinderParam(BindToXMLPayload.class) CatalogItem catalogItem); /** * Deletes a catalog item. @@ -134,7 +131,6 @@ public interface CatalogAsyncClient { @GET @Path("/metadata") @Consumes - @Produces(VCloudDirectorMediaType.METADATA) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getCatalogItemMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef); @@ -149,7 +145,7 @@ public interface CatalogAsyncClient { @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture mergeCatalogItemMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, - @PayloadParam("catalogItemMetadata") Metadata catalogItemMetadata); + @BinderParam(BindToXMLPayload.class) Metadata catalogItemMetadata); /** * Returns the metadata associated with the catalog item for the specified key. @@ -157,7 +153,6 @@ public interface CatalogAsyncClient { @GET @Path("/metadata/{key}") @Consumes - @Produces(VCloudDirectorMediaType.METADATA_ENTRY) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, @@ -168,12 +163,12 @@ public interface CatalogAsyncClient { */ @PUT @Path("/metadata/{key}") - @Consumes /* (VCloudDirectorMediaType.METADATA_VALUE) */ + @Consumes(VCloudDirectorMediaType.METADATA_VALUE) @Produces(VCloudDirectorMediaType.TASK) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture setCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, - @PathParam("key") String key, @PayloadParam("metadataValue") /* MetadataValue */ Object metadataValue); + @PathParam("key") String key, @BinderParam(BindToXMLPayload.class) MetadataValue metadataValue); /** * Deletes the metadata for the particular key for the catalog item. @@ -181,7 +176,6 @@ public interface CatalogAsyncClient { @DELETE @Path("/metadata/{key}") @Consumes - @Produces(VCloudDirectorMediaType.TASK) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture deleteCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java index 41f77828cf..981286730f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java @@ -25,6 +25,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; @@ -173,7 +174,7 @@ public interface CatalogClient { * @param value the metadata value * @return a task for the set operation */ - Task setCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key, /* MetadataValue */ Object value); + Task setCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key, MetadataValue value); /** * Deletes the metadata for the particular key for the catalog item. From 751d99c1437313a85a2f1ea097997206fc7ae31d Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 12:11:04 +0000 Subject: [PATCH 24/26] Updating domain objects --- .../director/v1_5/domain/CatalogItem.java | 8 ++++--- .../director/v1_5/domain/MetadataEntry.java | 13 +++++----- .../director/v1_5/domain/MetadataValue.java | 3 +-- .../vcloud/director/v1_5/domain/Org.java | 2 +- .../director/v1_5/domain/package-info.java | 24 +++++++++++++++++++ 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/package-info.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java index f098177137..eaf734f90a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogItem.java @@ -43,7 +43,7 @@ import com.google.common.collect.Sets; * * @author grkvlt@apache.org */ -@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Catalog") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogItem") public class CatalogItem extends EntityType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG_ITEM; @@ -197,14 +197,16 @@ public class CatalogItem extends EntityType { private List properties = Lists.newArrayList(); /** - * Gets the value of the entity property. + * A reference to a VappTemplate or Media object. */ public Reference getEntity() { return entity; } /** - * Gets the value of the properties property. + * User-specified key/value pair. + * + * This element has been superseded by the {@link Metadata} element, which is the preferred way to specify key/value pairs for objects. */ public List getProperties() { return this.properties; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index 82b28c77d4..52ec1c2824 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -29,7 +29,6 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; -import org.jclouds.vcloud.director.v1_5.domain.Link.Builder; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -61,7 +60,7 @@ public class MetadataEntry extends ResourceType { public static class Builder extends ResourceType.Builder { private String key; - private MetadataValue value; + private String value; /** * @see MetadataEntry#getKey() @@ -74,7 +73,7 @@ public class MetadataEntry extends ResourceType { /** * @see MetadataEntry#getValue() */ - public Builder value(MetadataValue value) { + public Builder value(String value) { this.value = value; return this; } @@ -83,7 +82,7 @@ public class MetadataEntry extends ResourceType { * @see MetadataEntry#getKey() * @see MetadataEntry#getValue() */ - public Builder entry(String key, MetadataValue value) { + public Builder entry(String key, String value) { this.key = key; this.value = value; return this; @@ -150,7 +149,7 @@ public class MetadataEntry extends ResourceType { // For JAXB and builder use } - private MetadataEntry(URI href, String key, MetadataValue value) { + private MetadataEntry(URI href, String key, String value) { super(href); this.key = checkNotNull(key, "key"); this.value = checkNotNull(value, "value"); @@ -159,7 +158,7 @@ public class MetadataEntry extends ResourceType { @XmlElement(namespace = VCLOUD_1_5_NS, name = "Key") private String key; @XmlElement(namespace = VCLOUD_1_5_NS, name = "Value") - private MetadataValue value; + private String value; /** * @return key of the entry @@ -171,7 +170,7 @@ public class MetadataEntry extends ResourceType { /** * @return value of the entry */ - public MetadataValue getValue() { + public String getValue() { return value; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java index 7ca328eb35..9ec17a6905 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataValue.java @@ -29,7 +29,6 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; -import org.jclouds.vcloud.director.v1_5.domain.MetadataValue.Builder; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -42,7 +41,7 @@ import com.google.common.collect.Sets; * <xs:complexType name="MetadataType"> * * - * @author danikov + * @author grkvlt@apache.org */ @XmlRootElement(namespace = VCLOUD_1_5_NS, name = "MetadataValue") public class MetadataValue extends ResourceType { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index ad304dba98..c510596089 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -219,7 +219,7 @@ public class Org extends EntityType { return isEnabled; } - public void isEnabled(Boolean isEnabled) { + public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/package-info.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/package-info.java new file mode 100644 index 0000000000..2494d9032c --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@XmlSchema(namespace = VCLOUD_1_5_NS, elementFormDefault = XmlNsForm.QUALIFIED) +package org.jclouds.vcloud.director.v1_5.domain; + +import javax.xml.bind.annotation.XmlNsForm; +import javax.xml.bind.annotation.XmlSchema; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; From 4fdaa3b6a67c0a8d651564c2f7d814f13e9f2d4d Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 12:20:50 +0000 Subject: [PATCH 25/26] Updated Catalog expect tests --- .../features/CatalogClientExpectTest.java | 323 +++++++----------- .../src/test/resources/catalog/catalog.xml | 12 + .../test/resources/catalog/catalogItem.xml | 9 + .../resources/catalog/catalogMetadata.xml | 8 + .../test/resources/catalog/newCatalogItem.xml | 5 + 5 files changed, 166 insertions(+), 191 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/catalog/catalog.xml create mode 100644 labs/vcloud-director/src/test/resources/catalog/catalogItem.xml create mode 100644 labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml create mode 100644 labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java index ffbcc5bc2c..31590b21bd 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java @@ -25,16 +25,20 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; -import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; -import org.jclouds.vcloud.director.v1_5.domain.Error; -import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Catalog; -import org.jclouds.vcloud.director.v1_5.domain.CatalogsList; +import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; +import org.jclouds.vcloud.director.v1_5.domain.CatalogItems; +import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; /** * Test the {@link CatalogClient} by observing its side effects. @@ -45,10 +49,10 @@ import com.google.common.collect.ImmutableMultimap; public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test - public void testCatalogListForValidOrg() { + public void testGetCatalog() { HttpRequest catalogRequest = HttpRequest.builder() .method("GET") - .endpoint(URI.create(endpoint + "/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .endpoint(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) @@ -57,221 +61,158 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT HttpResponse catalogResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/catalog/catalogslist.xml", VCloudDirectorMediaType.CATALOGS_LIST + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.CATALOG + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); - CatalogsList expected = CatalogsList.builder() - .name("Catalogs Lists") - .type("application/vnd.vmware.vcloud.catalogsList+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .catalog(Catalog.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("catalog") - .id("urn:vcloud:catalog:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) - .status("success") - .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") - .operationName("catalogCreateCatalog") - .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) - .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) - .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) - .owner(Reference.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("QunyingTestCatalog") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + Catalog expected = Catalog.builder() + .name("QunyingTestCatalog") + .type("application/vnd.vmware.vcloud.catalog+xml") + .id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("add") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) + .build()) + .catalogItems(CatalogItems.builder() + .item(Reference.builder() + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .name("ubuntu10") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .build()) - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .org(Reference.builder() - .type("application/vnd.vmware.vcloud.org+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .item(Reference.builder() + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .name("imageTesting") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a9e0afdb-a42b-4688-8409-2ac68cf22939")) .build()) .build()) - .catalog(Catalog.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("catalog") - .id("urn:vcloud:catalog:bd22e745-9c2a-4f82-a954-0e35b6f76ba5") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/bd22e745-9c2a-4f82-a954-0e35b6f76ba5")) - .status("success") - .operation("Enabled User (967d317c-4273-4a95-b8a4-bf63b78e9c69)") - .operationName("jobEnable") - .startTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00")) - .endTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00")) - .expiryTime(dateService.iso8601DateParse("2012-05-06T17:30:38.507-04:00")) - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("adrian@jclouds.org") - .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/8c360b93-ed25-4c9a-8e24-d48cd9966d93")) - .build()) - .org(Reference.builder() - .type("application/vnd.vmware.vcloud.org+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .build()) + .description("Testing") .build(); - Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build(); - - assertEquals(client.getCatalogClient().getCatalogList(orgRef), expected); - } - - @Test - public void testCatalogListForInvalidOrgId() { - HttpRequest catalogRequest = HttpRequest.builder() - .method("GET") - .endpoint(URI.create(endpoint + "/catalogsList/NOTAUUID")) - .headers(ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("x-vcloud-authorization", token) - .build()) - .build(); - - HttpResponse catalogResponse = HttpResponse.builder() - .statusCode(400) - .payload(payloadFromResourceWithContentType("/catalog/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) - .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); - - Error expected = Error.builder() - .message("validation error on field 'id': String value has invalid format or length") - .majorErrorCode(400) - .minorErrorCode("BAD_REQUEST") - .build(); - - Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID")).build(); - - try { - client.getCatalogClient().getCatalogList(orgRef); - fail("Should give HTTP 400 error"); - } catch (VCloudDirectorException vde) { - assertEquals(vde.getError(), expected); - } catch (Exception e) { - fail("Should have thrown a VCloudDirectorException"); - } - } - - @Test - public void testCatalogListForNotFoundOrgId() { - HttpRequest catalogRequest = HttpRequest.builder() - .method("GET") - .endpoint(URI.create(endpoint + "/catalogsList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")) - .headers(ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("x-vcloud-authorization", token) - .build()) - .build(); - - HttpResponse catalogResponse = HttpResponse.builder() - .statusCode(403) - .payload(payloadFromResourceWithContentType("/catalog/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) - .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); - - Error expected = Error.builder() - .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".") - .majorErrorCode(403) - .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") - .build(); - - Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build(); - - try { - client.getCatalogClient().getCatalogList(orgRef); - fail("Should give HTTP 400 error"); - } catch (VCloudDirectorException vde) { - assertEquals(vde.getError(), expected); - } catch (Exception e) { - fail("Should have thrown a VCloudDirectorException"); - } - } - - @Test - public void testGetCatalogForCatalogRef() { - HttpRequest catalogRequest = HttpRequest.builder() - .method("GET") - .endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) - .headers(ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("x-vcloud-authorization", token) - .build()) - .build(); - - HttpResponse catalogResponse = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.catalog + ";version=1.5")) - .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); - Reference catalogRef = Reference.builder() .type("application/vnd.vmware.vcloud.catalog+xml") - .name("catalog") - .href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .build(); - Catalog expected = Catalog.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("catalog") - .id("urn:vcloud:catalog:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) - .status("success") - .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") - .operationName("catalogCreateCatalog") - .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) - .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) - .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) - .owner(Reference.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("QunyingTestCatalog") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) - .build()) - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .org(Reference.builder() - .type("application/vnd.vmware.vcloud.org+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .build(); - assertEquals(client.getCatalogClient().getCatalog(catalogRef), expected); } @Test - public void testCancelCatalogByCatalogRef() { - HttpRequest catalogRequest = HttpRequest.builder() + public void testAddCatalogItem() { + HttpRequest catalogItemRequest = HttpRequest.builder() .method("POST") - .endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")) + .endpoint(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems")) + .headers(ImmutableMultimap. builder() + .put("Accept", "application/vnd.vmware.vcloud.catalogItem+xml") + .put("x-vcloud-authorization", token) + .build()) + .payload(payloadFromResourceWithContentType("/catalog/newCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM)) + .build(); + + HttpResponse catalogItemResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + + Reference catalogRef = Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build(); + + Reference ubuntu = Reference.builder() + .type("application/vnd.vmware.vcloud.vAppTemplate+xml") + .name("ubuntu10") + .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")) + .build(); + + CatalogItem newItem = CatalogItem.builder() + .name("newCatalogItem") + .description("New Catalog Item") + .entity(ubuntu) + .build(); + + CatalogItem expected = CatalogItem.builder() + .name("newCatalogItem") + .id("urn:vcloud:catalogitem:a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) + .build()) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) + .build()) + .link(Link.builder() + .rel("remove") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) + .build()) + .description("New Catalog Item") + .entity(ubuntu) + .build(); + + assertEquals(client.getCatalogClient().addCatalogItem(catalogRef, newItem), expected); + } + + @Test + public void testGetCatalogMetadata() { + HttpRequest catalogItemRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) .build()) .build(); - HttpResponse catalogResponse = HttpResponse.builder() - .statusCode(200) + HttpResponse catalogItemResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", VCloudDirectorMediaType.METADATA + ";version=1.5")) .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); Reference catalogRef = Reference.builder() .type("application/vnd.vmware.vcloud.catalog+xml") - .name("catalog") - .href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .build(); - client.getCatalogClient().cancelCatalog(catalogRef); + Metadata expected = Metadata.builder() + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api//catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .metadata(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build())) + .build(); + + assertEquals(client.getCatalogClient().getCatalogMetadata(catalogRef), expected); } } diff --git a/labs/vcloud-director/src/test/resources/catalog/catalog.xml b/labs/vcloud-director/src/test/resources/catalog/catalog.xml new file mode 100644 index 0000000000..f7fe4d9a94 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/catalog.xml @@ -0,0 +1,12 @@ + + + + + + Testing + + + + + false + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/catalog/catalogItem.xml b/labs/vcloud-director/src/test/resources/catalog/catalogItem.xml new file mode 100644 index 0000000000..39021f96d9 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/catalogItem.xml @@ -0,0 +1,9 @@ + + + + + + + New Catalog Item + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml b/labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml new file mode 100644 index 0000000000..0ff3052583 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml @@ -0,0 +1,8 @@ + + + + + key + value + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml b/labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml new file mode 100644 index 0000000000..d434d4f272 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml @@ -0,0 +1,5 @@ + + + New Catalog Item + + From 7ca842f44cc008d0144c11b8cc7a10e1db2941a7 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 10 Feb 2012 12:30:40 +0000 Subject: [PATCH 26/26] Make JAXB XML marshaller pretty-print --- .../main/java/org/jclouds/xml/internal/JAXBParser.java | 3 +-- .../org/jclouds/rest/binders/BindToXMLPayloadTest.java | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/jclouds/xml/internal/JAXBParser.java b/core/src/main/java/org/jclouds/xml/internal/JAXBParser.java index 65c56331d4..4f812a24cc 100644 --- a/core/src/main/java/org/jclouds/xml/internal/JAXBParser.java +++ b/core/src/main/java/org/jclouds/xml/internal/JAXBParser.java @@ -28,7 +28,6 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.xml.XMLParser; /** @@ -49,6 +48,7 @@ public class JAXBParser implements XMLParser { try { JAXBContext context = JAXBContext.newInstance(type); Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); marshaller.marshal(src, writer); return writer.toString(); @@ -57,7 +57,6 @@ public class JAXBParser implements XMLParser { } } - @SuppressWarnings("unchecked") @Override public T fromXML(final String xml, final Class type) throws IOException { try { diff --git a/core/src/test/java/org/jclouds/rest/binders/BindToXMLPayloadTest.java b/core/src/test/java/org/jclouds/rest/binders/BindToXMLPayloadTest.java index f387253024..478fc83c99 100644 --- a/core/src/test/java/org/jclouds/rest/binders/BindToXMLPayloadTest.java +++ b/core/src/test/java/org/jclouds/rest/binders/BindToXMLPayloadTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.rest.binders; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.*; import java.net.URI; @@ -52,8 +52,7 @@ public class BindToXMLPayloadTest { HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build(); request = binder.bindToRequest(request, obj); - assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER - + "Hello World"); + assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER + "\n\n Hello World\n\n"); assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML); } @@ -72,8 +71,7 @@ public class BindToXMLPayloadTest { .build(); request = binder.bindToRequest(request, obj); - assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER - + "Hello World"); + assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER + "\n\n Hello World\n\n"); assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML); }