* 'master' of http://github.com/spasam/jclouds:
  a.) When listing all public IPs in ecloud, the URL was incorrect. Was using something like ..../publicIps/publicIps.
This commit is contained in:
Adrian Cole 2010-10-18 01:01:18 -07:00
commit a96d332ea4
13 changed files with 319 additions and 102 deletions

View File

@ -97,7 +97,7 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
String network = defaultNetwork.toASCIIString();
String network = (defaultNetwork != null) ? defaultNetwork.toASCIIString() : null;
String fenceMode = defaultFenceMode;
String networkName = name;
if (options != null) {

View File

@ -415,8 +415,13 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
checkState(network != null, String.format("network named %s not in %s", networkName, networks.keySet()));
return network.getHref();
} catch (ConfigurationException e) {
throw new IllegalStateException(String.format("you must specify the property %s as one of %s",
PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e);
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not work well.
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's networks will
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If this property
// is not set, they are expected to add NetworkConfig to the options when launching a server.
return null;
//throw new IllegalStateException(String.format("you must specify the property %s as one of %s",
// PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e);
}
} catch (AuthorizationException e) {
authException.set(e);

View File

@ -19,14 +19,18 @@
package org.jclouds.vcloud.terremark;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.INTERNETSERVICESLIST_XML;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.INTERNETSERVICE_XML;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.KEYSLIST_XML;
import static org.jclouds.vcloud.terremark.TerremarkECloudMediaType.PUBLICIP_XML;
import java.net.URI;
import java.util.Set;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@ -42,14 +46,20 @@ import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.terremark.binders.BindCreateKeyToXmlPayload;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.functions.OrgURIToKeysListEndpoint;
import org.jclouds.vcloud.terremark.functions.VDCURIToInternetServicesEndpoint;
import org.jclouds.vcloud.terremark.functions.VDCURIToPublicIPsEndpoint;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -123,4 +133,81 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
@Override
ListenableFuture<? extends InternetService> getInternetService(@EndpointParam URI internetServiceId);
/**
* @see TerremarkVCloudExpressClient#findKeyPairInOrgNamed
*/
@GET
@Path("")
@XMLResponseParser(KeyPairByNameHandler.class)
@Consumes(KEYSLIST_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends KeyPair> findKeyPairInOrg(
@Nullable @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, String keyName);
/**
* @see TerremarkVCloudExpressClient#listKeyPairsInOrgNamed
*/
@GET
@Path("")
@Consumes(KEYSLIST_XML)
@XMLResponseParser(KeyPairsHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<? extends Set<KeyPair>> listKeyPairsInOrg(
@Nullable @EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org);
/**
* @see TerremarkVCloudExpressClient#listKeyPairs
*/
@GET
@Path("")
@Consumes(KEYSLIST_XML)
@XMLResponseParser(KeyPairsHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<? extends Set<KeyPair>> listKeyPairs(@EndpointParam URI keysList);
/**
* @see TerremarkVCloudExpressClient#generateKeyPairInOrg
*/
@POST
@Path("")
@Produces(KEYSLIST_XML)
@Consumes(KEYSLIST_XML)
@XMLResponseParser(KeyPairHandler.class)
@MapBinder(BindCreateKeyToXmlPayload.class)
ListenableFuture<? extends KeyPair> generateKeyPairInOrg(
@EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, @MapPayloadParam("name") String name,
@MapPayloadParam("isDefault") boolean makeDefault);
/**
* @see TerremarkVCloudExpressClient#getKeyPair
*/
@GET
@Path("")
@XMLResponseParser(KeyPairHandler.class)
@Consumes(APPLICATION_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends KeyPair> getKeyPair(@EndpointParam URI keyId);
// TODO
// /**
// * @see TerremarkVCloudClient#configureKeyPair
// */
// @PUT
// @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
// @Path("/extensions/key/{keyId}")
// @Produces(APPLICATION_XML)
// @Consumes(APPLICATION_XML)
// @XMLResponseParser(KeyPairHandler.class)
// ListenableFuture<? extends KeyPair> configureKeyPair(
// @PathParam("keyId") int keyId,
// @BinderParam(BindKeyPairConfigurationToXmlPayload.class)
// KeyPairConfiguration keyConfiguration);
/**
* @see TerremarkVCloudExpressClient#deleteKeyPair
*/
@DELETE
@Path("")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteKeyPair(@EndpointParam URI keyId);
}

View File

@ -58,4 +58,13 @@ public interface TerremarkECloudMediaType extends TerremarkVCloudMediaType {
public final static MediaType INTERNETSERVICESLIST_XML_TYPE = new MediaType("application",
"vnd.tmrk.ecloud.internetServicesList+xml");
/**
* "application/vnd.tmrk.ecloud.keysList+xml"
*/
public final static String KEYSLIST_XML = "application/vnd.tmrk.ecloud.keysList+xml";
/**
* "application/vnd.tmrk.ecloud.keysList+xml"
*/
public final static MediaType KEYSLIST_XML_TYPE = new MediaType("application", "vnd.tmrk.ecloud.keysList+xml");
}

View File

@ -35,10 +35,10 @@ public class TerremarkECloudPropertiesBuilder extends TerremarkVCloudPropertiesB
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "0.8b-ext2.3");
properties.setProperty(PROPERTY_API_VERSION, "0.8b-ext2.5");
properties.setProperty(PROPERTY_ENDPOINT, "https://services.enterprisecloud.terremark.com/api");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.3");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.5");
return properties;
}

View File

@ -258,7 +258,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
* @see TerremarkVCloudExpressClient#getPublicIpsAssociatedWithVDC
*/
@GET
@Path("/publicIps")
@Path("")
@Consumes(PUBLICIPSLIST_XML)
@XMLResponseParser(PublicIpAddressesHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)

View File

@ -31,6 +31,7 @@ import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
@ -142,4 +143,25 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
*/
Task configureVApp(VCloudExpressVApp vApp, VAppConfiguration configuration);
/**
*/
Set<KeyPair> listKeyPairsInOrg(URI org);
/**
* @throws IllegalStateException
* if a key of the same name already exists
*/
KeyPair generateKeyPairInOrg(URI org, String name, boolean makeDefault);
/**
*/
KeyPair findKeyPairInOrg(URI org, String keyPairName);
KeyPair getKeyPair(URI keyPair);
// TODO
// KeyPair configureKeyPair(int keyPairId, KeyPairConfiguration
// keyPairConfiguration);
void deleteKeyPair(URI keyPair);
}

View File

@ -20,12 +20,10 @@
package org.jclouds.vcloud.terremark;
import java.net.URI;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
@ -40,29 +38,6 @@ import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudExpressClient extends TerremarkVCloudClient {
/**
*/
Set<KeyPair> listKeyPairsInOrg(URI org);
/**
* @throws IllegalStateException
* if a key of the same name already exists
*/
KeyPair generateKeyPairInOrg(URI org, String name, boolean makeDefault);
/**
*/
KeyPair findKeyPairInOrg(URI org, String keyPairName);
KeyPair getKeyPair(URI keyPair);
// TODO
// KeyPair configureKeyPair(int keyPairId, KeyPairConfiguration
// keyPairConfiguration);
void deleteKeyPair(URI keyPair);
InternetService addInternetServiceToVDC(URI vDCId, String serviceName, Protocol protocol, int port,
AddInternetServiceOptions... options);
}

View File

@ -41,6 +41,7 @@ import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import com.google.inject.internal.Nullable;
import com.jamesmurty.utils.XMLBuilder;
/**
@ -55,7 +56,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
@Inject
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Nullable @Network URI network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
super(stringBinder, apiVersion, ns, schema, network, fenceMode);
}

View File

@ -19,8 +19,12 @@
package org.jclouds.vcloud.terremark.config;
import java.io.IOException;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.io.IOException;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
@ -28,12 +32,19 @@ import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.endpoints.KeysList;
import org.jclouds.vcloud.terremark.handlers.ParseTerremarkVCloudErrorFromHttpResponse;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient>
@ -69,4 +80,48 @@ public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient,
ParseTerremarkVCloudErrorFromHttpResponse.class);
}
@Singleton
public static class OrgNameToKeysListSupplier implements Supplier<Map<String, ReferenceType>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final TerremarkVCloudClient client;
@Inject
protected OrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier, TerremarkVCloudClient client) {
this.sessionSupplier = sessionSupplier;
this.client = client;
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return client.findOrgNamed(from.getName()).getKeysList();
}
});
}
}
@Provides
@Singleton
@KeysList
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToKeysListSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(authException,
seconds, new Supplier<Map<String, ReferenceType>>() {
@Override
public Map<String, ReferenceType> get() {
return supplier.get();
}
});
}
@Singleton
@Provides
@Named("CreateKey")
String provideCreateKey() throws IOException {
return Utils.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateKey.xml"));
}
}

View File

@ -19,32 +19,17 @@
package org.jclouds.vcloud.terremark.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.io.IOException;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
import org.jclouds.vcloud.terremark.endpoints.KeysList;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
/**
@ -84,52 +69,4 @@ public class TerremarkVCloudExpressRestClientModule extends
protected TerremarkVCloudClient provideTerremarkClient(TerremarkVCloudExpressClient in) {
return in;
}
@Singleton
public static class OrgNameToKeysListSupplier implements Supplier<Map<String, ReferenceType>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final TerremarkVCloudExpressClient client;
@Inject
protected OrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier, TerremarkVCloudExpressClient client) {
this.sessionSupplier = sessionSupplier;
this.client = client;
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return client.findOrgNamed(from.getName()).getKeysList();
}
});
}
}
@Provides
@Singleton
@KeysList
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToKeysListSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(authException,
seconds, new Supplier<Map<String, ReferenceType>>() {
@Override
public Map<String, ReferenceType> get() {
return supplier.get();
}
});
}
@Singleton
@Provides
@Named("CreateKey")
String provideCreateKey() throws IOException {
return Utils.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateKey.xml"));
}
}

View File

@ -19,7 +19,6 @@
package org.jclouds.vcloud.terremark.xml;
import static org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType.KEYSLIST_XML;
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
import static org.jclouds.vcloud.util.Utils.newReferenceType;
@ -28,6 +27,8 @@ import java.util.Map;
import javax.inject.Inject;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.TerremarkECloudMediaType;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl;
import org.jclouds.vcloud.xml.OrgHandler;
@ -57,7 +58,9 @@ public class TerremarkOrgHandler extends OrgHandler {
super.startElement(uri, localName, qName, attrs);
if (qName.equals("Link")) {
if (attributes.containsKey("type")) {
if (attributes.get("type").equals(KEYSLIST_XML)) {
String type = attributes.get("type");
if (type.equals(TerremarkVCloudExpressMediaType.KEYSLIST_XML)
|| type.equals(TerremarkECloudMediaType.KEYSLIST_XML)) {
keysList = newReferenceType(attributes);
}
}

View File

@ -27,15 +27,19 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
@ -50,20 +54,23 @@ import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExt
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestOrgNameToKeysListSupplier;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrgMapSupplier;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestTerremarkOrgVDCSupplier;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
@ -72,7 +79,10 @@ import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -298,6 +308,22 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testGetKeyPairInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("findKeyPairInOrg", URI.class, String.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), "keyPair");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/keysList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.keysList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairByNameHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testConfigureNodeWithDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", URI.class, String.class,
boolean.class, String.class);
@ -382,6 +408,58 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testListKeyPairsInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/keysList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.keysList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairsHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testListKeyPairsInOrgNotFound() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
processor.createRequest(method, URI.create("d"));
}
public void testGetKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getKeyPair", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/key/12"));
assertRequestLineEquals(request, "GET https://vcloud/extensions/key/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("deleteKeyPair", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/key/12"));
assertRequestLineEquals(request, "DELETE https://vcloud/extensions/key/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getNode", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/nodeService/12"));
@ -439,6 +517,51 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
bind(OrgVDCSupplier.class).to(TestTerremarkOrgVDCSupplier.class);
}
@Singleton
public static class TestOrgNameToKeysListSupplier extends OrgNameToKeysListSupplier {
@Inject
protected TestOrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier) {
super(sessionSupplier, null);
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI
.create(from.getHref().toASCIIString() + "/keysList"));
}
});
}
}
@Singleton
public static class TestTerremarkOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestTerremarkOrgMapSupplier() {
super(null, null);
}
@Override
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of("org", new TerremarkOrgImpl("org", null, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), null, ImmutableMap
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
TerremarkECloudMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc",
TerremarkECloudMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
TerremarkECloudMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), new ReferenceTypeImpl(
"keysList", TerremarkECloudMediaType.KEYSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"))));
}
}
@Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return URI.create("https://org");