mirror of https://github.com/apache/jclouds.git
Miscellaneous local blobstore cleanups
There are no more functional differences between the filesystem and transient blobstores. This is the last commit before introducing a unified LocalAsyncBlobStore class.
This commit is contained in:
parent
b890765e9e
commit
756e46333f
|
@ -33,7 +33,6 @@ import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
|
||||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -43,8 +42,6 @@ import java.util.concurrent.ExecutorService;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
@ -71,7 +68,6 @@ import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -81,7 +77,6 @@ import org.jclouds.io.ContentMetadata;
|
||||||
import org.jclouds.io.ContentMetadataCodec;
|
import org.jclouds.io.ContentMetadataCodec;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.annotations.ParamValidators;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
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) {
|
if (delimiter != null) {
|
||||||
SortedSet<String> commonPrefixes = newTreeSet(
|
SortedSet<String> commonPrefixes = newTreeSet(
|
||||||
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
||||||
|
@ -237,6 +232,15 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return immediateFuture(null);
|
return immediateFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<Void> clearContainer(final String container) {
|
||||||
|
storageStrategy.clearContainer(container);
|
||||||
|
return immediateFuture(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override parent method because it uses strange futures and listenables
|
* Override parent method because it uses strange futures and listenables
|
||||||
* that creates problem in the test if more than one test that deletes the
|
* 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);
|
return immediateFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListenableFuture<Boolean> 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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -285,11 +305,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Path("{container}")
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
||||||
@PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) {
|
final String name) {
|
||||||
boolean result = storageStrategy.createContainerInLocation(name, null);
|
boolean result = storageStrategy.createContainerInLocation(name, location);
|
||||||
return immediateFuture(result);
|
return immediateFuture(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createContainer(String container) {
|
public boolean createContainer(String container) {
|
||||||
|
filesystemContainerNameValidator.validate(container);
|
||||||
return createContainerInLocation(container, null);
|
return createContainerInLocation(container, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,6 +280,11 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSeparator() {
|
||||||
|
return File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean directoryExists(String container, String directory) {
|
public boolean directoryExists(String container, String directory) {
|
||||||
return buildPathAndChecksIfDirectoryExists(container, directory);
|
return buildPathAndChecksIfDirectoryExists(container, directory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,4 +127,7 @@ public interface LocalStorageStrategy {
|
||||||
* @return Location of container or null
|
* @return Location of container or null
|
||||||
*/
|
*/
|
||||||
Location getLocation(String containerName);
|
Location getLocation(String containerName);
|
||||||
|
|
||||||
|
/** @return path separator, either / or \ */
|
||||||
|
String getSeparator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
if (delimiter != null) {
|
||||||
SortedSet<String> commonPrefixes = newTreeSet(
|
SortedSet<String> commonPrefixes = newTreeSet(
|
||||||
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
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
|
@Override
|
||||||
public ListenableFuture<Void> deleteContainer(final String container) {
|
public ListenableFuture<Void> deleteContainer(final String container) {
|
||||||
|
|
|
@ -143,6 +143,11 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
|
||||||
return containerToLocation.get(containerName);
|
return containerToLocation.get(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSeparator() {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in) {
|
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in) {
|
||||||
checkNotNull(in, "blob");
|
checkNotNull(in, "blob");
|
||||||
checkNotNull(in.getPayload(), "blob.payload");
|
checkNotNull(in.getPayload(), "blob.payload");
|
||||||
|
|
Loading…
Reference in New Issue