Tie up odds and ends from LocalStorageStrategy

Use LocalStorageStrategy instead of TransientStorageStrategy and
handle IOExceptions.  Aso use dummy location in filesystem blobstore.
This commit is contained in:
Andrew Gaul 2012-07-18 06:21:50 -07:00 committed by Andrew Gaul
parent bf06b51788
commit 8a9265f015
5 changed files with 36 additions and 10 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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<UriBuilder> uriBuilders;
@Inject
@ -155,7 +155,13 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
return immediateFailedFuture(cnfe(container));
// Loading blobs from container
Iterable<String> blobBelongingToContainer = storageStrategy.getBlobKeysInsideContainer(container);
Iterable<String> 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<StorageMetadata> contents = newTreeSet(transform(blobBelongingToContainer,
new Function<String, StorageMetadata>() {
@ -303,10 +309,15 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Boolean> 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);

View File

@ -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);
}