mirror of https://github.com/apache/jclouds.git
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:
parent
103dd7315b
commit
7d20658b02
|
@ -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<URI> createDirectory(@PathParam("directoryName") String directoryName, PutOptions... options);
|
||||
|
|
|
@ -131,7 +131,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container) {
|
||||
return transform(async.createDirectory(container), new Function<URI, Boolean>() {
|
||||
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<URI, Boolean>() {
|
||||
|
||||
public Boolean apply(URI from) {
|
||||
return true;
|
||||
return from != null;
|
||||
}
|
||||
|
||||
}, userExecutor);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<AtmosAsyncClient>
|
|||
|
||||
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<AtmosAsyncClient>
|
|||
|
||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertFallbackClassEquals(method, EndpointIfAlreadyExists.class);
|
||||
assertFallbackClassEquals(method, NullOnKeyAlreadyExists.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
|
|
@ -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<? extends DirectoryEntry> r2 = getApi().listDirectory(id.getObjectName());
|
||||
assert r2 != null;
|
||||
}
|
||||
// subsequent creation should fail
|
||||
assertNull(getApi().createDirectory(privateDirectory));
|
||||
}
|
||||
|
||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateDirectory" })
|
||||
|
|
|
@ -106,4 +106,17 @@ public final class BlobStoreFallbacks {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue