Issue 536:terremark delete operation now returns tasks

This commit is contained in:
Adrian Cole 2011-04-19 16:57:37 -07:00
parent 83bed07d79
commit 2b111b2604
22 changed files with 597 additions and 363 deletions

View File

@ -18,16 +18,20 @@
*/
package org.jclouds.s3;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Annotates the parameter that this is a bucket.
*/
@Target(PARAMETER)
@Target({ PARAMETER, METHOD })
@Retention(RUNTIME)
@Qualifier
public @interface Bucket {
}

View File

@ -33,6 +33,28 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.blobstore.attr.BlobScope;
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.options.GetOptions;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.s3.binders.BindACLToXMLPayload;
import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured;
import org.jclouds.s3.binders.BindBucketLoggingToXmlPayload;
@ -65,26 +87,6 @@ import org.jclouds.s3.xml.ListAllMyBucketsHandler;
import org.jclouds.s3.xml.ListBucketHandler;
import org.jclouds.s3.xml.LocationConstraintHandler;
import org.jclouds.s3.xml.PayerHandler;
import org.jclouds.blobstore.attr.BlobScope;
import org.jclouds.blobstore.functions.ReturnFalseOnContainerNotFound;
import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
@ -121,8 +123,8 @@ public interface S3AsyncClient {
@ExceptionParser(ReturnNullOnKeyNotFound.class)
@ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
ListenableFuture<S3Object> getObject(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, GetOptions... options);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, GetOptions... options);
/**
* @see S3Client#headObject
@ -132,8 +134,8 @@ public interface S3AsyncClient {
@ExceptionParser(ReturnNullOnKeyNotFound.class)
@ResponseParser(ParseObjectMetadataFromHeaders.class)
ListenableFuture<ObjectMetadata> headObject(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
/**
* @see S3Client#objectExists
@ -142,8 +144,8 @@ public interface S3AsyncClient {
@Path("/{key}")
@ExceptionParser(ReturnFalseOnKeyNotFound.class)
ListenableFuture<Boolean> objectExists(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
/**
* @see S3Client#deleteObject
@ -152,8 +154,8 @@ public interface S3AsyncClient {
@Path("/{key}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteObject(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
/**
* @see S3Client#putObject
@ -162,9 +164,9 @@ public interface S3AsyncClient {
@Path("/{key}")
@ResponseParser(ParseETagHeader.class)
ListenableFuture<String> putObject(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") @ParamParser(ObjectKey.class) @BinderParam(BindS3ObjectMetadataToRequest.class) S3Object object,
PutObjectOptions... options);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") @ParamParser(ObjectKey.class) @BinderParam(BindS3ObjectMetadataToRequest.class) S3Object object,
PutObjectOptions... options);
/**
* @see S3Client#putBucketInRegion
@ -173,10 +175,9 @@ public interface S3AsyncClient {
@Path("/")
@ExceptionParser(ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class)
ListenableFuture<Boolean> putBucketInRegion(
// TODO endpoint based on region
@BinderParam(BindRegionToXmlPayload.class) @Nullable String region,
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
PutBucketOptions... options);
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @BinderParam(BindRegionToXmlPayload.class) @Nullable String region,
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
PutBucketOptions... options);
/**
* @see S3Client#deleteBucketIfEmpty
@ -185,7 +186,7 @@ public interface S3AsyncClient {
@Path("/")
@ExceptionParser(ReturnTrueOn404OrNotFoundFalseOnIllegalState.class)
ListenableFuture<Boolean> deleteBucketIfEmpty(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see S3Client#bucketExists
@ -195,7 +196,7 @@ public interface S3AsyncClient {
@QueryParams(keys = "max-keys", values = "0")
@ExceptionParser(ReturnFalseOnContainerNotFound.class)
ListenableFuture<Boolean> bucketExists(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see S3Client#getBucketLocation
@ -205,7 +206,7 @@ public interface S3AsyncClient {
@Path("/")
@XMLResponseParser(LocationConstraintHandler.class)
ListenableFuture<String> getBucketLocation(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see S3Client#getBucketPayer
@ -215,7 +216,7 @@ public interface S3AsyncClient {
@Path("/")
@XMLResponseParser(PayerHandler.class)
ListenableFuture<Payer> getBucketPayer(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see S3Client#setBucketPayer
@ -224,8 +225,8 @@ public interface S3AsyncClient {
@QueryParams(keys = "requestPayment")
@Path("/")
ListenableFuture<Void> setBucketPayer(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@BinderParam(BindPayerToXmlPayload.class) Payer payer);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@BinderParam(BindPayerToXmlPayload.class) Payer payer);
/**
* @see S3Client#listBucket
@ -234,8 +235,8 @@ public interface S3AsyncClient {
@Path("/")
@XMLResponseParser(ListBucketHandler.class)
ListenableFuture<ListBucketResponse> listBucket(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
ListBucketOptions... options);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
ListBucketOptions... options);
/**
* @see S3Client#listOwnedBuckets
@ -254,10 +255,10 @@ public interface S3AsyncClient {
@Headers(keys = "x-amz-copy-source", values = "/{sourceBucket}/{sourceObject}")
@XMLResponseParser(CopyObjectHandler.class)
ListenableFuture<ObjectMetadata> copyObject(
@PathParam("sourceBucket") String sourceBucket,
@PathParam("sourceObject") String sourceObject,
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String destinationBucket,
@PathParam("destinationObject") String destinationObject, CopyObjectOptions... options);
@PathParam("sourceBucket") String sourceBucket,
@PathParam("sourceObject") String sourceObject,
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String destinationBucket,
@PathParam("destinationObject") String destinationObject, CopyObjectOptions... options);
/**
* @see S3Client#getBucketACL
@ -268,7 +269,7 @@ public interface S3AsyncClient {
@ExceptionParser(ThrowContainerNotFoundOn404.class)
@Path("/")
ListenableFuture<AccessControlList> getBucketACL(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see S3Client#putBucketACL
@ -277,8 +278,8 @@ public interface S3AsyncClient {
@Path("/")
@QueryParams(keys = "acl")
ListenableFuture<Boolean> putBucketACL(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@BinderParam(BindACLToXMLPayload.class) AccessControlList acl);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@BinderParam(BindACLToXMLPayload.class) AccessControlList acl);
/**
* @see S3Client#getObjectACL
@ -289,8 +290,8 @@ public interface S3AsyncClient {
@XMLResponseParser(AccessControlListHandler.class)
@ExceptionParser(ThrowKeyNotFoundOn404.class)
ListenableFuture<AccessControlList> getObjectACL(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key);
/**
* @see S3Client#putObjectACL
@ -299,9 +300,8 @@ public interface S3AsyncClient {
@QueryParams(keys = "acl")
@Path("/{key}")
ListenableFuture<Boolean> putObjectACL(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key,
@BinderParam(BindACLToXMLPayload.class) AccessControlList acl);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @BinderParam(BindACLToXMLPayload.class) AccessControlList acl);
/**
* @see S3Client#getBucketLogging
@ -312,7 +312,7 @@ public interface S3AsyncClient {
@ExceptionParser(ThrowContainerNotFoundOn404.class)
@Path("/")
ListenableFuture<BucketLogging> getBucketLogging(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see S3Client#enableBucketLogging
@ -321,8 +321,8 @@ public interface S3AsyncClient {
@Path("/")
@QueryParams(keys = "logging")
ListenableFuture<Void> enableBucketLogging(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@BinderParam(BindBucketLoggingToXmlPayload.class) BucketLogging logging);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@BinderParam(BindBucketLoggingToXmlPayload.class) BucketLogging logging);
/**
* @see S3Client#putBucketLogging
@ -332,6 +332,6 @@ public interface S3AsyncClient {
@QueryParams(keys = "logging")
@Produces(MediaType.TEXT_XML)
ListenableFuture<Void> disableBucketLogging(
@Bucket @BinderParam(BindNoBucketLoggingToXmlPayload.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);
@Bucket @BinderParam(BindNoBucketLoggingToXmlPayload.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
}

View File

@ -45,10 +45,10 @@ import com.google.common.collect.Maps;
@Singleton
public class BindAsHostPrefixIfConfigured implements Binder {
private final Provider<UriBuilder> uriBuilderProvider;
private final BindAsHostPrefix bindAsHostPrefix;
private final boolean isVhostStyle;
private final String servicePath;
protected final Provider<UriBuilder> uriBuilderProvider;
protected final BindAsHostPrefix bindAsHostPrefix;
protected final boolean isVhostStyle;
protected final String servicePath;
@Inject
public BindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix,

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.s3.config;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
@ -34,6 +35,7 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner;
import org.jclouds.s3.Bucket;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.filters.RequestAuthorizeSignature;
@ -41,6 +43,7 @@ import org.jclouds.s3.handlers.ParseS3ErrorFromXmlContent;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
import com.google.inject.Scopes;
@ -60,6 +63,13 @@ public class S3RestClientModule<S extends S3Client, A extends S3AsyncClient> ext
super(sync, async);
}
@Provides
@Bucket
@Singleton
protected Map<String, String> bucketToRegion() {
return Maps.newConcurrentMap();
}
@Override
protected void configure() {
install(new S3ObjectModule());
@ -94,7 +104,7 @@ public class S3RestClientModule<S extends S3Client, A extends S3AsyncClient> ext
@TimeStamp
@Singleton
protected Supplier<String> provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) {
final DateService dateService) {
return Suppliers.memoizeWithExpiration(new Supplier<String>() {
public String get() {
return dateService.rfc822DateFormat();

View File

@ -20,6 +20,8 @@ package org.jclouds.s3.functions;
import static com.google.common.base.Preconditions.checkArgument;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;

View File

@ -20,8 +20,15 @@ package org.jclouds.s3.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.s3.Bucket;
/**
* Parses the response from Amazon S3 GET Bucket Location
@ -32,8 +39,15 @@ import org.jclouds.http.functions.ParseSax;
* @author Adrian Cole
*/
public class LocationConstraintHandler extends ParseSax.HandlerWithResult<String> {
private final ConcurrentMap<String, String> bucketToRegion;
private StringBuilder currentText = new StringBuilder();
private String region;
private String bucket;
@Inject
public LocationConstraintHandler(@Bucket ConcurrentMap<String, String> bucketToRegion) {
this.bucketToRegion = bucketToRegion;
}
public String getResult() {
return region;
@ -41,6 +55,18 @@ public class LocationConstraintHandler extends ParseSax.HandlerWithResult<String
public void endElement(String uri, String name, String qName) {
region = fromValue(currentOrNull(currentText));
bucketToRegion.put(bucket, region);
}
@Override
public LocationConstraintHandler setContext(HttpRequest request) {
super.setContext(request);
setBucket(GeneratedHttpRequest.class.cast(getRequest()).getArgs().get(0).toString());
return this;
}
void setBucket(String bucket) {
this.bucket = bucket;
}
/**

View File

@ -37,12 +37,12 @@ import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Task;
@ -52,6 +52,7 @@ import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
@ -164,7 +165,7 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends VCloudExpressVApp> getVApp(@EndpointParam URI vApp);
/**
* @see CommonVCloudClient#deployVApp
* @see VCloudExpressClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@ -173,7 +174,7 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#undeployVApp
* @see VCloudExpressClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@ -182,7 +183,7 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#powerOnVApp
* @see VCloudExpressClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@ -191,7 +192,7 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#powerOffVApp
* @see VCloudExpressClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@ -200,14 +201,14 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#shutdownVApp
* @see VCloudExpressClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#resetVApp
* @see VCloudExpressClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@ -216,7 +217,7 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#suspendVApp
* @see VCloudExpressClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@ -225,10 +226,10 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see CommonVCloudClient#deleteVApp
* @see VCloudExpressClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
@ResponseParser(ParseTaskFromLocationHeader.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> deleteVApp(@EndpointParam URI vAppId);
}

View File

@ -42,7 +42,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
public interface VCloudExpressClient extends CommonVCloudClient {
VCloudExpressVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName,
InstantiateVAppTemplateOptions... options);
InstantiateVAppTemplateOptions... options);
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
@ -63,7 +63,7 @@ public interface VCloudExpressClient extends CommonVCloudClient {
* if you specified an org, catalog, or catalog item name that isn't present
*/
VCloudExpressVAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
String itemName);
VCloudExpressVApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
@ -101,6 +101,6 @@ public interface VCloudExpressClient extends CommonVCloudClient {
*/
Task suspendVApp(URI vAppId);
void deleteVApp(URI vAppId);
Task deleteVApp(URI vAppId);
}

View File

@ -29,7 +29,6 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.util.ComputeServiceUtils;
@ -51,7 +50,7 @@ public class ParseOsFromVAppTemplateName implements Function<String, OperatingSy
@Override
public OperatingSystem apply(String from) {
OperatingSystemBuilder builder = new OperatingSystemBuilder();
OperatingSystem.Builder builder = OperatingSystem.builder();
OsFamily osFamily = parseOsFamilyOrUnrecognized(checkNotNull(from, "vapp template name"));
builder.family(osFamily);
builder.description(from);

View File

@ -60,7 +60,10 @@ public class VCloudExpressComputeClientImpl extends
@Override
protected void deleteVApp(VCloudExpressVApp vApp) {
logger.debug(">> deleting vApp(%s)", vApp.getName());
VCloudExpressClient.class.cast(client).deleteVApp(vApp.getHref());
Task task = VCloudExpressClient.class.cast(client).deleteVApp(vApp.getHref());
if (task != null)
if (!taskTester.apply(task.getHref()))
throw new RuntimeException(String.format("failed to %s %s: %s", "delete", vApp.getName(), task));
}
@Override

View File

@ -16,7 +16,8 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.functions;
package org.jclouds.vcloud.functions;
import java.net.URI;
import java.util.Date;

View File

@ -44,7 +44,6 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
@ -60,6 +59,7 @@ import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
@ -500,9 +500,9 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertResponseParserClassEquals(method, request, ParseTaskFromLocationHeader.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}

View File

@ -46,8 +46,8 @@ import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.XMLResponseParser;
@ -64,6 +64,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.binders.BindNodeConfigurationToXmlPayload;
import org.jclouds.vcloud.terremark.binders.BindVAppConfigurationToXmlPayload;
@ -77,7 +78,6 @@ import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.terremark.functions.ReturnVoidOnDeleteDefaultIp;
import org.jclouds.vcloud.terremark.functions.VDCURIToInternetServicesEndpoint;
import org.jclouds.vcloud.terremark.functions.VDCURIToPublicIPsEndpoint;

View File

@ -95,7 +95,7 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
*
*/
InternetService addInternetServiceToExistingIp(URI existingIpId, String serviceName, Protocol protocol, int port,
AddInternetServiceOptions... options);
AddInternetServiceOptions... options);
void deleteInternetService(URI internetServiceId);
@ -177,4 +177,5 @@ public interface TerremarkVCloudClient extends VCloudExpressClient {
// keyPairConfiguration);
void deleteKeyPair(URI keyPair);
}

View File

@ -24,9 +24,9 @@ import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Bui
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.inject.Inject;
@ -71,10 +71,10 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
@Inject
protected TerremarkVCloudComputeClient(TerremarkVCloudClient client,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
@Named("PASSWORD") Provider<String> passwordGenerator, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier) {
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
@Named("PASSWORD") Provider<String> passwordGenerator, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier) {
super(client, successTester, vAppStatusToNodeState);
this.client = client;
this.credentialsProvider = credentialsProvider;
@ -85,7 +85,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
@Override
public VCloudExpressVApp start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
InstantiateVAppTemplateOptions options, int... portsToOpen) {
if (options.getDiskSizeKilobytes() != null) {
logger.warn("trmk does not support resizing the primary disk; unsetting disk size");
}
@ -95,7 +95,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
String password = null;
VCloudExpressVAppTemplate template = client.getVAppTemplate(templateId);
if (template.getDescription().indexOf("Windows") != -1
&& options instanceof TerremarkInstantiateVAppTemplateOptions) {
&& options instanceof TerremarkInstantiateVAppTemplateOptions) {
password = passwordGenerator.get();
TerremarkInstantiateVAppTemplateOptions.class.cast(options).getProperties().put("password", password);
}
@ -104,7 +104,7 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
VCloudExpressVApp vAppResponse = super.start(VDC, templateId, name, options, portsToOpen);
if (password != null) {
credentialStore.put("node#" + vAppResponse.getHref().toASCIIString(), new Credentials(
defaultCredentials.identity, password));
defaultCredentials.identity, password));
}
if (portsToOpen.length > 0)
createPublicAddressMappedToPorts(vAppResponse.getHref(), portsToOpen);
@ -119,37 +119,41 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
InternetService is = null;
Protocol protocol;
switch (port) {
case 22:
protocol = Protocol.TCP;
break;
case 80:
case 8080:
protocol = Protocol.HTTP;
break;
case 443:
protocol = Protocol.HTTPS;
break;
default:
protocol = Protocol.HTTP;
break;
case 22:
protocol = Protocol.TCP;
break;
case 80:
case 8080:
protocol = Protocol.HTTP;
break;
case 443:
protocol = Protocol.HTTPS;
break;
default:
protocol = Protocol.HTTP;
break;
}
if (ip == null) {
Entry<InternetService, PublicIpAddress> entry = internetServiceAndPublicIpAddressSupplier
.getNewInternetServiceAndIp(vApp, port, protocol);
.getNewInternetServiceAndIp(vApp, port, protocol);
is = entry.getKey();
ip = entry.getValue();
} else {
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress(), protocol, port);
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
is = client.addInternetServiceToExistingIp(
ip.getId(),
vApp.getName() + "-" + port,
protocol,
port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
}
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getName(), is.getPublicIpAddress().getAddress(), is
.getProtocol(), is.getPort());
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getName(), is.getPublicIpAddress().getAddress(),
is.getProtocol(), is.getPort());
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress(), is.getPort(),
privateAddress, port);
privateAddress, port);
Node node = client.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port);
logger.debug("<< added Node(%s)", node.getName());
}
@ -163,13 +167,13 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
ipAddresses.add(service.getPublicIpAddress());
logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getName(), service.getPublicIpAddress()
.getAddress(), service.getPort(), node.getIpAddress(), node.getPort());
.getAddress(), service.getPort(), node.getIpAddress(), node.getPort());
client.deleteNode(node.getId());
logger.debug("<< deleted Node(%s)", node.getName());
Set<Node> nodes = client.getNodes(service.getId());
if (nodes.size() == 0) {
logger.debug(">> deleting InternetService(%s) %s:%d", service.getName(), service.getPublicIpAddress()
.getAddress(), service.getPort());
.getAddress(), service.getPort());
client.deleteInternetService(service.getId());
logger.debug("<< deleted InternetService(%s)", service.getName());
continue SERVICE;

View File

@ -20,8 +20,10 @@ package org.jclouds.json.config;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -33,6 +35,8 @@ import org.jclouds.json.Json;
import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue;
import org.jclouds.json.internal.GsonWrapper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Maps;
import com.google.common.primitives.Bytes;
import com.google.gson.Gson;
@ -51,6 +55,7 @@ import com.google.gson.reflect.TypeToken;
import com.google.inject.AbstractModule;
import com.google.inject.ImplementedBy;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Contains logic for parsing objects from Strings.
@ -63,13 +68,15 @@ public class GsonModule extends AbstractModule {
@Provides
@Singleton
Gson provideGson(JsonBallAdapter jsonAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter,
ByteArrayAdapter byteArrayAdapter, JsonAdapterBindings bindings) throws ClassNotFoundException, Exception {
ByteArrayAdapter byteArrayAdapter, SerializePropertiesDefaults propertiesAdapter, JsonAdapterBindings bindings)
throws ClassNotFoundException, Exception {
GsonBuilder builder = new GsonBuilder();
JcloudsGsonPackageAccessor.registerTypeHierarchyAdapter(builder, Enum.class,
new EnumTypeAdapterThatReturnsFromValue());
JcloudsGsonPackageAccessor.registerTypeHierarchyAdapter(builder, Map.class, new MapTypeAdapter());
builder.registerTypeAdapter(JsonBall.class, jsonAdapter);
builder.registerTypeAdapter(Date.class, adapter);
builder.registerTypeAdapter(Properties.class, propertiesAdapter);
builder.registerTypeAdapter(new TypeToken<List<Byte>>() {
}.getType(), byteListAdapter);
builder.registerTypeAdapter(byte[].class, byteArrayAdapter);
@ -169,6 +176,28 @@ public class GsonModule extends AbstractModule {
}
@Singleton
public static class SerializePropertiesDefaults implements JsonSerializer<Properties> {
private final Json json;
private final Type mapType = new TypeLiteral<Map<String, String>>() {
}.getRawType();
@Inject
public SerializePropertiesDefaults(Json json) {
this.json = json;
}
public JsonElement serialize(Properties src, Type typeOfSrc, JsonSerializationContext context) {
Builder<String, String> srcMap = ImmutableMap.<String, String> builder();
for (Enumeration<?> propNames = src.propertyNames(); propNames.hasMoreElements();) {
String propName = (String) propNames.nextElement();
srcMap.put(propName, src.getProperty(propName));
}
return new JsonLiteral(json.toJson(srcMap.build(), mapType));
}
}
@Singleton
public static class CDateAdapter implements DateAdapter {
private final DateService dateService;

View File

@ -21,6 +21,7 @@ package org.jclouds.json;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Properties;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
@ -44,6 +45,19 @@ public class JsonTest {
private Test enumValue;
}
public void testPropertiesSerializesDefaults() {
Properties props = new Properties();
props.put("string", "string");
props.put("number", "1");
props.put("boolean", "true");
assertEquals(json.toJson(props), "{\"string\":\"string\",\"boolean\":\"true\",\"number\":\"1\"}");
Properties props3 = new Properties(props);
assertEquals(json.toJson(props3), "{\"string\":\"string\",\"boolean\":\"true\",\"number\":\"1\"}");
Properties props2 = json.fromJson(json.toJson(props), Properties.class);
assertEquals(props2, props);
assertEquals(json.toJson(props2), json.toJson(props));
}
public void testMapStringObjectWithAllValidValuesOneDeep() {
Map<String, Object> map = Maps.newHashMap();
map.put("string", "string");

View File

@ -18,29 +18,13 @@
*/
package org.jclouds.aws.s3;
/**
*
*
* ====================================================================
* Licensed 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.
* ====================================================================
*/
import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER;
import java.util.Map;
import javax.annotation.Nullable;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@ -56,6 +40,7 @@ import org.jclouds.blobstore.attr.BlobScope;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.io.Payload;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.ParamValidators;
@ -63,14 +48,20 @@ import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.s3.Bucket;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured;
import org.jclouds.s3.domain.ObjectMetadata;
import org.jclouds.s3.filters.RequestAuthorizeSignature;
import org.jclouds.s3.functions.BindRegionToXmlPayload;
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
import org.jclouds.s3.options.PutBucketOptions;
import org.jclouds.s3.options.PutObjectOptions;
import org.jclouds.s3.predicates.validators.BucketNameValidator;
import org.jclouds.s3.xml.LocationConstraintHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -83,6 +74,31 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(RequestAuthorizeSignature.class)
@BlobScope(CONTAINER)
public interface AWSS3AsyncClient extends S3AsyncClient {
/**
* @see S3Client#putBucketInRegion
*/
@Override
@PUT
@Path("/")
@Endpoint(Bucket.class)
@ExceptionParser(ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class)
ListenableFuture<Boolean> putBucketInRegion(
@BinderParam(BindRegionToXmlPayload.class) @Nullable String region,
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
PutBucketOptions... options);
/**
* @see S3Client#getBucketLocation
*/
@Override
@GET
@QueryParams(keys = "location")
@Path("/")
@Endpoint(Bucket.class)
@XMLResponseParser(LocationConstraintHandler.class)
ListenableFuture<String> getBucketLocation(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName);
/**
* @see AWSS3Client#initiateMultipartUpload
*/
@ -91,9 +107,9 @@ public interface AWSS3AsyncClient extends S3AsyncClient {
@Path("/{key}")
@ResponseParser(UploadIdFromHttpResponseViaRegex.class)
ListenableFuture<String> initiateMultipartUpload(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") @ParamParser(ObjectMetadataKey.class) @BinderParam(BindObjectMetadataToRequest.class) ObjectMetadata objectMetadata,
PutObjectOptions... options);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") @ParamParser(ObjectMetadataKey.class) @BinderParam(BindObjectMetadataToRequest.class) ObjectMetadata objectMetadata,
PutObjectOptions... options);
/**
* @see AWSS3Client#abortMultipartUpload
@ -102,8 +118,8 @@ public interface AWSS3AsyncClient extends S3AsyncClient {
@Path("/{key}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> abortMultipartUpload(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @QueryParam("uploadId") String uploadId);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @QueryParam("uploadId") String uploadId);
/**
* @see AWSS3Client#uploadPart
@ -112,9 +128,9 @@ public interface AWSS3AsyncClient extends S3AsyncClient {
@Path("/{key}")
@ResponseParser(ParseETagHeader.class)
ListenableFuture<String> uploadPart(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @QueryParam("partNumber") int partNumber,
@QueryParam("uploadId") String uploadId, Payload part);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @QueryParam("partNumber") int partNumber,
@QueryParam("uploadId") String uploadId, Payload part);
/**
* @see AWSS3Client#completeMultipartUpload
@ -123,8 +139,8 @@ public interface AWSS3AsyncClient extends S3AsyncClient {
@Path("/{key}")
@ResponseParser(ETagFromHttpResponseViaRegex.class)
ListenableFuture<String> completeMultipartUpload(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @QueryParam("uploadId") String uploadId,
@BinderParam(BindPartIdsAndETagsToRequest.class) Map<Integer, String> parts);
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators({ BucketNameValidator.class }) String bucketName,
@PathParam("key") String key, @QueryParam("uploadId") String uploadId,
@BinderParam(BindPartIdsAndETagsToRequest.class) Map<Integer, String> parts);
}

View File

@ -18,14 +18,24 @@
*/
package org.jclouds.aws.s3.config;
import static org.jclouds.aws.domain.Region.US_STANDARD;
import static org.jclouds.location.reference.LocationConstants.ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.s3.AWSS3AsyncClient;
import org.jclouds.aws.s3.AWSS3Client;
import org.jclouds.aws.s3.binders.AssignCorrectHostnameAndBindAsHostPrefixIfConfigured;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.s3.Bucket;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured;
import org.jclouds.s3.config.S3RestClientModule;
import com.google.inject.Provides;
@ -39,6 +49,19 @@ import com.google.inject.Provides;
@ConfiguresRestClient
public class AWSS3RestClientModule extends S3RestClientModule<AWSS3Client, AWSS3AsyncClient> {
@Provides
@Singleton
@Bucket
protected URI provideLocationURI(@Named(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Override
protected void configure() {
bind(BindAsHostPrefixIfConfigured.class).to(AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.class);
super.configure();
}
public AWSS3RestClientModule() {
super(AWSS3Client.class, AWSS3AsyncClient.class);
}

View File

@ -21,8 +21,10 @@ package org.jclouds.aws.s3;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentMap;
import org.jclouds.aws.s3.config.AWSS3RestClientModule;
import org.jclouds.aws.s3.functions.ETagFromHttpResponseViaRegex;
@ -31,6 +33,7 @@ import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.io.Payload;
@ -40,15 +43,18 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.domain.ObjectMetadata;
import org.jclouds.s3.domain.ObjectMetadataBuilder;
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
import org.jclouds.s3.options.PutBucketOptions;
import org.jclouds.s3.options.PutObjectOptions;
import org.jclouds.s3.xml.LocationConstraintHandler;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -63,6 +69,21 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
this.provider = "aws-s3";
}
public void testGetBucketLocationEU() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class);
HttpRequest request = processor.createRequest(method, "eubucket");
assertRequestLineEquals(request, "GET https://eubucket.bucket/?location HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, LocationConstraintHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<AWSS3AsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<AWSS3AsyncClient>>() {
@ -75,15 +96,15 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
}
public void testInitiateMultipartUpload() throws SecurityException, NegativeArraySizeException,
NoSuchMethodException {
NoSuchMethodException {
Method method = AWSS3AsyncClient.class.getMethod("initiateMultipartUpload", String.class, ObjectMetadata.class,
PutObjectOptions[].class);
PutObjectOptions[].class);
HttpRequest request = processor.createRequest(method, "bucket", ObjectMetadataBuilder.create().key("foo")
.contentMD5(new byte[] { 1, 2, 3, 4 }).build());
.contentMD5(new byte[] { 1, 2, 3, 4 }).build());
assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploads HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Content-MD5: AQIDBA==\nContent-Type: binary/octet-stream\nHost: bucket."
+ url + "\n");
+ url + "\n");
assertPayloadEquals(request, null, null, false);
// as this is a payload-related command, but with no payload, be careful that we check
@ -92,9 +113,8 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploads HTTP/1.1");
assertNonPayloadHeadersEqual(request,
"Authorization: AWS identity:Sp1FX4svL9P2u2bFJwroaYpSANo=\nContent-MD5: AQIDBA==\n"
+ "Content-Type: binary/octet-stream\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket." + url
+ "\n");
"Authorization: AWS identity:Sp1FX4svL9P2u2bFJwroaYpSANo=\nContent-MD5: AQIDBA==\n"
+ "Content-Type: binary/octet-stream\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket." + url + "\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UploadIdFromHttpResponseViaRegex.class);
@ -106,9 +126,9 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
public void testAbortMultipartUpload() throws SecurityException, NegativeArraySizeException, NoSuchMethodException {
Method method = AWSS3AsyncClient.class
.getMethod("abortMultipartUpload", String.class, String.class, String.class);
HttpRequest request = processor.createRequest(method, "bucket", "foo", "asdsadasdas", 1, Payloads
.newStringPayload(""));
.getMethod("abortMultipartUpload", String.class, String.class, String.class);
HttpRequest request = processor.createRequest(method, "bucket", "foo", "asdsadasdas", 1,
Payloads.newStringPayload(""));
assertRequestLineEquals(request, "DELETE https://bucket." + url + "/foo?uploadId=asdsadasdas HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n");
@ -123,9 +143,9 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
public void testUploadPart() throws SecurityException, NegativeArraySizeException, NoSuchMethodException {
Method method = AWSS3AsyncClient.class.getMethod("uploadPart", String.class, String.class, int.class,
String.class, Payload.class);
HttpRequest request = processor.createRequest(method, "bucket", "foo", 1, "asdsadasdas", Payloads
.newStringPayload(""));
String.class, Payload.class);
HttpRequest request = processor.createRequest(method, "bucket", "foo", 1, "asdsadasdas",
Payloads.newStringPayload(""));
assertRequestLineEquals(request, "PUT https://bucket." + url + "/foo?partNumber=1&uploadId=asdsadasdas HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n");
@ -139,18 +159,18 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
}
public void testCompleteMultipartUpload() throws SecurityException, NegativeArraySizeException,
NoSuchMethodException {
NoSuchMethodException {
Method method = AWSS3AsyncClient.class.getMethod("completeMultipartUpload", String.class, String.class,
String.class, Map.class);
HttpRequest request = processor.createRequest(method, "bucket", "foo", "asdsadasdas", ImmutableMap
.<Integer, String> of(1, "\"a54357aff0632cce46d942af68356b38\""));
String.class, Map.class);
HttpRequest request = processor.createRequest(method, "bucket", "foo", "asdsadasdas",
ImmutableMap.<Integer, String> of(1, "\"a54357aff0632cce46d942af68356b38\""));
assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploadId=asdsadasdas HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n");
assertPayloadEquals(
request,
"<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>\"a54357aff0632cce46d942af68356b38\"</ETag></Part></CompleteMultipartUpload>",
"text/xml", false);
request,
"<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>\"a54357aff0632cce46d942af68356b38\"</ETag></Part></CompleteMultipartUpload>",
"text/xml", false);
assertResponseParserClassEquals(method, request, ETagFromHttpResponseViaRegex.class);
assertSaxResponseParserClassEquals(method, null);
@ -160,16 +180,16 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
}
public void testPutBucketEu() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
NoSuchMethodException, IOException {
Method method = AWSS3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array
.newInstance(PutBucketOptions.class, 0).getClass());
.newInstance(PutBucketOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "EU", "bucket");
assertRequestLineEquals(request, "PUT https://bucket." + url + "/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n");
assertPayloadEquals(request,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
"text/xml", false);
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
"text/xml", false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
@ -186,6 +206,18 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
super();
}
@Override
protected ConcurrentMap<String, String> bucketToRegion() {
ConcurrentMap<String, String> returnVal = Maps.newConcurrentMap();
returnVal.put("eubucket", "EU");
return returnVal;
}
@Override
protected URI provideLocationURI(String endpoint) {
return URI.create("https://bucket");
}
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "2009-11-08T15:54:08.897Z";

View File

@ -48,9 +48,9 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.config.CommonVCloudRestClientModule.OrgVDCSupplier;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
@ -62,6 +62,7 @@ import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule;
import org.jclouds.vcloud.terremark.domain.Protocol;
@ -104,8 +105,8 @@ import com.google.inject.TypeLiteral;
public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkECloudAsyncClient> {
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getNetwork", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"));
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
@ -118,9 +119,25 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testDelete() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("deleteVApp", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1"));
assertRequestLineEquals(request, "DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseTaskFromLocationHeader.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class,
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "vdc", "network");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2 HTTP/1.1");
@ -169,17 +186,19 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name");
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertPayloadEquals(
request,
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class);
@ -189,21 +208,26 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
}
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row").addNetworkConfig(
new NetworkConfig(URI.create("http://network"))));
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(
method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
URI.create("https://vcloud/vAppTemplate/3"),
"name",
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row")
.addNetworkConfig(new NetworkConfig(URI.create("http://network"))));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertPayloadEquals(
request,
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class);
@ -214,8 +238,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testActivatePublicIpInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("activatePublicIpInVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/publicIps/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.publicIp+xml\n");
@ -230,8 +254,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getAllInternetServicesInVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/internetServices/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetServicesList+xml\n");
@ -276,16 +300,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testAddInternetServiceToExistingIp() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/publicIp/12"),
"name", Protocol.TCP, 22);
"name", Protocol.TCP, 22);
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(
getClass().getResourceAsStream("/terremark/CreateInternetService-test2.xml")).replace(
"vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.ecloud.internetService+xml", false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateInternetService-test2.xml"))
.replace("vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.ecloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
@ -296,16 +320,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testAddInternetServiceToExistingIpOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/publicIp/12"),
"name", Protocol.TCP, 22, disabled().withDescription("yahoo").monitorDisabled());
"name", Protocol.TCP, 22, disabled().withDescription("yahoo").monitorDisabled());
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.ecloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(
getClass().getResourceAsStream("/CreateInternetService-options-test.xml")).replace(
"vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.ecloud.internetService+xml", false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateInternetService-options-test.xml"))
.replace("vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.ecloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null);
@ -315,16 +339,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addNode", URI.class, String.class, String.class,
int.class, AddNodeOptions[].class);
int.class, AddNodeOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/internetService/12"),
"10.2.2.2", "name", 22);
"10.2.2.2", "name", 22);
assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(
getClass().getResourceAsStream("/terremark/CreateNodeService-test2.xml")).replace(
"vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"), "application/vnd.tmrk.vCloud.nodeService+xml",
false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateNodeService-test2.xml"))
.replace("vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
@ -335,17 +359,17 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("addNode", URI.class, String.class, String.class,
int.class, AddNodeOptions[].class);
int.class, AddNodeOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/internetService/12"),
"10.2.2.2", "name", 22, AddNodeOptions.Builder.disabled().withDescription("yahoo"));
"10.2.2.2", "name", 22, AddNodeOptions.Builder.disabled().withDescription("yahoo"));
assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(
getClass().getResourceAsStream("/terremark/CreateNodeService-options-test.xml")).replace(
"vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"), "application/vnd.tmrk.vCloud.nodeService+xml",
false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateNodeService-options-test.xml"))
.replace("vCloudExpressExtensions-1.6", "eCloudExtensions-2.7"),
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
@ -355,8 +379,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
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");
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");
@ -371,16 +395,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testConfigureNodeWithDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", URI.class, String.class,
boolean.class, String.class);
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/nodeService/12"),
"name", true, "eggs");
"name", true, "eggs");
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:eCloudExtensions-2.7\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
request,
"<NodeService xmlns=\"urn:tmrk:eCloudExtensions-2.7\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
@ -390,16 +414,16 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public void testConfigureNodeNoDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", URI.class, String.class,
boolean.class, String.class);
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/nodeService/12"),
"name", true, null);
"name", true, null);
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:eCloudExtensions-2.7\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
request,
"<NodeService xmlns=\"urn:tmrk:eCloudExtensions-2.7\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
@ -443,7 +467,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
assertRequestLineEquals(request, "GET https://vcloud/extensions/template/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request,
"Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n");
"Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -455,8 +479,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
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"));
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");
@ -547,7 +571,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkECloudRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcloud/login");
}
@ -575,8 +599,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
@Override
public ReferenceType apply(ReferenceType from) {
return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI.create(from
.getHref().toASCIIString()
+ "/keysList"));
.getHref().toASCIIString() + "/keysList"));
}
});
}
@ -591,17 +614,21 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
@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
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"))));
}
}
@ -643,7 +670,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@ -664,21 +691,25 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of("vdc", new TerremarkVDCImpl("vdc", null, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), VDCStatus.READY, null, "description",
ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED, new Capacity("MB", 0, 0, 0, 0), new Capacity(
"MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), ImmutableMap.<String, ReferenceType> of(
"vapp", new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")), "network",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED,
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
TerremarkVCloudMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
new ReferenceTypeImpl("publicIps", TerremarkVCloudMediaType.PUBLICIPSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
new ReferenceTypeImpl("publicIps", TerremarkVCloudMediaType.PUBLICIPSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1")), new ReferenceTypeImpl(
"internetServices", TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
}
}
}

View File

@ -48,9 +48,9 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Catalog;
@ -62,6 +62,7 @@ import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
import org.jclouds.vcloud.terremark.domain.Protocol;
@ -104,8 +105,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"));
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
@ -118,9 +119,25 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
checkFilters(request);
}
public void testDelete() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("deleteVApp", URI.class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1"));
assertRequestLineEquals(request, "DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseTaskFromLocationHeader.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed",
String.class, String.class, String.class);
String.class, String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "item");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1");
@ -169,17 +186,19 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class,
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name");
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertPayloadEquals(
request,
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class);
@ -189,21 +208,26 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
}
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class,
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row").addNetworkConfig(
new NetworkConfig(URI.create("http://network"))));
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(
method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
URI.create("https://vcloud/vAppTemplate/3"),
"name",
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row")
.addNetworkConfig(new NetworkConfig(URI.create("http://network"))));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertPayloadEquals(
request,
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class);
@ -214,14 +238,15 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testAddInternetService() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addInternetServiceToVDC", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "name", Protocol.TCP, 22);
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "name", Protocol.TCP, 22);
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/internetServices/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-test2.xml")), "application/vnd.tmrk.vCloud.internetService+xml", false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateInternetService-test2.xml")),
"application/vnd.tmrk.vCloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
@ -232,16 +257,18 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addInternetServiceToVDC", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "name", Protocol.TCP, 22, disabled()
.withDescription("yahoo"));
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "name", Protocol.TCP, 22, disabled()
.withDescription("yahoo"));
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/internetServices/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml")),
"application/vnd.tmrk.vCloud.internetService+xml", false);
assertPayloadEquals(
request,
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml")),
"application/vnd.tmrk.vCloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null);
@ -251,8 +278,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getAllInternetServicesInVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/internetServices/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n");
@ -297,14 +324,15 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testAddInternetServiceToExistingIp() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/publicIp/12"),
"name", Protocol.TCP, 22);
"name", Protocol.TCP, 22);
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-test2.xml")), "application/vnd.tmrk.vCloud.internetService+xml", false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateInternetService-test2.xml")),
"application/vnd.tmrk.vCloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
@ -315,15 +343,17 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testAddInternetServiceToExistingIpOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addInternetServiceToExistingIp", URI.class,
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
String.class, Protocol.class, int.class, AddInternetServiceOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/publicIp/12"),
"name", Protocol.TCP, 22, disabled().withDescription("yahoo"));
"name", Protocol.TCP, 22, disabled().withDescription("yahoo"));
assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml")),
"application/vnd.tmrk.vCloud.internetService+xml", false);
assertPayloadEquals(
request,
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml")),
"application/vnd.tmrk.vCloud.internetService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null);
@ -333,14 +363,15 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addNode", URI.class, String.class,
String.class, int.class, AddNodeOptions[].class);
String.class, int.class, AddNodeOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/internetService/12"),
"10.2.2.2", "name", 22);
"10.2.2.2", "name", 22);
assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService-test2.xml")), "application/vnd.tmrk.vCloud.nodeService+xml", false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateNodeService-test2.xml")),
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
@ -351,15 +382,16 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("addNode", URI.class, String.class,
String.class, int.class, AddNodeOptions[].class);
String.class, int.class, AddNodeOptions[].class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/internetService/12"),
"10.2.2.2", "name", 22, AddNodeOptions.Builder.disabled().withDescription("yahoo"));
"10.2.2.2", "name", 22, AddNodeOptions.Builder.disabled().withDescription("yahoo"));
assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService-options-test.xml")), "application/vnd.tmrk.vCloud.nodeService+xml", false);
assertPayloadEquals(request,
Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateNodeService-options-test.xml")),
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
@ -369,8 +401,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testGetKeyPairInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("findKeyPairInOrg", URI.class, String.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), "keyPair");
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.vcloudExpress.keysList+xml\n");
@ -385,16 +417,16 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testConfigureNodeWithDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("configureNode", URI.class, String.class,
boolean.class, String.class);
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/nodeService/12"),
"name", true, "eggs");
"name", true, "eggs");
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
@ -404,16 +436,16 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testConfigureNodeNoDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("configureNode", URI.class, String.class,
boolean.class, String.class);
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/extensions/nodeService/12"),
"name", true, null);
"name", true, null);
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
@ -453,12 +485,12 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCustomizationOptions", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud/extensions/template/12/options/customization"));
HttpRequest request = processor.createRequest(method,
URI.create("https://vcloud/extensions/template/12/options/customization"));
assertRequestLineEquals(request, "GET https://vcloud/extensions/template/12/options/customization HTTP/1.1");
assertNonPayloadHeadersEqual(request,
"Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n");
"Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -470,8 +502,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public void testListKeyPairsInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("listKeyPairsInOrg", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
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.vcloudExpress.keysList+xml\n");
@ -596,7 +628,7 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
@Override
public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("trmk-vcloudexpress", "identity", "credential",
new Properties());
new Properties());
}
@RequiresHttp
@ -604,7 +636,7 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkVCloudExpressRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcloud/login");
}
@ -658,7 +690,7 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
@Override
public ReferenceType apply(ReferenceType from) {
return new ReferenceTypeImpl(from.getName(), TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI
.create(from.getHref().toASCIIString() + "/keysList"));
.create(from.getHref().toASCIIString() + "/keysList"));
}
});
@ -676,18 +708,21 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
@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",
TerremarkVCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc",
TerremarkVCloudExpressMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
TerremarkVCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), new ReferenceTypeImpl(
"keysList", TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI
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", TerremarkVCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of(
"vdc",
new ReferenceTypeImpl("vdc", TerremarkVCloudExpressMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
TerremarkVCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")),
new ReferenceTypeImpl("keysList", TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"))));
}
}
@ -703,22 +738,25 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of("vdc", new TerremarkVDCImpl("vdc", null, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), VDCStatus.READY, null, "description",
ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED, new Capacity("MB", 0, 0, 0, 0),
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
ImmutableMap.<String, ReferenceType> of("vapp", new ReferenceTypeImpl("vapp",
"application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")), "network",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED,
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
TerremarkVCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
new ReferenceTypeImpl("publicIps", TerremarkVCloudExpressMediaType.PUBLICIPSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
new ReferenceTypeImpl("publicIps", TerremarkVCloudExpressMediaType.PUBLICIPSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1")), new ReferenceTypeImpl(
"internetServices", TerremarkVCloudExpressMediaType.INTERNETSERVICESLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
}
}
@ -734,7 +772,7 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}