mirror of https://github.com/apache/jclouds.git
expose constructor for blobbuilderimpl
This commit is contained in:
parent
f322931755
commit
d69d31a5d2
|
@ -41,6 +41,7 @@ import org.jclouds.blobstore.domain.Blob;
|
|||
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||
import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.encryption.internal.JCECrypto;
|
||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||
|
@ -76,7 +77,11 @@ public class FilesystemStorageStrategyImplTest {
|
|||
storageStrategy = new FilesystemStorageStrategyImpl(new Provider<BlobBuilder>() {
|
||||
@Override
|
||||
public BlobBuilder get() {
|
||||
return new BlobBuilderImpl();
|
||||
try {
|
||||
return new BlobBuilderImpl(new JCECrypto());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}, TestUtils.TARGET_BASE_DIR, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
||||
|
@ -139,10 +144,9 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
public void testDeleteDirectory() throws IOException {
|
||||
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
||||
TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] { TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
|
||||
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
|
||||
|
||||
// delete directory in different ways
|
||||
storageStrategy.deleteDirectory(CONTAINER_NAME, "lev1" + FS + "lev2" + FS + "lev4");
|
||||
|
@ -158,10 +162,9 @@ public class FilesystemStorageStrategyImplTest {
|
|||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
||||
|
||||
// delete the directory and all the files inside
|
||||
TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] { TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
|
||||
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
|
||||
storageStrategy.deleteDirectory(CONTAINER_NAME, null);
|
||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||
}
|
||||
|
@ -208,10 +211,9 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
public void testClearContainer() throws IOException {
|
||||
storageStrategy.createContainer(CONTAINER_NAME);
|
||||
Set<String> blobs = TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
|
||||
Set<String> blobs = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||
TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
|
||||
// test if file exits
|
||||
for (String blob : blobs) {
|
||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
|
||||
|
@ -238,10 +240,9 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
public void testClearContainerAndThenDeleteContainer() throws IOException {
|
||||
storageStrategy.createContainer(CONTAINER_NAME);
|
||||
Set<String> blobs = TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
|
||||
Set<String> blobs = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||
TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
|
||||
// test if file exits
|
||||
for (String blob : blobs) {
|
||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
|
||||
|
@ -266,7 +267,7 @@ public class FilesystemStorageStrategyImplTest {
|
|||
public void testDeleteContainer() throws IOException {
|
||||
final String BLOB_KEY1 = "blobName.jpg";
|
||||
final String BLOB_KEY2 = "aa" + FS + "bb" + FS + "cc" + FS + "dd" + FS + "ee" + FS + "ff" + FS + "23" + FS
|
||||
+ "blobName.jpg";
|
||||
+ "blobName.jpg";
|
||||
boolean result;
|
||||
|
||||
result = storageStrategy.createContainer(CONTAINER_NAME);
|
||||
|
@ -399,12 +400,16 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
// create storageStrategy with an absolute path
|
||||
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||
new Provider<BlobBuilder>() {
|
||||
@Override
|
||||
public BlobBuilder get() {
|
||||
return new BlobBuilderImpl();
|
||||
}
|
||||
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
||||
new Provider<BlobBuilder>() {
|
||||
@Override
|
||||
public BlobBuilder get() {
|
||||
try {
|
||||
return new BlobBuilderImpl(new JCECrypto());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
||||
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
||||
|
||||
String blobKey;
|
||||
|
@ -422,8 +427,8 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
public void testBlobExists() throws IOException {
|
||||
String[] sourceBlobKeys = new String[] { TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("afasd" + FS + "asdma" + FS + "blobExists-", ".jpg") };
|
||||
TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("afasd" + FS + "asdma" + FS + "blobExists-", ".jpg") };
|
||||
|
||||
for (String blobKey : sourceBlobKeys) {
|
||||
assertFalse(storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " exists");
|
||||
|
@ -436,12 +441,11 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
public void testRemoveBlob() throws IOException {
|
||||
storageStrategy.createContainer(CONTAINER_NAME);
|
||||
Set<String> blobKeys = TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] { TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
|
||||
Set<String> blobKeys = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
|
||||
|
||||
Set<String> remainingBlobKeys = new HashSet<String>();
|
||||
for (String key : blobKeys) {
|
||||
|
@ -478,12 +482,11 @@ public class FilesystemStorageStrategyImplTest {
|
|||
|
||||
// create blobs
|
||||
storageStrategy.createContainer(CONTAINER_NAME);
|
||||
Set<String> createBlobKeys = TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] { TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
|
||||
Set<String> createBlobKeys = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
||||
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
|
||||
storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
||||
|
||||
List<String> retrievedBlobKeys = new ArrayList<String>();
|
||||
|
|
|
@ -26,10 +26,8 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
|
@ -40,20 +38,23 @@ import org.jclouds.io.Payload;
|
|||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.io.payloads.PhantomPayload;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BlobBuilderImpl implements BlobBuilder {
|
||||
private final Crypto crypto;
|
||||
|
||||
@Inject
|
||||
public BlobBuilderImpl(Crypto crypto) {
|
||||
this.crypto = checkNotNull(crypto, "crypto");
|
||||
}
|
||||
|
||||
private Payload payload;
|
||||
private String name;
|
||||
private Map<String, String> userMetadata = Maps.newLinkedHashMap();
|
||||
private StorageType type = StorageType.BLOB;
|
||||
@Inject
|
||||
private Crypto crypto;
|
||||
|
||||
@Override
|
||||
public BlobBuilder name(String name) {
|
||||
|
@ -129,15 +130,10 @@ public class BlobBuilderImpl implements BlobBuilder {
|
|||
private final Payload payload;
|
||||
private MessageDigest digest;
|
||||
|
||||
public PayloadBlobBuilderImpl(BlobBuilder builder, Payload payload, @Nullable Crypto crypto) {
|
||||
public PayloadBlobBuilderImpl(BlobBuilder builder, Payload payload, Crypto crypto) {
|
||||
this.builder = checkNotNull(builder, "builder");
|
||||
this.payload = checkNotNull(payload, "payload");
|
||||
try {
|
||||
this.digest = crypto != null ? crypto.md5() : MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Throwables.propagate(e);
|
||||
this.digest = null;
|
||||
}
|
||||
this.digest = checkNotNull(crypto, "crypto").md5();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue