JCLOUDS-334. Return URI only if container created

This allows us to honor the BlobStore.createContainerInLocation
interface and gives consistency with other providers.
This commit is contained in:
Andrew Gaul 2013-10-04 21:32:48 -07:00
parent f6b502707d
commit 1ee9a61fb5
6 changed files with 25 additions and 10 deletions

View File

@ -42,7 +42,6 @@ import org.jclouds.atmos.domain.BoundedSet;
import org.jclouds.atmos.domain.DirectoryEntry; import org.jclouds.atmos.domain.DirectoryEntry;
import org.jclouds.atmos.domain.SystemMetadata; import org.jclouds.atmos.domain.SystemMetadata;
import org.jclouds.atmos.domain.UserMetadata; import org.jclouds.atmos.domain.UserMetadata;
import org.jclouds.atmos.fallbacks.EndpointIfAlreadyExists;
import org.jclouds.atmos.filters.SignRequest; import org.jclouds.atmos.filters.SignRequest;
import org.jclouds.atmos.functions.AtmosObjectName; import org.jclouds.atmos.functions.AtmosObjectName;
import org.jclouds.atmos.functions.ParseDirectoryListFromContentAndHeaders; 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.functions.ReturnTrueIfGroupACLIsOtherRead;
import org.jclouds.atmos.options.ListOptions; import org.jclouds.atmos.options.ListOptions;
import org.jclouds.atmos.options.PutOptions; import org.jclouds.atmos.options.PutOptions;
import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists;
import org.jclouds.blobstore.BlobStoreFallbacks.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -115,7 +115,7 @@ public interface AtmosAsyncClient extends Closeable {
@Named("CreateDirectory") @Named("CreateDirectory")
@POST @POST
@Path("/{directoryName}/") @Path("/{directoryName}/")
@Fallback(EndpointIfAlreadyExists.class) @Fallback(NullOnKeyAlreadyExists.class)
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.WILDCARD) @Consumes(MediaType.WILDCARD)
ListenableFuture<URI> createDirectory(@PathParam("directoryName") String directoryName, PutOptions... options); ListenableFuture<URI> createDirectory(@PathParam("directoryName") String directoryName, PutOptions... options);

View File

@ -131,7 +131,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container) { public ListenableFuture<Boolean> createContainerInLocation(Location location, String container) {
return transform(async.createDirectory(container), new Function<URI, Boolean>() { return transform(async.createDirectory(container), new Function<URI, Boolean>() {
public Boolean apply(URI from) { public Boolean apply(URI from) {
return true; return from != null;
} }
}, userExecutor); }, userExecutor);
} }
@ -277,7 +277,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
return transform(async.createDirectory(container, publicRead()), new Function<URI, Boolean>() { return transform(async.createDirectory(container, publicRead()), new Function<URI, Boolean>() {
public Boolean apply(URI from) { public Boolean apply(URI from) {
return true; return from != null;
} }
}, userExecutor); }, userExecutor);

View File

@ -118,8 +118,7 @@ public class AtmosBlobStore extends BaseBlobStore {
*/ */
@Override @Override
public boolean createContainerInLocation(Location location, String container) { public boolean createContainerInLocation(Location location, String container) {
sync.createDirectory(container); return sync.createDirectory(container) != null;
return true;
} }
/** /**
@ -240,8 +239,7 @@ public class AtmosBlobStore extends BaseBlobStore {
@Override @Override
public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) {
if (options.isPublicRead()) { if (options.isPublicRead()) {
sync.createDirectory(container, publicRead()); return sync.createDirectory(container, publicRead()) != null;
return true;
} }
return createContainerInLocation(location, container); return createContainerInLocation(location, container);
} }

View File

@ -38,6 +38,7 @@ import org.jclouds.atmos.functions.ParseSystemMetadataFromHeaders;
import org.jclouds.atmos.functions.ReturnTrueIfGroupACLIsOtherRead; import org.jclouds.atmos.functions.ReturnTrueIfGroupACLIsOtherRead;
import org.jclouds.atmos.options.ListOptions; import org.jclouds.atmos.options.ListOptions;
import org.jclouds.atmos.options.PutOptions; import org.jclouds.atmos.options.PutOptions;
import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists;
import org.jclouds.blobstore.BlobStoreFallbacks.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
@ -137,7 +138,7 @@ public class AtmosAsyncClientTest extends BaseAsyncClientTest<AtmosAsyncClient>
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EndpointIfAlreadyExists.class); assertFallbackClassEquals(method, NullOnKeyAlreadyExists.class);
checkFilters(request); checkFilters(request);
} }
@ -153,7 +154,7 @@ public class AtmosAsyncClientTest extends BaseAsyncClientTest<AtmosAsyncClient>
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EndpointIfAlreadyExists.class); assertFallbackClassEquals(method, NullOnKeyAlreadyExists.class);
checkFilters(request); checkFilters(request);
} }

View File

@ -19,6 +19,7 @@ package org.jclouds.atmos;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.util.Predicates2.retry; import static org.jclouds.util.Predicates2.retry;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.io.IOException; import java.io.IOException;
@ -140,6 +141,8 @@ public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest {
BoundedSet<? extends DirectoryEntry> r2 = getApi().listDirectory(id.getObjectName()); BoundedSet<? extends DirectoryEntry> r2 = getApi().listDirectory(id.getObjectName());
assert r2 != null; assert r2 != null;
} }
// subsequent creation should fail
assertNull(getApi().createDirectory(privateDirectory));
} }
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateDirectory" }) @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateDirectory" })

View File

@ -106,4 +106,17 @@ public final class BlobStoreFallbacks {
throw propagate(t); throw propagate(t);
} }
} }
public static final class NullOnKeyAlreadyExists implements Fallback<Object> {
public ListenableFuture<Object> 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);
}
}
} }