mirror of https://github.com/apache/jclouds.git
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:
parent
8116d47b67
commit
4280bd1f14
|
@ -47,14 +47,17 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.TasksList;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||
import org.jclouds.vcloud.xml.OrgHandler;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||
import org.jclouds.vcloud.xml.VAppHandler;
|
||||
|
@ -70,6 +73,12 @@ import org.jclouds.vcloud.xml.VDCHandler;
|
|||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
public interface VCloudAsyncClient {
|
||||
|
||||
@GET
|
||||
@Endpoint(Org.class)
|
||||
@Consumes(VCloudMediaType.ORG_XML)
|
||||
@XMLResponseParser(OrgHandler.class)
|
||||
Future<? extends Organization> getOrganization();
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
|
||||
@Consumes(CATALOG_XML)
|
||||
|
@ -91,19 +100,19 @@ public interface VCloudAsyncClient {
|
|||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/action/deploy")
|
||||
@Path("/vApp/{vAppId}/action/deploy")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> deployVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
@DELETE
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}")
|
||||
@Path("/vApp/{vAppId}")
|
||||
Future<Void> deleteVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/action/undeploy")
|
||||
@Path("/vApp/{vAppId}/action/undeploy")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> undeployVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -113,7 +122,7 @@ public interface VCloudAsyncClient {
|
|||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/power/action/powerOn")
|
||||
@Path("/vApp/{vAppId}/power/action/powerOn")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> powerOnVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -123,7 +132,7 @@ public interface VCloudAsyncClient {
|
|||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/power/action/powerOff")
|
||||
@Path("/vApp/{vAppId}/power/action/powerOff")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> powerOffVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -132,7 +141,7 @@ public interface VCloudAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@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);
|
||||
|
||||
/**
|
||||
|
@ -141,7 +150,7 @@ public interface VCloudAsyncClient {
|
|||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/power/action/reset")
|
||||
@Path("/vApp/{vAppId}/power/action/reset")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> resetVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -151,7 +160,7 @@ public interface VCloudAsyncClient {
|
|||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/power/action/suspend")
|
||||
@Path("/vApp/{vAppId}/power/action/suspend")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> suspendVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -170,18 +179,18 @@ public interface VCloudAsyncClient {
|
|||
@GET
|
||||
@Consumes(VAPP_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}")
|
||||
@Path("/vApp/{vAppId}")
|
||||
@XMLResponseParser(VAppHandler.class)
|
||||
Future<? extends VApp> getVApp(@PathParam("vAppId") String appId);
|
||||
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/action/instantiateVAppTemplate")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
|
||||
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
|
||||
@Consumes(VAPP_XML)
|
||||
@XMLResponseParser(VAppHandler.class)
|
||||
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
Future<? extends VApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName,
|
||||
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
@PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.TasksList;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
|
@ -42,6 +43,11 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
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();
|
||||
|
||||
|
@ -86,6 +92,6 @@ public interface VCloudClient {
|
|||
|
||||
VApp getVApp(String appId);
|
||||
|
||||
VApp instantiateVAppTemplate(String appName, String templateId,
|
||||
VApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.vcloud.config.VCloudContextModule;
|
||||
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
||||
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -62,7 +61,6 @@ public class VCloudContextBuilder extends RestContextBuilder<VCloudAsyncClient,
|
|||
|
||||
@Override
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new VCloudDiscoveryRestClientModule());
|
||||
modules.add(new VCloudRestClientModule());
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,9 +24,15 @@
|
|||
package org.jclouds.vcloud.config;
|
||||
|
||||
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.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -35,30 +41,40 @@ import java.util.concurrent.TimeoutException;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.concurrent.ExpirableSupplier;
|
||||
import org.jclouds.concurrent.internal.SyncProxy;
|
||||
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.VCloudAsyncClient;
|
||||
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.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Network;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
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.VDC;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
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.Provides;
|
||||
|
||||
/**
|
||||
* Configures the VCloud authentication service connection, including logging
|
||||
* and http transport.
|
||||
* Configures the VCloud authentication service connection, including logging and http transport.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -66,96 +82,168 @@ import com.google.inject.Provides;
|
|||
@ConfiguresRestClient
|
||||
public class VCloudRestClientModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
|
||||
return factory.create(VCloudAsyncClient.class);
|
||||
}
|
||||
@VCloudToken
|
||||
@Provides
|
||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return cache.get().getVCloudToken();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public VCloudClient provideClient(VCloudAsyncClient client)
|
||||
throws IllegalArgumentException, SecurityException,
|
||||
NoSuchMethodException {
|
||||
return SyncProxy.create(VCloudClient.class, client);
|
||||
}
|
||||
@Provides
|
||||
@Org
|
||||
@Singleton
|
||||
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
|
||||
return Iterables.getLast(cache.get().getOrgs().values()).getLocation();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@CatalogItemRoot
|
||||
@Singleton
|
||||
String provideCatalogItemRoot(@VCloudLogin URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString().replace("/login", "/catalogItem");
|
||||
}
|
||||
@Provides
|
||||
@VCloudApi
|
||||
@Singleton
|
||||
URI provideVCloudApi(@VCloudLogin URI vcloudUri) {
|
||||
return URI.create(vcloudUri.toASCIIString().replace("/login", ""));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@VAppRoot
|
||||
@Singleton
|
||||
String provideVAppRoot(@VCloudLogin URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString().replace("/login", "/vapp");
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
@VAppTemplateRoot
|
||||
@Singleton
|
||||
String provideVAppTemplateRoot(@VCloudLogin URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString().replace("/login", "/vAppTemplate");
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
@VCloud
|
||||
protected URI provideBaseURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) {
|
||||
return URI.create(endpoint);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Organization provideOrganization(VCloudDiscovery discovery)
|
||||
throws ExecutionException, TimeoutException, InterruptedException {
|
||||
return discovery.getOrganization().get(180, TimeUnit.SECONDS);
|
||||
}
|
||||
@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
|
||||
@VDC
|
||||
@Singleton
|
||||
protected URI provideDefaultVDC(Organization org) {
|
||||
return org.getVDCs().values().iterator().next().getLocation();
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudLoginAsyncClient provideVCloudLogin(RestClientFactory factory) {
|
||||
return factory.create(VCloudLoginAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Catalog
|
||||
@Singleton
|
||||
protected URI provideCatalog(Organization org) {
|
||||
return org.getCatalog().getLocation();
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudVersionsAsyncClient provideVCloudVersions(RestClientFactory factory) {
|
||||
return factory.create(VCloudVersionsAsyncClient.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
protected String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
@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
|
||||
@Network
|
||||
@Singleton
|
||||
protected URI provideDefaultNetwork(VCloudAsyncClient client)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return client.getDefaultVDC().get(180, TimeUnit.SECONDS)
|
||||
.getAvailableNetworks().values().iterator().next()
|
||||
.getLocation();
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
|
||||
return factory.create(VCloudAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK)
|
||||
@Singleton
|
||||
String provideDefaultNetworkString(@Network URI network) {
|
||||
return network.toASCIIString();
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
public VCloudClient provideClient(VCloudAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(VCloudClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@TasksList
|
||||
@Singleton
|
||||
protected URI provideDefaultTasksList(Organization org) {
|
||||
return org.getTasksLists().values().iterator().next().getLocation();
|
||||
}
|
||||
@Provides
|
||||
@CatalogItemRoot
|
||||
@Singleton
|
||||
String provideCatalogItemRoot(@VCloudLogin URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString().replace("/login", "/catalogItem");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@VAppRoot
|
||||
@Singleton
|
||||
String provideVAppRoot(@VCloudLogin URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString().replace("/login", "/vapp");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@VAppTemplateRoot
|
||||
@Singleton
|
||||
String provideVAppTemplateRoot(@VCloudLogin URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString().replace("/login", "/vAppTemplate");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException,
|
||||
TimeoutException, InterruptedException {
|
||||
return discovery.getOrganization();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@VDC
|
||||
@Singleton
|
||||
protected URI provideDefaultVDC(Organization org) {
|
||||
return org.getVDCs().values().iterator().next().getLocation();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Catalog
|
||||
@Singleton
|
||||
protected URI provideCatalog(Organization org) {
|
||||
return org.getCatalog().getLocation();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
protected String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Network
|
||||
@Singleton
|
||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
return client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks().values()
|
||||
.iterator().next().getLocation();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK)
|
||||
@Singleton
|
||||
String provideDefaultNetworkString(@Network URI network) {
|
||||
return network.toASCIIString();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@TasksList
|
||||
@Singleton
|
||||
protected URI provideDefaultTasksList(Organization org) {
|
||||
return org.getTasksLists().values().iterator().next().getLocation();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ import org.jclouds.http.functions.ParseSax;
|
|||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.rest.domain.NamedResource;
|
||||
import org.jclouds.vcloud.VCloudToken;
|
||||
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
|
||||
import org.jclouds.vcloud.xml.OrgListHandler;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud;
|
||||
package org.jclouds.vcloud.internal;
|
||||
|
||||
import java.util.Map;
|
||||
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.ResponseParser;
|
||||
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.functions.ParseLoginResponseFromHeaders;
|
||||
|
||||
|
@ -46,7 +48,7 @@ import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
|
|||
*/
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudLogin.class)
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
public interface VCloudLogin {
|
||||
public interface VCloudLoginAsyncClient {
|
||||
|
||||
public interface VCloudSession {
|
||||
@VCloudToken
|
|
@ -21,7 +21,7 @@
|
|||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud;
|
||||
package org.jclouds.vcloud.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.SortedMap;
|
||||
|
@ -33,6 +33,7 @@ import javax.ws.rs.Path;
|
|||
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
|
||||
|
||||
|
@ -44,7 +45,7 @@ import org.jclouds.vcloud.xml.SupportedVersionsHandler;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Endpoint(VCloud.class)
|
||||
public interface VCloudVersions {
|
||||
public interface VCloudVersionsAsyncClient {
|
||||
|
||||
/**
|
||||
* Retrieve information for supported versions
|
|
@ -39,6 +39,7 @@ import org.jclouds.rest.RestClientTest;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.endpoints.TasksList;
|
||||
import org.jclouds.vcloud.endpoints.VCloudApi;
|
||||
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.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||
import org.jclouds.vcloud.xml.OrgHandler;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||
import org.jclouds.vcloud.xml.VAppHandler;
|
||||
|
@ -63,15 +65,27 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
|
||||
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 {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getCatalog");
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Accept: application/vnd.vmware.vcloud.catalog+xml\n");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -116,7 +130,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class);
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -131,7 +145,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class);
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -146,7 +160,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class);
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -161,7 +175,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class);
|
||||
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, "");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -176,7 +190,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class);
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -192,7 +206,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -207,7 +221,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class);
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -222,7 +236,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class);
|
||||
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");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -238,7 +252,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
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, "");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -296,10 +310,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
return new AbstractModule() {
|
||||
@Override
|
||||
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(String.class).annotatedWith(CatalogItemRoot.class)
|
||||
.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(TasksList.class).toInstance(
|
||||
URI.create("http://tasksList"));
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.URI;
|
|||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
|
@ -51,6 +52,16 @@ public class VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
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();
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
|
|
|
@ -84,10 +84,10 @@ public class VCloudComputeClient {
|
|||
public String start(String name, int minCores, int minMegs, Image image) {
|
||||
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
|
||||
String templateId = imageCatalogIdMap.get(image);
|
||||
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
|
||||
minCores, minMegs, templateId);
|
||||
VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId,
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
|
||||
name, minCores, minMegs, templateId, vDCId);
|
||||
VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
|
||||
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
|
||||
tmClient.getVApp(vAppResponse.getId());
|
||||
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -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.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
@ -40,14 +41,19 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||
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.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientFactory;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
|
||||
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
|
||||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.endpoints.VCloudLogin;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
|
||||
import org.jclouds.vcloud.reference.VCloudConstants;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -65,14 +71,46 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "live", testName = "vcloud.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 {
|
||||
|
||||
@SuppressWarnings( { "unused" })
|
||||
@Provides
|
||||
@Singleton
|
||||
RestContext<VCloudLogin, VCloudLogin> provideContext(Closer closer, VCloudLogin api,
|
||||
@VCloud URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
||||
return new RestContextImpl<VCloudLogin, VCloudLogin>(closer, api, api, endPoint, account);
|
||||
RestContext<VCloudLoginAsyncClient, VCloudLoginAsyncClient> provideContext(Closer closer,
|
||||
VCloudLoginAsyncClient api, @VCloudLogin URI endPoint) {
|
||||
return new RestContextImpl<VCloudLoginAsyncClient, VCloudLoginAsyncClient>(closer, api,
|
||||
api, endPoint, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,16 +119,11 @@ public class VCloudLoginLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
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 RestContext<VCloudLogin, VCloudLogin> context;
|
||||
private RestContext<VCloudLoginAsyncClient, VCloudLoginAsyncClient> context;
|
||||
|
||||
@Test
|
||||
public void testLogin() throws Exception {
|
||||
VCloudLogin authentication = context.getAsyncApi();
|
||||
VCloudLoginAsyncClient authentication = context.getAsyncApi();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
VCloudSession response = authentication.login().get(45, TimeUnit.SECONDS);
|
||||
assertNotNull(response);
|
||||
|
@ -101,9 +134,16 @@ public class VCloudLoginLiveTest {
|
|||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
context = new RestContextBuilder<VCloudLogin, VCloudLogin>(new TypeLiteral<VCloudLogin>() {
|
||||
}, new TypeLiteral<VCloudLogin>() {
|
||||
}, new Properties()) {
|
||||
final String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
||||
"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()) {
|
||||
|
||||
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_KEY, checkNotNull(key, "key"));
|
||||
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4");
|
||||
modules.add(new VCloudDiscoveryRestClientModule());
|
||||
modules.add(new VCloudLoginRestClientModule(endpoint));
|
||||
}
|
||||
|
||||
}.withModules(new Log4JLoggingModule(),
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.jclouds.rest.RestClientTest;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -52,11 +53,11 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@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 {
|
||||
Method method = VCloudLogin.class.getMethod("login");
|
||||
GeneratedHttpRequest<VCloudLogin> httpMethod = processor.createRequest(method);
|
||||
Method method = VCloudLoginAsyncClient.class.getMethod("login");
|
||||
GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
||||
assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
|
||||
|
@ -71,14 +72,14 @@ public class VCloudLoginTest extends RestClientTest<VCloudLogin> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<VCloudLogin> httpMethod) {
|
||||
protected void checkFilters(GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VCloudLogin>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VCloudLogin>>() {
|
||||
protected TypeLiteral<RestAnnotationProcessor<VCloudLoginAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VCloudLoginAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -67,8 +68,8 @@ public class VCloudVersionsLiveTest {
|
|||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VCloudVersions provideVCloudVersions(RestClientFactory factory) {
|
||||
return factory.create(VCloudVersions.class);
|
||||
protected VCloudVersionsAsyncClient provideVCloudVersions(RestClientFactory factory) {
|
||||
return factory.create(VCloudVersionsAsyncClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,9 +83,9 @@ public class VCloudVersionsLiveTest {
|
|||
@SuppressWarnings( { "unused" })
|
||||
@Provides
|
||||
@Singleton
|
||||
RestContext<VCloudVersions, VCloudVersions> provideContext(Closer closer, VCloudVersions api,
|
||||
RestContext<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient> provideContext(Closer closer, VCloudVersionsAsyncClient api,
|
||||
@VCloud URI endPoint) {
|
||||
return new RestContextImpl<VCloudVersions, VCloudVersions>(closer, api, api, endPoint, "");
|
||||
return new RestContextImpl<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(closer, api, api, endPoint, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,11 +97,11 @@ public class VCloudVersionsLiveTest {
|
|||
static String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
||||
"jclouds.test.endpoint");
|
||||
|
||||
private RestContext<VCloudVersions, VCloudVersions> context;
|
||||
private RestContext<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient> context;
|
||||
|
||||
@Test
|
||||
public void testGetSupportedVersions() throws Exception {
|
||||
VCloudVersions authentication = context.getAsyncApi();
|
||||
VCloudVersionsAsyncClient authentication = context.getAsyncApi();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SortedMap<String, URI> response = authentication.getSupportedVersions().get(45,
|
||||
TimeUnit.SECONDS);
|
||||
|
@ -111,9 +112,9 @@ public class VCloudVersionsLiveTest {
|
|||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
context = new RestContextBuilder<VCloudVersions, VCloudVersions>(
|
||||
new TypeLiteral<VCloudVersions>() {
|
||||
}, new TypeLiteral<VCloudVersions>() {
|
||||
context = new RestContextBuilder<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(
|
||||
new TypeLiteral<VCloudVersionsAsyncClient>() {
|
||||
}, new TypeLiteral<VCloudVersionsAsyncClient>() {
|
||||
}, new Properties()) {
|
||||
|
||||
public void addContextModule(List<Module> modules) {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.rest.RestClientTest;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
|
||||
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -51,11 +52,11 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@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 {
|
||||
Method method = VCloudVersions.class.getMethod("getSupportedVersions");
|
||||
GeneratedHttpRequest<VCloudVersions> httpMethod = processor.createRequest(method);
|
||||
Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions");
|
||||
GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
||||
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": application/vnd.vmware.vcloud.vcloud+xml\n");
|
||||
|
@ -69,13 +70,13 @@ public class VCloudVersionsTest extends RestClientTest<VCloudVersions> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<VCloudVersions> httpMethod) {
|
||||
protected void checkFilters(GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VCloudVersions>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VCloudVersions>>() {
|
||||
protected TypeLiteral<RestAnnotationProcessor<VCloudVersionsAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VCloudVersionsAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -31,12 +31,27 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSI
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
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.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.Utils;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.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;
|
||||
|
@ -49,8 +64,8 @@ import com.google.inject.Key;
|
|||
public class VCloudRestClientModuleTest {
|
||||
|
||||
protected Injector createInjector() {
|
||||
return Guice.createInjector(new VCloudRestClientModule(),
|
||||
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
|
||||
return Guice.createInjector(new VCloudRestClientModule(), new ParserModule(),
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.rest.internal.NamedResourceImpl;
|
||||
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.Test;
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@XMLResponseParser(CatalogHandler.class)
|
||||
@Override
|
||||
Future<? extends Catalog> getCatalog();
|
||||
|
||||
|
||||
@GET
|
||||
@Consumes(VAPP_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
|
@ -79,8 +79,8 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
|
|||
Future<? extends HostingDotComVApp> getVApp(@PathParam("vAppId") String appId);
|
||||
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/action/instantiateVAppTemplate")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
|
||||
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
|
||||
@Consumes(VAPP_XML)
|
||||
// required for hosting.com to operate
|
||||
|
@ -90,5 +90,5 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
|
|||
Future<? extends HostingDotComVApp> instantiateVAppTemplate(
|
||||
@MapPayloadParam("name") String appName,
|
||||
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
@PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public interface HostingDotComVCloudClient extends VCloudClient {
|
|||
|
||||
@Override
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
HostingDotComVApp instantiateVAppTemplate(String appName, String templateId,
|
||||
HostingDotComVApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
|
||||
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudContextModule;
|
||||
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule;
|
||||
|
||||
|
@ -64,7 +63,6 @@ public class HostingDotComVCloudContextBuilder extends
|
|||
|
||||
@Override
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new VCloudDiscoveryRestClientModule());
|
||||
modules.add(new HostingDotComVCloudRestClientModule());
|
||||
}
|
||||
|
||||
|
|
|
@ -69,12 +69,11 @@ public class HostingDotComVCloudComputeClient {
|
|||
public Map<String, String> start(String name, int minCores, int minMegs, Image image) {
|
||||
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
|
||||
String templateId = imageCatalogIdMap.get(image);
|
||||
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
|
||||
minCores, minMegs, templateId);
|
||||
HostingDotComVApp vAppResponse = (HostingDotComVApp) tmClient.instantiateVAppTemplate(name,
|
||||
templateId, InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(
|
||||
minMegs));
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
|
||||
name, minCores, minMegs, templateId, vDCId);
|
||||
HostingDotComVApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
|
||||
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
|
||||
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
|
||||
|
||||
logger.debug(">> deploying vApp(%s)", vAppResponse.getId());
|
||||
|
|
|
@ -95,15 +95,15 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
* @see TerremarkVCloudClient#instantiateVAppTemplate
|
||||
*/
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/action/instantiatevAppTemplate")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
|
||||
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
|
||||
@XMLResponseParser(TerremarkVAppHandler.class)
|
||||
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
@Override
|
||||
Future<? extends TerremarkVApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName,
|
||||
@MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
@PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#addInternetService
|
||||
|
@ -114,7 +114,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Produces(MediaType.APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.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,
|
||||
AddInternetServiceOptions... options);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
|||
public interface TerremarkVCloudClient extends VCloudClient {
|
||||
|
||||
@Override
|
||||
TerremarkVApp instantiateVAppTemplate(String appName, String templateId,
|
||||
TerremarkVApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
|
||||
import org.jclouds.vcloud.terremark.config.TerremarkVCloudContextModule;
|
||||
import org.jclouds.vcloud.terremark.config.TerremarkVCloudRestClientModule;
|
||||
|
||||
|
@ -64,7 +63,6 @@ public class TerremarkVCloudContextBuilder extends
|
|||
|
||||
@Override
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new VCloudDiscoveryRestClientModule());
|
||||
modules.add(new TerremarkVCloudRestClientModule());
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,8 @@ public class TerremarkVCloudComputeClient {
|
|||
private final TerremarkVCloudClient tmClient;
|
||||
|
||||
@Inject
|
||||
public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient, Predicate<String> successTester) {
|
||||
public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient,
|
||||
Predicate<String> successTester) {
|
||||
this.tmClient = tmClient;
|
||||
this.taskTester = successTester;
|
||||
}
|
||||
|
@ -77,10 +78,10 @@ public class TerremarkVCloudComputeClient {
|
|||
public String start(String name, int minCores, int minMegs, Image image) {
|
||||
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
|
||||
String templateId = imageCatalogIdMap.get(image);
|
||||
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
|
||||
minCores, minMegs, templateId);
|
||||
TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId,
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
|
||||
name, minCores, minMegs, templateId, vDCId);
|
||||
TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
|
||||
TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores)
|
||||
.megabytes(minMegs));
|
||||
logger.debug("<< instantiated VApp(%s)", vApp.getId());
|
||||
|
|
|
@ -105,12 +105,13 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
||||
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class,
|
||||
0).getClass());
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
InstantiateVAppTemplateOptions.class, 0).getClass());
|
||||
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(
|
||||
httpMethod,
|
||||
"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,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
||||
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class,
|
||||
0).getClass());
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
InstantiateVAppTemplateOptions.class, 0).getClass());
|
||||
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(
|
||||
httpMethod,
|
||||
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
|
|
|
@ -114,9 +114,10 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)";
|
||||
|
||||
String templateId = tmClient.getCatalog().get(catalogOs).getId();
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
|
||||
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);
|
||||
|
||||
|
@ -275,8 +276,8 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
.getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make it longer then
|
||||
// default internet
|
||||
// service timeout
|
||||
successTester = new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), 300, 10,
|
||||
TimeUnit.SECONDS);
|
||||
successTester = new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), 300,
|
||||
10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.io.IOException;
|
|||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -50,8 +49,8 @@ import com.google.inject.Key;
|
|||
public class TerremarkVCloudRestClientModuleTest {
|
||||
|
||||
protected Injector createInjector() {
|
||||
return Guice.createInjector(new TerremarkVCloudRestClientModule(),
|
||||
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
|
||||
return Guice.createInjector(new TerremarkVCloudRestClientModule(), new ParserModule(),
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8");
|
||||
|
|
Loading…
Reference in New Issue