Merge pull request #493 from danikov/vclouds-director-bugfixes-2

Issue 830: vCloud director Bugfixes
This commit is contained in:
Adrian Cole 2012-03-20 12:44:41 -07:00
commit 128a427db7
9 changed files with 251 additions and 21 deletions

View File

@ -46,7 +46,8 @@ import com.google.common.base.Objects.ToStringHelper;
*/ */
@XmlSeeAlso({ @XmlSeeAlso({
VAppReference.class, VAppReference.class,
CatalogReference.class CatalogReference.class,
RoleReference.class
}) })
@XmlRootElement(name = "Reference") @XmlRootElement(name = "Reference")
@XmlType(name = "ReferenceType") @XmlType(name = "ReferenceType")
@ -114,7 +115,7 @@ public class Reference {
return new Reference(this); return new Reference(this);
} }
protected B fromReference(Reference in) { public B fromReference(Reference in) {
return href(in.getHref()).id(in.getId()).name(in.getName()).type(in.getType()); return href(in.getHref()).id(in.getId()).name(in.getName()).type(in.getType());
} }

View File

@ -0,0 +1,75 @@
/*
* 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 java.net.URI;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "RoleReference")
public class RoleReference extends Reference {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
@Override
public Builder<?> toBuilder() {
return builder().fromRoleReference(this);
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
}
public static class Builder<B extends Builder<B>> extends Reference.Builder<B> {
@Override
public RoleReference build() {
return new RoleReference(this);
}
protected B fromRoleReference(RoleReference in) {
return fromReference(in);
}
}
public RoleReference(Builder<?> builder) {
super(builder);
}
public RoleReference(URI href, String id, String name, String type) {
super(href, id, name, type);
}
protected RoleReference() {
// For JAXB
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
RoleReference that = RoleReference.class.cast(o);
return super.equals(that);
}
// NOTE hashcode inheritted from Reference
}

View File

@ -0,0 +1,98 @@
/**
* 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 javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultReferences;
/**
*
* Container for ReferenceType elements that reference RoleType objects.
*
*
* <p>Java class for RoleReferences complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="RoleReferences">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
* &lt;sequence>
* &lt;element name="RoleReference" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement(name = "RoleReferences")
public class RoleReferences extends QueryResultReferences {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
@Override
public Builder<?> toBuilder() {
return builder().fromRoleReferences(this);
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
}
public static class Builder<B extends Builder<B>> extends QueryResultReferences.Builder<B> {
@Override
public RoleReferences build() {
return new RoleReferences(this);
}
public B fromRoleReferences(RoleReferences in) {
return fromQueryResultReferences(in);
}
}
protected RoleReferences(Builder<?> builder) {
super(builder);
}
protected RoleReferences() {
// for JAXB
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
RoleReferences that = RoleReferences.class.cast(o);
return super.equals(that);
}
// NOTE hashcode inheritted from QueryResultReferences
}

View File

@ -28,7 +28,9 @@ import javax.ws.rs.QueryParam;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.vcloud.director.v1_5.domain.RoleReferences;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -101,6 +103,14 @@ public interface AdminQueryAsyncClient extends QueryAsyncClient {
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<QueryResultRecords> rolesQuery(@QueryParam("filter") String filter); ListenableFuture<QueryResultRecords> rolesQuery(@QueryParam("filter") String filter);
@GET
@Path("/admin/roles/query")
@Consumes
@QueryParams(keys = { "format" }, values = { "references" })
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<RoleReferences> roleReferencesQueryAll();
@GET @GET
@Path("/admin/strandedUsers/query") @Path("/admin/strandedUsers/query")
@Consumes @Consumes

View File

@ -25,6 +25,7 @@ import javax.management.relation.Role;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Group;
import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.RoleReferences;
import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
@ -95,6 +96,17 @@ public interface AdminQueryClient extends QueryClient {
/** @see #queryAll() */ /** @see #queryAll() */
QueryResultRecords rolesQuery(String filter); QueryResultRecords rolesQuery(String filter);
/**
* Retrieves a list of {@link RoleReference}s by using REST API general QueryHandler.
*
* <pre>
* GET /admin/roles/query?format=references
* </pre>
*
* @see #rolesQueryAll(String)
*/
RoleReferences roleReferencesQueryAll();
/** /**
* Retrieves a list of {@link User}s by using REST API general QueryHandler. * Retrieves a list of {@link User}s by using REST API general QueryHandler.
* *

View File

@ -110,7 +110,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
@Test(testName = "PUT /admin/catalog/{id}/owner", @Test(testName = "PUT /admin/catalog/{id}/owner",
dependsOnMethods = { "testGetCatalog" }) dependsOnMethods = { "testGetCatalog" })
public void updateCatalogOwner() { public void updateCatalogOwner() {
User newOwnerUser = UserClientLiveTest.randomTestUser("testUpdateCatalogOwner"); User newOwnerUser = UserClientLiveTest.randomTestUser("testUpdateCatalogOwner", context);
newOwnerUser = context.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser); newOwnerUser = context.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser);
assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner"); assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner");

View File

@ -21,6 +21,8 @@ package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.vcloud.director.v1_5.domain.Checks; 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.RoleReferences;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultAdminUserRecord; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultAdminUserRecord;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultAdminVdcRecord; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultAdminVdcRecord;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
@ -92,6 +94,12 @@ public class AdminQueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkQueryResultRecord(record); Checks.checkQueryResultRecord(record);
assertEquals(record.getClass(), QueryResultRoleRecord.class, "incorrect record type admin query"); assertEquals(record.getClass(), QueryResultRoleRecord.class, "incorrect record type admin query");
} }
RoleReferences roleRefs = queryClient.roleReferencesQueryAll();
for (Reference ref : roleRefs.getReferences()) {
Checks.checkReferenceType(ref);
}
} }
@Test(testName = "GET /admin/strandedUsers/query") @Test(testName = "GET /admin/strandedUsers/query")

View File

@ -143,9 +143,10 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
media = mediaClient.getMedia(media.getHref()); media = mediaClient.getMedia(media.getHref());
Task task = Iterables.getOnlyElement(media.getTasks()); if (media.getTasks().size() == 1) {
Task task = Iterables.getOnlyElement(media.getTasks());
assertEquals(task.getStatus(), "running"); assertEquals(task.getStatus(), "running");
}
File file = Iterables.getOnlyElement(media.getFiles()); File file = Iterables.getOnlyElement(media.getFiles());
assertEquals(file.getSize(), new Long(iso.length)); assertEquals(file.getSize(), new Long(iso.length));

View File

@ -27,18 +27,25 @@ import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertFalse;
import java.net.URI; import java.net.URI;
import java.util.Random;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
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.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.Checks; 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.Error;
import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.RoleReferences;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRoleRecord;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.vcloud.director.v1_5.login.SessionClient; import org.jclouds.vcloud.director.v1_5.login.SessionClient;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -65,6 +72,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
*/ */
private Reference orgRef; private Reference orgRef;
private User user; private User user;
private static Random random = new Random();
@Override @Override
@BeforeClass(inheritGroups = true) @BeforeClass(inheritGroups = true)
@ -86,12 +94,38 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "POST /admin/org/{id}/users") @Test(testName = "POST /admin/org/{id}/users")
public void testCreateUser() { public void testCreateUser() {
User newUser = randomTestUser("testCreateUser"); User newUser = randomTestUser("testCreateUser", context);
user = userClient.createUser(orgRef.getHref(), newUser); user = userClient.createUser(orgRef.getHref(), newUser);
Checks.checkUser(newUser); Checks.checkUser(newUser);
} }
public static User randomTestUser(String prefix) { public static Reference vAppUserRole(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
RoleReferences roles = context.getApi().getAdminQueryClient().roleReferencesQueryAll();
for (Reference role : roles.getReferences()) {
if (equal(role.getName(), "vApp User")) {
return Reference.builder().fromReference(role).build();
}
}
return null;
}
public static Reference nonVAppUserRole(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
RoleReferences roles = context.getApi().getAdminQueryClient().roleReferencesQueryAll();
for (Reference role : roles.getReferences()) {
if (!equal(role.getName(), "vApp User")) {
return Reference.builder().fromReference(role).build();
}
}
return null;
}
public static User randomTestUser(String prefix, RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
return randomTestUser(prefix, vAppUserRole(context));
}
public static User randomTestUser(String prefix, Reference role) {
return User.builder() return User.builder()
.name(prefix+random.nextInt()) .name(prefix+random.nextInt())
.fullName("testFullName") .fullName("testFullName")
@ -104,10 +138,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.alertEmail("testAlert@test.com") .alertEmail("testAlert@test.com")
.isExternal(false) .isExternal(false)
.isGroupRole(false) .isGroupRole(false)
.role(Reference.builder() // FIXME: auto-fetch a role? or inject .role(role)
.name("vApp User")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/ff1e0c91-1288-3664-82b7-a6fa303af4d1"))
.build())
.password("password") .password("password")
.build(); .build();
} }
@ -123,9 +154,6 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "PUT /admin/user/{id}", @Test(testName = "PUT /admin/user/{id}",
dependsOnMethods = { "testGetUser" }) dependsOnMethods = { "testGetUser" })
public void testUpdateUser() { public void testUpdateUser() {
// TODO It seems that role.href doesn't need to be valid! I can run on
// greenhousedata with a bluelock uri!
User oldUser = user.toBuilder().build(); User oldUser = user.toBuilder().build();
User newUser = user.toBuilder() User newUser = user.toBuilder()
.fullName("new"+oldUser.getFullName()) .fullName("new"+oldUser.getFullName())
@ -141,10 +169,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.password("newPassword") .password("newPassword")
// TODO test setting other fields? // TODO test setting other fields?
// .name("new"+oldUser.getName()) // .name("new"+oldUser.getName())
// .role(Reference.builder() // FIXME: auto-fetch a role? or inject .role(nonVAppUserRole(context))
// .name("vApp Author")
// .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/1bf4457f-a253-3cf1-b163-f319f1a31802"))
// .build())
.build(); .build();
userClient.updateUser(user.getHref(), newUser); userClient.updateUser(user.getHref(), newUser);