Finishing up live tests for Catalog and Query, and general tifying of domain objects and constants

This commit is contained in:
Andrew Donald Kennedy 2012-02-17 19:21:41 +00:00
parent 473126e7ec
commit 4e6bb27e9d
24 changed files with 259 additions and 761 deletions

View File

@ -28,4 +28,30 @@ public class VCloudDirectorConstants {
/** The XML namespace used by the clients. */
public static final String VCLOUD_1_5_NS = "http://www.vmware.com/vcloud/v1.5";
/** The property used to configure the timeout for task completion. */
public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete";
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema";
/** Name of the default org that your vApp will join, if an org isn't explicitly specified. */
public static final String PROPERTY_VCLOUD_DEFAULT_ORG = "jclouds.vcloud.defaults.org";
/** Name of the default catalog to query, if it isn't explicitly specified. */
public static final String PROPERTY_VCLOUD_DEFAULT_CATALOG = "jclouds.vcloud.defaults.catalog";
/** Name of the VDC that your vApp will join, if a vDC isn't explicitly specified. */
public static final String PROPERTY_VCLOUD_DEFAULT_VDC = "jclouds.vcloud.defaults.vdc";
/** Name of the default network, in the default VDC that your vApp will join. */
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
/** TODO javadoc */
// public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode";
/** TODO javadoc */
public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns";
/** TODO javadoc */
public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema";
}

View File

@ -27,22 +27,33 @@ import org.jclouds.vcloud.director.v1_5.domain.Task;
public class VCloudDirectorException extends RuntimeException {
/** The serialVersionUID. */
private static final long serialVersionUID = -3200853408568729058L;
private static final long serialVersionUID = -5292516858598372960L;
private final Error error;
private final Task task;
public VCloudDirectorException(Error error) {
super("Error: " + error.getMessage());
this.error = error;
this.task = null;
}
public VCloudDirectorException(Task task) {
super("Task error: " + task.getError().getMessage());
this.error = task.getError();
this.task = task;
}
public Error getError() {
return error;
}
public boolean hasTask() {
return task != null;
}
public Task getTask() {
return task;
}
}

View File

@ -79,11 +79,19 @@ public class VCloudDirectorMediaType {
public static final String QUERY_RESULT_ID_RECORDS = "application/vnd.vmware.vcloud.query.idrecords+xml";
public static final String CONTROL_ACCESS = "application/vnd.vmware.vcloud.controlAccess+xml";
/**
* All acceptable media types.
*
* This list must be updated whenever a new media type constant is added.
*/
public static final List<String> ALL = Arrays.asList(
SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY,
METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK,
CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY,
MEDIA, OWNER, VDC, ADMIN_USER, QUERY_RESULT_RECORDS,
QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS
QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS,
CONTROL_ACCESS
);
}

View File

@ -18,9 +18,8 @@
*/
package org.jclouds.vcloud.director.v1_5;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.Constants.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.util.Properties;
@ -37,8 +36,20 @@ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder {
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 30*60 + "");
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60));
properties.setProperty(PROPERTY_API_VERSION, "1.5");
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE,
String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA));
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60));
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "https://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "80");
// TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything.
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l));
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300));
return properties;
}

View File

@ -19,6 +19,7 @@ package org.jclouds.vcloud.director.v1_5.config;
import static com.google.common.base.Throwables.*;
import static org.jclouds.rest.config.BinderUtils.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Map;
@ -35,6 +36,7 @@ import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.location.Provider;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
@ -59,14 +61,17 @@ import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401A
import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler;
import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient;
import org.jclouds.vcloud.director.v1_5.login.SessionClient;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

View File

@ -56,10 +56,17 @@ public class Link extends ReferenceType<Link> {
public static final String PREVIOUS_PAGE = "previousPage";
public static final String LAST_PAGE = "lastPage";
public static final String FIRST_PAGE = "firstPage";
public static final String CONTROL_ACCESS = "controlAccess";
/**
* All acceptable {@link Link#getRel()} values.
*
* This list must be updated whenever a new relationship is added.
*/
public static final List<String> ALL = Arrays.asList(
UP, DOWN, EDIT, ADD, DELETE, REMOVE, CATALOG_ITEM, TASK_CANCEL,
ALTERNATE, NEXT_PAGE, PREVIOUS_PAGE, LAST_PAGE, FIRST_PAGE
ALTERNATE, NEXT_PAGE, PREVIOUS_PAGE, LAST_PAGE, FIRST_PAGE,
CONTROL_ACCESS
);
}

View File

@ -16,67 +16,37 @@
* 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 org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS;
import static com.google.common.base.Objects.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
/**
*
* Represents a media.
*
*
* <p>Java class for Media complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Media">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}ResourceEntityType">
* &lt;sequence>
* &lt;element name="Owner" type="{http://www.vmware.com/vcloud/v1.5}OwnerType" minOccurs="0"/>
* &lt;/sequence>
* &lt;attribute name="imageType" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="size" use="required" type="{http://www.w3.org/2001/XMLSchema}long" />
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;complexType name="Media" /&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Media")
@XmlType(propOrder = {"owner"})
public class Media
extends ResourceEntityType<Media>
public class Media extends ResourceEntityType<Media> {
{
public static final class ImageType {
public static final String ISO = "iso";
public static final String FLOPPY = "floppy";
public static final List<String> ALL = Arrays.asList(
ISO, FLOPPY
);
public static final List<String> ALL = Arrays.asList(ISO, FLOPPY);
}
@SuppressWarnings("unchecked")
@ -84,6 +54,7 @@ public class Media
return new Builder();
}
@Override
public Builder toBuilder() {
return new Builder().fromMedia(this);
}
@ -118,7 +89,7 @@ public class Media
return this;
}
@Override
public Media build() {
Media media = new Media();
media.setOwner(owner);
@ -130,6 +101,7 @@ public class Media
/**
* @see ResourceEntityType#getFiles()
*/
@Override
public Builder files(FilesList files) {
super.files(files);
return this;
@ -138,6 +110,7 @@ public class Media
/**
* @see ResourceEntityType#getStatus()
*/
@Override
public Builder status(Integer status) {
super.status(status);
return this;
@ -215,16 +188,13 @@ public class Media
return this;
}
@Override
public Builder fromResourceEntityType(ResourceEntityType<Media> in) {
return Builder.class.cast(super.fromResourceEntityType(in));
}
public Builder fromMedia(Media in) {
return fromResourceEntityType(in)
.owner(in.getOwner())
.imageType(in.getImageType())
.size(in.getSize());
return fromResourceEntityType(in).owner(in.getOwner()).imageType(in.getImageType()).size(in.getSize());
}
}
@ -241,64 +211,33 @@ public class Media
/**
* Gets the value of the owner property.
*
* @return
* possible object is
* {@link Owner }
*
*/
public Owner getOwner() {
return owner;
}
/**
* Sets the value of the owner property.
*
* @param value
* allowed object is
* {@link Owner }
*
*/
public void setOwner(Owner value) {
this.owner = value;
}
/**
* Gets the value of the imageType property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getImageType() {
return imageType;
}
/**
* Sets the value of the imageType property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setImageType(String value) {
this.imageType = value;
}
/**
* Gets the value of the size property.
*
*/
public long getSize() {
return size;
}
/**
* Sets the value of the size property.
*
*/
public void setSize(long value) {
this.size = value;
}
@ -310,24 +249,18 @@ public class Media
if (o == null || getClass() != o.getClass())
return false;
Media that = Media.class.cast(o);
return equal(owner, that.owner) &&
equal(imageType, that.imageType) &&
equal(size, that.size);
return super.equals(that) &&
equal(this.owner, that.owner) && equal(this.imageType, that.imageType) && equal(this.size, that.size);
}
@Override
public int hashCode() {
return Objects.hashCode(owner,
imageType,
size);
return super.hashCode() + Objects.hashCode(owner, imageType, size);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("owner", owner)
.add("imageType", imageType)
.add("size", size).toString();
public ToStringHelper string() {
return super.string().add("owner", owner).add("imageType", imageType).add("size", size);
}
}

View File

@ -1,256 +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.domain;
import static com.google.common.base.Objects.*;
import static com.google.common.base.Preconditions.*;
import java.net.URI;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
/**
*
* Base type that represents a resource entity such as a vApp
* template or virtual media.
*
*
* <p>Java class for ResourceEntity complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="ResourceEntity">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
* &lt;sequence>
* &lt;element name="Files" type="{http://www.vmware.com/vcloud/v1.5}FilesListType" minOccurs="0"/>
* &lt;/sequence>
* &lt;attribute name="status" type="{http://www.w3.org/2001/XMLSchema}int" />
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ResourceEntity", propOrder = {
"files"
})
public class ResourceEntity extends EntityType<ResourceEntity> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromResourceEntity(this);
}
public static class Builder extends EntityType.Builder<ResourceEntity> {
private Object /* FilesList */ files;
private Integer status;
/**
* @see ResourceEntity#getFiles()
*/
public Builder files(Object /* FilesList */ files) {
this.files = files;
return this;
}
/**
* @see ResourceEntity#getStatus()
*/
public Builder status(Integer status) {
this.status = status;
return this;
}
public ResourceEntity build() {
ResourceEntity resourceEntity = new ResourceEntity();
resourceEntity.setFiles(files);
resourceEntity.setStatus(status);
return resourceEntity;
}
/**
* @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<Link> 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<ResourceEntity> in) {
return Builder.class.cast(super.fromEntityType(in));
}
public Builder fromResourceEntity(ResourceEntity in) {
return fromEntityType(in)
.files(in.getFiles())
.status(in.getStatus());
}
}
protected ResourceEntity() {
// For JAXB and builder use
}
@XmlElement(name = "Files")
protected Object /* FilesList */ files;
@XmlAttribute
protected Integer status;
/**
* Gets the value of the files property.
*
* @return
* possible object is
* {@link FilesList }
*
*/
public Object /* FilesList */ getFiles() {
return files;
}
/**
* Sets the value of the files property.
*
* @param value
* allowed object is
* {@link FilesList }
*
*/
public void setFiles(Object /* FilesList */ value) {
this.files = value;
}
/**
* Gets the value of the status property.
*
* @return
* possible object is
* {@link Integer }
*
*/
public Integer getStatus() {
return status;
}
/**
* Sets the value of the status property.
*
* @param value
* allowed object is
* {@link Integer }
*
*/
public void setStatus(Integer value) {
this.status = value;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ResourceEntity that = ResourceEntity.class.cast(o);
return equal(files, that.files) &&
equal(status, that.status);
}
@Override
public int hashCode() {
return Objects.hashCode(files,
status);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("files", files)
.add("status", status).toString();
}
}

View File

@ -19,58 +19,28 @@
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.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
/**
*
* Base type that represents a resource entity such as a vApp
* template or virtual media.
*
*
* <p>Java class for ResourceEntity complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
* Base type that represents a resource entity such as a vApp template or virtual media.
*
* <pre>
* &lt;complexType name="ResourceEntity">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
* &lt;sequence>
* &lt;element name="Files" type="{http://www.vmware.com/vcloud/v1.5}FilesListType" minOccurs="0"/>
* &lt;/sequence>
* &lt;attribute name="status" type="{http://www.w3.org/2001/XMLSchema}int" />
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;complexType name="ResourceEntity" &gt;
* </pre>
*
*
* @author danikov
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ResourceEntity", propOrder = {
"files"
})
//@XmlSeeAlso({
// MediaType.class,
// VAppTemplateType.class,
// AbstractVAppType.class,
// NetworkPoolType.class
//})
public class ResourceEntityType<T extends ResourceEntityType<T>> extends EntityType<T> {
public static <T extends ResourceEntityType<T>> Builder<T> builder() {
@ -103,7 +73,7 @@ public class ResourceEntityType<T extends ResourceEntityType<T>> extends EntityT
return this;
}
@Override
public ResourceEntityType<T> build() {
ResourceEntityType<T> resourceEntity = new ResourceEntityType<T>();
resourceEntity.setFiles(files);
@ -111,7 +81,6 @@ public class ResourceEntityType<T extends ResourceEntityType<T>> extends EntityT
return resourceEntity;
}
/**
* @see EntityType#getId()
*/
@ -166,23 +135,18 @@ public class ResourceEntityType<T extends ResourceEntityType<T>> extends EntityT
return this;
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Builder<T> fromResourceType(ResourceType<T> in) {
return Builder.class.cast(super.fromResourceType(in));
}
public Builder<T> fromResourceEntityType(ResourceEntityType<T> in) {
return fromResourceType(in)
.files(in.getFiles())
.status(in.getStatus());
return fromResourceType(in).files(in.getFiles()).status(in.getStatus());
}
}
public ResourceEntityType() {
// for JAXB
}
@XmlElement(name = "Files")
@ -192,48 +156,22 @@ public class ResourceEntityType<T extends ResourceEntityType<T>> extends EntityT
/**
* Gets the value of the files property.
*
* @return
* possible object is
* {@link FilesList }
*
*/
public FilesList getFiles() {
return files;
}
/**
* Sets the value of the files property.
*
* @param value
* allowed object is
* {@link FilesList }
*
*/
public void setFiles(FilesList value) {
this.files = value;
}
/**
* Gets the value of the status property.
*
* @return
* possible object is
* {@link Integer }
*
*/
public Integer getStatus() {
return status;
}
/**
* Sets the value of the status property.
*
* @param value
* allowed object is
* {@link Integer }
*
*/
public void setStatus(Integer value) {
this.status = value;
}
@ -245,21 +183,17 @@ public class ResourceEntityType<T extends ResourceEntityType<T>> extends EntityT
if (o == null || getClass() != o.getClass())
return false;
ResourceEntityType<?> that = ResourceEntityType.class.cast(o);
return equal(files, that.files) &&
equal(status, that.status);
return super.equals(that) && equal(this.files, that.files) && equal(this.status, that.status);
}
@Override
public int hashCode() {
return Objects.hashCode(files,
status);
return super.hashCode() + Objects.hashCode(files, status);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("files", files)
.add("status", status).toString();
public ToStringHelper string() {
return super.string().add("files", files).add("status", status);
}
}

View File

@ -148,13 +148,6 @@ public class Task extends EntityType<Task> {
return this;
}
/**
* @see Task#getStatus()
*/
public Builder status(TaskStatus status) {
return this.status(status.toString());
}
/**
* @see Task#getOperation()
*/
@ -418,12 +411,8 @@ public class Task extends EntityType<Task> {
* <li>aborted - The task was aborted by an administrative action.
* </ul>
*/
public TaskStatus getStatus() {
return TaskStatus.fromValue(status);
}
public void setStatus(TaskStatus status) {
this.setStatus(status.toString());
public String getStatus() {
return status;
}
public void setStatus(String status) {

View File

@ -1,41 +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.domain;
/**
*
* @author Adrian Cole
*
*/
public class TaskInErrorStateException extends RuntimeException {
private static final long serialVersionUID = 1L;
private final Task task;
public TaskInErrorStateException(Task task) {
super("error on task: " + task + " error: " + task.getError());
this.task = task;
}
public Task getTask() {
return task;
}
}

View File

@ -1,73 +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.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Adrian Cole
*/
public enum TaskStatus {
/**
* The task has completed and returned a value indicating success.
*/
SUCCESS,
/**
* The task is running.
*/
RUNNING,
/**
* The task has been queued for execution.
*/
QUEUED,
/**
* The task has completed and returned a value indicating an error.
*/
ERROR,
/**
* not an official status, temporarily in.
*/
CANCELLED, UNRECOGNIZED;
public String value() {
return name().toLowerCase();
}
@Override
public String toString() {
return value();
}
public static TaskStatus fromValue(String status) {
if ("CANCELED".equals(status.toUpperCase())) {
// TODO: ecloud hack
status = "CANCELLED";
} else if ("FAILED".equals(status.toUpperCase())) {
status = "ERROR";
} else if ("COMPLETED".equals(status.toUpperCase())) {
status = "SUCCESS";
}
try {
return valueOf(checkNotNull(status, "status").toUpperCase());
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -18,54 +18,19 @@
*/
package org.jclouds.vcloud.director.v1_5.domain.vapp;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntityType;
/**
*
* Represents a base type for VAppType and VmType.
*
*
* <p>Java class for AbstractVAppType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="AbstractVAppType">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}ResourceEntityType">
* &lt;sequence>
* &lt;element name="VAppParent" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType" minOccurs="0"/>
* &lt;element ref="{http://schemas.dmtf.org/ovf/envelope/1}Section" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;attribute name="deployed" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;complexType name="AbstractVAppType" &gt;
* </pre>
*
*
* @author grkvlt@apache.org
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AbstractVAppType", propOrder = {
"vAppParent",
"section"
})
public abstract class AbstractVAppType extends ResourceEntity {
public abstract class AbstractVAppType extends ResourceEntityType<AbstractVAppType> {
// @XmlElement(name = "VAppParent")
// protected ReferenceType vAppParent;

View File

@ -18,51 +18,15 @@
*/
package org.jclouds.vcloud.director.v1_5.domain.vapp;
import static com.google.common.base.Objects.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import com.google.common.base.Objects;
/**
*
* Represents a vApp.
*
*
* <p>Java class for VApp complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="VApp">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}AbstractVApp">
* &lt;sequence>
* &lt;element name="Owner" type="{http://www.vmware.com/vcloud/v1.5}OwnerType" minOccurs="0"/>
* &lt;element name="InMaintenanceMode" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
* &lt;element name="Children" type="{http://www.vmware.com/vcloud/v1.5}VAppChildrenType" minOccurs="0"/>
* &lt;/sequence>
* &lt;attribute name="ovfDescriptorUploaded" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;complexType name="VApp" /&gt;
* </pre>
*
*
* @author grkvlt@apache.org
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "VApp", propOrder = {
"owner",
"inMaintenanceMode",
"children"
})
public class VApp extends AbstractVAppType {
//
// @SuppressWarnings("unchecked")

View File

@ -18,53 +18,64 @@
*/
package org.jclouds.vcloud.director.v1_5.predicates;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TaskInErrorStateException;
import org.jclouds.vcloud.director.v1_5.domain.TaskStatus;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* Keeps testing {@link Task} to see if it has succeeded before a time limit has elapsed.
*
* Tests to see if a task succeeds.
*
* @author Adrian Cole
* @author grkvlt@apache.org
*/
@Singleton
public class TaskSuccess implements Predicate<URI> {
private final TaskClient taskClient;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public TaskSuccess(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
this.taskClient = context.getApi().getTaskClient();
}
private final RetryablePredicate<URI> retry;
private final Predicate<URI> checkSuccess = new Predicate<URI>() {
@Override
public boolean apply(URI taskUri) {
logger.trace("looking for status on task %s", taskUri);
Task task = taskClient.getTask(taskUri);
// perhaps task isn't available, yet
if (task == null)
return false;
logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task.getStatus());
if (task.getStatus() == TaskStatus.ERROR)
throw new TaskInErrorStateException(task);
return task.getStatus() == TaskStatus.SUCCESS;
if (task == null) return false;
logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus());
if (task.getStatus().equals(Task.Status.ERROR))
throw new VCloudDirectorException(task);
return task.getStatus().equals(Task.Status.SUCCESS);
}
};
@Resource
protected Logger logger = Logger.NULL;
@Inject
public TaskSuccess(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long maxWait) {
this.taskClient = context.getApi().getTaskClient();
this.retry = new RetryablePredicate<URI>(checkSuccess, maxWait);
}
/** @see Predicate#apply(Object) */
@Override
public boolean apply(URI input) {
return retry.apply(input);
}
}

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.vcloud.director.v1_5;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.*;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;

View File

@ -47,7 +47,7 @@ public class VCloudDirectorLiveTestConstants {
public static final String REQUIRED_VALUE_OBJECT_FMT = "ERR-03: The %s field of the %s must not be '%s'; allowed values: %s";
public static final String REQUIRED_VALUE_FMT = "ERR-04: The %s field must not be '%sr'; allowed values: %s";
public static final String REQUIRED_VALUE_FMT = "ERR-04: The %s field must not be '%s'; allowed values: %s";
public static final String MUST_BE_WELL_FORMED_FMT = "ERR-05: The %s field must be well formed: '%s'";

View File

@ -129,7 +129,7 @@ public class Checks {
public static void checkTask(Task task) {
// Check required fields
assertNotNull(task.getStatus(), String.format(NOT_NULL_OBJECT_FMT, "Status", "Task"));
assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format(REQUIRED_VALUE_OBJECT_FMT, "Status", "Task", task.getStatus(), Iterables.toString(Link.Rel.ALL)));
assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format(REQUIRED_VALUE_OBJECT_FMT, "Status", "Task", task.getStatus(), Iterables.toString(Task.Status.ALL)));
// Check optional fields
// NOTE operation cannot be checked

View File

@ -34,7 +34,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.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
@ -54,6 +54,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private CatalogClient catalogClient;
private QueryClient queryClient;
private MediaClient mediaClient;
/*
* Shared state between dependant tests.
@ -67,11 +68,13 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private CatalogItem newCatalogItem;
private Metadata catalogMetadata;
@BeforeGroups(groups = { "live" })
public void setupClients() {
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
catalogClient = context.getApi().getCatalogClient();
queryClient = context.getApi().getQueryClient();
mediaClient = context.getApi().getMediaClient();
}
private Metadata catalogItemMetadata;
@Test(testName = "GET /catalog/{id}")
@ -152,9 +155,8 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
});
MetadataValue metadataValue = catalogClient.getCatalogMetadataValue(catalogRef, "KEY");
// XXX
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(),
"The MetadataValue for KEY should have the same Value as the existing MetadataEntry");
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
checkMetadataValue(metadataValue);
}
@ -162,8 +164,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testGetCatalogItemMetadata() {
resetCatalogItemMetadata(catalogItemRef);
catalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef);
// XXX
assertEquals(catalogItemMetadata.getMetadataEntries().size(), 1, "There should be a single MetadataEntry");
assertEquals(catalogItemMetadata.getMetadataEntries().size(), 1, String.format(MUST_EXIST_FMT, "MetadataEntry", "CatalogItem"));
checkMetadata(catalogItemMetadata);
}
@ -176,9 +177,8 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata);
checkTask(mergeCatalogItemMetadata);
// TODO requires code from dan to be merged
// assertTrue(taskTester.apply(mergeCatalogItemMetadata.getHref()),
// String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
assertTrue(successTester.apply(mergeCatalogItemMetadata.getHref()),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef);
// XXX

View File

@ -29,7 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
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.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
@ -46,8 +46,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private NetworkClient networkClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
networkClient = context.getApi().getNetworkClient();
}

View File

@ -29,7 +29,7 @@ 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.Reference;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
@ -48,8 +48,8 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private OrgClient orgClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
orgClient = context.getApi().getOrgClient();
}

View File

@ -18,16 +18,13 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*;
import static org.testng.Assert.*;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
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.domain.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
@ -45,8 +42,8 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private CatalogClient catalogClient;
private QueryClient queryClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
catalogClient = context.getApi().getCatalogClient();
queryClient = context.getApi().getQueryClient();
}
@ -55,14 +52,18 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
* Shared state between dependant tests.
*/
private OrgList orgList;
private Reference orgRef;
private TasksList taskList;
private Task task;
private URI taskUri;
private QueryResultRecords<?> catalogRecords;
private CatalogReferences catalogReferences;
@Test(testName = "GET /catalogs/query/")
public void testQueryCatalogNoParam() {
assertTrue(true);
@Test(testName = "GET /catalogs/query")
public void testQueryAllCatalogs() {
catalogRecords = queryClient.catalogsQueryAll();
assertFalse(catalogRecords.getRecords().isEmpty(), String.format(NOT_EMPTY_OBJECT_FMT, "CatalogRecord", "QueryResultRecords"));
}
@Test(testName = "GET /catalogs/query?format=references", dependsOnMethods = { "testQueryAllCatalogs" })
public void testQueryAllCatalogReferences() {
catalogReferences = queryClient.catalogReferencesQueryAll();
assertFalse(catalogReferences.getReferences().isEmpty(), String.format(NOT_EMPTY_OBJECT_FMT, "CatalogReference", "CatalogReferences"));
}
}

View File

@ -29,7 +29,7 @@ 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.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
@ -49,8 +49,8 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private OrgClient orgClient;
private TaskClient taskClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
orgClient = context.getApi().getOrgClient();
taskClient = context.getApi().getTaskClient();
}

View File

@ -27,8 +27,8 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@ -41,21 +41,24 @@ import com.google.inject.Module;
*/
@Test(groups = "live")
public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest {
public BaseVCloudDirectorClientLiveTest() {
protected BaseVCloudDirectorClientLiveTest() {
provider = "vcloud-director";
}
protected TaskSuccess successTester;
protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context;
@BeforeGroups(groups = { "live" })
public void setupClient() {
@BeforeClass(groups = { "live" })
public void setupContext() {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
successTester = new TaskSuccess(context, 1000L);
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (context != null)
context.close();