diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java index f8ad7253d1..355e0d5def 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java @@ -42,7 +42,6 @@ import org.jclouds.atmos.domain.BoundedSet; import org.jclouds.atmos.domain.DirectoryEntry; import org.jclouds.atmos.domain.SystemMetadata; import org.jclouds.atmos.domain.UserMetadata; -import org.jclouds.atmos.fallbacks.EndpointIfAlreadyExists; import org.jclouds.atmos.filters.SignRequest; import org.jclouds.atmos.functions.AtmosObjectName; import org.jclouds.atmos.functions.ParseDirectoryListFromContentAndHeaders; @@ -52,6 +51,7 @@ import org.jclouds.atmos.functions.ParseUserMetadataFromHeaders; import org.jclouds.atmos.functions.ReturnTrueIfGroupACLIsOtherRead; import org.jclouds.atmos.options.ListOptions; import org.jclouds.atmos.options.PutOptions; +import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404; import org.jclouds.http.options.GetOptions; @@ -115,7 +115,7 @@ public interface AtmosAsyncClient extends Closeable { @Named("CreateDirectory") @POST @Path("/{directoryName}/") - @Fallback(EndpointIfAlreadyExists.class) + @Fallback(NullOnKeyAlreadyExists.class) @Produces(MediaType.APPLICATION_OCTET_STREAM) @Consumes(MediaType.WILDCARD) ListenableFuture createDirectory(@PathParam("directoryName") String directoryName, PutOptions... options); diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java index 79f7579dcc..2981273490 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java @@ -131,7 +131,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { public ListenableFuture createContainerInLocation(Location location, String container) { return transform(async.createDirectory(container), new Function() { public Boolean apply(URI from) { - return true; + return from != null; } }, userExecutor); } @@ -277,7 +277,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { return transform(async.createDirectory(container, publicRead()), new Function() { public Boolean apply(URI from) { - return true; + return from != null; } }, userExecutor); diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java index 58eb99b5b6..ce3bcfb1b9 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java @@ -118,8 +118,7 @@ public class AtmosBlobStore extends BaseBlobStore { */ @Override public boolean createContainerInLocation(Location location, String container) { - sync.createDirectory(container); - return true; + return sync.createDirectory(container) != null; } /** @@ -240,8 +239,7 @@ public class AtmosBlobStore extends BaseBlobStore { @Override public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { if (options.isPublicRead()) { - sync.createDirectory(container, publicRead()); - return true; + return sync.createDirectory(container, publicRead()) != null; } return createContainerInLocation(location, container); } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java index 2d35c04045..8287417072 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java @@ -38,6 +38,7 @@ import org.jclouds.atmos.functions.ParseSystemMetadataFromHeaders; import org.jclouds.atmos.functions.ReturnTrueIfGroupACLIsOtherRead; import org.jclouds.atmos.options.ListOptions; import org.jclouds.atmos.options.PutOptions; +import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; @@ -137,7 +138,7 @@ public class AtmosAsyncClientTest extends BaseAsyncClientTest assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, EndpointIfAlreadyExists.class); + assertFallbackClassEquals(method, NullOnKeyAlreadyExists.class); checkFilters(request); } @@ -153,7 +154,7 @@ public class AtmosAsyncClientTest extends BaseAsyncClientTest assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, EndpointIfAlreadyExists.class); + assertFallbackClassEquals(method, NullOnKeyAlreadyExists.class); checkFilters(request); } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java index dc9fd83fe0..cfc1962e49 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.atmos; import static com.google.common.base.Preconditions.checkState; import static org.jclouds.util.Predicates2.retry; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; import static org.testng.Assert.fail; import java.io.IOException; @@ -140,6 +141,8 @@ public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest { BoundedSet r2 = getApi().listDirectory(id.getObjectName()); assert r2 != null; } + // subsequent creation should fail + assertNull(getApi().createDirectory(privateDirectory)); } @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateDirectory" }) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreFallbacks.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreFallbacks.java index b645ed3d0e..5434545987 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreFallbacks.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreFallbacks.java @@ -106,4 +106,17 @@ public final class BlobStoreFallbacks { throw propagate(t); } } + + public static final class NullOnKeyAlreadyExists implements Fallback { + public ListenableFuture create(Throwable t) throws Exception { + return immediateFuture(createOrPropagate(t)); + } + + public Object createOrPropagate(Throwable t) throws Exception { + if (checkNotNull(t, "throwable") instanceof KeyAlreadyExistsException) { + return null; + } + throw propagate(t); + } + } }