mirror of https://github.com/apache/jclouds.git
Introduce LocalStorageStrategy
This commit will allow eventual unification of the filesystem and transient blobstores. No functional changes -- rename FilesystemStorageStrategy to LocalStorageStrategy and implement it in FilesystemStorageStrategyImpl and TransientStorageStrategy.
This commit is contained in:
parent
6264dee999
commit
c30c2c4809
|
@ -58,6 +58,7 @@ import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
|
@ -82,7 +83,6 @@ import org.jclouds.crypto.CryptoStreams;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
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;
|
||||||
|
@ -121,7 +121,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
protected final ContentMetadataCodec contentMetadataCodec;
|
protected final ContentMetadataCodec contentMetadataCodec;
|
||||||
protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
|
protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
|
||||||
protected final Factory blobFactory;
|
protected final Factory blobFactory;
|
||||||
protected final FilesystemStorageStrategy storageStrategy;
|
protected final LocalStorageStrategy storageStrategy;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FilesystemAsyncBlobStore(BlobStoreContext context,
|
protected FilesystemAsyncBlobStore(BlobStoreContext context,
|
||||||
|
@ -133,7 +133,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
Supplier<Location> defaultLocation,
|
Supplier<Location> defaultLocation,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations,
|
@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
Factory blobFactory, FilesystemStorageStrategy storageStrategy) {
|
Factory blobFactory, LocalStorageStrategy storageStrategy) {
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
super(context, blobUtils, service, defaultLocation, locations);
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
this.dateService = dateService;
|
this.dateService = dateService;
|
||||||
|
@ -340,7 +340,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
||||||
@PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) {
|
@PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) {
|
||||||
boolean result = storageStrategy.createContainer(name);
|
boolean result = storageStrategy.createContainerInLocation(name, null);
|
||||||
return immediateFuture(result);
|
return immediateFuture(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.filesystem.config;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobRequestSigner;
|
import org.jclouds.blobstore.BlobRequestSigner;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
|
@ -32,7 +33,6 @@ import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
||||||
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
|
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
|
||||||
import org.jclouds.rest.config.BinderUtils;
|
import org.jclouds.rest.config.BinderUtils;
|
||||||
|
@ -56,7 +56,7 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule());
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(FilesystemStorageStrategy.class).to(FilesystemStorageStrategyImpl.class);
|
bind(LocalStorageStrategy.class).to(FilesystemStorageStrategyImpl.class);
|
||||||
bind(BlobUtils.class).to(FileSystemBlobUtilsImpl.class);
|
bind(BlobUtils.class).to(FileSystemBlobUtilsImpl.class);
|
||||||
bind(FilesystemBlobKeyValidator.class).to(FilesystemBlobKeyValidatorImpl.class);
|
bind(FilesystemBlobKeyValidator.class).to(FilesystemBlobKeyValidatorImpl.class);
|
||||||
bind(FilesystemContainerNameValidator.class).to(FilesystemContainerNameValidatorImpl.class);
|
bind(FilesystemContainerNameValidator.class).to(FilesystemContainerNameValidatorImpl.class);
|
||||||
|
|
|
@ -35,14 +35,15 @@ import javax.inject.Provider;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
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 org.jclouds.rest.annotations.ParamValidators;
|
||||||
|
@ -55,7 +56,7 @@ import com.google.common.io.Files;
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy {
|
public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
||||||
|
|
||||||
private static final String BACK_SLASH = "\\";
|
private static final String BACK_SLASH = "\\";
|
||||||
|
|
||||||
|
@ -109,8 +110,13 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean createContainer(String container) {
|
public boolean createContainer(String container) {
|
||||||
|
return createContainerInLocation(container, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean createContainerInLocation(String container, Location location) {
|
||||||
|
// TODO: implement location
|
||||||
logger.debug("Creating container %s", container);
|
logger.debug("Creating container %s", container);
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
return createDirectoryWithResult(container, null);
|
return createDirectoryWithResult(container, null);
|
||||||
|
@ -151,7 +157,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name) {
|
public Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name) {
|
||||||
filesystemBlobKeyValidator.validate(name);
|
filesystemBlobKeyValidator.validate(name);
|
||||||
return blobBuilders.get().name(name).build();
|
return blobBuilders.get().name(name).build();
|
||||||
|
@ -195,7 +200,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
* @param blobKey
|
* @param blobKey
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public File getFileForBlobKey(String container, String blobKey) {
|
public File getFileForBlobKey(String container, String blobKey) {
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
filesystemBlobKeyValidator.validate(blobKey);
|
filesystemBlobKeyValidator.validate(blobKey);
|
||||||
|
@ -262,17 +266,14 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
return blobNames;
|
return blobNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean directoryExists(String container, String directory) {
|
public boolean directoryExists(String container, String directory) {
|
||||||
return buildPathAndChecksIfDirectoryExists(container, directory);
|
return buildPathAndChecksIfDirectoryExists(container, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createDirectory(String container, String directory) {
|
public void createDirectory(String container, String directory) {
|
||||||
createDirectoryWithResult(container, directory);
|
createDirectoryWithResult(container, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteDirectory(String container, String directory) {
|
public void deleteDirectory(String container, String directory) {
|
||||||
// create complete dir path
|
// create complete dir path
|
||||||
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
||||||
|
@ -284,7 +285,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long countBlobs(String container, ListContainerOptions options) {
|
public long countBlobs(String container, ListContainerOptions options) {
|
||||||
// TODO
|
// TODO
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
|
|
@ -23,27 +23,28 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link BlobUtils} interfaced and act as a bridge to
|
* Implements the {@link BlobUtils} interfaced and act as a bridge to
|
||||||
* {@link FilesystemStorageStrategy} when used inside {@link AsyncBlobStore}
|
* {@link LocalStorageStrategy} when used inside {@link AsyncBlobStore}
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
||||||
|
|
||||||
protected final FilesystemStorageStrategy storageStrategy;
|
protected final FilesystemStorageStrategyImpl storageStrategy;
|
||||||
protected final Provider<BlobBuilder> blobBuilders;
|
protected final Provider<BlobBuilder> blobBuilders;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FileSystemBlobUtilsImpl(FilesystemStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
public FileSystemBlobUtilsImpl(LocalStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
||||||
this.storageStrategy = checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
this.storageStrategy = (FilesystemStorageStrategyImpl) checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
||||||
this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders");
|
this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.encryption.internal.JCECrypto;
|
import org.jclouds.encryption.internal.JCECrypto;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
import org.jclouds.filesystem.utils.TestUtils;
|
import org.jclouds.filesystem.utils.TestUtils;
|
||||||
import org.jclouds.io.payloads.FilePayload;
|
import org.jclouds.io.payloads.FilePayload;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
|
@ -73,7 +72,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FilesystemStorageStrategy storageStrategy;
|
private FilesystemStorageStrategyImpl storageStrategy;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
@ -414,7 +413,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
||||||
|
|
||||||
// create storageStrategy with an absolute path
|
// create storageStrategy with an absolute path
|
||||||
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
FilesystemStorageStrategyImpl storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||||
new Provider<BlobBuilder>() {
|
new Provider<BlobBuilder>() {
|
||||||
@Override
|
@Override
|
||||||
public BlobBuilder get() {
|
public BlobBuilder get() {
|
||||||
|
|
|
@ -16,21 +16,20 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.filesystem.strategy;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.domain.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy for filesystem operations related to container and blob
|
* Strategy for local operations related to container and blob
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
public interface FilesystemStorageStrategy {
|
public interface LocalStorageStrategy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new container
|
* Creates a new container
|
||||||
|
@ -38,7 +37,7 @@ public interface FilesystemStorageStrategy {
|
||||||
* @param container
|
* @param container
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean createContainer(String container);
|
boolean createContainerInLocation(String container, Location location);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a container and all its content
|
* Deletes a container and all its content
|
||||||
|
@ -58,17 +57,17 @@ public interface FilesystemStorageStrategy {
|
||||||
* delete the container itself
|
* delete the container itself
|
||||||
* @param container
|
* @param container
|
||||||
*/
|
*/
|
||||||
void clearContainer(final String container);
|
void clearContainer(String container);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #clearContainer(String)} except you can use options to do things like recursive
|
* Like {@link #clearContainer(String)} except you can use options to do things like recursive
|
||||||
* deletes, or clear at a different path than root.
|
* deletes, or clear at a different path than root.
|
||||||
*
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* what to clear
|
* what to clear
|
||||||
* @param options
|
* @param options
|
||||||
* recursion and path to clear
|
* recursion and path to clear
|
||||||
*/
|
*/
|
||||||
void clearContainer(String container, ListContainerOptions options);
|
void clearContainer(String container, ListContainerOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,64 +77,26 @@ public interface FilesystemStorageStrategy {
|
||||||
Iterable<String> getAllContainerNames();
|
Iterable<String> getAllContainerNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if a directory exists
|
* Return true if a blob named by key exists
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
* container where the directory resides
|
|
||||||
* @param directory
|
|
||||||
* full path to the directory
|
|
||||||
*/
|
|
||||||
boolean directoryExists(String container, String directory);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a folder or a directory marker depending on the service
|
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
* container to create the directory in
|
|
||||||
* @param directory
|
|
||||||
* full path to the directory
|
|
||||||
*/
|
|
||||||
void createDirectory(String container, String directory);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a folder or a directory marker depending on the service
|
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
* container to delete the directory from
|
|
||||||
* @param directory
|
|
||||||
* full path to the directory to delete
|
|
||||||
*/
|
|
||||||
void deleteDirectory(String container, String directory);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new blob
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Blob newBlob(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param container
|
* @param container
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean blobExists(String container, String key);
|
boolean blobExists(String container, String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the blob with the given key belonging to the container with the given
|
* Load the blob with the given key belonging to the container with the given
|
||||||
* name. There must exist a resource on the file system whose complete name
|
* name. There must exist a resource on the file system whose complete name
|
||||||
* is given concatenating the container name and the key
|
* is given concatenating the container name and the key
|
||||||
*
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* it's the name of the container the blob belongs to
|
* it's the name of the container the blob belongs to
|
||||||
* @param key
|
* @param key
|
||||||
* it's the key of the blob
|
* it's the key of the blob
|
||||||
*
|
*
|
||||||
* @return the blob belonging to the given container with the given key
|
* @return the blob belonging to the given container with the given key
|
||||||
*/
|
*/
|
||||||
Blob getBlob(final String containerName, final String blobName);
|
Blob getBlob(String containerName, String blobName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the blobs key inside a container
|
* Returns all the blobs key inside a container
|
||||||
|
@ -146,23 +107,7 @@ public interface FilesystemStorageStrategy {
|
||||||
Iterable<String> getBlobKeysInsideContainer(String container) throws IOException;
|
Iterable<String> getBlobKeysInsideContainer(String container) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts number of blobs inside a container
|
* Remove blob named by the given key
|
||||||
* @param container
|
|
||||||
* @param options
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
long countBlobs(String container, ListContainerOptions options);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a {@link File} object that links to the blob
|
|
||||||
* @param container
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
File getFileForBlobKey(String container, String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param container
|
* @param container
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
|
@ -26,9 +26,10 @@ import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
|
||||||
public class TransientStorageStrategy {
|
public class TransientStorageStrategy implements LocalStorageStrategy {
|
||||||
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>();
|
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>();
|
||||||
private final ConcurrentMap<String, Location> containerToLocation = new ConcurrentHashMap<String, Location>();
|
private final ConcurrentMap<String, Location> containerToLocation = new ConcurrentHashMap<String, Location>();
|
||||||
private final Supplier<Location> defaultLocation;
|
private final Supplier<Location> defaultLocation;
|
||||||
|
@ -49,6 +50,12 @@ public class TransientStorageStrategy {
|
||||||
containerToBlobs.get(containerName).clear();
|
containerToBlobs.get(containerName).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearContainer(String container, ListContainerOptions options) {
|
||||||
|
// TODO implement options
|
||||||
|
clearContainer(container);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean createContainerInLocation(final String containerName, final Location location) {
|
public boolean createContainerInLocation(final String containerName, final Location location) {
|
||||||
ConcurrentMap<String, Blob> origValue = containerToBlobs.putIfAbsent(
|
ConcurrentMap<String, Blob> origValue = containerToBlobs.putIfAbsent(
|
||||||
containerName, new ConcurrentHashMap<String, Blob>());
|
containerName, new ConcurrentHashMap<String, Blob>());
|
||||||
|
|
Loading…
Reference in New Issue