From 0ee77f99ecad2413a4099feb9e441127c49bd287 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 12 Mar 2012 04:42:27 +0000 Subject: [PATCH 01/12] admin user client base --- .../v1_5/VCloudDirectorAsyncClient.java | 8 +++ .../director/v1_5/VCloudDirectorClient.java | 8 +++ .../VCloudDirectorRestClientModule.java | 3 + .../vcloud/director/v1_5/domain/User.java | 44 ++++++++------ .../v1_5/features/UserAsyncClient.java | 39 +++++++++++++ .../director/v1_5/features/UserClient.java | 43 ++++++++++++++ .../vcloud/director/v1_5/domain/Checks.java | 48 ++++++++++++++++ .../v1_5/features/UserClientExpectTest.java | 48 ++++++++++++++++ .../v1_5/features/UserClientLiveTest.java | 57 +++++++++++++++++++ 9 files changed, 281 insertions(+), 17 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java 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 10b75631fa..9beebf4384 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.Media; import org.jclouds.vcloud.director.v1_5.domain.Org; 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.User; 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; @@ -37,6 +38,7 @@ import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.QueryAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.UserAsyncClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient; import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient; @@ -128,4 +130,10 @@ public interface VCloudDirectorAsyncClient { */ @Delegate AdminOrgAsyncClient getAdminOrgClient(); + + /** + * @return asynchronous access to {@link User} features + */ + @Delegate + UserAsyncClient getUserClient(); } 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 87fee2652a..9ae0e70357 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.Media; import org.jclouds.vcloud.director.v1_5.domain.Org; 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.User; 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; @@ -41,6 +42,7 @@ import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.features.QueryClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.features.UploadClient; +import org.jclouds.vcloud.director.v1_5.features.UserClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient; import org.jclouds.vcloud.director.v1_5.features.VdcClient; @@ -131,4 +133,10 @@ public interface VCloudDirectorClient { */ @Delegate AdminOrgClient getAdminOrgClient(); + + /** + * @return synchronous access to {@link User} features + */ + @Delegate + UserClient getUserClient(); } 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 b77551ea0a..859060432d 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 @@ -64,6 +64,8 @@ import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient; import org.jclouds.vcloud.director.v1_5.features.UploadClient; +import org.jclouds.vcloud.director.v1_5.features.UserAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.UserClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient; import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient; @@ -109,6 +111,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule @@ -122,7 +125,7 @@ public class User private Integer deployedVmQuota; private Reference role; private String password; - private Object /* GroupsList */ groupReferences; + private List groups; /** * @see User#getFullName() @@ -261,20 +264,27 @@ public class User } /** - * @see User#getGroupReferences() + * @see User#getGroups() */ - public Builder groupReferences(Object /* GroupsList */ groupReferences) { - this.groupReferences = groupReferences; + public Builder groups(List groups) { + this.groups = ImmutableList.copyOf(groups); + return this; + } + + /** + * @see User#getGroups() + */ + public Builder group(Reference group) { + this.groups.add(checkNotNull(group, "group")); return this; } - public User build() { return new User(href, type, links, description, tasks, id, name, fullName, emailAddress, telephone, isEnabled, isLocked, im, nameInSource, isAlertEnabled, alertEmailPrefix, alertEmail, isExternal, isDefaultCached, isGroupRole, storedVmQuota, deployedVmQuota, - role, password, groupReferences); + role, password, groups); } @@ -357,7 +367,7 @@ public class User .deployedVmQuota(in.getDeployedVmQuota()) .role(in.getRole()) .password(in.getPassword()) - .groupReferences(in.getGroupReferences()); + .groups(in.getGroups()); } } @@ -395,14 +405,14 @@ public class User protected Reference role; @XmlElement(name = "Password") protected String password; - @XmlElement(name = "GroupReferences") - protected Object /* GroupsList */ groupReferences; + @XmlElementWrapper(name = "GroupReferences") + protected List groups; public User(URI href, String type, Set links, String description, Set tasks, String id, String name, String fullName, String emailAddress, String telephone, Boolean enabled, Boolean locked, String im, String nameInSource, Boolean alertEnabled, String alertEmailPrefix, String alertEmail, Boolean external, Boolean defaultCached, Boolean groupRole, Integer storedVmQuota, Integer deployedVmQuota, - Reference role, String password, Object groupReferences) { + Reference role, String password, List groups) { super(href, type, links, description, tasks, id, name); this.fullName = fullName; this.emailAddress = emailAddress; @@ -421,7 +431,7 @@ public class User this.deployedVmQuota = deployedVmQuota; this.role = role; this.password = password; - this.groupReferences = groupReferences; + this.groups = groups; } private User() { @@ -605,8 +615,8 @@ public class User * @return possible object is * {@link GroupsListType } */ - public Object /* GroupsList */ getGroupReferences() { - return groupReferences; + public List getGroups() { + return groups; } @Override @@ -633,7 +643,7 @@ public class User equal(deployedVmQuota, that.deployedVmQuota) && equal(role, that.role) && equal(password, that.password) && - equal(groupReferences, that.groupReferences); + equal(groups, that.groups); } @Override @@ -655,7 +665,7 @@ public class User deployedVmQuota, role, password, - groupReferences); + groups); } @Override @@ -678,7 +688,7 @@ public class User .add("deployedVmQuota", deployedVmQuota) .add("role", role) .add("password", password) - .add("groupReferences", groupReferences).toString(); + .add("groups", groups).toString(); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java new file mode 100644 index 0000000000..24c80c9c45 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java @@ -0,0 +1,39 @@ +/** + * 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 org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; + +/** + * @see GroupClient + * @author danikov + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface UserAsyncClient { +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java new file mode 100644 index 0000000000..694efaf5a5 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java @@ -0,0 +1,43 @@ +/** + * 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.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.Group; + +/** + * Provides synchronous access to {@link Group} objects. + * + * @see GroupAsyncClient + * @author danikov + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface UserClient { +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} 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 d6f966d534..4612365b00 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 @@ -748,4 +748,52 @@ public class Checks { // parent type checkResourceType(settings); } + + public static void checkUser(User user) { + // Check optional fields + // NOTE fullName cannot be checked + // NOTE isEnabled cannot be checked + // NOTE isLocked cannot be checked + // NOTE im cannot be checked + // NOTE nameInSource cannot be checked + // NOTE isAlertEnabled cannot be checked + // NOTE alterEmailPrefix cannot be checked + // NOTE isExternal cannot be checked + // NOTE isDefaultCached cannot be checked + // NOTE isGroupRole cannot be checked + // NOTE password cannot be checked + + if (user.getEmailAddress() != null) { + checkEmailAddress(user.getEmailAddress()); + } + if (user.getTelephone() != null) { + checkTelephone(user.getTelephone()); + } + if (user.getAlertEmail() != null) { + checkEmailAddress(user.getAlertEmail()); + } + if (user.getStoredVmQuota() != null) { + assertTrue(user.getStoredVmQuota() >= 0, String.format(OBJ_FIELD_GTE_0, + "User", "storedVmQuota", user.getStoredVmQuota())); + } + if (user.getDeployedVmQuota() != null) { + assertTrue(user.getDeployedVmQuota() >= 0, String.format(OBJ_FIELD_GTE_0, + "User", "deployedVmQuota", user.getDeployedVmQuota())); + } + if (user.getRole() != null) { + checkReferenceType(user.getRole()); + } + if (user.getGroups() != null) { + for (Reference group : user.getGroups()) { + checkReferenceType(group); + } + } + + // parent type + checkEntityType(user); + } + + public static void checkTelephone(String number) { + // TODO: regex validate telephone + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java new file mode 100644 index 0000000000..0100e1aecd --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java @@ -0,0 +1,48 @@ +/* + * 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 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 GroupClient} by observing its side effects. + * + * @author danikov + */ +@Test(groups = { "unit", "admin", "adminUser"}, singleThreaded = true, testName = "UserClientExpectTest") +public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + private Reference userRef = Reference.builder() + .href(URI.create(endpoint + "/admin/user/???")) + .build(); + +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java new file mode 100644 index 0000000000..5e715b70bc --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.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 org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests live behavior of {@link AdminGroupClient}. + * + * @author danikov + */ +@Test(groups = { "live", "admin", "adminUser" }, singleThreaded = true, testName = "UserClientLiveTest") +public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { + + public static final String GROUP = "admin group"; + + /* + * Convenience references to API clients. + */ + + /* + * Shared state between dependant tests. + */ + + @Override + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { + } + +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} From bdc09ee0537e3a50b2f301b029cb1781a4bbb631 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 12 Mar 2012 08:24:20 +0000 Subject: [PATCH 02/12] create/get/delete user --- .../v1_5/VCloudDirectorMediaType.java | 6 +- .../vcloud/director/v1_5/domain/User.java | 17 ++- .../v1_5/features/UserAsyncClient.java | 49 +++++++- .../director/v1_5/features/UserClient.java | 35 +++++- .../v1_5/features/UserClientExpectTest.java | 117 ++++++++++++++++-- .../v1_5/features/UserClientLiveTest.java | 85 ++++++++++++- .../src/test/resources/user/createUser.xml | 21 ++++ .../test/resources/user/createUserSource.xml | 16 +++ .../src/test/resources/user/user.xml | 22 ++++ 9 files changed, 345 insertions(+), 23 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/user/createUser.xml create mode 100644 labs/vcloud-director/src/test/resources/user/createUserSource.xml create mode 100644 labs/vcloud-director/src/test/resources/user/user.xml 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 be26e4b8c0..3b11b91782 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 @@ -153,6 +153,10 @@ public class VCloudDirectorMediaType { public static final String ADMIN_ORG_NETWORK = "application/vnd.vmware.admin.orgNetwork+xml"; + public static final String USER = "application/vnd.vmware.admin.user+xml"; + + public static final String ROLE = "application/vnd.vmware.admin.role+xml"; + /** * All acceptable media types. * @@ -173,6 +177,6 @@ public class VCloudDirectorMediaType { PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS, ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS, ORG_SETTINGS, ADMIN_NETWORK, - ADMIN_ORG_NETWORK + ADMIN_ORG_NETWORK, USER, ROLE ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java index 2ff0303b55..d3c91e8a31 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java @@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.testng.collections.Lists; + import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -125,7 +127,7 @@ public class User private Integer deployedVmQuota; private Reference role; private String password; - private List groups; + private List groups = Lists.newArrayList(); /** * @see User#getFullName() @@ -267,7 +269,7 @@ public class User * @see User#getGroups() */ public Builder groups(List groups) { - this.groups = ImmutableList.copyOf(groups); + this.groups = groups == null ? null : ImmutableList.copyOf(groups); return this; } @@ -287,6 +289,14 @@ public class User role, password, groups); } + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } /** * @see EntityType#getId() @@ -616,7 +626,7 @@ public class User * {@link GroupsListType } */ public List getGroups() { - return groups; + return groups == null ? Lists.newArrayList() : groups; } @Override @@ -690,5 +700,4 @@ public class User .add("password", password) .add("groups", groups).toString(); } - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java index 24c80c9c45..efec47c519 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java @@ -18,8 +18,27 @@ */ package org.jclouds.vcloud.director.v1_5.features; +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.Path; +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.User; 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 GroupClient @@ -27,13 +46,37 @@ import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; */ @RequestFilters(AddVCloudAuthorizationToRequest.class) public interface UserAsyncClient { -// POST /admin/org/{id}/users + /** + * @see UserClient#createUser(URI, User) + */ + @POST + @Path("/users") + @Consumes(VCloudDirectorMediaType.USER) + @Produces(VCloudDirectorMediaType.USER) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture createUser(@EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) User user); -// GET /admin/user/{id} + /** + * @see UserClient#getUser(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getUser(@EndpointParam URI userRef); // PUT /admin/user/{id} -// DELETE /admin/user/{id} + /** + * @see UserClient#deleteUser(URI) + */ + @DELETE + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteUser(@EndpointParam URI userRef); // POST /admin/user/{id}/action/unlock } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java index 694efaf5a5..a69bbac130 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java @@ -18,10 +18,12 @@ */ 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.Group; +import org.jclouds.vcloud.director.v1_5.domain.User; /** * Provides synchronous access to {@link Group} objects. @@ -31,13 +33,40 @@ import org.jclouds.vcloud.director.v1_5.domain.Group; */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface UserClient { -// POST /admin/org/{id}/users + /** + * Creates or imports a user in an organization. The user could be enabled or disabled. + * + *
+    * POST /admin/org/{id}/users
+    * 
+ * + * @param orgRef the reference for the org + * @return the created user + */ + User createUser(URI orgRef, User user); -// GET /admin/user/{id} + /** + * Retrieves a user. This entity could be enabled or disabled. + * + *
+    * GET /admin/user/{id}
+    * 
+ * + * @param userRef the reference for the user + * @return a user + */ + User getUser(URI userRef); // PUT /admin/user/{id} -// DELETE /admin/user/{id} + /** + * Deletes a user. Enabled and disabled users could be deleted. + * + *
+    * DELETE /admin/catalog/{id}
+    * 
+ */ + void deleteUser(URI userRef); // POST /admin/user/{id}/action/unlock } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java index 0100e1aecd..f9a1ac83dd 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java @@ -18,9 +18,16 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; +import static org.testng.Assert.assertEquals; +import java.net.URI; +import java.util.Collections; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -32,17 +39,113 @@ import org.testng.annotations.Test; @Test(groups = { "unit", "admin", "adminUser"}, singleThreaded = true, testName = "UserClientExpectTest") public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { - private Reference userRef = Reference.builder() - .href(URI.create(endpoint + "/admin/user/???")) + private Reference orgRef = Reference.builder() + .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build(); -// POST /admin/org/{id}/users + private Reference userRef = Reference.builder() + .href(URI.create(endpoint + "/admin/user/b37223f3-8792-477a-820f-334998f61cd6")) + .build(); -// GET /admin/user/{id} + @Test + public void testCreateUser() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("POST", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalogs") + .xmlFilePayload("/user/createUserSource.xml", VCloudDirectorMediaType.USER) + .acceptMedia(VCloudDirectorMediaType.USER) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/user/createUser.xml", VCloudDirectorMediaType.USER) + .httpResponseBuilder().build()); + + User source = createUserSource(); + User expected = createUser(); + + assertEquals(client.getUserClient().createUser(orgRef.getHref(), source), expected); + } + + public static final User createUserSource() { + return User.builder() + .name("test") + .fullName("testFullName") + .emailAddress("test@test.com") + .telephone("555-1234") + .isEnabled(false) + .im("testIM") + .isAlertEnabled(false) + .alertEmailPrefix("testPrefix") + .alertEmail("testAlert@test.com") + .isExternal(false) + .isGroupRole(false) + .role(Reference.builder() + .type("application/vnd.vmware.admin.role+xml") + .name("vApp User") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/ff1e0c91-1288-3664-82b7-a6fa303af4d1")) + .build()) + .password("password") + .groups(Collections.emptyList()) + .build(); + } + + public static final User createUser() { + return createUserSource().toBuilder() + .id("urn:vcloud:user:b37223f3-8792-477a-820f-334998f61cd6") + .type("application/vnd.vmware.admin.user+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6")) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.user+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6")) + .build()) + .link(Link.builder() + .rel("remove") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6")) + .build()) + .isLocked(false) + .isDefaultCached(false) + .storedVmQuota(0) + .deployedVmQuota(0) + .password(null) + .build(); + } + + @Test + public void testGetUser() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/user/user.xml", VCloudDirectorMediaType.USER) + .httpResponseBuilder().build()); + + User expected = user(); + + assertEquals(client.getUserClient().getUser(userRef.getHref()), expected); + } + + public static final User user() { + return createUser().toBuilder() + .nameInSource("test") + .build(); + } // PUT /admin/user/{id} -// DELETE /admin/user/{id} - // POST /admin/user/{id}/action/unlock + + @Test + public void testDeleteUser() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("DELETE", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .httpResponseBuilder().statusCode(204).build()); + + client.getUserClient().deleteUser(userRef.getHref()); + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java index 5e715b70bc..0b317cfb87 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java @@ -18,10 +18,25 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +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.Checks; +import org.jclouds.vcloud.director.v1_5.domain.Error; +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.domain.User; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.collect.Iterables; + /** * Tests live behavior of {@link AdminGroupClient}. * @@ -30,28 +45,88 @@ import org.testng.annotations.Test; @Test(groups = { "live", "admin", "adminUser" }, singleThreaded = true, testName = "UserClientLiveTest") public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { - public static final String GROUP = "admin group"; + public static final String USER = "admin user"; /* * Convenience references to API clients. */ + UserClient userClient; /* * Shared state between dependant tests. */ + private ReferenceType orgRef; + private User user; @Override @BeforeClass(inheritGroups = true) public void setupRequiredClients() { + userClient = context.getApi().getUserClient(); + orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint); } -// POST /admin/org/{id}/users + @Test(testName = "POST /admin/org/{id}/users") + public void testCreateUser() { + User newUser = User.builder() + .name("test") + .fullName("testFullName") + .emailAddress("test@test.com") + .telephone("555-1234") + .isEnabled(false) + .im("testIM") + .isAlertEnabled(false) + .alertEmailPrefix("testPrefix") + .alertEmail("testAlert@test.com") + .isExternal(false) + .isGroupRole(false) + .role(Reference.builder() // FIXME: auto-fetch a role? or inject + .name("vApp User") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/ff1e0c91-1288-3664-82b7-a6fa303af4d1")) + .build()) + .password("password") +// .group() + .build(); + user = userClient.createUser(orgRef.getHref(), newUser); + + Checks.checkUser(user); + } -// GET /admin/user/{id} + @Test(testName = "GET /admin/user/{id}", + dependsOnMethods = { "testCreateUser" }) + public void testGetUser() { + user = userClient.getUser(user.getHref()); + + Checks.checkUser(user); + } // PUT /admin/user/{id} -// DELETE /admin/user/{id} - // POST /admin/user/{id}/action/unlock + + @Test(testName = "DELETE /admin/user/{id}", + dependsOnMethods = { "testGetUser" } ) + public void testDeleteUser() { + userClient.deleteUser(user.getHref()); + + Error expected = Error.builder() + .message("No access to entity \"(com.vmware.vcloud.entity.user:"+ + user.getId().substring("urn:vcloud:user:".length())+")\".") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + try { + user = userClient.getUser(user.getHref()); + fail("Should give HTTP 403 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + user = null; + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + + if (user != null) { // guard against NPE on the .toStrings + assertNull(user, String.format(OBJ_DEL, USER, user.toString())); + } + } } diff --git a/labs/vcloud-director/src/test/resources/user/createUser.xml b/labs/vcloud-director/src/test/resources/user/createUser.xml new file mode 100644 index 0000000000..7736d548bd --- /dev/null +++ b/labs/vcloud-director/src/test/resources/user/createUser.xml @@ -0,0 +1,21 @@ + + + + + testFullName + test@test.com + 555-1234 + false + false + testIM + false + testPrefix + testAlert@test.com + false + false + false + 0 + 0 + + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/user/createUserSource.xml b/labs/vcloud-director/src/test/resources/user/createUserSource.xml new file mode 100644 index 0000000000..f3ff55dcc0 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/user/createUserSource.xml @@ -0,0 +1,16 @@ + + + testFullName + test@test.com + 555-1234 + false + testIM + false + testPrefix + testAlert@test.com + false + false + + password + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/user/user.xml b/labs/vcloud-director/src/test/resources/user/user.xml new file mode 100644 index 0000000000..4ee7b3d970 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/user/user.xml @@ -0,0 +1,22 @@ + + + + + testFullName + test@test.com + 555-1234 + false + false + testIM + test + false + testPrefix + testAlert@test.com + false + false + false + 0 + 0 + + + \ No newline at end of file From 1309d803e82e57998c3a657642b1ac991c8a74cd Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 12 Mar 2012 09:45:18 +0000 Subject: [PATCH 03/12] update User --- .../vcloud/director/v1_5/domain/User.java | 3 +- .../v1_5/features/UserAsyncClient.java | 14 +++- .../director/v1_5/features/UserClient.java | 13 +++- .../v1_5/features/UserClientExpectTest.java | 40 +++++++++++- .../v1_5/features/UserClientLiveTest.java | 65 ++++++++++++++++++- .../src/test/resources/user/updateUser.xml | 21 ++++++ .../test/resources/user/updateUserSource.xml | 23 +++++++ 7 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/user/updateUser.xml create mode 100644 labs/vcloud-director/src/test/resources/user/updateUserSource.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java index d3c91e8a31..2b5066da3d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java @@ -30,10 +30,9 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import org.testng.collections.Lists; - import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java index efec47c519..a0fc05fc2b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java @@ -24,6 +24,7 @@ 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; @@ -55,7 +56,7 @@ public interface UserAsyncClient { @Produces(VCloudDirectorMediaType.USER) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture createUser(@EndpointParam URI orgRef, + ListenableFuture createUser(@EndpointParam URI userRef, @BinderParam(BindToXMLPayload.class) User user); /** @@ -67,7 +68,16 @@ public interface UserAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getUser(@EndpointParam URI userRef); -// PUT /admin/user/{id} + /** + * @see UserClient#updateUser(URI, User) + */ + @PUT + @Consumes(VCloudDirectorMediaType.USER) + @Produces(VCloudDirectorMediaType.USER) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateUser(@EndpointParam URI userRef, + @BinderParam(BindToXMLPayload.class) User user); /** * @see UserClient#deleteUser(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java index a69bbac130..d812bb1bb7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java @@ -57,7 +57,18 @@ public interface UserClient { */ User getUser(URI userRef); -// PUT /admin/user/{id} + /** + * Modifies a user. The user object could be enabled or disabled. + * Note: the lock status cannot be changed using this call: use unlockUser. + * + *
+    * PUT /admin/user/{id}
+    * 
+ * + * @param userRef the reference for the user + * @return the modified user + */ + User updateUser(URI userRef, User user); /** * Deletes a user. Enabled and disabled users could be deleted. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java index f9a1ac83dd..fa95254858 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java @@ -132,7 +132,45 @@ public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build(); } -// PUT /admin/user/{id} + @Test + public void testUpdateUser() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6") + .xmlFilePayload("/user/updateUserSource.xml", VCloudDirectorMediaType.USER) + .acceptMedia(VCloudDirectorMediaType.USER) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/user/updateUser.xml", VCloudDirectorMediaType.USER) + .httpResponseBuilder().build()); + + User source = updateUserSource(); + User expected = updateUser(); + + assertEquals(client.getUserClient().updateUser(userRef.getHref(), source), expected); + } + + public static final User updateUserSource() { + return user().toBuilder() + .fullName("new"+user().getFullName()) + .emailAddress("new"+user().getEmailAddress()) + .telephone("1-"+user().getTelephone()) + .isEnabled(true) + .im("new"+user().getIM()) + .isAlertEnabled(true) + .alertEmailPrefix("new"+user().getAlertEmailPrefix()) + .alertEmail("new"+user().getAlertEmail()) + .storedVmQuota(1) + .deployedVmQuota(1) + .password("newPassword") + .build(); + } + + public static final User updateUser() { + return updateUserSource().toBuilder() + .password(null) + .build(); + } // POST /admin/user/{id}/action/unlock diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java index 0b317cfb87..1634dfaa9c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java @@ -18,9 +18,12 @@ */ 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.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.net.URI; @@ -28,6 +31,7 @@ import java.net.URI; 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.Error; +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.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.User; @@ -99,12 +103,69 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkUser(user); } -// PUT /admin/user/{id} + @Test(testName = "PUT /admin/user/{id}", + dependsOnMethods = { "testGetUser" }) + public void testUpdateUser() { + User oldUser = user.toBuilder().build(); + User newUser = user.toBuilder() +// .name("new"+oldUser.getName()) + .fullName("new"+oldUser.getFullName()) + .emailAddress("new"+oldUser.getEmailAddress()) + .telephone("1-"+oldUser.getTelephone()) + .isEnabled(true) + .im("new"+oldUser.getIM()) + .isAlertEnabled(true) + .alertEmailPrefix("new"+oldUser.getAlertEmailPrefix()) + .alertEmail("new"+oldUser.getAlertEmail()) +// .role(Reference.builder() // FIXME: auto-fetch a role? or inject +// .name("vApp Author") +// .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/1bf4457f-a253-3cf1-b163-f319f1a31802")) +// .build()) + .storedVmQuota(1) + .deployedVmQuota(1) + .password("newPassword") + .build(); + + try { + userClient.updateUser(user.getHref(), newUser); + user = userClient.getUser(user.getHref()); + Checks.checkUser(user); +// assertTrue(equal(user.getName(), newUser.getName()), +// String.format(OBJ_FIELD_UPDATABLE, USER, "name")); + assertTrue(equal(user.getFullName(), newUser.getFullName()), + String.format(OBJ_FIELD_UPDATABLE, USER, "fullName")); + assertTrue(equal(user.getEmailAddress(), newUser.getEmailAddress()), + String.format(OBJ_FIELD_UPDATABLE, USER, "emailAddress")); + assertTrue(equal(user.getTelephone(), newUser.getTelephone()), + String.format(OBJ_FIELD_UPDATABLE, USER, "telephone")); + assertTrue(equal(user.isEnabled(), newUser.isEnabled()), + String.format(OBJ_FIELD_UPDATABLE, USER, "isEnabled")); + assertTrue(equal(user.getIM(), newUser.getIM()), + String.format(OBJ_FIELD_UPDATABLE, USER, "im")); + assertTrue(equal(user.isAlertEnabled(), newUser.isAlertEnabled()), + String.format(OBJ_FIELD_UPDATABLE, USER, "isAlertEnabled")); + assertTrue(equal(user.getAlertEmailPrefix(), newUser.getAlertEmailPrefix()), + String.format(OBJ_FIELD_UPDATABLE, USER, "alertEmailPrefix")); + assertTrue(equal(user.getAlertEmail(), newUser.getAlertEmail()), + String.format(OBJ_FIELD_UPDATABLE, USER, "alertEmail")); +// assertTrue(equal(user.getRole(), newUser.getRole()), +// String.format(OBJ_FIELD_UPDATABLE, USER, "role")); + assertTrue(equal(user.getStoredVmQuota(), newUser.getStoredVmQuota()), + String.format(OBJ_FIELD_UPDATABLE, USER, "storedVmQuota")); + assertTrue(equal(user.getDeployedVmQuota(), newUser.getDeployedVmQuota()), + String.format(OBJ_FIELD_UPDATABLE, USER, "deployedVmQuota")); + + // FIXME: assert password is changed with session client? + } finally { + userClient.updateUser(user.getHref(), oldUser); + user = userClient.getUser(user.getHref()); + } + } // POST /admin/user/{id}/action/unlock @Test(testName = "DELETE /admin/user/{id}", - dependsOnMethods = { "testGetUser" } ) + dependsOnMethods = { "testUpdateUser" } ) public void testDeleteUser() { userClient.deleteUser(user.getHref()); diff --git a/labs/vcloud-director/src/test/resources/user/updateUser.xml b/labs/vcloud-director/src/test/resources/user/updateUser.xml new file mode 100644 index 0000000000..9fe120f336 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/user/updateUser.xml @@ -0,0 +1,21 @@ + + + + newtestFullName + newtest@test.com + 1-555-1234 + true + false + newtestIM + test + true + newtestPrefix + newtestAlert@test.com + false + false + false + 1 + 1 + + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/user/updateUserSource.xml b/labs/vcloud-director/src/test/resources/user/updateUserSource.xml new file mode 100644 index 0000000000..1fd1fc4513 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/user/updateUserSource.xml @@ -0,0 +1,23 @@ + + + + + newtestFullName + newtest@test.com + 1-555-1234 + true + false + newtestIM + test + true + newtestPrefix + newtestAlert@test.com + false + false + false + 1 + 1 + + newPassword + + \ No newline at end of file From 1f17f07e97703a4997060b02545748fb696b861a Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 10:59:28 +0000 Subject: [PATCH 04/12] made cloning single threaded --- .../java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java | 2 -- .../config/VirtualBoxComputeServiceContextModule.java | 3 --- .../CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java index b9e0a15e96..d5668ec389 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java @@ -27,8 +27,6 @@ import org.jclouds.byon.Node; import org.jclouds.byon.config.CacheNodeStoreModule; import org.jclouds.compute.StandaloneComputeServiceContextBuilder; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.concurrent.MoreExecutors; -import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import com.google.common.base.Predicate; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index 45a63abc1f..95f8c662de 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -33,7 +33,6 @@ import javax.inject.Singleton; import org.eclipse.jetty.server.Server; import org.jclouds.byon.Node; -import org.jclouds.byon.config.CacheNodeStoreModule; import org.jclouds.byon.functions.NodeToNodeMetadata; import org.jclouds.byon.suppliers.SupplyFromProviderURIOrNodesProperty; import org.jclouds.compute.ComputeServiceAdapter; @@ -49,7 +48,6 @@ import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; -import org.jclouds.concurrent.SingleThreaded; import org.jclouds.domain.Location; import org.jclouds.functions.IdentityFunction; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; @@ -105,7 +103,6 @@ import com.google.inject.TypeLiteral; * @author Mattias Holmqvist, Andrea Turli */ @SuppressWarnings({ "unchecked", "rawtypes" }) -@SingleThreaded public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapterContextModule { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java index 3b1bc25fcf..dd21171765 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java @@ -88,7 +88,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu || e.getMessage().contains("Could not find a registered machine with UUID {"); } - private IMachine cloneMachine(CloneSpec cloneSpec) { + private synchronized IMachine cloneMachine(CloneSpec cloneSpec) { VmSpec vmSpec = cloneSpec.getVmSpec(); NetworkSpec networkSpec = cloneSpec.getNetworkSpec(); boolean isLinkedClone = cloneSpec.isLinked(); From 12a9b414e3a5598be1f9c7a7b9bbcd38f31f7013 Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 11:27:44 +0000 Subject: [PATCH 05/12] isolated experimentlivetest so that it emulates as closely as possible client usage --- .../compute/VirtualBoxExperimentLiveTest.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java index a4d330d48b..b4fe0f1577 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java @@ -26,35 +26,47 @@ import java.util.Set; import javax.annotation.Resource; import javax.inject.Named; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.ssh.SshClient; -import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; /** * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxExperimentLiveTest") -public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest { - +public class VirtualBoxExperimentLiveTest { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; + ComputeServiceContext context; + + @BeforeClass + public void setUp() { + context = new ComputeServiceContextFactory().createContext("virtualbox", "toor", "password", + ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule())); + } + @Test public void testLaunchCluster() throws RunNodesException { int numNodes = 4; final String clusterName = "test-launch-cluster"; - Set nodes = context.getComputeService().createNodesInGroup(clusterName, - numNodes); + Set nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes); assertEquals(numNodes, nodes.size(), "wrong number of nodes"); for (NodeMetadata node : nodes) { logger.debug("Created Node: %s", node); From e94b71934725781a4c01f242264fad3a24d84595 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 12 Mar 2012 11:41:05 +0000 Subject: [PATCH 06/12] user unlock action (pseudo-impl only) --- .../director/v1_5/features/UserAsyncClient.java | 10 +++++++++- .../vcloud/director/v1_5/features/UserClient.java | 9 ++++++++- .../v1_5/features/UserClientLiveTest.java | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java index a0fc05fc2b..82c41560b3 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java @@ -88,5 +88,13 @@ public interface UserAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture deleteUser(@EndpointParam URI userRef); -// POST /admin/user/{id}/action/unlock + /** + * @see UserClient#unlockUser(URI) + */ + @POST + @Path("/action/unlock") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture unlockUser(@EndpointParam URI userRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java index d812bb1bb7..350e03af21 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java @@ -79,5 +79,12 @@ public interface UserClient { */ void deleteUser(URI userRef); -// POST /admin/user/{id}/action/unlock + /** + * Unlocks a user. + * + *
+    * POST /admin/user/{id}/action/unlock
+    * 
+ */ + void unlockUser(URI userRef); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java index 1634dfaa9c..a635d4ed6c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java @@ -162,10 +162,21 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { } } -// POST /admin/user/{id}/action/unlock +// + + + @Test(testName = "POST /admin/user/{id}/action/unlock", + dependsOnMethods = { "testUpdateUser" } ) + public void testUnlockUser() { + //TODO: check previous tests a) enabled lockout, b) set password + //TODO: attempt too many times with the wrong password + //TODO: verify access is denied + //TODO: unlock user + //TODO: verify access is renewed + } @Test(testName = "DELETE /admin/user/{id}", - dependsOnMethods = { "testUpdateUser" } ) + dependsOnMethods = { "testUnlockUser" } ) public void testDeleteUser() { userClient.deleteUser(user.getHref()); From 91a0980537dc4a023bd8e65b74d8d47ba067a944 Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 11:59:45 +0000 Subject: [PATCH 07/12] made destroying nodes synchornized due to session lock issues --- .../compute/VirtualBoxComputeServiceAdapter.java | 6 +++--- ...isterMachineFromIMachineIfNotAlreadyExists.java | 5 +++-- .../jclouds/virtualbox/functions/NodeCreator.java | 14 ++++++++++---- .../admin/StartVBoxIfNotAlreadyRunning.java | 6 ++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java index 771ce60b61..1f15abbb0b 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java @@ -150,7 +150,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter apply(NodeSpec nodeSpec) { + public synchronized NodeAndInitialCredentials apply(NodeSpec nodeSpec) { checkNotNull(nodeSpec, "NodeSpec"); @@ -102,6 +107,7 @@ public class NodeCreator implements Function runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); + + try { + // wait for a couple of seconds to make sure vbox has correctly started + Thread.sleep(2000L); + } catch (InterruptedException e) { + } } manager = managerForNode.apply(host); manager.connect(provider.toASCIIString(), identity, credential); From 3370dd819d4489d63ad5decb5064ab16611f71e4 Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 14:38:37 +0000 Subject: [PATCH 08/12] changed the vm/hardware identifier to the name instead of the id since the id will change over time! --- .../virtualbox/functions/IMachineToHardware.java | 6 +++--- .../virtualbox/functions/IMachineToHardwareTest.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java index 913d40a63e..164bf41d36 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java @@ -48,10 +48,10 @@ public class IMachineToHardware implements Function { IGuestOSType guestOSType = virtualBoxManager.get().getVBox().getGuestOSType(osTypeId); Boolean is64Bit = guestOSType.getIs64Bit(); HardwareBuilder hardwareBuilder = new HardwareBuilder(); - hardwareBuilder.ids(vm.getId()); - hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getId())); + hardwareBuilder.ids(vm.getName()); + hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getName())); hardwareBuilder.is64Bit(is64Bit); - hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getId())); + hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getName())); hardwareBuilder.hypervisor("VirtualBox"); return hardwareBuilder.build(); } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java index 99b63c51c2..436826f927 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java @@ -46,10 +46,10 @@ public class IMachineToHardwareTest { IGuestOSType guestOsType = createNiceMock(IGuestOSType.class); String linuxDescription = "Ubuntu Linux 10.04"; - String machineId = "hw-machineId"; + String machineName = "hw-machineId"; expect(vm.getOSTypeId()).andReturn("os-type").anyTimes(); - expect(vm.getId()).andReturn(machineId).anyTimes(); + expect(vm.getName()).andReturn(machineName).anyTimes(); expect(vm.getDescription()).andReturn(linuxDescription).anyTimes(); @@ -61,11 +61,11 @@ public class IMachineToHardwareTest { Hardware hardware = new IMachineToHardware(Suppliers.ofInstance(vbm)).apply(vm); - assertEquals(hardware.getId(), machineId); - assertEquals(hardware.getProviderId(), machineId); + assertEquals(hardware.getId(), machineName); + assertEquals(hardware.getProviderId(), machineName); // for starters assume 1-to-1 relationship hardware to image (which // correlate to a single source IMachine) - assertEquals(hardware.supportsImage().toString(), ImagePredicates.idEquals(machineId).toString()); + assertEquals(hardware.supportsImage().toString(), ImagePredicates.idEquals(machineName).toString()); } From 8f92009699a30cfd81d86dc2fe7d65f693d607ff Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 15:03:56 +0000 Subject: [PATCH 09/12] improved hardware matching (hardware's id is now the same as the image id *without* prefix) --- .../jclouds/virtualbox/functions/IMachineToHardware.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java index 164bf41d36..cc2a7ae53c 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java @@ -25,6 +25,7 @@ import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VirtualBoxManager; @@ -44,14 +45,14 @@ public class IMachineToHardware implements Function { @Override public Hardware apply(@Nullable IMachine vm) { String osTypeId = vm.getOSTypeId(); - + String vmNameWithoutPrefix = vm.getName().replace(VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX, ""); + IGuestOSType guestOSType = virtualBoxManager.get().getVBox().getGuestOSType(osTypeId); Boolean is64Bit = guestOSType.getIs64Bit(); HardwareBuilder hardwareBuilder = new HardwareBuilder(); - hardwareBuilder.ids(vm.getName()); - hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getName())); + hardwareBuilder.ids(vmNameWithoutPrefix); hardwareBuilder.is64Bit(is64Bit); - hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getName())); + hardwareBuilder.supportsImage(ImagePredicates.idEquals(vmNameWithoutPrefix)); hardwareBuilder.hypervisor("VirtualBox"); return hardwareBuilder.build(); } From 8ba6e91b7cf3576134ab5b4098ca708ba4ab7202 Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 15:32:31 +0000 Subject: [PATCH 10/12] improved hardware matching. *adapter now returns the list of images instead of a no-id mock hardware --- .../config/VirtualBoxComputeServiceContextModule.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index 95f8c662de..bc3e206501 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -24,8 +24,8 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECO import java.io.File; import java.io.InputStream; import java.net.URI; -import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutionException; import javax.inject.Named; @@ -78,6 +78,7 @@ import org.jclouds.virtualbox.functions.admin.ImagesToYamlImagesFromYamlDescript import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; import org.jclouds.virtualbox.predicates.SshResponds; +import org.testng.internal.annotations.Sets; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.LockType; import org.virtualbox_4_1.MachineState; @@ -218,7 +219,13 @@ public class VirtualBoxComputeServiceContextModule extends @Override protected Supplier provideHardware(ComputeServiceAdapter adapter, Function transformer) { - return Suppliers.ofInstance(Collections.singleton(new HardwareBuilder().id("").build())); + // since no vms might be available we need to list images + Iterable images = adapter.listImages(); + Set hardware = Sets.newHashSet(); + for (Image image : images) { + hardware.add(new HardwareBuilder().ids(image.getId()).hypervisor("VirtualBox").name(image.getName()).build()); + } + return Suppliers.ofInstance(hardware); } @Override From 5efcea6839ce570386cd525a270066f63c089aad Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 15:56:15 +0000 Subject: [PATCH 11/12] changed delay to sockettester --- .../functions/admin/StartVBoxIfNotAlreadyRunning.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java index 750dac9399..1a796c83ba 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java @@ -70,7 +70,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier @Provider Supplier providerSupplier, @Identity String identity, @Credential String credential) { this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.socketTester = checkNotNull(socketTester, "socketTester"); - this.socketTester.seconds(1L); + this.socketTester.seconds(3L); this.host = checkNotNull(host, "host"); this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed"); this.identity = checkNotNull(identity, "identity"); @@ -94,10 +94,8 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); - try { - // wait for a couple of seconds to make sure vbox has correctly started - Thread.sleep(2000L); - } catch (InterruptedException e) { + if (!!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))){ + throw new RuntimeException("could not connect to virtualbox"); } } manager = managerForNode.apply(host); From 93b08a01e3d07ec6cc5aebc93a4e69ce9e753b8f Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Mon, 12 Mar 2012 16:03:04 +0000 Subject: [PATCH 12/12] deleted extraneous exclamation point --- .../functions/admin/StartVBoxIfNotAlreadyRunning.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java index 1a796c83ba..3afb07c8a2 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java @@ -94,7 +94,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); - if (!!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))){ + if (!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))){ throw new RuntimeException("could not connect to virtualbox"); } }