diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java index c8c25bdbdb..8d1aca8592 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java @@ -33,7 +33,6 @@ import static com.google.common.util.concurrent.Futures.immediateFailedFuture; import static com.google.common.util.concurrent.Futures.immediateFuture; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.util.Date; import java.util.Set; @@ -43,8 +42,6 @@ import java.util.concurrent.ExecutorService; import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import org.jclouds.Constants; import org.jclouds.blobstore.BlobStoreContext; @@ -71,7 +68,6 @@ import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.collect.Memoized; import org.jclouds.domain.Location; -import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -81,7 +77,6 @@ import org.jclouds.io.ContentMetadata; import org.jclouds.io.ContentMetadataCodec; import org.jclouds.io.Payload; import org.jclouds.logging.Logger; -import org.jclouds.rest.annotations.ParamValidators; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -190,7 +185,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { } } - final String delimiter = options.isRecursive() ? null : File.separator; + final String delimiter = options.isRecursive() ? null : storageStrategy.getSeparator(); if (delimiter != null) { SortedSet commonPrefixes = newTreeSet( transform(contents, new CommonPrefixes(prefix, delimiter))); @@ -237,6 +232,15 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { return immediateFuture(null); } + /** + * {@inheritDoc} + */ + @Override + public ListenableFuture clearContainer(final String container) { + storageStrategy.clearContainer(container); + return immediateFuture(null); + } + /** * Override parent method because it uses strange futures and listenables * that creates problem in the test if more than one test that deletes the @@ -251,6 +255,22 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { return immediateFuture(null); } + public ListenableFuture deleteContainerIfEmpty(final String container) { + Boolean returnVal = true; + if (storageStrategy.containerExists(container)) { + try { + if (Iterables.isEmpty(storageStrategy.getBlobKeysInsideContainer(container))) + storageStrategy.deleteContainer(container); + else + returnVal = false; + } catch (IOException e) { + logger.error(e, "An error occurred loading blobs contained into container %s", container); + Throwables.propagate(e); + } + } + return immediateFuture(returnVal); + } + /** * {@inheritDoc} */ @@ -285,11 +305,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { /** * {@inheritDoc} */ - @Path("{container}") @Override public ListenableFuture createContainerInLocation(final Location location, - @PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) { - boolean result = storageStrategy.createContainerInLocation(name, null); + final String name) { + boolean result = storageStrategy.createContainerInLocation(name, location); return immediateFuture(result); } diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index 414292960b..c652dd7d62 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -116,6 +116,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { } public boolean createContainer(String container) { + filesystemContainerNameValidator.validate(container); return createContainerInLocation(container, null); } @@ -279,6 +280,11 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { return null; } + @Override + public String getSeparator() { + return File.separator; + } + public boolean directoryExists(String container, String directory) { return buildPathAndChecksIfDirectoryExists(container, directory); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java index 16bce85215..a6a6ec7b4c 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java @@ -127,4 +127,7 @@ public interface LocalStorageStrategy { * @return Location of container or null */ Location getLocation(String containerName); + + /** @return path separator, either / or \ */ + String getSeparator(); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index f7696af7f3..72fde80d74 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -181,7 +181,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { } } - final String delimiter = options.isRecursive() ? null : "/"; + final String delimiter = options.isRecursive() ? null : storageStrategy.getSeparator(); if (delimiter != null) { SortedSet commonPrefixes = newTreeSet( transform(contents, new CommonPrefixes(prefix, delimiter))); @@ -238,7 +238,12 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { } /** - * {@inheritDoc} + * Override parent method because it uses strange futures and listenables + * that creates problem in the test if more than one test that deletes the + * container is executed + * + * @param container + * @return */ @Override public ListenableFuture deleteContainer(final String container) { diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java index 89e1480bb3..421c3fb576 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java @@ -143,6 +143,11 @@ public class TransientStorageStrategy implements LocalStorageStrategy { return containerToLocation.get(containerName); } + @Override + public String getSeparator() { + return "/"; + } + private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in) { checkNotNull(in, "blob"); checkNotNull(in.getPayload(), "blob.payload");