From 09adeebe3d03aa37f2aae9aa3ab9db59ce06f5c4 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Tue, 17 Nov 2009 02:53:10 +0000 Subject: [PATCH] Issue 112: created vcloud tester, converted to lookup api version dynamically git-svn-id: http://jclouds.googlecode.com/svn/trunk@2295 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../org/jclouds/vcloud/VCloudAsyncClient.java | 34 +-- .../java/org/jclouds/vcloud/VCloudClient.java | 16 +- .../java/org/jclouds/vcloud/VCloudLogin.java | 5 +- .../vcloud/VCloudPropertiesBuilder.java | 2 + .../org/jclouds/vcloud/VCloudVersions.java | 58 +++++ .../VCloudDiscoveryRestClientModule.java | 31 ++- .../vcloud/config/VCloudRestClientModule.java | 10 +- .../jclouds/vcloud/domain/NamedResource.java | 2 +- .../jclouds/vcloud/domain/Organization.java | 2 +- .../java/org/jclouds/vcloud/domain/VDC.java | 2 +- .../domain/internal/NamedResourceImpl.java | 31 ++- .../domain/internal/OrganizationImpl.java | 13 +- .../vcloud/domain/internal/VDCImpl.java | 17 +- .../jclouds/vcloud/endpoints/VCloudApi.java | 45 ++++ .../jclouds/vcloud/endpoints/VCloudLogin.java | 45 ++++ .../vcloud/functions/CatalogIdToUri.java | 6 +- .../jclouds/vcloud/functions/VAppIdToUri.java | 6 +- .../vcloud/reference/VCloudConstants.java | 1 + .../jclouds/vcloud/xml/CatalogHandler.java | 11 +- .../org/jclouds/vcloud/xml/OrgHandler.java | 13 +- .../vcloud/xml/SupportedVersionsHandler.java | 66 +++++ .../org/jclouds/vcloud/xml/VDCHandler.java | 13 +- .../org/jclouds/vcloud/VCloudClientTest.java | 20 +- .../vcloud/VCloudDiscoveryLiveTest.java | 2 + .../jclouds/vcloud/VCloudDiscoveryTest.java | 4 +- .../jclouds/vcloud/VCloudLoginLiveTest.java | 2 + .../org/jclouds/vcloud/VCloudLoginTest.java | 5 +- .../vcloud/VCloudVersionsLiveTest.java | 132 ++++++++++ .../jclouds/vcloud/VCloudVersionsTest.java | 100 ++++++++ .../VCloudDiscoveryRestClientModuleTest.java | 7 +- .../config/VCloudRestClientModuleTest.java | 72 ------ .../vcloud/xml/CatalogHandlerTest.java | 70 +++--- .../jclouds/vcloud/xml/OrgHandlerTest.java | 10 +- .../xml/SupportedVersionsHandlerTest.java | 60 +++++ .../jclouds/vcloud/xml/VDCHandlerTest.java | 6 +- vcloud/core/src/test/resources/log4j.xml | 38 ++- vcloud/core/src/test/resources/versions.xml | 7 + .../terremark/TerremarkVCloudAsyncClient.java | 34 +-- .../terremark/TerremarkVCloudClient.java | 16 +- .../TerremarkVCloudPropertiesBuilder.java | 4 +- .../terremark/domain/InternetService.java | 26 +- .../jclouds/vcloud/terremark/domain/Node.java | 26 +- .../vcloud/terremark/domain/ResourceType.java | 2 - .../domain/internal/TerremarkVDCImpl.java | 2 +- .../terremark/domain/internal/VAppImpl.java | 2 +- .../terremark/xml/InternetServiceHandler.java | 4 +- .../vcloud/terremark/xml/NodeHandler.java | 4 +- .../terremark/xml/TerremarkVAppHandler.java | 8 +- .../TerremarkVCloudClientLiveTest.java | 30 +-- .../terremark/TerremarkVCloudClientTest.java | 74 +++--- .../TerremarkVCloudComputeClientLiveTest.java | 212 ++++++++++++++++ .../vcloud/terremark/VCloudComputeClient.java | 232 ++++++++++++++++++ .../TerremarkVCloudRestClientModuleTest.java | 6 +- .../xml/InternetServiceHandlerTest.java | 6 +- .../vcloud/terremark/xml/NodeHandlerTest.java | 5 +- .../xml/TerremarkVAppHandlerTest.java | 4 +- .../xml/TerremarkVDCHandlerTest.java | 4 +- 57 files changed, 1295 insertions(+), 370 deletions(-) create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/VCloudVersions.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudApi.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudLogin.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/xml/SupportedVersionsHandler.java create mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java create mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java delete mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java create mode 100644 vcloud/core/src/test/java/org/jclouds/vcloud/xml/SupportedVersionsHandlerTest.java create mode 100644 vcloud/core/src/test/resources/versions.xml create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index 93dc9525c5..f50173d5ae 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -84,70 +84,70 @@ public interface VCloudAsyncClient { @POST @Consumes(TASK_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/action/deploy") @XMLResponseParser(TaskHandler.class) - Future deployVApp(@PathParam("vAppId") int vAppId); + Future deployVApp(@PathParam("vAppId") String vAppId); @DELETE - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}") - Future deleteVApp(@PathParam("vAppId") int vAppId); + Future deleteVApp(@PathParam("vAppId") String vAppId); @POST @Consumes(TASK_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/action/undeploy") @XMLResponseParser(TaskHandler.class) - Future undeployVApp(@PathParam("vAppId") int vAppId); + Future undeployVApp(@PathParam("vAppId") String vAppId); /** * This call powers on the vApp, as specified in the vApp's ovf:Startup element. */ @POST @Consumes(TASK_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/power/action/powerOn") @XMLResponseParser(TaskHandler.class) - Future powerOnVApp(@PathParam("vAppId") int vAppId); + Future powerOnVApp(@PathParam("vAppId") String vAppId); /** * This call powers off the vApp, as specified in the vApp's ovf:Startup element. */ @POST @Consumes(TASK_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/power/action/powerOff") @XMLResponseParser(TaskHandler.class) - Future powerOffVApp(@PathParam("vAppId") int vAppId); + Future powerOffVApp(@PathParam("vAppId") String vAppId); /** * This call shuts down the vApp. */ @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/power/action/shutdown") - Future shutdownVApp(@PathParam("vAppId") int vAppId); + Future shutdownVApp(@PathParam("vAppId") String vAppId); /** * This call resets the vApp. */ @POST @Consumes(TASK_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/power/action/reset") @XMLResponseParser(TaskHandler.class) - Future resetVApp(@PathParam("vAppId") int vAppId); + Future resetVApp(@PathParam("vAppId") String vAppId); /** * This call suspends the vApp. */ @POST @Consumes(TASK_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}/power/action/suspend") @XMLResponseParser(TaskHandler.class) - Future suspendVApp(@PathParam("vAppId") int vAppId); + Future suspendVApp(@PathParam("vAppId") String vAppId); @GET @Consumes(TASK_XML) @@ -160,7 +160,7 @@ public interface VCloudAsyncClient { @GET @Consumes(VAPP_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}") Future getVAppString(@PathParam("vAppId") String appId); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index d721160026..4ae620bbbe 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -51,36 +51,36 @@ public interface VCloudClient { @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) TasksList getDefaultTasksList(); - Task deployVApp(int vAppId); + Task deployVApp(String vAppId); - void deleteVApp(int vAppId); + void deleteVApp(String vAppId); - Task undeployVApp(int vAppId); + Task undeployVApp(String vAppId); /** * This call powers on the vApp, as specified in the vApp's ovf:Startup element. */ - Task powerOnVApp(int vAppId); + Task powerOnVApp(String vAppId); /** * This call powers off the vApp, as specified in the vApp's ovf:Startup element. */ - Task powerOffVApp(int vAppId); + Task powerOffVApp(String vAppId); /** * This call shuts down the vApp. */ - void shutdownVApp(int vAppId); + void shutdownVApp(String vAppId); /** * This call resets the vApp. */ - Task resetVApp(int vAppId); + Task resetVApp(String vAppId); /** * This call suspends the vApp. */ - Task suspendVApp(int vAppId); + Task suspendVApp(String vAppId); Task getTask(URI task); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java index f25dae9c84..304f1c6ca3 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java @@ -28,7 +28,6 @@ import java.util.concurrent.Future; import javax.ws.rs.Consumes; import javax.ws.rs.POST; -import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import org.jclouds.http.filters.BasicAuthentication; @@ -37,7 +36,6 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.domain.NamedLink; import org.jclouds.vcloud.endpoints.Org; -import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; /** @@ -47,7 +45,7 @@ import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; * @see * @author Adrian Cole */ -@Endpoint(VCloud.class) +@Endpoint(org.jclouds.vcloud.endpoints.VCloudLogin.class) @RequestFilters(BasicAuthentication.class) public interface VCloudLogin { @@ -65,7 +63,6 @@ public interface VCloudLogin { */ @POST @ResponseParser(ParseLoginResponseFromHeaders.class) - @Path("/login") @Consumes(MediaType.APPLICATION_XML) Future login(); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index 6244866b34..7190900356 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -28,6 +28,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import java.net.URI; import java.util.Properties; @@ -43,6 +44,7 @@ public class VCloudPropertiesBuilder extends HttpPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + ""); return properties; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudVersions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudVersions.java new file mode 100644 index 0000000000..50ce7c37f7 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudVersions.java @@ -0,0 +1,58 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import java.net.URI; +import java.util.SortedMap; +import java.util.concurrent.Future; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.xml.SupportedVersionsHandler; + +/** + * Establishes a context with a VCloud endpoint. + *

+ * + * @see + * @author Adrian Cole + */ +@Endpoint(VCloud.class) +public interface VCloudVersions { + + /** + * Retrieve information for supported versions + */ + @GET + @XMLResponseParser(SupportedVersionsHandler.class) + @Path("/versions") + @Consumes(MediaType.APPLICATION_XML) + Future> getSupportedVersions(); +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java index db173e7bec..2f768a2cd2 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java @@ -27,10 +27,13 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.inject.Named; import javax.inject.Singleton; @@ -38,14 +41,17 @@ import javax.inject.Singleton; import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.http.RequiresHttp; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudDiscovery; import org.jclouds.vcloud.VCloudLogin; import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.VCloudVersions; import org.jclouds.vcloud.VCloudLogin.VCloudSession; import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; @@ -58,6 +64,7 @@ import com.google.inject.Provides; * @author Adrian Cole */ @RequiresHttp +@ConfiguresRestClient public class VCloudDiscoveryRestClientModule extends AbstractModule { @Override @@ -77,6 +84,13 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule { return Iterables.getLast(cache.get().getOrgs().values()).getLocation(); } + @Provides + @VCloudApi + @Singleton + URI provideVCloudApi(@org.jclouds.vcloud.endpoints.VCloudLogin URI vcloudUri) { + return URI.create(vcloudUri.toASCIIString().replace("/login", "")); + } + /** * borrowing concurrency code to ensure that caching takes place properly */ @@ -99,10 +113,19 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule { @Provides @Singleton @VCloud - protected URI provideAuthenticationURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) { + protected URI provideBaseURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) { return URI.create(endpoint); } + @Provides + @Singleton + @org.jclouds.vcloud.endpoints.VCloudLogin + protected URI provideAuthenticationURI(VCloudVersions versionService, + @Named(PROPERTY_VCLOUD_VERSION) String version) throws InterruptedException, + ExecutionException, TimeoutException { + return versionService.getSupportedVersions().get(30, TimeUnit.SECONDS).get(version); + } + @Provides @Singleton protected VCloudLogin provideVCloudLogin(RestClientFactory factory) { @@ -115,6 +138,12 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule { return factory.create(VCloudDiscovery.class); } + @Provides + @Singleton + protected VCloudVersions provideVCloudVersions(RestClientFactory factory) { + return factory.create(VCloudVersions.class); + } + @Provides @Singleton public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUD_USER) String user, diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index af617fc6cb..2f4b275873 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -41,7 +41,7 @@ import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.TasksList; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudLogin; import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot; @@ -78,15 +78,15 @@ public class VCloudRestClientModule extends AbstractModule { @Provides @CatalogItemRoot @Singleton - String provideCatalogItemRoot(@VCloud URI vcloudUri) { - return vcloudUri.toASCIIString() + "/catalogItem"; + String provideCatalogItemRoot(@VCloudLogin URI vcloudUri) { + return vcloudUri.toASCIIString().replace("/login", "/catalogItem"); } @Provides @VAppRoot @Singleton - String provideVAppRoot(@VCloud URI vcloudUri) { - return vcloudUri.toASCIIString() + "/vapp"; + String provideVAppRoot(@VCloudLogin URI vcloudUri) { + return vcloudUri.toASCIIString().replace("/login", "/vapp"); } @Provides diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java index 677e74c4e4..0b1da8af26 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java @@ -13,5 +13,5 @@ import com.google.inject.ImplementedBy; */ @ImplementedBy(NamedResourceImpl.class) public interface NamedResource extends NamedLink, Comparable { - int getId(); + String getId(); } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java index a2d4ba38ee..df34042e7e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java @@ -44,7 +44,7 @@ import com.google.inject.ImplementedBy; public interface Organization { String getName(); - int getId(); + String getId(); URI getLocation(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java index 01879b3eb6..0e22fe5498 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java @@ -40,7 +40,7 @@ public interface VDC { String getName(); - int getId(); + String getId(); URI getLocation(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java index d054677a91..094ea91675 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java @@ -12,37 +12,26 @@ import org.jclouds.vcloud.domain.NamedResource; * */ public class NamedResourceImpl extends NamedLinkImpl implements NamedResource { - private final int id; + private final String id; - public NamedResourceImpl(int id, String name, String type, URI location) { + public NamedResourceImpl(String id, String name, String type, URI location) { super(name, type, location); this.id = id; } - public int getId() { + public String getId() { return id; } public int compareTo(NamedResource that) { - final int BEFORE = -1; - final int EQUAL = 0; - final int AFTER = 1; - - if (this == that) - return EQUAL; - - if (this.id < that.getId()) - return BEFORE; - if (this.id > that.getId()) - return AFTER; - return EQUAL; + return (this == that) ? 0 : this.id.compareTo(that.getId()); } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + id; + result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @@ -55,9 +44,17 @@ public class NamedResourceImpl extends NamedLinkImpl implements NamedResource { if (getClass() != obj.getClass()) return false; NamedResourceImpl other = (NamedResourceImpl) obj; - if (id != other.id) + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) return false; return true; } + @Override + public String toString() { + return "NamedResourceImpl [id=" + id + ", name=" + getName() + ", location=" + + getLocation() + ", type=" + getType() + "]"; + } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java index 9a819a7455..b3e5b40b52 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java @@ -39,14 +39,14 @@ import org.jclouds.vcloud.endpoints.VDC; * */ public class OrganizationImpl implements Organization { - private final int id; + private final String id; private final String name; private final URI location; private final NamedLink catalog; private final Map vdcs; private final Map tasksLists; - public OrganizationImpl(int id, String name, URI location, NamedLink catalog, + public OrganizationImpl(String id, String name, URI location, NamedLink catalog, Map vdcs, Map tasksLists) { this.id = id; this.name = name; @@ -56,7 +56,7 @@ public class OrganizationImpl implements Organization { this.tasksLists = tasksLists; } - public int getId() { + public String getId() { return id; } @@ -88,7 +88,7 @@ public class OrganizationImpl implements Organization { final int prime = 31; int result = 1; result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); - result = prime * result + id; + result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode()); @@ -110,7 +110,10 @@ public class OrganizationImpl implements Organization { return false; } else if (!catalog.equals(other.catalog)) return false; - if (id != other.id) + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) return false; if (location == null) { if (other.location != null) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java index e910324517..7ade0eaf8b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java @@ -41,7 +41,7 @@ import org.jclouds.vcloud.domain.VDC; */ public class VDCImpl implements VDC { - private final int id; + private final String id; private final String name; private final URI location; private final String description; @@ -53,15 +53,13 @@ public class VDCImpl implements VDC { private final Map availableNetworks; private final Map resourceEntities; - public VDCImpl(int id, String name, URI location, String description, Capacity storageCapacity, + public VDCImpl(String id, String name, URI location, String description, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, Quota deployedVmsQuota, Map resourceEntities, Map availableNetworks) { this.id = id; this.name = checkNotNull(name, "name"); - ; this.location = checkNotNull(location, "location"); - ; this.description = description; this.storageCapacity = storageCapacity; this.cpuCapacity = cpuCapacity; @@ -69,15 +67,13 @@ public class VDCImpl implements VDC { this.instantiatedVmsQuota = instantiatedVmsQuota; this.deployedVmsQuota = deployedVmsQuota; this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks"); - ; this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities"); - ; } /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public int getId() { + public String getId() { return id; } @@ -105,7 +101,7 @@ public class VDCImpl implements VDC { result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode()); result = prime * result + ((deployedVmsQuota == null) ? 0 : deployedVmsQuota.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + id; + result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((instantiatedVmsQuota == null) ? 0 : instantiatedVmsQuota.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode()); @@ -145,7 +141,10 @@ public class VDCImpl implements VDC { return false; } else if (!description.equals(other.description)) return false; - if (id != other.id) + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) return false; if (instantiatedVmsQuota == null) { if (other.instantiatedVmsQuota != null) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudApi.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudApi.java new file mode 100644 index 0000000000..fbb5f82f55 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudApi.java @@ -0,0 +1,45 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.endpoints; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Represents a component related to vCloud. + * + * @see + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface VCloudApi { + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudLogin.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudLogin.java new file mode 100644 index 0000000000..30145aefe9 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloudLogin.java @@ -0,0 +1,45 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.endpoints; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Represents a component related to vCloud. + * + * @see + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface VCloudLogin { + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/CatalogIdToUri.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/CatalogIdToUri.java index 9236a81aed..77c556c7d8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/CatalogIdToUri.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/CatalogIdToUri.java @@ -20,9 +20,9 @@ public class CatalogIdToUri implements Function { private String catalogItemRoot; public String apply(Object from) { - checkArgument(checkNotNull(from, "from") instanceof Integer, - "this binder is only valid for Integers!"); - return String.format("%s/%d", catalogItemRoot, from); + checkArgument(checkNotNull(from, "from") instanceof String, + "this binder is only valid for String!"); + return String.format("%s/%s", catalogItemRoot, from); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java index 45fd170f8f..0a43243be0 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java @@ -20,9 +20,9 @@ public class VAppIdToUri implements Function { private String vAppRoot; public String apply(Object from) { - checkArgument(checkNotNull(from, "from") instanceof Integer, - "this binder is only valid for Integers!"); - return String.format("%s/%d", vAppRoot, from); + checkArgument(checkNotNull(from, "from") instanceof String, + "this binder is only valid for Strings!"); + return String.format("%s/%s", vAppRoot, from); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java index fe6dcaca8f..0917b202d6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java @@ -29,6 +29,7 @@ package org.jclouds.vcloud.reference; * @author Adrian Cole */ public interface VCloudConstants { + public static final String PROPERTY_VCLOUD_VERSION = "jclouds.vcloud.version"; public static final String PROPERTY_VCLOUD_ENDPOINT = "jclouds.vcloud.endpoint"; public static final String PROPERTY_VCLOUD_USER = "jclouds.vcloud.user"; public static final String PROPERTY_VCLOUD_KEY = "jclouds.vcloud.key"; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java index 37459484a1..ea2884acd6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java @@ -84,11 +84,12 @@ public class CatalogHandler extends ParseSax.HandlerWithResult { } public NamedResource newNamedResource(Attributes attributes) { - return new NamedResourceImpl(Integer.parseInt(attributes - .getValue(attributes.getIndex("href")).replace(catalogItemRoot + "/", "")), - attributes.getValue(attributes.getIndex("name")), attributes.getValue(attributes - .getIndex("type")), URI.create(attributes.getValue(attributes - .getIndex("href")))); + String href = attributes.getValue(attributes.getIndex("href")); + String id = href.replace(catalogItemRoot + "/", ""); + assert !id.contains("https://") : String.format( + "parse of %s should have stripped, but didn't %s", href, id); + return new NamedResourceImpl(id, attributes.getValue(attributes.getIndex("name")), attributes + .getValue(attributes.getIndex("type")), URI.create(href)); } public void putNamedResource(Map map, Attributes attributes) { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java index c77294373e..be346c4bbb 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java @@ -40,7 +40,7 @@ import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -55,7 +55,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult { private Map tasksLists = Maps.newHashMap(); private NamedLink catalog; @Inject - @VCloud + @VCloudApi URI vcloudUri; public Organization getResult() { @@ -83,11 +83,10 @@ public class OrgHandler extends ParseSax.HandlerWithResult { } public NamedResource newNamedResource(Attributes attributes) { - return new NamedResourceImpl( - Integer.parseInt(attributes.getValue(attributes.getIndex("href")).replace( - vcloudUri.toASCIIString() + "/org/", "")), attributes.getValue(attributes - .getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI - .create(attributes.getValue(attributes.getIndex("href")))); + return new NamedResourceImpl(attributes.getValue(attributes.getIndex("href")).replace( + vcloudUri.toASCIIString() + "/org/", ""), attributes.getValue(attributes + .getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI + .create(attributes.getValue(attributes.getIndex("href")))); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/SupportedVersionsHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/SupportedVersionsHandler.java new file mode 100644 index 0000000000..ab056d9cf5 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/SupportedVersionsHandler.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.xml; + +import java.net.URI; +import java.util.SortedMap; + +import org.jclouds.http.functions.ParseSax; + +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class SupportedVersionsHandler extends ParseSax.HandlerWithResult> { + private StringBuilder currentText = new StringBuilder(); + + private SortedMap contents = Maps.newTreeMap(); + private String version; + private URI location; + + public SortedMap getResult() { + return contents; + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("Version")) { + version = currentOrNull(); + } else if (qName.equals("LoginUrl")) { + location = URI.create(currentOrNull()); + } else if (qName.equals("VersionInfo")) { + contents.put(version, location); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java index 3b53f75e2b..62b91ed88d 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java @@ -38,7 +38,7 @@ import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.VDCImpl; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -54,7 +54,7 @@ public class VDCHandler extends ParseSax.HandlerWithResult { private Map resourceEntities = Maps.newHashMap(); private Map availableNetworks = Maps.newHashMap(); @Inject - @VCloud + @VCloudApi URI vcloudUri; private String description; @@ -125,11 +125,10 @@ public class VDCHandler extends ParseSax.HandlerWithResult { } public NamedResource newNamedResource(Attributes attributes) { - return new NamedResourceImpl(Integer.parseInt(attributes - .getValue(attributes.getIndex("href")).replace(vcloudUri.toASCIIString() + "/vdc/", - "")), attributes.getValue(attributes.getIndex("name")), attributes - .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes - .getIndex("href")))); + return new NamedResourceImpl(attributes.getValue(attributes.getIndex("href")).replace( + vcloudUri.toASCIIString() + "/vdc/", ""), attributes.getValue(attributes + .getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI + .create(attributes.getValue(attributes.getIndex("href")))); } protected String currentOrNull() { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java index 9e23a2ffbe..a129940070 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java @@ -40,7 +40,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.TasksList; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot; @@ -112,7 +112,7 @@ public class VCloudClientTest extends RestClientTest { } public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("deployVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/deploy HTTP/1.1"); @@ -127,7 +127,7 @@ public class VCloudClientTest extends RestClientTest { } public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("undeployVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/undeploy HTTP/1.1"); @@ -142,7 +142,7 @@ public class VCloudClientTest extends RestClientTest { } public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("deleteVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vapp/1 HTTP/1.1"); @@ -157,7 +157,7 @@ public class VCloudClientTest extends RestClientTest { } public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/powerOn HTTP/1.1"); @@ -172,7 +172,7 @@ public class VCloudClientTest extends RestClientTest { } public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, @@ -188,7 +188,7 @@ public class VCloudClientTest extends RestClientTest { } public void testReset() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("resetVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/reset HTTP/1.1"); @@ -203,7 +203,7 @@ public class VCloudClientTest extends RestClientTest { } public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("suspendVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/suspend HTTP/1.1"); @@ -218,7 +218,7 @@ public class VCloudClientTest extends RestClientTest { } public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", int.class); + Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); assertRequestLineEquals(httpMethod, @@ -289,7 +289,7 @@ public class VCloudClientTest extends RestClientTest { bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); bind(URI.class).annotatedWith(TasksList.class).toInstance( URI.create("http://tasksList")); - bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create("http://vcloud")); + bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud")); bind(SetVCloudTokenCookie.class).toInstance( new SetVCloudTokenCookie(new Provider() { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java index 76adbca4d8..a1c7fa2ce9 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java @@ -27,6 +27,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -116,6 +117,7 @@ public class VCloudDiscoveryLiveTest { protected void addClientModule(List modules) { properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint, "endpoint").toString()); + properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java index d47f707129..4f5f52e17c 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java @@ -38,7 +38,7 @@ import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.endpoints.Org; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.xml.OrgHandler; import org.testng.annotations.Test; @@ -106,7 +106,7 @@ public class VCloudDiscoveryTest extends RestClientTest { } @SuppressWarnings("unused") @Provides - @VCloud + @VCloudApi URI provide() { return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java index c15a18fc60..7e01488833 100755 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java @@ -27,6 +27,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import static org.testng.Assert.assertNotNull; import java.net.URI; @@ -113,6 +114,7 @@ public class VCloudLoginLiveTest { protected void addClientModule(List modules) { properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint, "endpoint").toString()); + properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java index 5e13368fab..5b7a3ca00c 100755 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java @@ -39,7 +39,6 @@ import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.testng.annotations.Test; @@ -87,8 +86,8 @@ public class VCloudLoginTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { - bind(URI.class).annotatedWith(VCloud.class).toInstance( - URI.create("http://localhost:8080")); + bind(URI.class).annotatedWith(org.jclouds.vcloud.endpoints.VCloudLogin.class) + .toInstance(URI.create("http://localhost:8080/login")); try { bind(BasicAuthentication.class).toInstance(new BasicAuthentication("user", "pass")); } catch (UnsupportedEncodingException e) { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java new file mode 100644 index 0000000000..a7b7997403 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java @@ -0,0 +1,132 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.List; +import java.util.Properties; +import java.util.SortedMap; +import java.util.concurrent.TimeUnit; + +import javax.inject.Singleton; + +import org.jclouds.concurrent.WithinThreadExecutorService; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.http.RequiresHttp; +import org.jclouds.lifecycle.Closer; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.RestClientFactory; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextBuilder; +import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.vcloud.endpoints.VCloud; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VCloudVersions} + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "vcloud.VCloudVersionsLiveTest") +public class VCloudVersionsLiveTest { + + @RequiresHttp + @ConfiguresRestClient + private static final class VCloudVersionsRestClientModule extends AbstractModule { + @SuppressWarnings("unused") + @Provides + @Singleton + protected VCloudVersions provideVCloudVersions(RestClientFactory factory) { + return factory.create(VCloudVersions.class); + } + + @Override + protected void configure() { + bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create(endpoint)); + } + } + + private final class VCloudVersionsContextModule extends AbstractModule { + + @SuppressWarnings( { "unused" }) + @Provides + @Singleton + RestContext provideContext(Closer closer, VCloudVersions api, + @VCloud URI endPoint) { + return new RestContextImpl(closer, api, api, endPoint, ""); + } + + @Override + protected void configure() { + + } + } + + static String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), + "jclouds.test.endpoint"); + + private RestContext context; + + @Test + public void testGetSupportedVersions() throws Exception { + VCloudVersions authentication = context.getAsyncApi(); + for (int i = 0; i < 5; i++) { + SortedMap response = authentication.getSupportedVersions().get(45, + TimeUnit.SECONDS); + assertNotNull(response); + assertNotNull(response.containsKey("0.8")); + } + } + + @BeforeClass + void setupFactory() { + context = new RestContextBuilder( + new TypeLiteral() { + }, new TypeLiteral() { + }, new Properties()) { + + public void addContextModule(List modules) { + + modules.add(new VCloudVersionsContextModule()); + } + + @Override + protected void addClientModule(List modules) { + modules.add(new VCloudVersionsRestClientModule()); + } + + }.withModules(new Log4JLoggingModule(), + new ExecutorServiceModule(new WithinThreadExecutorService())).buildContext(); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java new file mode 100644 index 0000000000..8178819598 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java @@ -0,0 +1,100 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.xml.SupportedVersionsHandler; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VCloudVersions} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VCloudVersionsTest") +public class VCloudVersionsTest extends RestClientTest { + + public void testLogin() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudVersions.class.getMethod("getSupportedVersions"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); + + assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1"); + assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": " + MediaType.APPLICATION_XML + "\n"); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, SupportedVersionsHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 0); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(VCloud.class).toInstance( + URI.create("http://localhost:8080")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } + + }; + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModuleTest.java index da19e68d64..0ab12dc281 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModuleTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModuleTest.java @@ -27,6 +27,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import static org.testng.Assert.assertEquals; import java.util.Map; @@ -42,6 +43,7 @@ import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.domain.NamedLink; import org.jclouds.util.Jsr330; import org.jclouds.vcloud.VCloudLogin; @@ -60,10 +62,11 @@ import com.google.inject.Injector; public class VCloudDiscoveryRestClientModuleTest { Injector createInjector() { - return Guice.createInjector(new VCloudDiscoveryRestClientModule(), new ParserModule(), - new AbstractModule() { + return Guice.createInjector(new VCloudDiscoveryRestClientModule(), new Log4JLoggingModule(), + new ParserModule(), new AbstractModule() { @Override protected void configure() { + bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to( diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java deleted file mode 100644 index a42bb63b26..0000000000 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.config; - -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.functions.config.ParserModule; -import org.jclouds.util.Jsr330; -import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; -import org.jclouds.vcloud.endpoints.internal.VAppRoot; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "vcloud.VCloudRestClientModuleTest") -public class VCloudRestClientModuleTest extends VCloudDiscoveryRestClientModuleTest { - - protected Injector createInjector() { - return Guice.createInjector(new VCloudRestClientModule(), - new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() { - @Override - protected void configure() { - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user"); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret"); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to( - "http://localhost"); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL)) - .to("2"); - } - }); - } - - @Test - void testCatalogItemRoot() { - assertEquals(createInjector().getInstance(Key.get(String.class, CatalogItemRoot.class)), - "http://localhost/catalogItem"); - assertEquals(createInjector().getInstance(Key.get(String.class, VAppRoot.class)), - "http://localhost/vapp"); - } - -} \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java index 171b6aefda..2e7ce93ebb 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java @@ -79,84 +79,84 @@ public class CatalogHandlerTest { assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); - assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5, + assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5 + "", "CentOS 5.3 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5"))); - assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6, + assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6 + "", "CentOS 5.3 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6"))); - assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7, "RHEL 5.3 (32-bit)", - CATALOGITEM_XML, + assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7 + "", + "RHEL 5.3 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7"))); - assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8, "RHEL 5.3 (64-bit)", - CATALOGITEM_XML, + assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8 + "", + "RHEL 5.3 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8"))); - assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11, + assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11 + "", "Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11"))); - assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12, + assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12 + "", "Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12"))); - assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9, + assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9 + "", "Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9"))); - assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10, + assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10 + "", "Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10"))); - assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1, + assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1 + "", "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1"))); - assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2, + assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2 + "", "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2"))); - assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3, + assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3 + "", "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3"))); - assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4, + assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4 + "", "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4"))); assertEquals( result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), new NamedResourceImpl( - 23, + 23 + "", "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23"))); - assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl(13, - "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, + assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl( + 13 + "", "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13"))); - assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl(15, - "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, + assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl( + 15 + "", "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15"))); assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl( - 16, "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, + 16 + "", "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16"))); - assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl(17, - "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, + assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl( + 17 + "", "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17"))); - assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl(18, - "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, + assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl( + 18 + "", "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18"))); assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl( - 19, "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, + 19 + "", "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19"))); assertEquals( result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), new NamedResourceImpl( - 14, + 14 + "", "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14"))); - assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20, + assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20 + "", "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20"))); - assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21, + assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21 + "", "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21"))); - assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl(22, - "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, + assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl( + 22 + "", "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"))); } @@ -185,19 +185,19 @@ public class CatalogHandlerTest { assertEquals(result.getLocation(), URI .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); - assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1, + assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1 + "", "Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1"))); - assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl(2, - "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI + assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl( + 2 + "", "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))); - assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3, + assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3 + "", "Cent OS 64 Bit Template", CATALOGITEM_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3"))); - assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4, + assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4 + "", "cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"))); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java index a044a437b5..74bbaac29d 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java @@ -38,7 +38,7 @@ import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Organization; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -68,7 +68,7 @@ public class OrgHandlerTest { @SuppressWarnings("unused") @Provides @Singleton - @VCloud + @VCloudApi URI provide(){ return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); } @@ -79,7 +79,7 @@ public class OrgHandlerTest { Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) .parse(is); assertEquals(result.getName(), "adrian@jclouds.org"); - assertEquals(result.getId(), 48); + assertEquals(result.getId(), 48+""); assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog", @@ -111,7 +111,7 @@ public class OrgHandlerTest { @SuppressWarnings("unused") @Provides @Singleton - @VCloud + @VCloudApi URI provide(){ return URI.create("https://vcloud.safesecureweb.com/api/v0.8"); } @@ -121,7 +121,7 @@ public class OrgHandlerTest { Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) .parse(is); assertEquals(result.getName(), "Customer 188849"); - assertEquals(result.getId(), 188849); + assertEquals(result.getId(), 188849+""); assertEquals(result.getLocation(), URI .create("https://vcloud.safesecureweb.com/api/v0.8/org/188849")); assertEquals(result.getCatalog(), new NamedLinkImpl("HMS Shared Catalog", CATALOG_XML, URI diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/SupportedVersionsHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/SupportedVersionsHandlerTest.java new file mode 100644 index 0000000000..e5eca25970 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/SupportedVersionsHandlerTest.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.SortedMap; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.ParserModule; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedMap; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code SupportedVersionsHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.SupportedVersionsHandlerTest") +public class SupportedVersionsHandlerTest { + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/versions.xml"); + + Injector injector = Guice.createInjector(new ParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + + SortedMap result = factory.create( + injector.getInstance(SupportedVersionsHandler.class)).parse(is); + assertEquals(result, ImmutableSortedMap.of("0.8", URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/login"))); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java index c84fa999ce..b8ee61068b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java @@ -36,7 +36,7 @@ import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -63,7 +63,7 @@ public class VDCHandlerTest { @SuppressWarnings("unused") @Provides - @VCloud + @VCloudApi URI provide() { return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); } @@ -103,7 +103,7 @@ public class VDCHandlerTest { @SuppressWarnings("unused") @Provides - @VCloud + @VCloudApi URI provide() { return URI.create("https://vcloud.safesecureweb.com/api/v0.8"); } diff --git a/vcloud/core/src/test/resources/log4j.xml b/vcloud/core/src/test/resources/log4j.xml index 05c47af5d2..f98e3505db 100755 --- a/vcloud/core/src/test/resources/log4j.xml +++ b/vcloud/core/src/test/resources/log4j.xml @@ -77,6 +77,31 @@ + + + + + + + + + + + + + + + + + + + + + @@ -84,7 +109,11 @@ - + + + + + @@ -100,6 +129,13 @@ + + + + + + + diff --git a/vcloud/core/src/test/resources/versions.xml b/vcloud/core/src/test/resources/versions.xml new file mode 100644 index 0000000000..4651754418 --- /dev/null +++ b/vcloud/core/src/test/resources/versions.xml @@ -0,0 +1,7 @@ + + + 0.8 + https://services.vcloudexpress.terremark.com/api/v0.8/login + + \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java index 40e59d43bd..4a4041e7de 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java @@ -83,7 +83,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(TerremarkVAppHandler.class) @MapBinder(InstantiateVAppTemplateOptions.class) Future instantiateVAppTemplate(@MapEntityParam("name") String appName, - @MapEntityParam("template") @ParamParser(CatalogIdToUri.class) int templateId, + @MapEntityParam("template") @ParamParser(CatalogIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); @POST @@ -97,61 +97,61 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { AddInternetServiceOptions... options); @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/publicIps/{ipId}/InternetServices") @Produces(MediaType.APPLICATION_XML) @XMLResponseParser(InternetServiceHandler.class) @MapBinder(AddInternetServiceOptions.class) Future addInternetServiceToExistingIp( - @PathParam("ipId") int existingIpId, @MapEntityParam("name") String serviceName, + @PathParam("ipId") String existingIpId, @MapEntityParam("name") String serviceName, @MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port, AddInternetServiceOptions... options); @DELETE - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}") - Future deleteInternetService(@PathParam("internetServiceId") int internetServiceId); + Future deleteInternetService(@PathParam("internetServiceId") String internetServiceId); @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}") @XMLResponseParser(InternetServiceHandler.class) Future getInternetService( - @PathParam("internetServiceId") int internetServiceId); + @PathParam("internetServiceId") String internetServiceId); @POST - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}/nodes") @Produces(MediaType.APPLICATION_XML) @XMLResponseParser(NodeHandler.class) @MapBinder(AddNodeOptions.class) Future addNode( - @PathParam("internetServiceId") int internetServiceId, + @PathParam("internetServiceId") String internetServiceId, @MapEntityParam("ipAddress") @ParamParser(InetAddressToHostAddress.class) InetAddress ipAddress, @MapEntityParam("name") String name, @MapEntityParam("port") int port, AddNodeOptions... options); @GET - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/nodeServices/{nodeId}") @XMLResponseParser(NodeHandler.class) - Future getNode(@PathParam("nodeId") int nodeId); + Future getNode(@PathParam("nodeId") String nodeId); @DELETE - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/nodeServices/{nodeId}") - Future deleteNode(@PathParam("nodeId") int nodeId); + Future deleteNode(@PathParam("nodeId") String nodeId); @GET @Consumes(VAPP_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}") @XMLResponseParser(TerremarkVAppHandler.class) - Future getVApp(@PathParam("vAppId") int vAppId); + Future getVApp(@PathParam("vAppId") String vAppId); @GET @Consumes(VAPP_XML) - @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}") - Future getVAppString(@PathParam("vAppId") int vAppId); + Future getVAppString(@PathParam("vAppId") String vAppId); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index ab0943446b..ff1fca29b7 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -45,26 +45,26 @@ import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS) public interface TerremarkVCloudClient extends VCloudClient { - VApp instantiateVAppTemplate(String appName, int templateId, + VApp instantiateVAppTemplate(String appName, String templateId, InstantiateVAppTemplateOptions... options); InternetService addInternetService(String serviceName, String protocol, int port, AddInternetServiceOptions... options); - InternetService addInternetServiceToExistingIp(int existingIpId, String serviceName, + InternetService addInternetServiceToExistingIp(String existingIpId, String serviceName, String protocol, int port, AddInternetServiceOptions... options); - void deleteInternetService(int internetServiceId); + void deleteInternetService(String internetServiceId); - InternetService getInternetService(int internetServiceId); + InternetService getInternetService(String internetServiceId); - Node addNode(int internetServiceId, InetAddress ipAddress, String name, int port, + Node addNode(String internetServiceId, InetAddress ipAddress, String name, int port, AddNodeOptions... options); - Node getNode(int nodeId); + Node getNode(String nodeId); - void deleteNode(int nodeId); + void deleteNode(String nodeId); - VApp getVApp(int vAppId); + VApp getVApp(String vAppId); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java index 1e2d4a7021..9d68423bbf 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java @@ -40,7 +40,7 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder { protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, - "https://services.vcloudexpress.terremark.com/api/v0.8"); + "https://services.vcloudexpress.terremark.com/api"); return properties; } @@ -49,6 +49,6 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder { } public TerremarkVCloudPropertiesBuilder(String id, String secret) { - super(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"), id, secret); + super(URI.create("https://services.vcloudexpress.terremark.com/api"), id, secret); } } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java index 0086a8796e..33075ebdb3 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java @@ -29,7 +29,7 @@ import java.net.URI; * @author Adrian Cole */ public class InternetService implements Comparable { - private final int id; + private final String id; private final String name; private final URI location; private final PublicIpAddress publicIpAddress; @@ -39,7 +39,7 @@ public class InternetService implements Comparable { private final int timeout; private final String description; - public InternetService(int id, String name, URI location, PublicIpAddress publicIpAddress, + public InternetService(String id, String name, URI location, PublicIpAddress publicIpAddress, int port, String protocol, boolean enabled, int timeout, String description) { this.id = id; this.name = name; @@ -82,7 +82,7 @@ public class InternetService implements Comparable { int result = 1; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + id; + result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + port; @@ -108,7 +108,10 @@ public class InternetService implements Comparable { return false; if (enabled != other.enabled) return false; - if (id != other.id) + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) return false; if (location == null) { if (other.location != null) @@ -138,21 +141,10 @@ public class InternetService implements Comparable { } public int compareTo(InternetService that) { - final int BEFORE = -1; - final int EQUAL = 0; - final int AFTER = 1; - - if (this == that) - return EQUAL; - - if (this.getId() < that.getId()) - return BEFORE; - if (this.getId() > that.getId()) - return AFTER; - return EQUAL; + return (this == that) ? 0 : this.getId().compareTo(that.getId()); } - public int getId() { + public String getId() { return id; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java index 1696bd92ca..3dd569ba0c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java @@ -30,7 +30,7 @@ import java.net.URI; * @author Adrian Cole */ public class Node implements Comparable { - private final int id; + private final String id; private final String name; private final URI location; private final InetAddress ipAddress; @@ -38,7 +38,7 @@ public class Node implements Comparable { private final boolean enabled; private final String description; - public Node(int id, String name, URI location, InetAddress ipAddress, int port, + public Node(String id, String name, URI location, InetAddress ipAddress, int port, boolean enabled, String description) { this.id = id; this.name = name; @@ -61,7 +61,7 @@ public class Node implements Comparable { return description; } - public int getId() { + public String getId() { return id; } @@ -74,18 +74,7 @@ public class Node implements Comparable { } public int compareTo(Node that) { - final int BEFORE = -1; - final int EQUAL = 0; - final int AFTER = 1; - - if (this == that) - return EQUAL; - - if (this.getId() < that.getId()) - return BEFORE; - if (this.getId() > that.getId()) - return AFTER; - return EQUAL; + return (this == that) ? 0 : this.getId().compareTo(that.getId()); } public InetAddress getIpAddress() { @@ -98,7 +87,7 @@ public class Node implements Comparable { int result = 1; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + id; + result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); @@ -122,7 +111,10 @@ public class Node implements Comparable { return false; if (enabled != other.enabled) return false; - if (id != other.id) + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) return false; if (ipAddress == null) { if (other.ipAddress != null) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java index e62ce3e73a..d726cf7d79 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java @@ -9,8 +9,6 @@ import org.jclouds.vcloud.VCloudAsyncClient; * VirtualResource such as disks or CPU * * @author Adrian Cole - * @see VCloudAsyncClient#getVApp - * * */ public enum ResourceType { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java index ebad799171..1fa973dc47 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java @@ -49,7 +49,7 @@ public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC { /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public TerremarkVDCImpl(int id, String name, URI location, String description, + public TerremarkVDCImpl(String id, String name, URI location, String description, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, Quota deployedVmsQuota, Map availableNetworks, Map resourceEntities, diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java index 44c90ce8d2..490b843474 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java @@ -62,7 +62,7 @@ public class VAppImpl extends NamedResourceImpl implements VApp { /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public VAppImpl(int id, String name, String type, URI location, VAppStatus status, long size, + public VAppImpl(String id, String name, String type, URI location, VAppStatus status, long size, Link vDC, Link computeOptions, Link customizationOptions, ListMultimap networkToAddresses, String operatingSystemDescription, VirtualSystem system, diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java index 5b2b6d64e6..0426893223 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java @@ -47,7 +47,7 @@ public class InternetServiceHandler extends HandlerWithResult { private boolean inPublicIpAddress; private int addressId; - private int id; + private String id; private URI location; private URI addressLocation; private String serviceName; @@ -83,7 +83,7 @@ public class InternetServiceHandler extends HandlerWithResult { if (inPublicIpAddress) addressId = Integer.parseInt(currentOrNull()); else - id = Integer.parseInt(currentOrNull()); + id = currentOrNull(); } else if (qName.equals("Href") && currentOrNull() != null) { if (inPublicIpAddress) addressLocation = URI.create(currentOrNull()); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java index 500bcfddba..6f148b67fd 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java @@ -42,7 +42,7 @@ public class NodeHandler extends HandlerWithResult { protected Logger logger = Logger.NULL; private StringBuilder currentText = new StringBuilder(); - private int id; + private String id; private URI location; private String serviceName; private InetAddress address; @@ -62,7 +62,7 @@ public class NodeHandler extends HandlerWithResult { public void endElement(String uri, String name, String qName) { if (qName.equals("Id")) { - id = Integer.parseInt(currentOrNull()); + id = currentOrNull(); } else if (qName.equals("Href") && currentOrNull() != null) { location = URI.create(currentOrNull()); } else if (qName.equals("Name")) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java index c96c22cce2..b69b42d818 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java @@ -168,10 +168,10 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult { } public NamedResource newNamedResource(Attributes attributes) { - return new NamedResourceImpl(Integer.parseInt(attributes - .getValue(attributes.getIndex("href")).replace(vAppRoot + "/", "")), attributes - .getValue(attributes.getIndex("name")), attributes.getValue(attributes - .getIndex("type")), URI.create(attributes.getValue(attributes.getIndex("href")))); + return new NamedResourceImpl(attributes.getValue(attributes.getIndex("href")).replace( + vAppRoot + "/", ""), attributes.getValue(attributes.getIndex("name")), attributes + .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes + .getIndex("href")))); } public void putNamedResource(Map map, Attributes attributes) { diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index d9f42a9c32..b874d362ab 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -46,7 +46,6 @@ import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudClientLiveTest; import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.domain.InternetService; @@ -58,7 +57,6 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; import com.google.inject.Injector; /** @@ -106,24 +104,20 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { String catalogOs = "CentOS 5.3 (32-bit)"; String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; - int templateId = tmClient.getCatalog().get(catalogOs).getId(); + String templateId = tmClient.getCatalog().get(catalogOs).getId(); System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis()); vApp = tmClient.instantiateVAppTemplate(serverName, templateId); assertEquals(vApp.getStatus(), VAppStatus.CREATING); - Task instantiateTask = getLastTaskFor(vApp.getVDC().getLocation()); - assertEquals(instantiateTask.getStatus(), TaskStatus.QUEUED); - // in terremark, this should be a no-op, as it should simply return the above task, which is // already deploying Task deployTask = tmClient.deployVApp(vApp.getId()); - assertEquals(deployTask.getLocation(), instantiateTask.getLocation()); // check to see the result of calling deploy twice deployTask = tmClient.deployVApp(vApp.getId()); - assertEquals(deployTask.getLocation(), instantiateTask.getLocation()); + assertEquals(deployTask.getLocation(), deployTask.getLocation()); vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getStatus(), VAppStatus.CREATING); @@ -141,8 +135,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk); assertEquals(vApp.getStatus(), VAppStatus.OFF); - assert successTester.apply(tmClient.powerOnVApp(vApp.getId()) - .getLocation()); + assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getLocation()); System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis()); vApp = tmClient.getVApp(vApp.getId()); @@ -181,8 +174,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { assertEquals(e.getResponse().getStatusCode(), 501); } - assert successTester.apply(tmClient.resetVApp(vApp.getId()) - .getLocation()); + assert successTester.apply(tmClient.resetVApp(vApp.getId()).getLocation()); vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getStatus(), VAppStatus.ON); @@ -192,8 +184,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { // vApp = tmClient.getVApp(vApp.getId()); // assertEquals(vApp.getStatus(), VAppStatus.ON); - assert successTester.apply(tmClient.powerOffVApp(vApp.getId()) - .getLocation()); + assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation()); vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getStatus(), VAppStatus.OFF); @@ -216,12 +207,6 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { .get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); } - private Task getLastTaskFor(URI owner) throws InterruptedException, ExecutionException, - TimeoutException { - return Iterables.getLast(tmClient.getDefaultTasksList() - .getTasksByOwner().get(owner)); - } - private void doCheckPass(InetAddress address) throws IOException { InetSocketAddress socket = new InetSocketAddress(address, 22); @@ -250,8 +235,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { tmClient.deleteInternetService(is.getId()); if (vApp != null) { try { - successTester.apply(tmClient.powerOffVApp(vApp.getId()) - .getLocation()); + successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation()); } catch (Exception e) { } @@ -265,7 +249,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder( - account, key).build()).withModules(new Log4JLoggingModule(), + account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(), new JschSshClientModule()).buildInjector(); connection = tmClient = injector.getInstance(TerremarkVCloudClient.class); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java index e49b347787..8eaf66585a 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java @@ -48,7 +48,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Network; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot; @@ -93,10 +93,10 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", 3); + "name", 3 + ""); assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); assertHeadersEqual( @@ -115,10 +115,10 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", 3, cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); + "name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); assertHeadersEqual( @@ -136,9 +136,9 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, "name", "tcp", 22); @@ -156,9 +156,9 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, "name", "tcp", 22, disabled().withDescription("yahoo")); @@ -175,8 +175,10 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); + Method method = TerremarkVCloudAsyncClient.class + .getMethod("getInternetService", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1"); assertHeadersEqual(httpMethod, ""); @@ -191,8 +193,10 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); + Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService", + String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1"); assertHeadersEqual(httpMethod, ""); @@ -208,10 +212,10 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12, - "name", "tcp", 22); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12, "name", "tcp", 22); assertRequestLineEquals(httpMethod, "POST http://vcloud/publicIps/12/InternetServices HTTP/1.1"); @@ -229,10 +233,10 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12, - "name", "tcp", 22, disabled().withDescription("yahoo")); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12, "name", "tcp", 22, disabled().withDescription("yahoo")); assertRequestLineEquals(httpMethod, "POST http://vcloud/publicIps/12/InternetServices HTTP/1.1"); @@ -247,11 +251,11 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12, - InetAddress.getByName("10.2.2.2"), "name", 22); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12, InetAddress.getByName("10.2.2.2"), "name", 22); assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1"); assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n"); @@ -266,11 +270,11 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12, - InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled() + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12, InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled() .withDescription("yahoo")); assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1"); @@ -285,8 +289,9 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); + Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1"); assertHeadersEqual(httpMethod, ""); @@ -300,8 +305,9 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); + Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1"); assertHeadersEqual(httpMethod, ""); @@ -334,7 +340,7 @@ public class TerremarkVCloudClientTest extends RestClientTest + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.terremark; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.predicates.AddressReachable; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.predicates.SocketOpen; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.predicates.TaskSuccess; +import org.jclouds.vcloud.terremark.VCloudComputeClient.Image; +import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.Node; +import org.jclouds.vcloud.terremark.domain.ResourceType; +import org.jclouds.vcloud.terremark.domain.VApp; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.inject.AbstractModule; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; +import com.google.inject.internal.ImmutableMap; + +/** + * Tests behavior of {@code TerremarkVCloudClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest") +public class TerremarkVCloudComputeClientLiveTest { + VCloudComputeClient client; + TerremarkVCloudClient tmClient; + + private String id; + private InetAddress privateAddress; + + public static final String PREFIX = System.getProperty("user.name") + "-terremark"; + + private static class Expectation { + final long hardDisk; + final String os; + + public Expectation(long hardDisk, String os) { + this.hardDisk = hardDisk; + this.os = os; + } + } + + private Map expectationMap = ImmutableMap. builder() + .put(Image.CENTOS_53, + new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (32-bit)")).put( + Image.RHEL_53, + new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (32-bit)")).put( + Image.UMBUNTU_SERVER_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")) + .put(Image.UMBUNTU_JEOS_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")).put( + Image.CENTOS_53_64, + new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( + Image.RHEL_53_64, + new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( + Image.UMBUNTU_SERVER_90_64, new Expectation(4194304, "Ubuntu Linux (64-bit)")) + .put(Image.UMBUNTU_JEOS_90_64, new Expectation(4194304, "Ubuntu Linux (64-bit)")) + .build(); + + private InternetService is; + private Node node; + private InetAddress publicIp; + private Predicate addressTester; + + @Test + public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, + IOException { + Image toTest = Image.CENTOS_53; + + String serverName = getCompatibleServerName(toTest); + int processorCount = 1; + int memory = 512; + + id = client.start(serverName, processorCount, memory, toTest); + Expectation expectation = expectationMap.get(toTest); + + VApp vApp = tmClient.getVApp(id); + verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory, + expectation.hardDisk); + assertEquals(vApp.getStatus(), VAppStatus.ON); + } + + private String getCompatibleServerName(Image toTest) { + String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0, + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + return serverName; + } + + @Test(dependsOnMethods = "testPowerOn") + public void testGetAnyPrivateAddress() { + privateAddress = client.getAnyPrivateAddress(id); + assert !addressTester.apply(privateAddress); + } + + @Test(dependsOnMethods = "testGetAnyPrivateAddress") + public void testSshLoadBalanceIp() { + is = tmClient.addInternetService("SSH", "TCP", 22); + node = tmClient.addNode(is.getId(), privateAddress, id + "-SSH", 22); + publicIp = is.getPublicIpAddress().getAddress(); + assert addressTester.apply(publicIp); + client.testSsh(publicIp); + } + + private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, + int processorCount, int memory, long hardDisk) { + assertEquals(vApp.getName(), serverName); + assertEquals(vApp.getOperatingSystemDescription(), expectedOs); + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) + .getVirtualQuantity(), processorCount); + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) + .getVirtualQuantity(), 1); + assertEquals( + vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(), + memory); + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) + .getVirtualQuantity(), hardDisk); + assertEquals(vApp.getSize(), vApp.getResourceAllocationByType() + .get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); + } + + @AfterTest + void cleanup() throws InterruptedException, ExecutionException, TimeoutException { + if (node != null) + tmClient.deleteNode(node.getId()); + if (is != null) + tmClient.deleteInternetService(is.getId()); + if (id != null) + client.stop(id); + } + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); + String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); + Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder( + account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(), + new JschSshClientModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + private Predicate socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 10, + TimeUnit.SECONDS);// make it longer then + // default internet + } + + @SuppressWarnings("unused") + @Provides + private Predicate addressTester(AddressReachable open) { + return open; + } + + @SuppressWarnings("unused") + @Provides + private Predicate successTester(TaskSuccess success) { + return new RetryablePredicate(success, 300, 10, TimeUnit.SECONDS); + } + + }).buildInjector(); + client = injector.getInstance(VCloudComputeClient.class); + tmClient = injector.getInstance(TerremarkVCloudClient.class); + addressTester = injector.getInstance(Key.get(new TypeLiteral>() { + })); + } + +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java new file mode 100644 index 0000000000..fbfa6839d7 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java @@ -0,0 +1,232 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.terremark; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.URI; +import java.util.Map; + +import javax.annotation.Resource; +import javax.inject.Inject; + +import org.jclouds.logging.Logger; +import org.jclouds.ssh.SshClient; +import org.jclouds.ssh.SshClient.Factory; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.terremark.domain.VApp; +import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import com.google.common.collect.MapMaker; + +/** + * + * @author Adrian Cole + */ +public class VCloudComputeClient { + @Resource + protected Logger logger = Logger.NULL; + + private final Predicate socketTester; + private final Predicate taskTester; + private final TerremarkVCloudClient tmClient; + + @Inject + public VCloudComputeClient(TerremarkVCloudClient tmClient, Factory sshFactory, + Predicate socketTester, Predicate successTester) { + this.tmClient = tmClient; + this.sshFactory = sshFactory; + this.socketTester = socketTester; + this.taskTester = successTester; + } + + private final Factory sshFactory; + + public enum Image { + CENTOS_53, CENTOS_53_64, RHEL_53, RHEL_53_64, UMBUNTU_JEOS_90, UMBUNTU_JEOS_90_64, UMBUNTU_SERVER_90, UMBUNTU_SERVER_90_64 + } + + private Map imageCatalogNameMap = ImmutableMap. builder().put( + Image.CENTOS_53, "CentOS 5.3 (32-bit)").put(Image.RHEL_53, "RHEL 5.3 (32-bit)").put( + Image.UMBUNTU_JEOS_90, "Ubuntu JeOS 9.04 (32-bit)").put(Image.UMBUNTU_SERVER_90, + "Ubuntu Server 9.04 (64-bit)").put(Image.CENTOS_53_64, "CentOS 5.3 (64-bit)").put( + Image.RHEL_53_64, "RHEL 5.3 (64-bit)").put(Image.UMBUNTU_JEOS_90_64, + "Ubuntu JeOS 9.04 (64-bit)").put(Image.UMBUNTU_SERVER_90_64, + "Ubuntu Server 9.04 (64-bit)").build(); + + private Map catalogNameTemplateIdMap = new MapMaker() + .makeComputingMap(new Function() { + @Override + public String apply(String from) { + return tmClient.getCatalog().get(from).getId(); + } + }); + + public String start(String name, int minCores, int minMegs, Image image) { + checkArgument(imageCatalogNameMap.containsKey(image), "image not configured: " + image); + String templateId = catalogNameTemplateIdMap.get(imageCatalogNameMap.get(image)); + + logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) image(%s)", name, + minCores, minMegs, image); + VApp vApp = tmClient.instantiateVAppTemplate(name, templateId, + InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); + logger.debug("<< instantiated VApp(%s)", vApp.getId()); + + logger.debug(">> deploying vApp(%s)", vApp.getId()); + vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.deployVApp(vApp.getId()), + "deploy", VAppStatus.OFF); + logger.debug("<< deployed vApp(%s)", vApp.getId()); + + logger.debug(">> powering vApp(%s)", vApp.getId()); + vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()), + "powerOn", VAppStatus.ON); + logger.debug("<< on vApp(%s)", vApp.getId()); + + return vApp.getId(); + } + + /** + * + * @throws ElementNotFoundException + * if no address is configured + */ + public InetAddress getAnyPrivateAddress(String id) { + VApp vApp = tmClient.getVApp(id); + return Iterables.getLast(vApp.getNetworkToAddresses().values()); + } + + public void testSsh(InetAddress address) { + InetSocketAddress sshSocket = new InetSocketAddress(address, 22); + logger.debug(">> sshConnect socket(%s)", sshSocket); + checkSsh(sshSocket, "vcloud", "p4ssw0rd"); + logger.debug("<< sshOk socket(%s)", sshSocket); + } + + public void reboot(String id) { + VApp vApp = tmClient.getVApp(id); + logger.debug(">> rebooting vApp(%s)", vApp.getId()); + blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset", + VAppStatus.ON); + logger.debug("<< on vApp(%s)", vApp.getId()); + } + + public void stop(String id) { + VApp vApp = tmClient.getVApp(id); + if (vApp.getStatus() != VAppStatus.OFF) { + logger.debug(">> powering off vApp(%s)", vApp.getId()); + blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()), + "powerOff", VAppStatus.OFF); + logger.debug("<< off vApp(%s)", vApp.getId()); + } + logger.debug(">> deleting vApp(%s)", vApp.getId()); + tmClient.deleteVApp(id); + logger.debug("<< deleted vApp(%s)", vApp.getId()); + } + + private void checkSsh(InetSocketAddress socket, String username, String password) { + if (!socketTester.apply(socket)) { + throw new SocketNotOpenException(socket); + } + SshClient connection = sshFactory.create(socket, username, password); + try { + connection.connect(); + } finally { + if (connection != null) + connection.disconnect(); + } + } + + private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType, + VAppStatus expectedStatus) { + if (!taskTester.apply(deployTask.getLocation())) { + throw new TaskException(taskType, vApp, deployTask); + } + + vApp = tmClient.getVApp(vApp.getId()); + if (vApp.getStatus() != expectedStatus) { + throw new VAppException(String.format("vApp %s status %s should be %s after %s", vApp + .getId(), vApp.getStatus(), expectedStatus, taskType), vApp); + } + return vApp; + } + + public static class TaskException extends VAppException { + + private final Task task; + /** The serialVersionUID */ + private static final long serialVersionUID = 251801929573211256L; + + public TaskException(String type, VApp vApp, Task task) { + super(String.format("failed to %s vApp %s status %s;task %s status %s", type, + vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); + this.task = task; + } + + public Task getTask() { + return task; + } + + } + + public static class SocketNotOpenException extends RuntimeException { + + private final InetSocketAddress socket; + /** The serialVersionUID */ + private static final long serialVersionUID = 251801929573211256L; + + public SocketNotOpenException(InetSocketAddress socket) { + super("socket not open: " + socket); + this.socket = socket; + } + + public InetSocketAddress getSocket() { + return socket; + } + + } + + public static class VAppException extends RuntimeException { + + private final VApp vApp; + /** The serialVersionUID */ + private static final long serialVersionUID = 251801929573211256L; + + public VAppException(String message, VApp vApp) { + super(message); + this.vApp = vApp; + } + + public VApp getvApp() { + return vApp; + } + + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java index bd58d48a32..9ab22bb98a 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java @@ -27,6 +27,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -35,7 +36,6 @@ import org.jclouds.http.functions.config.ParserModule; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; -import org.jclouds.vcloud.config.VCloudRestClientModuleTest; import org.testng.annotations.Test; import com.google.inject.AbstractModule; @@ -47,14 +47,14 @@ import com.google.inject.Key; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.TerremarkVCloudRestClientModuleTest") -public class TerremarkVCloudRestClientModuleTest extends VCloudRestClientModuleTest { +public class TerremarkVCloudRestClientModuleTest { - @Override protected Injector createInjector() { return Guice.createInjector(new TerremarkVCloudRestClientModule(), new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() { @Override protected void configure() { + bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to( diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java index 5eec2d5102..114ad2f811 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java @@ -55,8 +55,8 @@ public class InternetServiceHandlerTest extends BaseHandlerTest { InternetService result = (InternetService) factory.create( injector.getInstance(InternetServiceHandler.class)).parse(is); - assertEquals(result, new InternetService(523, "IS_for_Jim", null, new PublicIpAddress(4208, - InetAddress.getByName("10.1.22.159"), null), 80, "HTTP", false, 1, + assertEquals(result, new InternetService(523 + "", "IS_for_Jim", null, new PublicIpAddress( + 4208, InetAddress.getByName("10.1.22.159"), null), 80, "HTTP", false, 1, "Some test service")); } @@ -68,7 +68,7 @@ public class InternetServiceHandlerTest extends BaseHandlerTest { assertEquals( result, new InternetService( - 524, + 524 + "", "IS_for_Jim2", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"), diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java index 072ffca053..9cfc74b488 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java @@ -45,9 +45,8 @@ public class NodeHandlerTest extends BaseHandlerTest { public void test1() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/terremark/NodeService.xml"); - Node result = (Node) factory.create( - injector.getInstance(NodeHandler.class)).parse(is); - assertEquals(result, new Node(242, "Node for Jim", URI + Node result = (Node) factory.create(injector.getInstance(NodeHandler.class)).parse(is); + assertEquals(result, new Node(242 + "", "Node for Jim", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"), InetAddress.getByName("172.16.20.3"), 80, false, "Some test node")); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java index 2d56f5e5f6..45e7819359 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java @@ -85,7 +85,7 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( is); - assertEquals(result.getId(), 13775); + assertEquals(result.getId(), 13775+""); assertEquals(result.getName(), "adriantest"); assertEquals(result.getStatus(), VAppStatus.CREATING); @@ -105,7 +105,7 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( is); - assertEquals(result.getId(), 13850); + assertEquals(result.getId(), 13850+""); assertEquals(result.getName(), "adriantest1"); assertEquals(result.getStatus(), VAppStatus.OFF); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java index a9477c0836..4e2a481fb4 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java @@ -34,7 +34,7 @@ import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.internal.NamedLinkImpl; -import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.endpoints.VCloudApi; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.testng.annotations.Test; @@ -62,7 +62,7 @@ public class TerremarkVDCHandlerTest { @SuppressWarnings("unused") @Provides - @VCloud + @VCloudApi URI provide() { return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); }