From 8a9265f015d5bfe05e48b9751ba22ea932746418 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 18 Jul 2012 06:21:50 -0700 Subject: [PATCH] Tie up odds and ends from LocalStorageStrategy Use LocalStorageStrategy instead of TransientStorageStrategy and handle IOExceptions. Aso use dummy location in filesystem blobstore. --- .../filesystem/FilesystemAsyncBlobStore.java | 4 +-- .../FilesystemStorageStrategyImpl.java | 5 +++ .../blobstore/LocalStorageStrategy.java | 5 +++ .../blobstore/TransientAsyncBlobStore.java | 31 ++++++++++++++----- .../blobstore/TransientStorageStrategy.java | 1 + 5 files changed, 36 insertions(+), 10 deletions(-) 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 a533e03632..b5cdd7e44e 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java @@ -324,6 +324,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { MutableStorageMetadata cmd = create(); cmd.setName(name); cmd.setType(StorageType.CONTAINER); + cmd.setLocation(storageStrategy.getLocation(name)); return cmd; } }), null)); @@ -461,9 +462,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { } try { - // TODO - // must override existing file? - storageStrategy.putBlob(containerName, blob); } catch (IOException e) { logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey, 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 5e1814faf0..2bdd94e89d 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 @@ -266,6 +266,11 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { return blobNames; } + @Override + public Location getLocation(final String containerName) { + return null; + } + 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 1d830afdd0..c359cf7dd2 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java @@ -121,4 +121,9 @@ public interface LocalStorageStrategy { */ void putBlob(String containerName, Blob blob) throws IOException; + /** + * @param containerName name of container + * @return Location of container or null + */ + Location getLocation(String containerName); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index 4e6074a6a6..463de6d3a4 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -119,7 +119,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { protected final ContentMetadataCodec contentMetadataCodec; protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName; protected final Factory blobFactory; - protected final TransientStorageStrategy storageStrategy; + protected final LocalStorageStrategy storageStrategy; protected final Provider uriBuilders; @Inject @@ -155,7 +155,13 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { return immediateFailedFuture(cnfe(container)); // Loading blobs from container - Iterable blobBelongingToContainer = storageStrategy.getBlobKeysInsideContainer(container); + Iterable blobBelongingToContainer = null; + try { + blobBelongingToContainer = storageStrategy.getBlobKeysInsideContainer(container); + } catch (IOException e) { + logger.error(e, "An error occurred loading blobs contained into container %s", container); + Throwables.propagate(e); + } SortedSet contents = newTreeSet(transform(blobBelongingToContainer, new Function() { @@ -303,10 +309,15 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { public ListenableFuture deleteContainerIfEmpty(final String container) { Boolean returnVal = true; if (storageStrategy.containerExists(container)) { - if (Iterables.isEmpty(storageStrategy.getBlobKeysInsideContainer(container))) - storageStrategy.deleteContainer(container); - else - returnVal = false; + 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); } @@ -470,7 +481,13 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { blob = createUpdatedCopyOfBlobInContainer(containerName, blob); - storageStrategy.putBlob(containerName, blob); + try { + storageStrategy.putBlob(containerName, blob); + } catch (IOException e) { + logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey, + containerName); + Throwables.propagate(e); + } String eTag = getEtag(blob); return immediateFuture(eTag); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java index a9030c1f42..7b506c5aa6 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java @@ -95,6 +95,7 @@ public class TransientStorageStrategy implements LocalStorageStrategy { return containerToBlobs.get(containerName).keySet(); } + @Override public Location getLocation(final String containerName) { return containerToLocation.get(containerName); }