create catalog

This commit is contained in:
danikov 2012-03-11 22:06:17 +00:00
parent 1f3971fae8
commit cbd9afc176
8 changed files with 203 additions and 13 deletions

View File

@ -111,4 +111,11 @@ public class Reference extends ReferenceType<Reference> {
Reference that = Reference.class.cast(o);
return super.equals(that);
}
public ReferenceType<?> toAdminReference(String endpoint) {
return toBuilder()
.type(null)
.href(URI.create(getHref().toASCIIString().replace(endpoint, endpoint+"/admin")))
.build();
}
}

View File

@ -50,6 +50,18 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface AdminCatalogAsyncClient extends CatalogAsyncClient {
/**
* @see AdminClient#createCatalog(URI, AdminCatalog)
*/
@POST
@Path("/catalogs")
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<AdminCatalog> createCatalog(@EndpointParam URI orgRef,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
/**
* @see AdminClient#getCatalog(URI)
*/

View File

@ -35,6 +35,19 @@ import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminCatalogClient extends CatalogClient {
/**
* Creates a catalog in an organization. The catalog will always be created in unpublished state.
*
* <pre>
* POST /admin/org/{id}/catalogs
* </pre>
*
* @param orgRef the reference for the org
* @return contains a , which will point to the running asynchronous creation operation.
*/
AdminCatalog createCatalog(URI orgRef, AdminCatalog catalog);
/**
* Retrieves a catalog.
*

View File

@ -73,4 +73,6 @@ public class VCloudDirectorLiveTestConstants {
public static final String OBJ_FIELD_CLONE = "ERR-123: %s %s must be a clone of \"%s\" (%s)";
public static final String OBJ_FIELD_EMPTY_TO_DELETE = "ERR-124: %s must have no %s to be deleted (%s)";
}

View File

@ -30,6 +30,8 @@ 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.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksInProgress;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
import org.testng.annotations.Test;
@ -41,12 +43,36 @@ import org.testng.annotations.Test;
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogClientExpectTest")
public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
private Reference orgRef = Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("QunyingTestCatalog")
.href(URI.create(endpoint + "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build();
private 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();
@Test
public void testCreateCatalog() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("POST", "/admin/org/???/catalogs")
.xmlFilePayload("/catalog/admin/createCatalogSource.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.acceptMedia(VCloudDirectorMediaType.ADMIN_CATALOG)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/createCatalog.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.httpResponseBuilder().build());
AdminCatalog source = createCatalogSource();
AdminCatalog expected = createCatalog();
assertEquals(client.getAdminCatalogClient().createCatalog(catalogRef.getHref(), source), expected);
}
@Test
public void testGetCatalog() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
@ -150,6 +176,93 @@ public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientEx
client.getAdminCatalogClient().deleteCatalog(catalogRef.getHref());
}
public static final AdminCatalog createCatalogSource() {
return AdminCatalog.builder()
.name("Test Catalog")
.description("created by testCreateCatalog()")
.build();
}
public static final AdminCatalog createCatalog() {
return AdminCatalog.builder()
.name("Test Catalog")
.id("urn:vcloud:catalog:c56d9159-7838-446f-bb35-9ee12dfbbef3")
.type("application/vnd.vmware.admin.catalog+xml")
.description("created by testCreateCatalog()")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"))
.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/c56d9159-7838-446f-bb35-9ee12dfbbef3"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.owner+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3/owner"))
.build())
.link(Link.builder()
.rel("add")
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3/catalogItems"))
.build())
.link(Link.builder()
.rel("edit")
.type("application/vnd.vmware.admin.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"))
.build())
.link(Link.builder()
.rel("remove")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3/metadata"))
.build())
.description("created by testCreateCatalog()")
.tasksInProgress(TasksInProgress.builder()
.task(Task.builder()
.status("running")
.startTime(dateService.iso8601DateParse("2012-03-11T18:43:02.429-04:00"))
.operationName("catalogCreateCatalog")
.operation("Creating Catalog Test Catalog(c56d9159-7838-446f-bb35-9ee12dfbbef3)")
.expiryTime(dateService.iso8601DateParse("2012-06-09T18:43:02.429-04:00"))
.name("task")
.id("urn:vcloud:task:20f556f9-9125-4090-9092-0da9f72bedf4")
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/20f556f9-9125-4090-9092-0da9f72bedf4"))
.link(Link.builder()
.rel("task:cancel")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/20f556f9-9125-4090-9092-0da9f72bedf4/action/cancel"))
.build())
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Test Catalog")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"))
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("dan@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/ae75edd2-12de-414c-8e85-e6ea10442c08"))
.build())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.build())
.build())
.catalogItems(CatalogItems.builder()
.build())
.isPublished(false)
.build();
}
public static final AdminCatalog catalog() {
return AdminCatalog.builder()
.name("QunyingTestCatalog")

View File

@ -20,6 +20,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_EMPTY_TO_DELETE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
@ -43,6 +44,8 @@ import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTes
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link AdminCatalogClient}.
*
@ -62,7 +65,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
/*
* Shared state between dependant tests.
*/
private ReferenceType<?> catalogRef;
private ReferenceType<?> orgRef;
private AdminCatalog catalog;
private Owner owner;
@ -70,15 +73,26 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
@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();
orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint);
}
@Test(testName = "GET /admin/catalog/{id}")
@Test(testName = "POST /admin/org/{id}/catalogs")
public void testCreateCatalog() {
AdminCatalog newCatalog = AdminCatalog.builder()
.name("Test Catalog")
.description("created by testCreateCatalog()")
.build();
catalog = catalogClient.createCatalog(orgRef.getHref(), newCatalog);
Checks.checkAdminCatalog(catalog);
// FIXME: documentation suggests we should wait for a task here
}
@Test(testName = "GET /admin/catalog/{id}",
dependsOnMethods = { "testCreateCatalog" })
public void testGetCatalog() {
assertNotNull(catalogRef, String.format(REF_REQ_LIVE, "Catalog"));
catalog = catalogClient.getCatalog(catalogRef.getHref());
catalog = catalogClient.getCatalog(catalog.getHref());
Checks.checkAdminCatalog(catalog);
}
@ -153,7 +167,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
}
@Test(testName = "POST /admin/catalog/{id}/action/publish",
dependsOnMethods = { "testUpdateCatalog" }, enabled = false )
dependsOnMethods = { "testUpdateCatalog" }, enabled = false ) // FIXME: fails with a 403
public void testPublishCatalog() {
assertTrue(!catalog.isPublished(), String.format(OBJ_FIELD_EQ,
CATALOG, "isPublished", false, catalog.isPublished()));
@ -162,8 +176,8 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
.isPublished(true)
.build();
catalogClient.publishCatalog(catalogRef.getHref(), params);
catalog = catalogClient.getCatalog(catalogRef.getHref());
catalogClient.publishCatalog(catalog.getHref(), params);
catalog = catalogClient.getCatalog(catalog.getHref());
assertTrue(catalog.isPublished(), String.format(OBJ_FIELD_EQ,
CATALOG, "isPublished", true, catalog.isPublished()));
@ -171,18 +185,22 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
}
@Test(testName = "DELETE /admin/catalog/{id}",
dependsOnMethods = { "testPublishCatalog" }, enabled = false )
dependsOnMethods = { "testUpdateCatalog" } )
public void testDeleteCatalog() {
catalogClient.deleteCatalog(catalogRef.getHref());
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
// catalog.getCatalogItems().getCatalogItems().toString()));
catalogClient.deleteCatalog(catalog.getHref());
Error expected = Error.builder()
.message("???")
.message("No access to entity \"(com.vmware.vcloud.entity.catalog:"+
catalog.getId().substring("urn:vcloud:catalog:".length())+")\".")
.majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build();
try {
catalog = catalogClient.getCatalog(catalogRef.getHref());
catalog = catalogClient.getCatalog(catalog.getHref());
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<AdminCatalog xmlns="http://www.vmware.com/vcloud/v1.5" name="Test Catalog" id="urn:vcloud:catalog:c56d9159-7838-446f-bb35-9ee12dfbbef3" type="application/vnd.vmware.admin.catalog+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3" 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/c56d9159-7838-446f-bb35-9ee12dfbbef3"/>
<Link rel="down" type="application/vnd.vmware.vcloud.owner+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3/owner"/>
<Link rel="add" type="application/vnd.vmware.vcloud.catalogItem+xml" href="https://vcloudbeta.bluelock.com/api/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3/catalogItems"/>
<Link rel="edit" type="application/vnd.vmware.admin.catalog+xml" href="https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"/>
<Link rel="remove" href="https://vcloudbeta.bluelock.com/api/admin/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"/>
<Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3/metadata"/>
<Description>created by testCreateCatalog()</Description>
<Tasks>
<Task status="running" startTime="2012-03-11T18:43:02.429-04:00" operationName="catalogCreateCatalog" operation="Creating Catalog Test Catalog(c56d9159-7838-446f-bb35-9ee12dfbbef3)" expiryTime="2012-06-09T18:43:02.429-04:00" name="task" id="urn:vcloud:task:20f556f9-9125-4090-9092-0da9f72bedf4" type="application/vnd.vmware.vcloud.task+xml" href="https://vcloudbeta.bluelock.com/api/task/20f556f9-9125-4090-9092-0da9f72bedf4">
<Link rel="task:cancel" href="https://vcloudbeta.bluelock.com/api/task/20f556f9-9125-4090-9092-0da9f72bedf4/action/cancel"/>
<Owner type="application/vnd.vmware.vcloud.catalog+xml" name="Test Catalog" href="https://vcloudbeta.bluelock.com/api/catalog/c56d9159-7838-446f-bb35-9ee12dfbbef3"/>
<User type="application/vnd.vmware.admin.user+xml" name="dan@cloudsoftcorp.com" href="https://vcloudbeta.bluelock.com/api/admin/user/ae75edd2-12de-414c-8e85-e6ea10442c08"/>
<Organization type="application/vnd.vmware.vcloud.org+xml" name="JClouds" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
</Task>
</Tasks>
<CatalogItems/>
<IsPublished>false</IsPublished>
</AdminCatalog>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AdminCatalog name="Test Catalog" xmlns="http://www.vmware.com/vcloud/v1.5">
<Description>created by testCreateCatalog()</Description>
</AdminCatalog>