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 40bbac8771..a7515639a3 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 @@ -26,6 +26,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.ovf.Network; +import org.jclouds.vcloud.director.v1_5.features.AdminCatalogAsyncClient; 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; @@ -106,4 +107,9 @@ public interface VCloudDirectorAsyncClient { @Delegate VAppTemplateAsyncClient getVAppTemplateClient(); + /** + * @return asynchronous access to {@link Catalog} features + */ + @Delegate + AdminCatalogAsyncClient getAdminCatalogClient(); } 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 15d4195af1..294b49b5a8 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 @@ -29,6 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.ovf.Network; +import org.jclouds.vcloud.director.v1_5.features.AdminCatalogClient; import org.jclouds.vcloud.director.v1_5.features.CatalogClient; import org.jclouds.vcloud.director.v1_5.features.MediaClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; @@ -84,7 +85,7 @@ public interface VCloudDirectorClient { */ @Delegate CatalogClient getCatalogClient(); - + /** * @return synchronous access to {@link Media} features */ @@ -108,5 +109,11 @@ public interface VCloudDirectorClient { */ @Delegate VAppTemplateClient getVAppTemplateClient(); + + /** + * @return synchronous access to {@link Catalog} features + */ + @Delegate + AdminCatalogClient getAdminCatalogClient(); } 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 ce8a01df2b..f9622b0723 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 @@ -127,6 +127,10 @@ public class VCloudDirectorMediaType { public static final String ENVELOPE = "application/vnd.???"; + public static final String ADMIN_CATALOG = "application/vnd.vmware.admin.catalog+xml"; + + public static final String ADMIN_ORGANIZATION = "application/vnd.vmware.admin.organization+xml"; + /** * * All acceptable media types. @@ -140,12 +144,10 @@ public class VCloudDirectorMediaType { MEDIA, OWNER, VDC, ADMIN_USER, V_APP, V_APP_TEMPLATE, CAPTURE_VAPP_PARAMS, CLONE_V_APP_PARAMS, CLONE_V_APP_TEMPLATE_PARAMS, COMPOSE_VAPP_PARAMS, INSTANTIATE_VAPP_TEMPLATE_PARAMS, - UPLOAD_VAPP_TEMPLATE_PARAMS, + UPLOAD_VAPP_TEMPLATE_PARAMS, ADMIN_CATALOG, ADMIN_ORGANIZATION, QUERY_RESULT_RECORDS, QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS, - CONTROL_ACCESS, - VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, - CLONE_MEDIA_PARAMS - , - LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE + CONTROL_ACCESS, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, + NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, + CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE ); } 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 7163767131..e5c7a0da58 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 @@ -85,6 +85,7 @@ public class VCloudDirectorRestClientModule extends RestClientModuleJava class for AdminCatalog complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="AdminCatalog">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}CatalogType">
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "AdminCatalog") +public class AdminCatalog extends CatalogType { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromAdminCatalog(this); + } + + public static class Builder extends CatalogType.Builder { + + public AdminCatalog build() { + return new AdminCatalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); + } + + /** + * @see CatalogType#getOwner() + */ + public Builder owner(Owner owner) { + super.owner(owner); + return this; + } + + /** + * @see CatalogType#getCatalogItems() + */ + public Builder catalogItems(CatalogItems catalogItems) { + super.catalogItems(catalogItems); + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder isPublished(Boolean isPublished) { + super.isPublished(isPublished); + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder published() { + super.published(); + return this; + } + + /** + * @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 EntityType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromCatalogType(CatalogType in) { + return Builder.class.cast(super.fromCatalogType(in)); + } + public Builder fromAdminCatalog(AdminCatalog in) { + return fromCatalogType(in); + } + } + + @SuppressWarnings("unused") + private AdminCatalog() { + // For JAXB + } + + public AdminCatalog(URI href, String type, Set links, String description, TasksInProgress tasksInProgress, String id, + String name, Owner owner, CatalogItems catalogItems, Boolean published) { + super(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, published); + } +} 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 index 4495669a1d..7454d952d1 100644 --- 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 @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; 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; @@ -39,7 +39,7 @@ import com.google.common.collect.Sets; * @author grkvlt@apache.org */ @XmlRootElement(name = "Catalog") -public class Catalog extends EntityType { +public class Catalog extends CatalogType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG; @@ -53,17 +53,18 @@ public class Catalog extends EntityType { return new Builder().fromCatalog(this); } - public static class Builder extends EntityType.Builder { - - private Entity owner; - private CatalogItems catalogItems; - private Boolean isPublished; + public static class Builder extends CatalogType.Builder { + @Override + public Catalog build() { + return new Catalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); + } + /** * @see Catalog#getOwner() */ - public Builder owner(Entity owner) { - this.owner = owner; + public Builder owner(Owner owner) { + super.owner(owner); return this; } @@ -71,7 +72,7 @@ public class Catalog extends EntityType { * @see Catalog#getCatalogItems() */ public Builder catalogItems(CatalogItems catalogItems) { - this.catalogItems = catalogItems; + super.catalogItems(catalogItems); return this; } @@ -79,7 +80,7 @@ public class Catalog extends EntityType { * @see Catalog#isPublished() */ public Builder isPublished(Boolean isPublished) { - this.isPublished = isPublished; + super.isPublished(isPublished); return this; } @@ -87,15 +88,10 @@ public class Catalog extends EntityType { * @see Catalog#isPublished() */ public Builder published() { - this.isPublished = Boolean.TRUE; + super.isPublished(isPublished); return this; } - @Override - public Catalog build() { - return new Catalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); - } - /** * @see EntityType#getName() */ @@ -169,53 +165,22 @@ public class Catalog extends EntityType { } @Override - public Builder fromEntityType(EntityType in) { - return Builder.class.cast(super.fromEntityType(in)); + public Builder fromCatalogType(CatalogType in) { + return Builder.class.cast(super.fromCatalogType(in)); } public Builder fromCatalog(Catalog in) { - return fromEntityType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); + return fromCatalogType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); } } public Catalog(URI href, String type, Set links, String description, TasksInProgress tasksInProgress, String id, - String name, Entity owner, CatalogItems catalogItems, Boolean published) { - super(href, type, links, description, tasksInProgress, id, name); - this.owner = owner; - this.catalogItems = catalogItems; - this.isPublished = published; + String name, Owner owner, CatalogItems catalogItems, Boolean published) { + super(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, published); } + @SuppressWarnings("unused") private Catalog() { - // For JAXB and builder use + // for JAXB } - - @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; - } - - /** - * Gets the value of the catalogItems property. - */ - public CatalogItems getCatalogItems() { - return catalogItems; - } - - /** - * Gets the value of the isPublished property. - */ - public Boolean isPublished() { - return isPublished; - } - } 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 index 01037a1dfa..15b42492b3 100644 --- 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 @@ -18,16 +18,20 @@ */ 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 java.util.Collection; import java.util.Collections; 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; /** @@ -85,7 +89,7 @@ public class CatalogItems { // For JAXB and builder use } - private CatalogItems(Collection tasks) { + private CatalogItems(Set catalogItems) { this.catalogItems = catalogItems; } @@ -98,4 +102,28 @@ public class CatalogItems { public Set getCatalogItems() { return Collections.unmodifiableSet(this.catalogItems); } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + CatalogItems that = CatalogItems.class.cast(o); + return equal(this.catalogItems, that.catalogItems); + } + + @Override + public int hashCode() { + return Objects.hashCode(catalogItems); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("catalogItems", catalogItems); + } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java new file mode 100644 index 0000000000..04c153d13b --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java @@ -0,0 +1,242 @@ +/* + * 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.equal; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElement; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Container for references to VappTemplate and Media objects. + *

+ *

+ * <complexType name="CatalogType" />
+ * 
+ * + * @author danikov + */ +public class CatalogType> extends EntityType { + + public static > Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromCatalogType(this); + } + + public static class Builder> extends EntityType.Builder { + + protected Owner owner; + protected CatalogItems catalogItems; + protected Boolean isPublished; + + /** + * @see CatalogType#getOwner() + */ + public Builder owner(Owner owner) { + this.owner = owner; + return this; + } + + /** + * @see CatalogType#getCatalogItems() + */ + public Builder catalogItems(CatalogItems catalogItems) { + this.catalogItems = catalogItems; + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder isPublished(Boolean isPublished) { + this.isPublished = isPublished; + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder published() { + this.isPublished = Boolean.TRUE; + return this; + } + + @Override + public CatalogType build() { + return new CatalogType(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); + } + + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + super.name(name); + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String description) { + super.description(description); + return this; + } + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + super.id(id); + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + super.tasksInProgress(tasksInProgress); + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(links); + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + @SuppressWarnings("unchecked") + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + + public Builder fromCatalogType(CatalogType in) { + return fromEntityType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); + } + } + + public CatalogType(URI href, String type, Set links, String description, TasksInProgress tasksInProgress, String id, + String name, Owner owner, CatalogItems catalogItems, Boolean published) { + super(href, type, links, description, tasksInProgress, id, name); + this.owner = owner; + this.catalogItems = catalogItems; + this.isPublished = published; + } + + protected CatalogType() { + // For JAXB + } + + @XmlElement(name = "Owner") + private Owner owner; + @XmlElement(name = "CatalogItems") + private CatalogItems catalogItems; + @XmlElement(name = "IsPublished") + private Boolean isPublished; + + /** + * Gets the value of the owner property. + */ + public Owner getOwner() { + return owner; + } + + /** + * Gets the value of the catalogItems property. + */ + public CatalogItems getCatalogItems() { + return catalogItems; + } + + /** + * Gets the value of the isPublished property. + */ + public Boolean isPublished() { + return isPublished; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + CatalogType that = CatalogType.class.cast(o); + return super.equals(that) && + equal(this.owner, that.owner) && + equal(this.catalogItems, that.catalogItems) && + equal(this.isPublished, that.isPublished); + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), owner, catalogItems, catalogItems); + } + + @Override + public ToStringHelper string() { + return super.string().add("owner", owner) + .add("catalogItems", catalogItems) + .add("isPublished", isPublished); + } + +} 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 index bd4ec005ed..4571917f6b 100644 --- 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 @@ -18,6 +18,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 java.util.Collection; @@ -27,6 +28,8 @@ 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; import com.google.common.collect.Sets; @@ -98,5 +101,28 @@ public class CatalogsList { public Set getCatalogItems() { return this.catalogReferences; } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + CatalogsList that = CatalogsList.class.cast(o); + return equal(this.catalogReferences, that.catalogReferences); + } + + @Override + public int hashCode() { + return Objects.hashCode(catalogReferences); + } + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("catalogReferences", catalogReferences); + } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java index b20e2fdee4..2736f5af3f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Set; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @@ -59,7 +60,6 @@ public class Owner extends ResourceType { - @SuppressWarnings("unchecked") public static Builder builder() { return new Builder(); } @@ -134,6 +134,7 @@ public class Owner } } + @SuppressWarnings("unused") private Owner() { // For JAXB and builder use } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java new file mode 100644 index 0000000000..b212d8c74a --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java @@ -0,0 +1,57 @@ +/** + * 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 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.AdminCatalog; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see AdminCatalogClient + * @author danikov + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface AdminCatalogAsyncClient { + + /** + * Retrieves an admin catalog. + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getCatalog(@EndpointParam URI catalogRef); + +// PUT /admin/catalog/{id} +// DELETE /admin/catalog/{id} +// POST /admin/catalog/{id}/action/publish +// GET /admin/catalog/{id}/owner +// PUT /admin/catalog/{id}/owner +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java new file mode 100644 index 0000000000..cc84b2200a --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java @@ -0,0 +1,47 @@ +/** + * 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.AdminCatalog; + +/** + * Provides synchronous access to {@link AdminCatalog} objects. + * + * @see AdminCatalogAsyncClient + * @author danikov + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface AdminCatalogClient { + + /** + * Retrieves a catalog. + * + *
+    * GET /admin/catalog/{id}
+    * 
+ * + * @param catalogRef the reference for the catalog + * @return a catalog + */ + AdminCatalog getCatalog(URI catalogRef); +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index fcf5d55f3d..9e6044946d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -20,10 +20,10 @@ package org.jclouds.vcloud.director.v1_5.domain; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_BE_WELL_FORMED_FMT; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_REQ; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_CONTAIN_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_NULL_OBJECT_FMT; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_REQ; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_GTE_0; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_FMT; @@ -228,11 +228,16 @@ public class Checks { // Check parent type checkEntityType(org); } + + public static void checkAdminCatalog(AdminCatalog catalog) { + // Check parent type + checkCatalogType(catalog); + } - public static void checkCatalog(Catalog catalog) { + public static void checkCatalogType(CatalogType catalog) { // Check optional elements/attributes - Entity owner = catalog.getOwner(); - if (owner != null) checkEntityType(owner); + Owner owner = catalog.getOwner(); + if (owner != null) checkOwner(owner); CatalogItems catalogItems = catalog.getCatalogItems(); if (catalogItems != null) { for (Reference catalogItemReference : catalogItems.getCatalogItems()) { @@ -245,6 +250,16 @@ public class Checks { checkEntityType(catalog); } + private static void checkOwner(Owner owner) { + // Check optional elements/attributes + if (owner.getUser() != null) { + checkReferenceType(owner.getUser()); + } + + // Check parent type + checkResourceType(owner); + } + public static void checkCatalogItem(CatalogItem catalogItem) { // Check parent type checkEntityType(catalogItem); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java new file mode 100644 index 0000000000..493c6210d6 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java @@ -0,0 +1,139 @@ +/* + * 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 static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; +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.Owner; +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +/** + * Test the {@link CatalogClient} by observing its side effects. + * + * @author grkvlt@apache.org + */ +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogClientExpectTest") +public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + @Test + public void testGetCatalog() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/catalog/admin/catalog.xml", VCloudDirectorMediaType.ADMIN_CATALOG) + .httpResponseBuilder().build()); + + AdminCatalog expected = catalog(); + + Reference catalogRef = Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build(); + + assertEquals(client.getAdminCatalogClient().getCatalog(catalogRef.getURI()), expected); + } + + public static final AdminCatalog catalog() { + return AdminCatalog.builder() + .name("QunyingTestCatalog") + .id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4") + .type("application/vnd.vmware.admin.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.admin.organization+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("alternate") + .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.owner+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner")) + .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("edit") + .type("application/vnd.vmware.admin.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .link(Link.builder() + .rel("remove") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/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/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) + .build()) + .description("Testing") + .owner(Owner.builder() + .type("application/vnd.vmware.vcloud.owner+xml") + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("qunying.huang@enstratus.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69")) + .build()) + .build()) + .catalogItems(CatalogItems.builder() + .item(Reference.builder() + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .name("image") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/67a469a1-aafe-4b5b-bb31-a6202ad8961f")) + .build()) + .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()) + .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()) + .item(Reference.builder() + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .name("TestCase") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/f7598606-aea4-41d7-8f67-2090e28e7876")) + .build()) + .build()) + .isPublished(false) + .build(); + } +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java new file mode 100644 index 0000000000..a634387ab2 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java @@ -0,0 +1,69 @@ +/* + * 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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; +import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests live behavior of {@link AdminCatalogClient}. + * + * @author danikov + */ +@Test(groups = { "live", "admin", "catalog" }, singleThreaded = true, testName = "CatalogClientLiveTest") +public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { + + /* + * Convenience references to API clients. + */ + + private AdminCatalogClient catalogClient; + + /* + * Shared state between dependant tests. + */ + private ReferenceType catalogRef; + private AdminCatalog catalog; + + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { + catalogClient = context.getApi().getAdminCatalogClient(); + catalogRef = Reference.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build(); + } + + @Test(testName = "GET /admin/catalog/{id}") + public void testGetCatalog() { + assertNotNull(catalogRef, String.format(REF_REQ_LIVE, "Catalog")); + catalog = catalogClient.getCatalog(catalogRef.getURI()); + + Checks.checkAdminCatalog(catalog); + } +} 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 83213fa32f..2df331d169 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 @@ -460,6 +460,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .build()) .build()) .description("Testing") + .isPublished(false) .build(); } diff --git a/labs/vcloud-director/src/test/resources/catalog/admin/catalog.xml b/labs/vcloud-director/src/test/resources/catalog/admin/catalog.xml new file mode 100644 index 0000000000..e116661308 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/admin/catalog.xml @@ -0,0 +1,21 @@ + + + + + + + + + + Testing + + + + + + + + + + false + \ No newline at end of file