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

Issue 830: vCloud director Admin Catalog (updateCatalog)
This commit is contained in:
Adrian Cole 2012-03-06 08:16:21 -08:00
commit 643ccd3b27
6 changed files with 212 additions and 2 deletions

View File

@ -22,11 +22,16 @@ import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.RequestFilters;
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.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -41,7 +46,7 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface AdminCatalogAsyncClient {
/**
* Retrieves an admin catalog.
* @see AdminClient#getCatalog(URI)
*/
@GET
@Consumes
@ -49,7 +54,17 @@ public interface AdminCatalogAsyncClient {
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<AdminCatalog> getCatalog(@EndpointParam URI catalogRef);
// PUT /admin/catalog/{id}
/**
* @see AdminClient#getCatalog(URI)
*/
@PUT
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<AdminCatalog> updateCatalog(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
// DELETE /admin/catalog/{id}
// POST /admin/catalog/{id}/action/publish
// GET /admin/catalog/{id}/owner

View File

@ -44,4 +44,16 @@ public interface AdminCatalogClient {
* @return a catalog
*/
AdminCatalog getCatalog(URI catalogRef);
/**
* Modifies a catalog. A catalog could be published or unpublished. The IsPublished property is treated as a
* read only value by the server. In order to control publishing settings use the 'publish' action must be used.
*
* <pre>
* PUT /admin/catalog/{id}
* </pre>
*
* @return the updated catalog
*/
AdminCatalog updateCatalog(URI catalogRef, AdminCatalog catalog);
}

View File

@ -62,6 +62,29 @@ public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientEx
assertEquals(client.getAdminCatalogClient().getCatalog(catalogRef.getURI()), expected);
}
@Test
public void testModifyCatalog() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")
.xmlFilePayload("/catalog/admin/updateCatalogSource.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.acceptMedia(VCloudDirectorMediaType.ADMIN_CATALOG)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/updateCatalog.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.httpResponseBuilder().build());
AdminCatalog expected = modifyCatalog();
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().updateCatalog(catalogRef.getURI(), expected), expected);
}
public static final AdminCatalog catalog() {
return AdminCatalog.builder()
.name("QunyingTestCatalog")
@ -136,4 +159,79 @@ public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientEx
.isPublished(false)
.build();
}
public static final AdminCatalog modifyCatalog() {
return AdminCatalog.builder()
.name("new 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("new 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();
}
}

View File

@ -18,8 +18,11 @@
*/
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_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
@ -38,6 +41,8 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live", "admin", "catalog" }, singleThreaded = true, testName = "CatalogClientLiveTest")
public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String CATALOG = "admin catalog";
/*
* Convenience references to API clients.
@ -66,4 +71,42 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
Checks.checkAdminCatalog(catalog);
}
@Test(testName = "PUT /admin/catalog/{id}", dependsOnMethods = { "testGetCatalog" })
public void testUpdateCatalog() {
String oldName = catalog.getName();
String newName = "new "+oldName;
String oldDescription = catalog.getDescription();
String newDescription = "new "+oldDescription;
// TODO: can we update/manage catalogItems directly like this? or does it just do a merge (like metadata)
// CatalogItems oldCatalogItems = catalog.getCatalogItems();
// CatalogItems newCatalogItems = CatalogItems.builder().build();
try {
catalog = catalog.toBuilder()
.name(newName)
.description(newDescription)
// .catalogItems(newCatalogItems)
.build();
catalog = catalogClient.updateCatalog(catalog.getURI(), catalog);
assertTrue(equal(catalog.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "name"));
assertTrue(equal(catalog.getDescription(), newDescription),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "description"));
// assertTrue(equal(catalog.getCatalogItems(), newCatalogItems), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "catalogItems"));
//TODO negative tests?
Checks.checkAdminCatalog(catalog);
} finally {
catalog = catalog.toBuilder()
.name(oldName)
.description(oldDescription)
// .catalogItems(oldCatalogItems)
.build();
catalog = catalogClient.updateCatalog(catalog.getURI(), catalog);
}
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<AdminCatalog xmlns="http://www.vmware.com/vcloud/v1.5" name="new QunyingTestCatalog" id="urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4" type="application/vnd.vmware.admin.catalog+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="up" type="application/vnd.vmware.admin.organization+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
<Link rel="alternate" type="application/vnd.vmware.vcloud.catalog+xml" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="down" type="application/vnd.vmware.vcloud.owner+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner"/>
<Link rel="add" type="application/vnd.vmware.vcloud.catalogItem+xml" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems"/>
<Link rel="edit" type="application/vnd.vmware.admin.catalog+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="remove" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata"/>
<Description>new Testing</Description>
<Owner type="application/vnd.vmware.vcloud.owner+xml">
<User type="application/vnd.vmware.admin.user+xml" name="qunying.huang@enstratus.com" href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"/>
</Owner>
<CatalogItems>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="image" href="https://vcloudbeta.bluelock.com/api/catalogItem/67a469a1-aafe-4b5b-bb31-a6202ad8961f"/>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="ubuntu10" href="https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"/>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="imageTesting" href="https://vcloudbeta.bluelock.com/api/catalogItem/a9e0afdb-a42b-4688-8409-2ac68cf22939"/>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="TestCase" href="https://vcloudbeta.bluelock.com/api/catalogItem/f7598606-aea4-41d7-8f67-2090e28e7876"/>
</CatalogItems>
<IsPublished>false</IsPublished>
</AdminCatalog>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AdminCatalog name="new QunyingTestCatalog" id="urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4" type="application/vnd.vmware.admin.catalog+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4" xmlns="http://www.vmware.com/vcloud/v1.5">
<Link rel="up" type="application/vnd.vmware.admin.organization+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
<Link rel="alternate" type="application/vnd.vmware.vcloud.catalog+xml" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="down" type="application/vnd.vmware.vcloud.owner+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner"/>
<Link rel="add" type="application/vnd.vmware.vcloud.catalogItem+xml" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems"/>
<Link rel="edit" type="application/vnd.vmware.admin.catalog+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="remove" href="https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata"/>
<Description>new Testing</Description>
<Owner type="application/vnd.vmware.vcloud.owner+xml">
<User type="application/vnd.vmware.admin.user+xml" name="qunying.huang@enstratus.com" href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"/>
</Owner>
<CatalogItems>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="image" href="https://vcloudbeta.bluelock.com/api/catalogItem/67a469a1-aafe-4b5b-bb31-a6202ad8961f"/>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="ubuntu10" href="https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"/>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="imageTesting" href="https://vcloudbeta.bluelock.com/api/catalogItem/a9e0afdb-a42b-4688-8409-2ac68cf22939"/>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml" name="TestCase" href="https://vcloudbeta.bluelock.com/api/catalogItem/f7598606-aea4-41d7-8f67-2090e28e7876"/>
</CatalogItems>
<IsPublished>false</IsPublished>
</AdminCatalog>