Issue 112: added datacenter to instantiate vapp args, added getOrganization

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2458 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-18 01:16:16 +00:00
parent 8116d47b67
commit 4280bd1f14
32 changed files with 470 additions and 821 deletions

View File

@ -47,14 +47,17 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.VAppTemplateIdToUri; import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VAppHandler;
@ -70,6 +73,12 @@ import org.jclouds.vcloud.xml.VDCHandler;
@RequestFilters(SetVCloudTokenCookie.class) @RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudAsyncClient { public interface VCloudAsyncClient {
@GET
@Endpoint(Org.class)
@Consumes(VCloudMediaType.ORG_XML)
@XMLResponseParser(OrgHandler.class)
Future<? extends Organization> getOrganization();
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML) @Consumes(CATALOG_XML)
@ -91,19 +100,19 @@ public interface VCloudAsyncClient {
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/action/deploy") @Path("/vApp/{vAppId}/action/deploy")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> deployVApp(@PathParam("vAppId") String vAppId); Future<? extends Task> deployVApp(@PathParam("vAppId") String vAppId);
@DELETE @DELETE
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vApp/{vAppId}")
Future<Void> deleteVApp(@PathParam("vAppId") String vAppId); Future<Void> deleteVApp(@PathParam("vAppId") String vAppId);
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/action/undeploy") @Path("/vApp/{vAppId}/action/undeploy")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> undeployVApp(@PathParam("vAppId") String vAppId); Future<? extends Task> undeployVApp(@PathParam("vAppId") String vAppId);
@ -113,7 +122,7 @@ public interface VCloudAsyncClient {
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/powerOn") @Path("/vApp/{vAppId}/power/action/powerOn")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> powerOnVApp(@PathParam("vAppId") String vAppId); Future<? extends Task> powerOnVApp(@PathParam("vAppId") String vAppId);
@ -123,7 +132,7 @@ public interface VCloudAsyncClient {
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/powerOff") @Path("/vApp/{vAppId}/power/action/powerOff")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> powerOffVApp(@PathParam("vAppId") String vAppId); Future<? extends Task> powerOffVApp(@PathParam("vAppId") String vAppId);
@ -132,7 +141,7 @@ public interface VCloudAsyncClient {
*/ */
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/shutdown") @Path("/vApp/{vAppId}/power/action/shutdown")
Future<Void> shutdownVApp(@PathParam("vAppId") String vAppId); Future<Void> shutdownVApp(@PathParam("vAppId") String vAppId);
/** /**
@ -141,7 +150,7 @@ public interface VCloudAsyncClient {
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/reset") @Path("/vApp/{vAppId}/power/action/reset")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> resetVApp(@PathParam("vAppId") String vAppId); Future<? extends Task> resetVApp(@PathParam("vAppId") String vAppId);
@ -151,7 +160,7 @@ public interface VCloudAsyncClient {
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/suspend") @Path("/vApp/{vAppId}/power/action/suspend")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> suspendVApp(@PathParam("vAppId") String vAppId); Future<? extends Task> suspendVApp(@PathParam("vAppId") String vAppId);
@ -170,18 +179,18 @@ public interface VCloudAsyncClient {
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vApp/{vAppId}")
@XMLResponseParser(VAppHandler.class) @XMLResponseParser(VAppHandler.class)
Future<? extends VApp> getVApp(@PathParam("vAppId") String appId); Future<? extends VApp> getVApp(@PathParam("vAppId") String appId);
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/action/instantiateVAppTemplate") @Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class) @XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
Future<? extends VApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName, Future<? extends VApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options); @PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
} }

View File

@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
@ -42,6 +43,11 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient { public interface VCloudClient {
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within
* the organization.
*/
Organization getOrganization();
Catalog getCatalog(); Catalog getCatalog();
@ -86,6 +92,6 @@ public interface VCloudClient {
VApp getVApp(String appId); VApp getVApp(String appId);
VApp instantiateVAppTemplate(String appName, String templateId, VApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
} }

View File

@ -33,7 +33,6 @@ import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.RestContextBuilder;
import org.jclouds.vcloud.config.VCloudContextModule; import org.jclouds.vcloud.config.VCloudContextModule;
import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -62,7 +61,6 @@ public class VCloudContextBuilder extends RestContextBuilder<VCloudAsyncClient,
@Override @Override
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {
modules.add(new VCloudDiscoveryRestClientModule());
modules.add(new VCloudRestClientModule()); modules.add(new VCloudRestClientModule());
} }

View File

@ -1,58 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.util.concurrent.Future;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.OrgHandler;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudDiscovery {
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within
* the organization.
*/
@GET
@Endpoint(Org.class)
@Consumes(VCloudMediaType.ORG_XML)
@XMLResponseParser(OrgHandler.class)
Future<? extends Organization> getOrganization();
}

View File

@ -1,156 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.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;
import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.encryption.EncryptionService;
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;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class VCloudDiscoveryRestClientModule extends AbstractModule {
@Override
protected void configure() {
}
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
return cache.get().getVCloudToken();
}
@Provides
@Org
@Singleton
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
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
*/
@Provides
@Singleton
Supplier<VCloudSession> provideVCloudTokenCache(
@Named(PROPERTY_VCLOUD_SESSIONINTERVAL) long seconds, final VCloudLogin login) {
return new ExpirableSupplier<VCloudSession>(new Supplier<VCloudSession>() {
public VCloudSession get() {
try {
return login.login().get(180, TimeUnit.SECONDS);
} catch (Exception e) {
Utils.<RuntimeException> rethrowIfRuntimeOrSameType(e);
throw new RuntimeException("Error logging in", e);
}
}
}, seconds, TimeUnit.SECONDS);
}
@Provides
@Singleton
@VCloud
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(180, TimeUnit.SECONDS).get(version);
}
@Provides
@Singleton
protected VCloudLogin provideVCloudLogin(RestClientFactory factory) {
return factory.create(VCloudLogin.class);
}
@Provides
@Singleton
protected VCloudDiscovery provideVCloudDiscovery(RestClientFactory factory) {
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,
@Named(PROPERTY_VCLOUD_KEY) String key, EncryptionService encryptionService)
throws UnsupportedEncodingException {
return new BasicAuthentication(user, key, encryptionService);
}
}

View File

@ -24,9 +24,15 @@
package org.jclouds.vcloud.config; package org.jclouds.vcloud.config;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
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.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -35,30 +41,40 @@ import java.util.concurrent.TimeoutException;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.RestClientFactory;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudDiscovery; import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList; import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.endpoints.VCloudLogin; import org.jclouds.vcloud.endpoints.VCloudLogin;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot; import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
* Configures the VCloud authentication service connection, including logging * Configures the VCloud authentication service connection, including logging and http transport.
* and http transport.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -70,6 +86,81 @@ public class VCloudRestClientModule extends AbstractModule {
protected void configure() { protected void configure() {
} }
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
return cache.get().getVCloudToken();
}
@Provides
@Org
@Singleton
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
return Iterables.getLast(cache.get().getOrgs().values()).getLocation();
}
@Provides
@VCloudApi
@Singleton
URI provideVCloudApi(@VCloudLogin URI vcloudUri) {
return URI.create(vcloudUri.toASCIIString().replace("/login", ""));
}
/**
* borrowing concurrency code to ensure that caching takes place properly
*/
@Provides
@Singleton
Supplier<VCloudSession> provideVCloudTokenCache(
@Named(PROPERTY_VCLOUD_SESSIONINTERVAL) long seconds, final VCloudLoginAsyncClient login) {
return new ExpirableSupplier<VCloudSession>(new Supplier<VCloudSession>() {
public VCloudSession get() {
try {
return login.login().get(180, TimeUnit.SECONDS);
} catch (Exception e) {
Utils.<RuntimeException> rethrowIfRuntimeOrSameType(e);
throw new RuntimeException("Error logging in", e);
}
}
}, seconds, TimeUnit.SECONDS);
}
@Provides
@Singleton
@VCloud
protected URI provideBaseURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_VCLOUD_VERSION) String version) throws InterruptedException,
ExecutionException, TimeoutException {
return versionService.getSupportedVersions().get(180, TimeUnit.SECONDS).get(version);
}
@Provides
@Singleton
protected VCloudLoginAsyncClient provideVCloudLogin(RestClientFactory factory) {
return factory.create(VCloudLoginAsyncClient.class);
}
@Provides
@Singleton
protected VCloudVersionsAsyncClient provideVCloudVersions(RestClientFactory factory) {
return factory.create(VCloudVersionsAsyncClient.class);
}
@Provides
@Singleton
public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUD_USER) String user,
@Named(PROPERTY_VCLOUD_KEY) String key, EncryptionService encryptionService)
throws UnsupportedEncodingException {
return new BasicAuthentication(user, key, encryptionService);
}
@Provides @Provides
@Singleton @Singleton
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) { protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
@ -78,9 +169,8 @@ public class VCloudRestClientModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
public VCloudClient provideClient(VCloudAsyncClient client) public VCloudClient provideClient(VCloudAsyncClient client) throws IllegalArgumentException,
throws IllegalArgumentException, SecurityException, SecurityException, NoSuchMethodException {
NoSuchMethodException {
return SyncProxy.create(VCloudClient.class, client); return SyncProxy.create(VCloudClient.class, client);
} }
@ -107,9 +197,9 @@ public class VCloudRestClientModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
protected Organization provideOrganization(VCloudDiscovery discovery) protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException,
throws ExecutionException, TimeoutException, InterruptedException { TimeoutException, InterruptedException {
return discovery.getOrganization().get(180, TimeUnit.SECONDS); return discovery.getOrganization();
} }
@Provides @Provides
@ -130,19 +220,17 @@ public class VCloudRestClientModule extends AbstractModule {
@Provides @Provides
@Named("InstantiateVAppTemplateParams") @Named("InstantiateVAppTemplateParams")
protected String provideInstantiateVAppTemplateParams() throws IOException { protected String provideInstantiateVAppTemplateParams() throws IOException {
InputStream is = getClass().getResourceAsStream( InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
"/InstantiateVAppTemplateParams.xml");
return Utils.toStringAndClose(is); return Utils.toStringAndClose(is);
} }
@Provides @Provides
@Network @Network
@Singleton @Singleton
protected URI provideDefaultNetwork(VCloudAsyncClient client) protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
throws InterruptedException, ExecutionException, TimeoutException { ExecutionException, TimeoutException {
return client.getDefaultVDC().get(180, TimeUnit.SECONDS) return client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks().values()
.getAvailableNetworks().values().iterator().next() .iterator().next().getLocation();
.getLocation();
} }
@Provides @Provides

View File

@ -40,8 +40,8 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.VCloudToken; import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.xml.OrgListHandler; import org.jclouds.vcloud.xml.OrgListHandler;
import com.google.common.base.Function; import com.google.common.base.Function;

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud.internal;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -34,6 +34,8 @@ import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
@ -46,7 +48,7 @@ import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
*/ */
@Endpoint(org.jclouds.vcloud.endpoints.VCloudLogin.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudLogin.class)
@RequestFilters(BasicAuthentication.class) @RequestFilters(BasicAuthentication.class)
public interface VCloudLogin { public interface VCloudLoginAsyncClient {
public interface VCloudSession { public interface VCloudSession {
@VCloudToken @VCloudToken

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud.internal;
import java.net.URI; import java.net.URI;
import java.util.SortedMap; import java.util.SortedMap;
@ -33,6 +33,7 @@ import javax.ws.rs.Path;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.xml.SupportedVersionsHandler; import org.jclouds.vcloud.xml.SupportedVersionsHandler;
@ -44,7 +45,7 @@ import org.jclouds.vcloud.xml.SupportedVersionsHandler;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Endpoint(VCloud.class) @Endpoint(VCloud.class)
public interface VCloudVersions { public interface VCloudVersionsAsyncClient {
/** /**
* Retrieve information for supported versions * Retrieve information for supported versions

View File

@ -39,6 +39,7 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList; import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.endpoints.VCloudApi; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
@ -46,6 +47,7 @@ import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VAppHandler;
@ -63,15 +65,27 @@ import com.google.inject.TypeLiteral;
*/ */
@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest") @Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> { public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganization");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog"); Method method = VCloudAsyncClient.class.getMethod("getCatalog");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
httpMethod,
"Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -116,7 +130,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/deploy HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/action/deploy HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -131,7 +145,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "GET http://vcloud/vapp/1 HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://vcloud/vApp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -146,7 +160,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/undeploy HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/action/undeploy HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -161,7 +175,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vapp/1 HTTP/1.1"); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vApp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -176,7 +190,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/powerOn HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/power/action/powerOn HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -192,7 +206,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://vcloud/vapp/1/power/action/powerOff HTTP/1.1"); "POST http://vcloud/vApp/1/power/action/powerOff HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -207,7 +221,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/reset HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/power/action/reset HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -222,7 +236,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/suspend HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/power/action/suspend HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -238,7 +252,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://vcloud/vapp/1/power/action/shutdown HTTP/1.1"); "POST http://vcloud/vApp/1/power/action/shutdown HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
@ -296,10 +310,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
return new AbstractModule() { return new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
bind(String.class).annotatedWith(CatalogItemRoot.class) bind(String.class).annotatedWith(CatalogItemRoot.class)
.toInstance("http://catalogItem"); .toInstance("http://catalogItem");
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapps"); bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vApps");
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
bind(URI.class).annotatedWith(TasksList.class).toInstance( bind(URI.class).annotatedWith(TasksList.class).toInstance(
URI.create("http://tasksList")); URI.create("http://tasksList"));

View File

@ -32,6 +32,7 @@ import java.net.URI;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
@ -51,6 +52,16 @@ public class VCloudClientLiveTest {
@Test @Test
public void testOrganization() throws Exception { public void testOrganization() throws Exception {
Organization response = connection.getOrganization();
assertNotNull(response);
assertNotNull(account);
assertNotNull(response.getCatalog());
assertEquals(response.getTasksLists().size(), 1);
assertEquals(response.getVDCs().size(), 1);
}
@Test
public void testCatalog() throws Exception {
Catalog response = connection.getCatalog(); Catalog response = connection.getCatalog();
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());

View File

@ -84,10 +84,10 @@ public class VCloudComputeClient {
public String start(String name, int minCores, int minMegs, Image image) { public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
String templateId = imageCatalogIdMap.get(image); String templateId = imageCatalogIdMap.get(image);
String vDCId = tmClient.getDefaultVDC().getId();
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name, logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
minCores, minMegs, templateId); name, minCores, minMegs, templateId, vDCId);
VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
tmClient.getVApp(vAppResponse.getId()); tmClient.getVApp(vAppResponse.getId());
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());

View File

@ -1,130 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.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;
import java.net.URI;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.reference.VCloudConstants;
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 VCloudDiscovery}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.VCloudDiscoveryLiveTest")
public class VCloudDiscoveryLiveTest {
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint");
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
private final class VCloudDiscoveryContextModule extends AbstractModule {
@SuppressWarnings( { "unused" })
@Provides
@Singleton
RestContext<VCloudDiscovery, VCloudDiscovery> provideContext(Closer closer,
VCloudDiscovery api, @VCloud URI endPoint,
@Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
return new RestContextImpl<VCloudDiscovery, VCloudDiscovery>(closer, api, api, endPoint,
account);
}
@Override
protected void configure() {
}
}
private RestContext<VCloudDiscovery, VCloudDiscovery> context;
@Test
public void testOrganization() throws Exception {
Organization response = context.getAsyncApi().getOrganization().get(45, TimeUnit.SECONDS);
assertNotNull(response);
assertNotNull(account);
assertNotNull(response.getCatalog());
assertEquals(response.getTasksLists().size(), 1);
assertEquals(response.getVDCs().size(), 1);
}
@BeforeClass
void setupFactory() {
context = new RestContextBuilder<VCloudDiscovery, VCloudDiscovery>(
new TypeLiteral<VCloudDiscovery>() {
}, new TypeLiteral<VCloudDiscovery>() {
}, new Properties()) {
public void addContextModule(List<Module> modules) {
modules.add(new VCloudDiscoveryContextModule());
}
@Override
protected void addClientModule(List<Module> 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");
modules.add(new VCloudDiscoveryRestClientModule());
}
}.withModules(new Log4JLoggingModule(),
new ExecutorServiceModule(new WithinThreadExecutorService())).buildContext();
}
}

View File

@ -1,116 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.inject.Provider;
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.Org;
import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.OrgHandler;
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 VCloudDiscovery}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudDiscoveryTest")
public class VCloudDiscoveryTest extends RestClientTest<VCloudDiscovery> {
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudDiscovery.class.getMethod("getOrganization");
GeneratedHttpRequest<VCloudDiscovery> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
@Override
protected void checkFilters(GeneratedHttpRequest<VCloudDiscovery> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<VCloudDiscovery>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VCloudDiscovery>>() {
};
}
@Override
protected Module createModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
bind(SetVCloudTokenCookie.class).toInstance(
new SetVCloudTokenCookie(new Provider<String>() {
public String get() {
return "token";
}
}));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
@SuppressWarnings("unused")
@Provides
@VCloudApi
URI provide() {
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
}
};
}
}

View File

@ -30,6 +30,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -40,14 +41,19 @@ import javax.inject.Singleton;
import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; 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.RestContext;
import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudLogin.VCloudSession; import org.jclouds.vcloud.endpoints.VCloudLogin;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.reference.VCloudConstants; import org.jclouds.vcloud.reference.VCloudConstants;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -65,14 +71,46 @@ import com.google.inject.TypeLiteral;
@Test(groups = "live", testName = "vcloud.VCloudLoginLiveTest") @Test(groups = "live", testName = "vcloud.VCloudLoginLiveTest")
public class VCloudLoginLiveTest { public class VCloudLoginLiveTest {
@RequiresHttp
@ConfiguresRestClient
private static final class VCloudLoginRestClientModule extends AbstractModule {
final String endpoint;
public VCloudLoginRestClientModule(String endpoint) {
this.endpoint = endpoint;
}
@SuppressWarnings("unused")
@Provides
@Singleton
protected VCloudLoginAsyncClient provideVCloudLogin(RestClientFactory factory) {
return factory.create(VCloudLoginAsyncClient.class);
}
@SuppressWarnings("unused")
@Provides
@Singleton
public BasicAuthentication provideBasicAuthentication(
@Named(PROPERTY_VCLOUD_USER) String user, @Named(PROPERTY_VCLOUD_KEY) String key,
EncryptionService encryptionService) throws UnsupportedEncodingException {
return new BasicAuthentication(user, key, encryptionService);
}
@Override
protected void configure() {
bind(URI.class).annotatedWith(VCloudLogin.class).toInstance(URI.create(endpoint));
}
}
private final class VCloudLoginContextModule extends AbstractModule { private final class VCloudLoginContextModule extends AbstractModule {
@SuppressWarnings( { "unused" }) @SuppressWarnings( { "unused" })
@Provides @Provides
@Singleton @Singleton
RestContext<VCloudLogin, VCloudLogin> provideContext(Closer closer, VCloudLogin api, RestContext<VCloudLoginAsyncClient, VCloudLoginAsyncClient> provideContext(Closer closer,
@VCloud URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) { VCloudLoginAsyncClient api, @VCloudLogin URI endPoint) {
return new RestContextImpl<VCloudLogin, VCloudLogin>(closer, api, api, endPoint, account); return new RestContextImpl<VCloudLoginAsyncClient, VCloudLoginAsyncClient>(closer, api,
api, endPoint, "");
} }
@Override @Override
@ -81,16 +119,11 @@ public class VCloudLoginLiveTest {
} }
} }
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), private RestContext<VCloudLoginAsyncClient, VCloudLoginAsyncClient> context;
"jclouds.test.endpoint");
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
private RestContext<VCloudLogin, VCloudLogin> context;
@Test @Test
public void testLogin() throws Exception { public void testLogin() throws Exception {
VCloudLogin authentication = context.getAsyncApi(); VCloudLoginAsyncClient authentication = context.getAsyncApi();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
VCloudSession response = authentication.login().get(45, TimeUnit.SECONDS); VCloudSession response = authentication.login().get(45, TimeUnit.SECONDS);
assertNotNull(response); assertNotNull(response);
@ -101,8 +134,15 @@ public class VCloudLoginLiveTest {
@BeforeClass @BeforeClass
void setupFactory() { void setupFactory() {
context = new RestContextBuilder<VCloudLogin, VCloudLogin>(new TypeLiteral<VCloudLogin>() { final String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
}, new TypeLiteral<VCloudLogin>() { "jclouds.test.endpoint");
final String account = checkNotNull(System.getProperty("jclouds.test.user"),
"jclouds.test.user");
final String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
context = new RestContextBuilder<VCloudLoginAsyncClient, VCloudLoginAsyncClient>(
new TypeLiteral<VCloudLoginAsyncClient>() {
}, new TypeLiteral<VCloudLoginAsyncClient>() {
}, new Properties()) { }, new Properties()) {
public void addContextModule(List<Module> modules) { public void addContextModule(List<Module> modules) {
@ -118,7 +158,7 @@ public class VCloudLoginLiveTest {
properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user"));
properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key"));
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4");
modules.add(new VCloudDiscoveryRestClientModule()); modules.add(new VCloudLoginRestClientModule(endpoint));
} }
}.withModules(new Log4JLoggingModule(), }.withModules(new Log4JLoggingModule(),

View File

@ -40,6 +40,7 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -52,11 +53,11 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.VCloudLoginTest") @Test(groups = "unit", testName = "vcloud.VCloudLoginTest")
public class VCloudLoginTest extends RestClientTest<VCloudLogin> { public class VCloudLoginTest extends RestClientTest<VCloudLoginAsyncClient> {
public void testLogin() throws SecurityException, NoSuchMethodException, IOException { public void testLogin() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudLogin.class.getMethod("login"); Method method = VCloudLoginAsyncClient.class.getMethod("login");
GeneratedHttpRequest<VCloudLogin> httpMethod = processor.createRequest(method); GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1"); assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
@ -71,14 +72,14 @@ public class VCloudLoginTest extends RestClientTest<VCloudLogin> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<VCloudLogin> httpMethod) { protected void checkFilters(GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
} }
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<VCloudLogin>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<VCloudLoginAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VCloudLogin>>() { return new TypeLiteral<RestAnnotationProcessor<VCloudLoginAsyncClient>>() {
}; };
} }

View File

@ -45,6 +45,7 @@ import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -67,8 +68,8 @@ public class VCloudVersionsLiveTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@Singleton @Singleton
protected VCloudVersions provideVCloudVersions(RestClientFactory factory) { protected VCloudVersionsAsyncClient provideVCloudVersions(RestClientFactory factory) {
return factory.create(VCloudVersions.class); return factory.create(VCloudVersionsAsyncClient.class);
} }
@Override @Override
@ -82,9 +83,9 @@ public class VCloudVersionsLiveTest {
@SuppressWarnings( { "unused" }) @SuppressWarnings( { "unused" })
@Provides @Provides
@Singleton @Singleton
RestContext<VCloudVersions, VCloudVersions> provideContext(Closer closer, VCloudVersions api, RestContext<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient> provideContext(Closer closer, VCloudVersionsAsyncClient api,
@VCloud URI endPoint) { @VCloud URI endPoint) {
return new RestContextImpl<VCloudVersions, VCloudVersions>(closer, api, api, endPoint, ""); return new RestContextImpl<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(closer, api, api, endPoint, "");
} }
@Override @Override
@ -96,11 +97,11 @@ public class VCloudVersionsLiveTest {
static String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), static String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint"); "jclouds.test.endpoint");
private RestContext<VCloudVersions, VCloudVersions> context; private RestContext<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient> context;
@Test @Test
public void testGetSupportedVersions() throws Exception { public void testGetSupportedVersions() throws Exception {
VCloudVersions authentication = context.getAsyncApi(); VCloudVersionsAsyncClient authentication = context.getAsyncApi();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
SortedMap<String, URI> response = authentication.getSupportedVersions().get(45, SortedMap<String, URI> response = authentication.getSupportedVersions().get(45,
TimeUnit.SECONDS); TimeUnit.SECONDS);
@ -111,9 +112,9 @@ public class VCloudVersionsLiveTest {
@BeforeClass @BeforeClass
void setupFactory() { void setupFactory() {
context = new RestContextBuilder<VCloudVersions, VCloudVersions>( context = new RestContextBuilder<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(
new TypeLiteral<VCloudVersions>() { new TypeLiteral<VCloudVersionsAsyncClient>() {
}, new TypeLiteral<VCloudVersions>() { }, new TypeLiteral<VCloudVersionsAsyncClient>() {
}, new Properties()) { }, new Properties()) {
public void addContextModule(List<Module> modules) { public void addContextModule(List<Module> modules) {

View File

@ -38,6 +38,7 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.xml.SupportedVersionsHandler; import org.jclouds.vcloud.xml.SupportedVersionsHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -51,11 +52,11 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.VCloudVersionsTest") @Test(groups = "unit", testName = "vcloud.VCloudVersionsTest")
public class VCloudVersionsTest extends RestClientTest<VCloudVersions> { public class VCloudVersionsTest extends RestClientTest<VCloudVersionsAsyncClient> {
public void testLogin() throws SecurityException, NoSuchMethodException, IOException { public void testLogin() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudVersions.class.getMethod("getSupportedVersions"); Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions");
GeneratedHttpRequest<VCloudVersions> httpMethod = processor.createRequest(method); GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1"); assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": application/vnd.vmware.vcloud.vcloud+xml\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": application/vnd.vmware.vcloud.vcloud+xml\n");
@ -69,13 +70,13 @@ public class VCloudVersionsTest extends RestClientTest<VCloudVersions> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<VCloudVersions> httpMethod) { protected void checkFilters(GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 0); assertEquals(httpMethod.getFilters().size(), 0);
} }
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<VCloudVersions>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<VCloudVersionsAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VCloudVersions>>() { return new TypeLiteral<RestAnnotationProcessor<VCloudVersionsAsyncClient>>() {
}; };
} }

View File

@ -1,161 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.functions.config.ParserModule;
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.NamedResource;
import org.jclouds.util.Jsr330;
import org.jclouds.vcloud.VCloudLogin;
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudDiscoveryRestClientModuleTest")
public class VCloudDiscoveryRestClientModuleTest {
Injector createInjector() {
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(
"http://localhost");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL))
.to("2");
}
});
}
public static abstract class FutureBase<V> implements Future<V> {
public boolean cancel(boolean b) {
return false;
}
public boolean isCancelled() {
return false;
}
public boolean isDone() {
return true;
}
public V get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
return get();
}
}
@Test
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
VCloudDiscoveryRestClientModule module = new VCloudDiscoveryRestClientModule();
VCloudLogin login = new VCloudLogin() {
private final AtomicInteger token = new AtomicInteger();
public Future<VCloudSession> login() {
return new FutureBase<VCloudSession>() {
@Override
public VCloudSession get() throws InterruptedException, ExecutionException {
return new VCloudSession() {
public Map<String, NamedResource> getOrgs() {
return null;
}
public String getVCloudToken() {
return token.incrementAndGet() + "";
}
};
}
};
}
};
Supplier<VCloudSession> map = module.provideVCloudTokenCache(1, login);
for (int i = 0; i < 10; i++)
map.get();
assert "1".equals(map.get().getVCloudToken());
Thread.sleep(1001);
assert "2".equals(map.get().getVCloudToken());
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
}
}

View File

@ -31,12 +31,27 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSI
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
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.rest.domain.NamedResource;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -49,8 +64,8 @@ import com.google.inject.Key;
public class VCloudRestClientModuleTest { public class VCloudRestClientModuleTest {
protected Injector createInjector() { protected Injector createInjector() {
return Guice.createInjector(new VCloudRestClientModule(), return Guice.createInjector(new VCloudRestClientModule(), new ParserModule(),
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() { new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8");
@ -73,4 +88,86 @@ public class VCloudRestClientModuleTest {
} }
@Test
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
VCloudRestClientModule module = new VCloudRestClientModule();
VCloudLoginAsyncClient login = new VCloudLoginAsyncClient() {
private final AtomicInteger token = new AtomicInteger();
public Future<VCloudSession> login() {
return new Future<VCloudSession>() {
@Override
public VCloudSession get() throws InterruptedException, ExecutionException {
return new VCloudSession() {
public Map<String, NamedResource> getOrgs() {
return null;
}
public String getVCloudToken() {
return token.incrementAndGet() + "";
}
};
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public VCloudSession get(long timeout, TimeUnit unit) throws InterruptedException,
ExecutionException, TimeoutException {
return get();
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return false;
}
};
}
};
Supplier<VCloudSession> map = module.provideVCloudTokenCache(1, login);
for (int i = 0; i < 10; i++)
map.get();
assert "1".equals(map.get().getVCloudToken());
Thread.sleep(1001);
assert "2".equals(map.get().getVCloudToken());
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
}
} }

View File

@ -33,7 +33,7 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.internal.NamedResourceImpl; import org.jclouds.rest.internal.NamedResourceImpl;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudLogin.VCloudSession; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -79,8 +79,8 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
Future<? extends HostingDotComVApp> getVApp(@PathParam("vAppId") String appId); Future<? extends HostingDotComVApp> getVApp(@PathParam("vAppId") String appId);
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/action/instantiateVAppTemplate") @Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
// required for hosting.com to operate // required for hosting.com to operate
@ -90,5 +90,5 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
Future<? extends HostingDotComVApp> instantiateVAppTemplate( Future<? extends HostingDotComVApp> instantiateVAppTemplate(
@MapPayloadParam("name") String appName, @MapPayloadParam("name") String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options); @PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
} }

View File

@ -42,7 +42,7 @@ public interface HostingDotComVCloudClient extends VCloudClient {
@Override @Override
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
HostingDotComVApp instantiateVAppTemplate(String appName, String templateId, HostingDotComVApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
@Override @Override

View File

@ -32,7 +32,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.RestContextBuilder;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudContextModule; import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudContextModule;
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule; import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule;
@ -64,7 +63,6 @@ public class HostingDotComVCloudContextBuilder extends
@Override @Override
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {
modules.add(new VCloudDiscoveryRestClientModule());
modules.add(new HostingDotComVCloudRestClientModule()); modules.add(new HostingDotComVCloudRestClientModule());
} }

View File

@ -69,12 +69,11 @@ public class HostingDotComVCloudComputeClient {
public Map<String, String> start(String name, int minCores, int minMegs, Image image) { public Map<String, String> start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
String templateId = imageCatalogIdMap.get(image); String templateId = imageCatalogIdMap.get(image);
String vDCId = tmClient.getDefaultVDC().getId();
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name, logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
minCores, minMegs, templateId); name, minCores, minMegs, templateId, vDCId);
HostingDotComVApp vAppResponse = (HostingDotComVApp) tmClient.instantiateVAppTemplate(name, HostingDotComVApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
templateId, InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes( InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
minMegs));
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
logger.debug(">> deploying vApp(%s)", vAppResponse.getId()); logger.debug(">> deploying vApp(%s)", vAppResponse.getId());

View File

@ -95,15 +95,15 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
* @see TerremarkVCloudClient#instantiateVAppTemplate * @see TerremarkVCloudClient#instantiateVAppTemplate
*/ */
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/action/instantiatevAppTemplate") @Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@XMLResponseParser(TerremarkVAppHandler.class) @XMLResponseParser(TerremarkVAppHandler.class)
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class) @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
@Override @Override
Future<? extends TerremarkVApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName, Future<? extends TerremarkVApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName,
@MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId, @MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options); @PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
/** /**
* @see TerremarkVCloudClient#addInternetService * @see TerremarkVCloudClient#addInternetService
@ -114,7 +114,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@Produces(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML)
@XMLResponseParser(InternetServiceHandler.class) @XMLResponseParser(InternetServiceHandler.class)
@MapBinder(AddInternetServiceOptions.class) @MapBinder(AddInternetServiceOptions.class)
Future<? extends InternetService> addInternetService(@MapPayloadParam("name") String serviceName, Future<? extends InternetService> addInternetService(
@MapPayloadParam("name") String serviceName,
@MapPayloadParam("protocol") Protocol protocol, @MapPayloadParam("port") int port, @MapPayloadParam("protocol") Protocol protocol, @MapPayloadParam("port") int port,
AddInternetServiceOptions... options); AddInternetServiceOptions... options);

View File

@ -51,7 +51,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
public interface TerremarkVCloudClient extends VCloudClient { public interface TerremarkVCloudClient extends VCloudClient {
@Override @Override
TerremarkVApp instantiateVAppTemplate(String appName, String templateId, TerremarkVApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
@Override @Override

View File

@ -32,7 +32,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.RestContextBuilder;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudContextModule; import org.jclouds.vcloud.terremark.config.TerremarkVCloudContextModule;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudRestClientModule; import org.jclouds.vcloud.terremark.config.TerremarkVCloudRestClientModule;
@ -64,7 +63,6 @@ public class TerremarkVCloudContextBuilder extends
@Override @Override
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {
modules.add(new VCloudDiscoveryRestClientModule());
modules.add(new TerremarkVCloudRestClientModule()); modules.add(new TerremarkVCloudRestClientModule());
} }

View File

@ -65,7 +65,8 @@ public class TerremarkVCloudComputeClient {
private final TerremarkVCloudClient tmClient; private final TerremarkVCloudClient tmClient;
@Inject @Inject
public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient, Predicate<String> successTester) { public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient,
Predicate<String> successTester) {
this.tmClient = tmClient; this.tmClient = tmClient;
this.taskTester = successTester; this.taskTester = successTester;
} }
@ -77,10 +78,10 @@ public class TerremarkVCloudComputeClient {
public String start(String name, int minCores, int minMegs, Image image) { public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
String templateId = imageCatalogIdMap.get(image); String templateId = imageCatalogIdMap.get(image);
String vDCId = tmClient.getDefaultVDC().getId();
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name, logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
minCores, minMegs, templateId); name, minCores, minMegs, templateId, vDCId);
TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores) TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores)
.megabytes(minMegs)); .megabytes(minMegs));
logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug("<< instantiated VApp(%s)", vApp.getId());

View File

@ -105,12 +105,13 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, String.class, String.class, String.class, Array.newInstance(
0).getClass()); InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", 3 + ""); "name", 3 + "", "1");
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); assertRequestLineEquals(httpMethod,
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, httpMethod,
"Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); "Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
@ -127,12 +128,14 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
public void testInstantiateVAppTemplateOptions() throws SecurityException, public void testInstantiateVAppTemplateOptions() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, String.class, String.class, String.class, Array.newInstance(
0).getClass()); InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); "name", 3 + "", "1", cpuCount(4).megabytes(1024).inNetwork(
URI.create("http://newnet")));
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); assertRequestLineEquals(httpMethod,
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, httpMethod,
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); "Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");

View File

@ -114,9 +114,10 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)";
String templateId = tmClient.getCatalog().get(catalogOs).getId(); String templateId = tmClient.getCatalog().get(catalogOs).getId();
String vDCId = tmClient.getDefaultVDC().getId();
System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis()); System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis());
vApp = tmClient.instantiateVAppTemplate(serverName, templateId); vApp = tmClient.instantiateVAppTemplate(serverName, templateId, vDCId);
assertEquals(vApp.getStatus(), VAppStatus.CREATING); assertEquals(vApp.getStatus(), VAppStatus.CREATING);
@ -275,8 +276,8 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
.getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make it longer then .getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make it longer then
// default internet // default internet
// service timeout // service timeout
successTester = new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), 300, 10, successTester = new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), 300,
TimeUnit.SECONDS); 10, TimeUnit.SECONDS);
} }
} }

View File

@ -35,7 +35,6 @@ import java.io.IOException;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -50,8 +49,8 @@ import com.google.inject.Key;
public class TerremarkVCloudRestClientModuleTest { public class TerremarkVCloudRestClientModuleTest {
protected Injector createInjector() { protected Injector createInjector() {
return Guice.createInjector(new TerremarkVCloudRestClientModule(), return Guice.createInjector(new TerremarkVCloudRestClientModule(), new ParserModule(),
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() { new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8");