Return false if container already exists in AWS-S3

AWS-S3 returns the incorrect creation status when a container already
exists in the us-standard (or default) region.  Fixes JCLOUDS-334.
This commit is contained in:
Diwaker Gupta 2013-10-09 13:49:29 -07:00 committed by Andrew Gaul
parent e30f865215
commit 13f38d628d
2 changed files with 34 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import javax.inject.Named;
import javax.inject.Provider;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.AWSS3ApiMetadata;
import org.jclouds.aws.s3.AWSS3AsyncClient;
import org.jclouds.aws.s3.AWSS3Client;
@ -36,6 +37,7 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.options.CreateContainerOptions;
import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils;
@ -51,11 +53,13 @@ import org.jclouds.s3.domain.AccessControlList;
import org.jclouds.s3.domain.BucketMetadata;
import org.jclouds.s3.domain.CannedAccessPolicy;
import org.jclouds.s3.domain.ObjectMetadata;
import org.jclouds.s3.options.PutBucketOptions;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@ -121,4 +125,17 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore {
blob2Object.apply(blob), options);
}
@Override
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container,
CreateContainerOptions options) {
if ((location == null || location.getId().equals(Region.US_STANDARD)) &&
Futures.getUnchecked(containerExists(container))) {
// AWS-S3 returns the incorrect creation status when a container
// already exists in the us-standard (or default) region. See
// JCLOUDS-334 for details.
// TODO: executing on the calling thread
return Futures.immediateFuture(Boolean.FALSE);
}
return super.createContainerInLocation(location, container, options);
}
}

View File

@ -23,6 +23,7 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Provider;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.AWSS3ApiMetadata;
import org.jclouds.aws.s3.AWSS3Client;
import org.jclouds.aws.s3.blobstore.options.AWSS3PutObjectOptions;
@ -33,6 +34,7 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.options.CreateContainerOptions;
import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils;
@ -53,6 +55,8 @@ import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provide AWS S3 specific extensions.
@ -113,4 +117,17 @@ public class AWSS3BlobStore extends S3BlobStore {
return getContext().unwrap(AWSS3ApiMetadata.CONTEXT_TOKEN).getApi().putObject(container, blob2Object.apply(blob),
options);
}
@Override
public boolean createContainerInLocation(Location location, String container,
CreateContainerOptions options) {
if ((location == null || location.getId().equals(Region.US_STANDARD)) &&
containerExists(container)) {
// AWS-S3 returns the incorrect creation status when a container
// already exists in the us-standard (or default) region. See
// JCLOUDS-334 for details.
return false;
}
return super.createContainerInLocation(location, container, options);
}
}