Merge pull request #402 from danikov/vclouds-director-admin-catalog

Issue 830: vCloud director Admin Catalog (publishCatalog)
This commit is contained in:
Adrian Cole 2012-03-07 07:59:59 -08:00
commit 72e3599a8b
10 changed files with 217 additions and 16 deletions

View File

@ -131,6 +131,8 @@ public class VCloudDirectorMediaType {
public static final String ADMIN_ORGANIZATION = "application/vnd.vmware.admin.organization+xml";
public static final String PUBLISH_CATALOG_PARAMS = "application/vnd.vmware.admin.publishCatalogParams+xml";
/**
*
* All acceptable media types.
@ -148,6 +150,7 @@ public class VCloudDirectorMediaType {
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
CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE,
PUBLISH_CATALOG_PARAMS
);
}

View File

@ -0,0 +1,134 @@
/**
* 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 javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
/**
*
* Parameters used when publishing catalogs.
*
*
* <p>Java class for PublishCatalogParams complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="PublishCatalogParams">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
* &lt;sequence>
* &lt;element name="IsPublished" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
* &lt;/sequence>
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "PublishCatalogParams")
@XmlType(propOrder = {
"isPublished"
})
public class PublishCatalogParams {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromPublishCatalogParams(this);
}
public static class Builder {
private boolean isPublished;
/**
* @see PublishCatalogParams#getIsPublished()
*/
public Builder isPublished(boolean isPublished) {
this.isPublished = isPublished;
return this;
}
public PublishCatalogParams build() {
return new PublishCatalogParams(isPublished);
}
public Builder fromPublishCatalogParams(PublishCatalogParams in) {
return isPublished(in.isPublished());
}
}
@SuppressWarnings("unused")
private PublishCatalogParams() {
// For JAXB and builder use
}
public PublishCatalogParams(Boolean isPublished) {
this.isPublished = isPublished;
}
@XmlElement(name = "IsPublished")
protected boolean isPublished;
/**
* 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;
PublishCatalogParams that = PublishCatalogParams.class.cast(o);
return equal(isPublished, that.isPublished);
}
@Override
public int hashCode() {
return Objects.hashCode(isPublished);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("isPublished", isPublished).toString();
}
}

View File

@ -23,6 +23,7 @@ import java.net.URI;
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.Produces;
@ -36,6 +37,7 @@ import org.jclouds.rest.binders.BindToXMLPayload;
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.Owner;
import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -46,7 +48,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author danikov
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface AdminCatalogAsyncClient {
public interface AdminCatalogAsyncClient extends CatalogAsyncClient {
/**
* @see AdminClient#getCatalog(URI)
@ -55,6 +57,7 @@ public interface AdminCatalogAsyncClient {
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
@Override
ListenableFuture<AdminCatalog> getCatalog(@EndpointParam URI catalogRef);
/**
@ -99,6 +102,15 @@ public interface AdminCatalogAsyncClient {
ListenableFuture<Void> setOwner(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) Owner newOwner);
// DELETE /admin/catalog/{id}
// POST /admin/catalog/{id}/action/publish
/**
* @see AdminClient#AdminClient(URI, PublishCatalogParams)
*/
@POST
@Path("/action/publish")
@Consumes
@Produces(VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Void> publishCatalog(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) PublishCatalogParams params);
}

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
/**
* Provides synchronous access to {@link AdminCatalog} objects.
@ -32,7 +33,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Owner;
* @author danikov
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminCatalogClient {
public interface AdminCatalogClient extends CatalogClient {
/**
* Retrieves a catalog.
@ -44,6 +45,7 @@ public interface AdminCatalogClient {
* @param catalogRef the reference for the catalog
* @return a catalog
*/
@Override
AdminCatalog getCatalog(URI catalogRef);
/**
@ -86,4 +88,12 @@ public interface AdminCatalogClient {
* </pre>
*/
void setOwner(URI catalogRef, Owner newOwner);
/**
* Publish a catalog. Publishing a catalog makes the catalog visible to all organizations in a vCloud.
*/
void publishCatalog(URI catalogRef, PublishCatalogParams params);
//TODO: lot of work to pass in a single boolean, would like to polymorphically include something like:
//void publishCatalog(URI catalogRef)
}

View File

@ -36,8 +36,9 @@ import org.jclouds.rest.annotations.JAXBResponseParser;
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.CatalogType;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncClient.Writable;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -57,7 +58,7 @@ public interface CatalogAsyncClient {
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Catalog> getCatalog(@EndpointParam URI catalogUri);
ListenableFuture<? extends CatalogType<?>> getCatalog(@EndpointParam URI catalogUri);
/**
* Creates a catalog item in a catalog.

View File

@ -25,6 +25,7 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
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.CatalogType;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
/**
@ -46,7 +47,7 @@ public interface CatalogClient {
* @param catalogUri the reference for the catalog
* @return a catalog
*/
Catalog getCatalog(URI catalogUri);
CatalogType<?> getCatalog(URI catalogUri);
/**
* Creates a catalog item in a catalog.

View File

@ -28,6 +28,7 @@ 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.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
import org.testng.annotations.Test;
@ -118,6 +119,24 @@ public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientEx
client.getAdminCatalogClient().setOwner(catalogRef.getURI(), newOwner);
}
@Test
public void testPublishCatalog() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("POST", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/action/publish")
.xmlFilePayload("/catalog/admin/publishCatalogParams.xml", VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
PublishCatalogParams params = PublishCatalogParams.builder()
.isPublished(true)
.build();
client.getAdminCatalogClient().publishCatalog(catalogRef.getURI(), params);
}
@Test
public void testDeleteCatalog() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,

View File

@ -19,9 +19,7 @@
package org.jclouds.vcloud.director.v1_5.features;
import static com.google.common.base.Objects.equal;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
@ -35,6 +33,7 @@ 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.Error;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
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;
@ -98,7 +97,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
.name("adk@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
.build())
.build();
.build();
try {
catalogClient.setOwner(catalog.getURI(), newOwner);
@ -149,8 +148,26 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
}
}
@Test(testName = "DELETE /admin/catalog/{id}",
@Test(testName = "POST /admin/catalog/{id}/action/publish",
dependsOnMethods = { "testUpdateCatalog" }, enabled = false )
public void testPublishCatalog() {
assertTrue(!catalog.isPublished(), String.format(OBJ_FIELD_EQ,
CATALOG, "isPublished", false, catalog.isPublished()));
PublishCatalogParams params = PublishCatalogParams.builder()
.isPublished(true)
.build();
catalogClient.publishCatalog(catalogRef.getURI(), params);
catalog = catalogClient.getCatalog(catalogRef.getURI());
assertTrue(catalog.isPublished(), String.format(OBJ_FIELD_EQ,
CATALOG, "isPublished", true, catalog.isPublished()));
}
@Test(testName = "DELETE /admin/catalog/{id}",
dependsOnMethods = { "testPublishCatalog" }, enabled = false )
public void testDeleteCatalog() {
catalogClient.deleteCatalog(catalogRef.getURI());

View File

@ -34,8 +34,8 @@ import static org.testng.Assert.fail;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
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.CatalogType;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
@ -74,7 +74,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private ReferenceType<?> catalogRef;
private ReferenceType<?> catalogItemRef;
private ReferenceType<?> newCatalogItemRef;
private Catalog catalog;
private CatalogType<?> catalog;
private CatalogItem catalogItem;
private CatalogItem newCatalogItem;
private Metadata catalogMetadata;
@ -123,7 +123,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "PUT /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" }, enabled = false)
public void testUpdateCatalogItem() {
Catalog catalog = catalogClient.getCatalog(catalogRef.getHref());
CatalogType<?> catalog = catalogClient.getCatalog(catalogRef.getHref());
newCatalogItemRef = Iterables.find(catalog.getCatalogItems().getCatalogItems(), new Predicate<Reference>() {
@Override
public boolean apply(Reference input) {

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<PublishCatalogParams xmlns="http://www.vmware.com/vcloud/v1.5">
<IsPublished>true</IsPublished>
</PublishCatalogParams>