From 830d90874d281c2c39a58f7a75d5178a31bada7b Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Mon, 2 Nov 2009 09:13:40 +0000 Subject: [PATCH] Issue 73: updated to allow container listings to have pagination git-svn-id: http://jclouds.googlecode.com/svn/trunk@2037 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../jclouds/aws/s3/blobstore/S3BlobStore.java | 26 ++-- .../BucketToContainerListOptions.java | 8 +- .../functions/BucketToResourceList.java | 10 +- .../ContainerToBucketListOptions.java | 6 +- .../functions/ResourceToBucketList.java | 12 +- .../jclouds/aws/s3/internal/StubS3Client.java | 4 +- aws/s3/perftest/pom.xml | 5 - .../blob/blobstore/AzureBlobStore.java | 38 +++--- .../ListBlobsOptionsToListOptions.java | 8 +- .../ListBlobsResponseToResourceList.java | 10 +- .../ListOptionsToListBlobsOptions.java | 6 +- .../ResourceToListBlobsResponse.java | 6 +- .../strategy/FindMD5InBlobProperties.java | 4 +- .../blob/internal/StubAzureBlobClient.java | 2 +- .../java/org/jclouds/blobstore/BlobMap.java | 4 +- .../java/org/jclouds/blobstore/BlobStore.java | 12 +- .../org/jclouds/blobstore/InputStreamMap.java | 4 +- .../blobstore/KeyAlreadyExistsException.java | 61 +++++++++ .../blobstore/config/BlobStoreMapModule.java | 6 +- .../domain/ListContainerResponse.java | 36 +++++ ...oundedSortedSet.java => ListResponse.java} | 4 +- .../internal/ListContainerResponseImpl.java | 44 ++++++ ...ndedTreeSet.java => ListResponseImpl.java} | 12 +- .../functions/BlobToHttpGetOptions.java | 2 +- .../blobstore/internal/BaseBlobMap.java | 12 +- .../blobstore/internal/BlobMapImpl.java | 4 +- .../internal/BlobStoreContextImpl.java | 6 +- .../internal/InputStreamMapImpl.java | 4 +- .../options/ListContainerOptions.java | 126 ++++++++++++++++++ .../blobstore/options/ListOptions.java | 45 +------ .../blobstore/strategy/ClearListStrategy.java | 4 +- .../strategy/ContainsValueInListStrategy.java | 4 +- .../blobstore/strategy/CountListStrategy.java | 4 +- .../strategy/GetBlobsInListStrategy.java | 4 +- .../strategy/ListBlobMetadataStrategy.java | 4 +- .../internal/CountBlobTypeInList.java | 4 +- .../internal/DeleteAllKeysInList.java | 4 +- .../strategy/internal/FindMD5InList.java | 4 +- .../GetAllBlobsInListAndRetryOnFailure.java | 4 +- .../internal/ListBlobMetadataInContainer.java | 8 +- .../BaseBlobStoreIntegrationTest.java | 1 + .../BaseContainerIntegrationTest.java | 29 ++-- .../integration/internal/StubBlobStore.java | 31 +++-- .../blobstore/options/ListOptionsTest.java | 32 ++--- .../cloudfiles/CloudFilesClient.java | 4 +- .../blobstore/CloudFilesBlobStore.java | 49 ++++--- ...ntainerOptionsToListContainerOptions.java} | 13 +- .../functions/ContainerToResourceList.java | 10 +- ...tionsToBlobStoreListContainerOptions.java} | 13 +- .../functions/ResourceToObjectList.java | 10 +- ...tainerCDNMetadataListFromJsonResponse.java | 16 +-- .../ParseObjectInfoListFromJsonResponse.java | 10 +- .../cloudfiles/CloudFilesClientLiveTest.java | 23 +++- .../internal/StubCloudFilesClient.java | 19 ++- .../src/test/resources/test_list_cdn.json | 6 +- 55 files changed, 528 insertions(+), 309 deletions(-) create mode 100644 blobstore/core/src/main/java/org/jclouds/blobstore/KeyAlreadyExistsException.java create mode 100644 blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListContainerResponse.java rename blobstore/core/src/main/java/org/jclouds/blobstore/domain/{BoundedSortedSet.java => ListResponse.java} (93%) create mode 100644 blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListContainerResponseImpl.java rename blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/{BoundedTreeSet.java => ListResponseImpl.java} (83%) rename {azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob => blobstore/core/src/main/java/org/jclouds}/blobstore/functions/BlobToHttpGetOptions.java (97%) create mode 100644 blobstore/core/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java rename rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/{ListOptionsToListContainerOptions.java => BlobStoreListContainerOptionsToListContainerOptions.java} (80%) rename rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/{ListContainerOptionsToListOptions.java => ListContainerOptionsToBlobStoreListContainerOptions.java} (79%) diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java index 47c5f6c7a8..05afae4f4b 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/S3BlobStore.java @@ -24,7 +24,7 @@ package org.jclouds.aws.s3.blobstore; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.blobstore.options.ListOptions.Builder.recursive; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import java.util.SortedSet; import java.util.concurrent.Callable; @@ -50,9 +50,11 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.domain.internal.ListResponseImpl; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.concurrent.FutureFunctionWrapper; import org.jclouds.http.options.GetOptions; @@ -60,7 +62,6 @@ import org.jclouds.logging.Logger.LoggerFactory; import com.google.common.base.Function; import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; @ConsistencyModel(ConsistencyModels.EVENTUAL) public class S3BlobStore implements BlobStore { @@ -150,17 +151,20 @@ public class S3BlobStore implements BlobStore { return wrapFuture(returnVal, object2Blob); } - public Future> list() { - return wrapFuture(connection.listOwnedBuckets(), - new Function, SortedSet>() { - public SortedSet apply(SortedSet from) { - return Sets.newTreeSet(Iterables.transform(from, bucket2ResourceMd)); + public Future> list() { + return wrapFuture( + connection.listOwnedBuckets(), + new Function, org.jclouds.blobstore.domain.ListResponse>() { + public org.jclouds.blobstore.domain.ListResponse apply( + SortedSet from) { + return new ListResponseImpl(Iterables.transform(from, + bucket2ResourceMd), null, null, false); } }); } - public Future> list(String container, - ListOptions... optionsList) { + public Future> list(String container, + ListContainerOptions... optionsList) { ListBucketOptions httpOptions = container2BucketListOptions.apply(optionsList); Future returnVal = connection.listBucket(container, httpOptions); return wrapFuture(returnVal, bucket2ResourceList); diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToContainerListOptions.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToContainerListOptions.java index cd83f67e96..f17031b981 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToContainerListOptions.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToContainerListOptions.java @@ -26,7 +26,7 @@ package org.jclouds.aws.s3.blobstore.functions; import javax.inject.Singleton; import org.jclouds.aws.s3.options.ListBucketOptions; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.common.base.Function; @@ -34,9 +34,9 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class BucketToContainerListOptions implements Function { - public ListOptions apply(ListBucketOptions[] optionsList) { - ListOptions options = new ListOptions(); +public class BucketToContainerListOptions implements Function { + public ListContainerOptions apply(ListBucketOptions[] optionsList) { + ListContainerOptions options = new ListContainerOptions(); if (optionsList.length != 0) { if (optionsList[0].getDelimiter() == null) { options.recursive(); diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceList.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceList.java index 6d04f4ccbd..0f77bf450a 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceList.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/BucketToResourceList.java @@ -29,9 +29,9 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.s3.domain.ListBucketResponse; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.domain.internal.BoundedTreeSet; +import org.jclouds.blobstore.domain.internal.ListContainerResponseImpl; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -42,7 +42,7 @@ import com.google.common.collect.Sets; */ @Singleton public class BucketToResourceList implements - Function> { + Function> { private final ObjectToBlobMetadata object2blobMd; private final CommonPrefixesToResourceMetadata prefix2ResourceMd; @@ -53,10 +53,10 @@ public class BucketToResourceList implements this.prefix2ResourceMd = prefix2ResourceMd; } - public BoundedSortedSet apply(ListBucketResponse from) { + public ListContainerResponse apply(ListBucketResponse from) { SortedSet contents = Sets.newTreeSet(Iterables.concat(Iterables.transform( from, object2blobMd), prefix2ResourceMd.apply(from.getCommonPrefixes()))); - return new BoundedTreeSet(contents, from.getPrefix(), from.getMarker(), + return new ListContainerResponseImpl(contents, from.getPrefix(), from.getMarker(), from.getMaxKeys(), from.isTruncated()); } diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ContainerToBucketListOptions.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ContainerToBucketListOptions.java index af23ea01d2..846f04ba53 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ContainerToBucketListOptions.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ContainerToBucketListOptions.java @@ -26,7 +26,7 @@ package org.jclouds.aws.s3.blobstore.functions; import javax.inject.Singleton; import org.jclouds.aws.s3.options.ListBucketOptions; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.common.base.Function; @@ -34,8 +34,8 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class ContainerToBucketListOptions implements Function { - public ListBucketOptions apply(ListOptions[] optionsList) { +public class ContainerToBucketListOptions implements Function { + public ListBucketOptions apply(ListContainerOptions[] optionsList) { ListBucketOptions httpOptions = new ListBucketOptions(); if (optionsList.length != 0) { if (!optionsList[0].isRecursive()) { diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ResourceToBucketList.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ResourceToBucketList.java index 00026507df..16928d10e8 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ResourceToBucketList.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/blobstore/functions/ResourceToBucketList.java @@ -33,7 +33,7 @@ import org.jclouds.aws.s3.domain.MutableObjectMetadata; import org.jclouds.aws.s3.domain.ObjectMetadata; import org.jclouds.aws.s3.domain.internal.TreeSetListBucketResponse; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.domain.ResourceType; @@ -47,7 +47,7 @@ import com.google.common.collect.Sets; */ @Singleton public class ResourceToBucketList implements - Function, ListBucketResponse> { + Function, ListBucketResponse> { private final BlobToObjectMetadata blob2ObjectMd; @Inject @@ -55,9 +55,9 @@ public class ResourceToBucketList implements this.blob2ObjectMd = blob2ObjectMd; } - public ListBucketResponse apply(BoundedSortedSet list) { + public ListBucketResponse apply(ListContainerResponse list) { - SortedSet contents = Sets.newTreeSet(Iterables.transform(Iterables.filter( + Iterable contents = Iterables.transform(Iterables.filter( list, new Predicate() { public boolean apply(ResourceMetadata input) { @@ -70,7 +70,7 @@ public class ResourceToBucketList implements return blob2ObjectMd.apply((BlobMetadata) from); } - })); + }); SortedSet commonPrefixes = Sets.newTreeSet(Iterables.transform(Iterables.filter(list, new Predicate() { @@ -87,6 +87,6 @@ public class ResourceToBucketList implements })); return new TreeSetListBucketResponse(null, contents, list.getPath(), list.getMarker(), list - .getMaxResults(), "/", contents.size() == list.getMaxResults(), commonPrefixes); + .getMaxResults(), "/", Iterables.size(contents) == list.getMaxResults(), commonPrefixes); } } \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3Client.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3Client.java index 0209348165..08db559667 100755 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3Client.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3Client.java @@ -62,7 +62,7 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.integration.internal.StubBlobStore; import org.jclouds.blobstore.integration.internal.StubBlobStore.FutureBase; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.concurrent.FutureFunctionWrapper; import org.jclouds.http.options.GetOptions; import org.jclouds.logging.Logger.LoggerFactory; @@ -141,7 +141,7 @@ public class StubS3Client implements S3Client { } public Future listBucket(final String name, ListBucketOptions... optionsList) { - ListOptions options = bucket2ContainerListOptions.apply(optionsList); + ListContainerOptions options = bucket2ContainerListOptions.apply(optionsList); return wrapFuture(blobStore.list(name, options), resource2BucketList); } diff --git a/aws/s3/perftest/pom.xml b/aws/s3/perftest/pom.xml index 9f70602a79..da0f11bcc2 100644 --- a/aws/s3/perftest/pom.xml +++ b/aws/s3/perftest/pom.xml @@ -128,11 +128,6 @@ test - - 1 diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java index d476b4d626..ecd7400dad 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/AzureBlobStore.java @@ -24,7 +24,7 @@ package org.jclouds.azure.storage.blob.blobstore; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.blobstore.options.ListOptions.Builder.recursive; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import java.util.SortedSet; import java.util.concurrent.Callable; @@ -37,7 +37,6 @@ import org.jclouds.azure.storage.blob.AzureBlobClient; import org.jclouds.azure.storage.blob.blobstore.functions.AzureBlobToBlob; import org.jclouds.azure.storage.blob.blobstore.functions.BlobPropertiesToBlobMetadata; import org.jclouds.azure.storage.blob.blobstore.functions.BlobToAzureBlob; -import org.jclouds.azure.storage.blob.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.azure.storage.blob.blobstore.functions.ContainerToResourceMetadata; import org.jclouds.azure.storage.blob.blobstore.functions.ListBlobsResponseToResourceList; import org.jclouds.azure.storage.blob.blobstore.functions.ListOptionsToListBlobsOptions; @@ -50,9 +49,11 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.domain.internal.ListResponseImpl; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.concurrent.FutureFunctionWrapper; import org.jclouds.http.options.GetOptions; @@ -60,7 +61,6 @@ import org.jclouds.logging.Logger.LoggerFactory; import com.google.common.base.Function; import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; @ConsistencyModel(ConsistencyModels.STRICT) public class AzureBlobStore implements BlobStore { @@ -78,13 +78,14 @@ public class AzureBlobStore implements BlobStore { private final ExecutorService service; @Inject - private AzureBlobStore(AzureBlobClient connection, Blob.Factory blobFactory, LoggerFactory logFactory, - ClearListStrategy clearContainerStrategy, BlobPropertiesToBlobMetadata object2BlobMd, - AzureBlobToBlob object2Blob, BlobToAzureBlob blob2Object, + private AzureBlobStore(AzureBlobClient connection, Blob.Factory blobFactory, + LoggerFactory logFactory, ClearListStrategy clearContainerStrategy, + BlobPropertiesToBlobMetadata object2BlobMd, AzureBlobToBlob object2Blob, + BlobToAzureBlob blob2Object, ListOptionsToListBlobsOptions container2ContainerListOptions, BlobToHttpGetOptions blob2ObjectGetOptions, - ContainerToResourceMetadata container2ResourceMd, ListBlobsResponseToResourceList container2ResourceList, - ExecutorService service) { + ContainerToResourceMetadata container2ResourceMd, + ListBlobsResponseToResourceList container2ResourceList, ExecutorService service) { this.connection = checkNotNull(connection, "connection"); this.blobFactory = checkNotNull(blobFactory, "blobFactory"); this.logFactory = checkNotNull(logFactory, "logFactory"); @@ -143,17 +144,20 @@ public class AzureBlobStore implements BlobStore { return wrapFuture(returnVal, object2Blob); } - public Future> list() { - return wrapFuture(connection.listContainers(), - new Function, SortedSet>() { - public SortedSet apply(SortedSet from) { - return Sets.newTreeSet(Iterables.transform(from, container2ResourceMd)); + public Future> list() { + return wrapFuture( + connection.listContainers(), + new Function, org.jclouds.blobstore.domain.ListResponse>() { + public org.jclouds.blobstore.domain.ListResponse apply( + SortedSet from) { + return new ListResponseImpl(Iterables.transform(from, + container2ResourceMd), null, null, false); } }); } - public Future> list(String container, - ListOptions... optionsList) { + public Future> list(String container, + ListContainerOptions... optionsList) { ListBlobsOptions httpOptions = container2ContainerListOptions.apply(optionsList); Future returnVal = connection.listBlobs(container, httpOptions); return wrapFuture(returnVal, container2ResourceList); diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsOptionsToListOptions.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsOptionsToListOptions.java index 02e5df3972..b465d1f69b 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsOptionsToListOptions.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsOptionsToListOptions.java @@ -26,7 +26,7 @@ package org.jclouds.azure.storage.blob.blobstore.functions; import javax.inject.Singleton; import org.jclouds.azure.storage.blob.options.ListBlobsOptions; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.common.base.Function; @@ -34,9 +34,9 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class ListBlobsOptionsToListOptions implements Function { - public ListOptions apply(ListBlobsOptions[] optionsList) { - ListOptions options = new ListOptions(); +public class ListBlobsOptionsToListOptions implements Function { + public ListContainerOptions apply(ListBlobsOptions[] optionsList) { + ListContainerOptions options = new ListContainerOptions(); if (optionsList.length != 0) { if (optionsList[0].getDelimiter() == null) { options.recursive(); diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsResponseToResourceList.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsResponseToResourceList.java index e05271bc73..a744d755f9 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsResponseToResourceList.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListBlobsResponseToResourceList.java @@ -30,9 +30,9 @@ import javax.inject.Singleton; import org.jclouds.azure.storage.blob.domain.ListBlobsResponse; import org.jclouds.azure.storage.blob.domain.ListableBlobProperties; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.domain.internal.BoundedTreeSet; +import org.jclouds.blobstore.domain.internal.ListContainerResponseImpl; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -43,7 +43,7 @@ import com.google.common.collect.Sets; */ @Singleton public class ListBlobsResponseToResourceList implements - Function> { + Function> { private final ListableBlobPropertiesToBlobMetadata object2blobMd; private final CommonPrefixesToResourceMetadata prefix2ResourceMd; @@ -55,10 +55,10 @@ public class ListBlobsResponseToResourceList implements this.prefix2ResourceMd = prefix2ResourceMd; } - public BoundedSortedSet apply(ListBlobsResponse from) { + public ListContainerResponse apply(ListBlobsResponse from) { SortedSet contents = Sets.newTreeSet(Iterables.concat(Iterables.transform( from, object2blobMd), prefix2ResourceMd.apply(from.getBlobPrefixes()))); - return new BoundedTreeSet(contents, from.getPrefix(), from.getMarker(), + return new ListContainerResponseImpl(contents, from.getPrefix(), from.getMarker(), from.getMaxResults(), from.size() == from.getMaxResults()); } diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListOptionsToListBlobsOptions.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListOptionsToListBlobsOptions.java index 488b17e336..f763572c54 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListOptionsToListBlobsOptions.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ListOptionsToListBlobsOptions.java @@ -26,7 +26,7 @@ package org.jclouds.azure.storage.blob.blobstore.functions; import javax.inject.Singleton; import org.jclouds.azure.storage.blob.options.ListBlobsOptions; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.common.base.Function; @@ -34,8 +34,8 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class ListOptionsToListBlobsOptions implements Function { - public ListBlobsOptions apply(ListOptions[] optionsList) { +public class ListOptionsToListBlobsOptions implements Function { + public ListBlobsOptions apply(ListContainerOptions[] optionsList) { ListBlobsOptions httpOptions = new ListBlobsOptions(); if (optionsList.length != 0) { if (!optionsList[0].isRecursive()) { diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ResourceToListBlobsResponse.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ResourceToListBlobsResponse.java index 2d3b7db664..2f065f802f 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ResourceToListBlobsResponse.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/ResourceToListBlobsResponse.java @@ -33,7 +33,7 @@ import org.jclouds.azure.storage.blob.domain.ListableBlobProperties; import org.jclouds.azure.storage.blob.domain.MutableBlobProperties; import org.jclouds.azure.storage.blob.domain.internal.TreeSetListBlobsResponse; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.domain.ResourceType; @@ -47,7 +47,7 @@ import com.google.common.collect.Sets; */ @Singleton public class ResourceToListBlobsResponse implements - Function, ListBlobsResponse> { + Function, ListBlobsResponse> { private final BlobMetadataToBlobProperties blob2ObjectMd; @Inject @@ -55,7 +55,7 @@ public class ResourceToListBlobsResponse implements this.blob2ObjectMd = blob2ObjectMd; } - public ListBlobsResponse apply(BoundedSortedSet list) { + public ListBlobsResponse apply(ListContainerResponse list) { Iterable contents = Iterables.transform(Iterables.filter(list, new Predicate() { diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/strategy/FindMD5InBlobProperties.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/strategy/FindMD5InBlobProperties.java index d224dc039e..d2370129b5 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/strategy/FindMD5InBlobProperties.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/strategy/FindMD5InBlobProperties.java @@ -10,7 +10,7 @@ import org.jclouds.azure.storage.blob.domain.BlobProperties; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.functions.ObjectMD5; import org.jclouds.blobstore.internal.BlobRuntimeException; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy; import org.jclouds.util.Utils; @@ -35,7 +35,7 @@ public class FindMD5InBlobProperties implements ContainsValueInListStrategy { this.client = client; } - public boolean execute(String containerName, Object value, ListOptions options) { + public boolean execute(String containerName, Object value, ListContainerOptions options) { try { byte[] toSearch = objectMD5.apply(value); for (BlobMetadata metadata : getAllBlobMetadata.execute(containerName, options)) { diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobClient.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobClient.java index 29dd1f2dfd..39d88006ce 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobClient.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobClient.java @@ -123,7 +123,7 @@ public class StubAzureBlobClient implements AzureBlobClient { } public Future listBlobs(String container, ListBlobsOptions... optionsList) { - org.jclouds.blobstore.options.ListOptions options = container2ContainerListOptions + org.jclouds.blobstore.options.ListContainerOptions options = container2ContainerListOptions .apply(optionsList); return wrapFuture(blobStore.list(container, options), resource2ObjectList); } diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/BlobMap.java b/blobstore/core/src/main/java/org/jclouds/blobstore/BlobMap.java index 1ded2bff62..84310da501 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/BlobMap.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/BlobMap.java @@ -25,7 +25,7 @@ package org.jclouds.blobstore; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.internal.BlobMapImpl; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.inject.ImplementedBy; @@ -42,7 +42,7 @@ public interface BlobMap extends ListableMap { Blob newBlob(); public static interface Factory { - BlobMap create(String containerName, ListOptions listOptions); + BlobMap create(String containerName, ListContainerOptions listOptions); } } \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/BlobStore.java b/blobstore/core/src/main/java/org/jclouds/blobstore/BlobStore.java index 76ac3eda05..9cf84dbf0c 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/BlobStore.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/BlobStore.java @@ -23,15 +23,15 @@ */ package org.jclouds.blobstore; -import java.util.SortedSet; import java.util.concurrent.Future; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.options.GetOptions; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; /** * Provides hooks needed to run a blob store @@ -43,7 +43,7 @@ public interface BlobStore { /** * Lists all root-level resources available to the account. */ - Future> list(); + Future> list(); /** * Lists all resources available at the specified path. Note that path may be a container, or a @@ -52,8 +52,8 @@ public interface BlobStore { * @param parent * - base path to list; non-recursive */ - Future> list(String container, - ListOptions... options); + Future> list(String container, + ListContainerOptions... options); boolean exists(String container); diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/InputStreamMap.java b/blobstore/core/src/main/java/org/jclouds/blobstore/InputStreamMap.java index 1306ae89a1..332479f434 100755 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/InputStreamMap.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/InputStreamMap.java @@ -28,7 +28,7 @@ import java.io.InputStream; import java.util.Map; import org.jclouds.blobstore.internal.InputStreamMapImpl; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.inject.ImplementedBy; @@ -47,7 +47,7 @@ import com.google.inject.ImplementedBy; @ImplementedBy(InputStreamMapImpl.class) public interface InputStreamMap extends ListableMap { public static interface Factory { - InputStreamMap create(String containerName, ListOptions listOptions); + InputStreamMap create(String containerName, ListContainerOptions listOptions); } InputStream putString(String key, String value); diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/KeyAlreadyExistsException.java b/blobstore/core/src/main/java/org/jclouds/blobstore/KeyAlreadyExistsException.java new file mode 100644 index 0000000000..a928871e06 --- /dev/null +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/KeyAlreadyExistsException.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.blobstore; + +/** + * Thrown when a blob was attempted to be replaced while it already exists + * + * @author Adrian Cole + */ +public class KeyAlreadyExistsException extends RuntimeException { + + private String container; + private String key; + + public KeyAlreadyExistsException() { + super(); + } + + public KeyAlreadyExistsException(String container, String key, Exception from) { + super(String.format("%s already exists in container %s", key, container), from); + this.container = container; + this.key = key; + } + + public KeyAlreadyExistsException(Exception from) { + super(from); + } + + public String getContainer() { + return container; + } + + public String getKey() { + return key; + } + + /** The serialVersionUID */ + private static final long serialVersionUID = -2272965726680821281L; + +} diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/config/BlobStoreMapModule.java b/blobstore/core/src/main/java/org/jclouds/blobstore/config/BlobStoreMapModule.java index d932523127..d41315e2de 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/config/BlobStoreMapModule.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/config/BlobStoreMapModule.java @@ -8,7 +8,7 @@ import org.jclouds.blobstore.InputStreamMap; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.internal.BlobMapImpl; import org.jclouds.blobstore.internal.InputStreamMapImpl; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.CountListStrategy; @@ -49,7 +49,7 @@ public class BlobStoreMapModule extends AbstractModule { @Inject CountListStrategy containerCountStrategy; - public BlobMap create(String containerName, ListOptions listOptions) { + public BlobMap create(String containerName, ListContainerOptions listOptions) { return new BlobMapImpl(connection, getAllBlobs, getAllBlobMetadata, containsValueStrategy, clearContainerStrategy, containerCountStrategy, containerName, listOptions); } @@ -72,7 +72,7 @@ public class BlobStoreMapModule extends AbstractModule { @Inject CountListStrategy containerCountStrategy; - public InputStreamMap create(String containerName, ListOptions listOptions) { + public InputStreamMap create(String containerName, ListContainerOptions listOptions) { return new InputStreamMapImpl(connection, blobFactory, getAllBlobs, getAllBlobMetadata, containsValueStrategy, clearContainerStrategy, containerCountStrategy, containerName, listOptions); diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListContainerResponse.java b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListContainerResponse.java new file mode 100644 index 0000000000..851de3e9cf --- /dev/null +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListContainerResponse.java @@ -0,0 +1,36 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.blobstore.domain; + + +/** + * + * @author Adrian Cole + * + */ +public interface ListContainerResponse extends ListResponse { + + String getPath(); + +} \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/domain/BoundedSortedSet.java b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListResponse.java similarity index 93% rename from blobstore/core/src/main/java/org/jclouds/blobstore/domain/BoundedSortedSet.java rename to blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListResponse.java index 5981868f1c..7d44f09f44 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/domain/BoundedSortedSet.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/ListResponse.java @@ -30,9 +30,7 @@ import java.util.SortedSet; * @author Adrian Cole * */ -public interface BoundedSortedSet extends SortedSet { - - String getPath(); +public interface ListResponse extends SortedSet { String getMarker(); diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListContainerResponseImpl.java b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListContainerResponseImpl.java new file mode 100644 index 0000000000..05400d156a --- /dev/null +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListContainerResponseImpl.java @@ -0,0 +1,44 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.blobstore.domain.internal; + +import org.jclouds.blobstore.domain.ListContainerResponse; + +public class ListContainerResponseImpl extends ListResponseImpl implements ListContainerResponse { + + /** The serialVersionUID */ + private static final long serialVersionUID = -7133632087734650835L; + protected final String path; + + public ListContainerResponseImpl(Iterable contents, String path, String marker, + Integer maxResults, boolean isTruncated) { + super(contents, marker, maxResults, isTruncated); + this.path = path; + } + + public String getPath() { + return path; + } + +} \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/BoundedTreeSet.java b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListResponseImpl.java similarity index 83% rename from blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/BoundedTreeSet.java rename to blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListResponseImpl.java index ce0c50c3d3..23300336fd 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/BoundedTreeSet.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/domain/internal/ListResponseImpl.java @@ -25,32 +25,26 @@ package org.jclouds.blobstore.domain.internal; import java.util.TreeSet; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; import com.google.common.collect.Iterables; -public class BoundedTreeSet extends TreeSet implements BoundedSortedSet { +public class ListResponseImpl extends TreeSet implements ListResponse { /** The serialVersionUID */ private static final long serialVersionUID = -7133632087734650835L; - protected final String path; protected final String marker; protected final Integer maxResults; protected final boolean truncated; - public BoundedTreeSet(Iterable contents, String path, String marker, Integer maxResults, + public ListResponseImpl(Iterable contents, String marker, Integer maxResults, boolean isTruncated) { Iterables.addAll(this, contents); - this.path = path; this.marker = marker; this.maxResults = maxResults; this.truncated = isTruncated; } - public String getPath() { - return path; - } - public String getMarker() { return marker; } diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/BlobToHttpGetOptions.java b/blobstore/core/src/main/java/org/jclouds/blobstore/functions/BlobToHttpGetOptions.java similarity index 97% rename from azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/BlobToHttpGetOptions.java rename to blobstore/core/src/main/java/org/jclouds/blobstore/functions/BlobToHttpGetOptions.java index 635b412211..1feac2500b 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/blobstore/functions/BlobToHttpGetOptions.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/functions/BlobToHttpGetOptions.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.azure.storage.blob.blobstore.functions; +package org.jclouds.blobstore.functions; import javax.inject.Singleton; diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BaseBlobMap.java b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BaseBlobMap.java index a084032a92..10780dab76 100755 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BaseBlobMap.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BaseBlobMap.java @@ -36,12 +36,12 @@ import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.domain.ResourceType; import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; @@ -70,7 +70,7 @@ public abstract class BaseBlobMap { protected final String containerName; protected final Function prefixer; protected final Function pathStripper; - protected final ListOptions options; + protected final ListContainerOptions options; protected final GetBlobsInListStrategy getAllBlobs; protected final ListBlobMetadataStrategy getAllBlobMetadata; protected final ContainsValueInListStrategy containsValueStrategy; @@ -130,7 +130,7 @@ public abstract class BaseBlobMap { ListBlobMetadataStrategy getAllBlobMetadata, ContainsValueInListStrategy containsValueStrategy, ClearListStrategy deleteBlobsStrategy, CountListStrategy countStrategy, - String containerName, ListOptions options) { + String containerName, ListContainerOptions options) { this.connection = checkNotNull(connection, "connection"); this.containerName = checkNotNull(containerName, "container"); this.options = options; @@ -153,9 +153,9 @@ public abstract class BaseBlobMap { /** * {@inheritDoc} *

- * This returns the number of keys in the {@link BoundedSortedSet} + * This returns the number of keys in the {@link ListResponse} * - * @see BoundedSortedSet#getContents() + * @see ListResponse#getContents() */ public int size() { return (int) countStrategy.execute(containerName, options); diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobMapImpl.java b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobMapImpl.java index 4bbc6c5d2d..ea665c6ff8 100755 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobMapImpl.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobMapImpl.java @@ -36,7 +36,7 @@ import org.jclouds.blobstore.BlobMap; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.CountListStrategy; @@ -63,7 +63,7 @@ public class BlobMapImpl extends BaseBlobMap implements BlobMap { ListBlobMetadataStrategy getAllBlobMetadata, ContainsValueInListStrategy containsValueStrategy, ClearListStrategy clearContainerStrategy, CountListStrategy containerCountStrategy, - String containerName, ListOptions listOptions) { + String containerName, ListContainerOptions listOptions) { super(connection, getAllBlobs, getAllBlobMetadata, containsValueStrategy, clearContainerStrategy, containerCountStrategy, containerName, listOptions); } diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java index 57cebdddd1..970a6222f3 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java @@ -31,7 +31,7 @@ import org.jclouds.blobstore.BlobMap; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.InputStreamMap; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.internal.RestContextImpl; @@ -57,7 +57,7 @@ public class BlobStoreContextImpl extends RestContextImpl implements BlobS checkNotNull(path, "path"); String container = BlobStoreUtils.parseContainerFromPath(path); String prefix = BlobStoreUtils.parsePrefixFromPath(path); - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); if (prefix != null) options.underPath(prefix); return blobMapFactory.create(container, options); @@ -67,7 +67,7 @@ public class BlobStoreContextImpl extends RestContextImpl implements BlobS checkNotNull(path, "path"); String container = BlobStoreUtils.parseContainerFromPath(path); String prefix = BlobStoreUtils.parsePrefixFromPath(path); - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); if (prefix != null) options.underPath(prefix); return inputStreamMapFactory.create(container, options); diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java index 48b65f3385..e839595238 100755 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/internal/InputStreamMapImpl.java @@ -38,7 +38,7 @@ import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.InputStreamMap; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.CountListStrategy; @@ -67,7 +67,7 @@ public class InputStreamMapImpl extends BaseBlobMap implements Inpu GetBlobsInListStrategy getAllBlobs, ListBlobMetadataStrategy getAllBlobMetadata, ContainsValueInListStrategy containsValueStrategy, ClearListStrategy clearContainerStrategy, CountListStrategy containerCountStrategy, - String containerName, ListOptions listOptions) { + String containerName, ListContainerOptions listOptions) { super(connection, getAllBlobs, getAllBlobMetadata, containsValueStrategy, clearContainerStrategy, containerCountStrategy, containerName, listOptions); } diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java b/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java new file mode 100644 index 0000000000..16becf0373 --- /dev/null +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java @@ -0,0 +1,126 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.blobstore.options; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Contains options supported in the list container operation.

+ * Usage

The recommended way to instantiate a ListOptions object is to statically import + * ListContainerOptions.* and invoke a static creation method followed by an instance mutator (if needed): + *

+ * + * import static org.jclouds.blobstore.options.ListContainerOptions.Builder.* + *

+ * BlobStore connection = // get connection + * Future> list = connection.list("container",underPath("home/users").maxResults(1000)); + * + * + * @author Adrian Cole + */ +public class ListContainerOptions extends ListOptions { + + private String path; + + private boolean recursive; + + + public String getPath() { + return path; + } + + public boolean isRecursive() { + return recursive; + } + + /** + * Returns a pseudo-directory listing. + * + */ + public ListContainerOptions underPath(String path) { + checkArgument(!recursive, "path and recursive combination currently not supported"); + this.path = checkNotNull(path, "path"); + return this; + } + + /** + * {@inheritDoc} + */ + public ListContainerOptions afterMarker(String marker) { + return (ListContainerOptions) super.afterMarker(marker); + } + + /** + * {@inheritDoc} + */ + public ListContainerOptions maxResults(int maxKeys) { + return (ListContainerOptions) super.maxResults(maxKeys); + } + + /** + * return a listing of all objects inside the store, recursively. + */ + public ListContainerOptions recursive() { +// checkArgument(path == null, "path and recursive combination currently not supported"); + this.recursive = true; + return this; + } + + public static class Builder { + + /** + * @see ListContainerOptions#underPath(String) + */ + public static ListContainerOptions underPath(String path) { + ListContainerOptions options = new ListContainerOptions(); + return options.underPath(path); + } + + /** + * @see ListContainerOptions#afterMarker(String) + */ + public static ListContainerOptions afterMarker(String marker) { + ListContainerOptions options = new ListContainerOptions(); + return options.afterMarker(marker); + } + + /** + * @see ListContainerOptions#maxResults(int) + */ + public static ListContainerOptions maxResults(int maxKeys) { + ListContainerOptions options = new ListContainerOptions(); + return options.maxResults(maxKeys); + } + + /** + * @see ListContainerOptions#recursive() + */ + public static ListContainerOptions recursive() { + ListContainerOptions options = new ListContainerOptions(); + return options.recursive(); + } + + } +} diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListOptions.java b/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListOptions.java index 8b3d075acc..7a316b699e 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListOptions.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/options/ListOptions.java @@ -35,7 +35,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * import static org.jclouds.blobstore.options.ListOptions.Builder.* *

* BlobStore connection = // get connection - * Future> list = connection.list("container",underPath("home/users").maxResults(1000)); + * Future> list = connection.list(maxResults(1000)); * * * @author Adrian Cole @@ -43,36 +43,16 @@ import static com.google.common.base.Preconditions.checkNotNull; public class ListOptions { private Integer maxKeys; - private String path; private String marker; - private boolean recursive; public Integer getMaxResults() { return maxKeys; } - public String getPath() { - return path; - } - public String getMarker() { return marker; } - public boolean isRecursive() { - return recursive; - } - - /** - * Returns a pseudo-directory listing. - * - */ - public ListOptions underPath(String path) { - checkArgument(!recursive, "path and recursive combination currently not supported"); - this.path = checkNotNull(path, "path"); - return this; - } - /** * Place to continue a listing at. This must be the value returned from the last list object, as * not all blobstores use lexigraphic lists. @@ -92,25 +72,9 @@ public class ListOptions { return this; } - /** - * return a listing of all objects inside the store, recursively. - */ - public ListOptions recursive() { -// checkArgument(path == null, "path and recursive combination currently not supported"); - this.recursive = true; - return this; - } public static class Builder { - /** - * @see ListOptions#underPath(String) - */ - public static ListOptions underPath(String path) { - ListOptions options = new ListOptions(); - return options.underPath(path); - } - /** * @see ListOptions#afterMarker(String) */ @@ -127,13 +91,6 @@ public class ListOptions { return options.maxResults(maxKeys); } - /** - * @see ListOptions#recursive() - */ - public static ListOptions recursive() { - ListOptions options = new ListOptions(); - return options.recursive(); - } } } diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ClearListStrategy.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ClearListStrategy.java index cc1675cb9e..da78f37b3e 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ClearListStrategy.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ClearListStrategy.java @@ -23,7 +23,7 @@ */ package org.jclouds.blobstore.strategy; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.DeleteAllKeysInList; import com.google.inject.ImplementedBy; @@ -36,5 +36,5 @@ import com.google.inject.ImplementedBy; @ImplementedBy(DeleteAllKeysInList.class) public interface ClearListStrategy { - void execute(String containerName, ListOptions options); + void execute(String containerName, ListContainerOptions options); } \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ContainsValueInListStrategy.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ContainsValueInListStrategy.java index f0b972ea41..6cf1c17ba6 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ContainsValueInListStrategy.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ContainsValueInListStrategy.java @@ -23,7 +23,7 @@ */ package org.jclouds.blobstore.strategy; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.FindMD5InList; import com.google.inject.ImplementedBy; @@ -36,6 +36,6 @@ import com.google.inject.ImplementedBy; @ImplementedBy(FindMD5InList.class) public interface ContainsValueInListStrategy { - boolean execute(String containerName, Object value, ListOptions options); + boolean execute(String containerName, Object value, ListContainerOptions options); } \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/CountListStrategy.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/CountListStrategy.java index cbf813c85c..9bd5bb99c3 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/CountListStrategy.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/CountListStrategy.java @@ -23,7 +23,7 @@ */ package org.jclouds.blobstore.strategy; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.CountBlobTypeInList; import com.google.inject.ImplementedBy; @@ -36,6 +36,6 @@ import com.google.inject.ImplementedBy; @ImplementedBy(CountBlobTypeInList.class) public interface CountListStrategy { - long execute(String containerName, ListOptions options); + long execute(String containerName, ListContainerOptions options); } \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/GetBlobsInListStrategy.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/GetBlobsInListStrategy.java index 1d1b511b89..83a5c874c8 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/GetBlobsInListStrategy.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/GetBlobsInListStrategy.java @@ -26,7 +26,7 @@ package org.jclouds.blobstore.strategy; import java.util.SortedSet; import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.GetAllBlobsInListAndRetryOnFailure; import com.google.inject.ImplementedBy; @@ -39,6 +39,6 @@ import com.google.inject.ImplementedBy; @ImplementedBy(GetAllBlobsInListAndRetryOnFailure.class) public interface GetBlobsInListStrategy { - SortedSet execute(String containerName, ListOptions options); + SortedSet execute(String containerName, ListContainerOptions options); } \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ListBlobMetadataStrategy.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ListBlobMetadataStrategy.java index 57e07dd39f..fff899f29d 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ListBlobMetadataStrategy.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/ListBlobMetadataStrategy.java @@ -26,7 +26,7 @@ package org.jclouds.blobstore.strategy; import java.util.SortedSet; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.internal.ListBlobMetadataInContainer; import com.google.inject.ImplementedBy; @@ -39,6 +39,6 @@ import com.google.inject.ImplementedBy; @ImplementedBy(ListBlobMetadataInContainer.class) public interface ListBlobMetadataStrategy { - SortedSet execute(String containerName, ListOptions options); + SortedSet execute(String containerName, ListContainerOptions options); } \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/CountBlobTypeInList.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/CountBlobTypeInList.java index a8751fcb6d..ae4dac8da4 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/CountBlobTypeInList.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/CountBlobTypeInList.java @@ -26,7 +26,7 @@ package org.jclouds.blobstore.strategy.internal; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.CountListStrategy; import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy; @@ -44,7 +44,7 @@ public class CountBlobTypeInList implements CountListStrategy { this.getAllBlobMetadata = getAllBlobMetadata; } - public long execute(String container, ListOptions options) { + public long execute(String container, ListContainerOptions options) { return getAllBlobMetadata.execute(container, options).size(); } diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java index e3bf884d12..3e53f6e854 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java @@ -35,7 +35,7 @@ import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.domain.ResourceType; import org.jclouds.blobstore.internal.BlobRuntimeException; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.strategy.ClearContainerStrategy; import org.jclouds.blobstore.strategy.ClearListStrategy; @@ -70,7 +70,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr execute(containerName, null); } - public void execute(final String containerName, ListOptions options) { + public void execute(final String containerName, ListContainerOptions options) { Set> deletes = Sets.newHashSet(); for (ResourceMetadata md : getAllBlobMetadata.execute(containerName, options)) { if (md.getType() == ResourceType.BLOB) diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/FindMD5InList.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/FindMD5InList.java index c1c4205087..847ecbde90 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/FindMD5InList.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/FindMD5InList.java @@ -31,7 +31,7 @@ import javax.inject.Singleton; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.functions.ObjectMD5; import org.jclouds.blobstore.internal.BlobRuntimeException; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy; import org.jclouds.util.Utils; @@ -53,7 +53,7 @@ public class FindMD5InList implements ContainsValueInListStrategy { this.getAllBlobMetadata = getAllBlobMetadata; } - public boolean execute(String containerName, Object value, ListOptions options) { + public boolean execute(String containerName, Object value, ListContainerOptions options) { try { byte[] toSearch = objectMD5.apply(value); for (BlobMetadata metadata : getAllBlobMetadata.execute(containerName, options)) { diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java index 26191d3fa7..fd178c26c1 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java @@ -41,7 +41,7 @@ import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.internal.BlobRuntimeException; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.strategy.GetBlobsInListStrategy; import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy; @@ -82,7 +82,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg this.getAllBlobMetadata = getAllBlobMetadata; } - public SortedSet execute(String container, ListOptions options) { + public SortedSet execute(String container, ListContainerOptions options) { SortedSet objects = Sets.newTreeSet(); Map> futureObjects = Maps.newHashMap(); for (BlobMetadata md : getAllBlobMetadata.execute(container, options)) { diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/ListBlobMetadataInContainer.java b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/ListBlobMetadataInContainer.java index e4ef9bfde9..fe4781c621 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/ListBlobMetadataInContainer.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/strategy/internal/ListBlobMetadataInContainer.java @@ -32,11 +32,11 @@ import javax.inject.Singleton; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.domain.ResourceType; import org.jclouds.blobstore.internal.BlobRuntimeException; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy; import org.jclouds.util.Utils; @@ -63,9 +63,9 @@ public class ListBlobMetadataInContainer implements ListBlobMetadataStrategy { this.connection = connection; } - public SortedSet execute(String container, ListOptions options) { + public SortedSet execute(String container, ListContainerOptions options) { try { - BoundedSortedSet resources = connection.list(container, + ListResponse resources = connection.list(container, options).get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); SortedSet blobM = Sets.newTreeSet(); for (ResourceMetadata from : resources) { diff --git a/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java b/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java index 8a8bccc776..36e2a449d2 100644 --- a/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java +++ b/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java @@ -154,6 +154,7 @@ public class BaseBlobStoreIntegrationTest { createContainerAndEnsureEmpty(context, containerName); containerJsr330.put(containerName); } catch (Throwable e) { + e.printStackTrace(); // throw away the container and try again with the next index deleteContainerOrWarnIfUnable(context, containerName); containerCount++; diff --git a/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java b/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java index eec60e0dfa..cd9ab8fdb0 100755 --- a/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java +++ b/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java @@ -23,9 +23,9 @@ */ package org.jclouds.blobstore.integration.internal; -import static org.jclouds.blobstore.options.ListOptions.Builder.afterMarker; -import static org.jclouds.blobstore.options.ListOptions.Builder.maxResults; -import static org.jclouds.blobstore.options.ListOptions.Builder.underPath; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.afterMarker; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.underPath; import static org.testng.Assert.assertEquals; import java.io.UnsupportedEncodingException; @@ -35,7 +35,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.util.Utils; import org.testng.annotations.Test; @@ -78,7 +79,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTes String containerName = getContainerName(); try { addAlphabetUnderRoot(containerName); - BoundedSortedSet container = context.getBlobStore().list( + ListResponse container = context.getBlobStore().list( containerName, afterMarker("y")).get(10, TimeUnit.SECONDS); assertEquals(container.getMarker(), "y"); assert !container.isTruncated(); @@ -95,7 +96,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTes String prefix = "apps"; addTenObjectsUnderPrefix(containerName, prefix); add15UnderRoot(containerName); - BoundedSortedSet container = context.getBlobStore().list( + ListResponse container = context.getBlobStore().list( containerName).get(10, TimeUnit.SECONDS); assert !container.isTruncated(); assertEquals(container.size(), 16); @@ -113,7 +114,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTes addTenObjectsUnderPrefix(containerName, prefix); add15UnderRoot(containerName); - BoundedSortedSet container = context.getBlobStore().list( + ListContainerResponse container = context.getBlobStore().list( containerName, underPath("apps/")).get(10, TimeUnit.SECONDS); assert !container.isTruncated(); assertEquals(container.size(), 10); @@ -129,7 +130,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTes String containerName = getContainerName(); try { addAlphabetUnderRoot(containerName); - BoundedSortedSet container = context.getBlobStore().list( + ListResponse container = context.getBlobStore().list( containerName, maxResults(5)).get(10, TimeUnit.SECONDS); assertEquals(container.getMaxResults(), 5); assert container.isTruncated(); @@ -139,18 +140,6 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTes } } - @Test(groups = { "integration", "live" }) - public void testListWhenContentsUnderPath() throws Exception { - String containerName = getContainerName(); - try { - add5BlobsUnderPathAnd5UnderRootToContainer(containerName); - context.getBlobStore().clearContainer(containerName).get(60, TimeUnit.SECONDS); - assertConsistencyAwareContainerSize(containerName, 0); - } finally { - returnContainer(containerName); - } - } - @Test(groups = { "integration", "live" }) public void containerExists() throws Exception { String containerName = getContainerName(); diff --git a/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/StubBlobStore.java b/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/StubBlobStore.java index 2793827317..805093862d 100755 --- a/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/StubBlobStore.java +++ b/blobstore/core/src/test/java/org/jclouds/blobstore/integration/internal/StubBlobStore.java @@ -60,16 +60,18 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.MutableResourceMetadata; import org.jclouds.blobstore.domain.ResourceMetadata; import org.jclouds.blobstore.domain.ResourceType; -import org.jclouds.blobstore.domain.internal.BoundedTreeSet; +import org.jclouds.blobstore.domain.internal.ListResponseImpl; +import org.jclouds.blobstore.domain.internal.ListContainerResponseImpl; import org.jclouds.blobstore.domain.internal.MutableResourceMetadataImpl; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.options.GetOptions; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -152,11 +154,11 @@ public class StubBlobStore implements BlobStore { }; } - public Future> list(final String name, - ListOptions... optionsList) { - final ListOptions options = (optionsList.length == 0) ? new ListOptions() : optionsList[0]; - return new FutureBase>() { - public BoundedSortedSet get() throws InterruptedException, + public Future> list(final String name, + ListContainerOptions... optionsList) { + final ListContainerOptions options = (optionsList.length == 0) ? new ListContainerOptions() : optionsList[0]; + return new FutureBase>() { + public ListContainerResponse get() throws InterruptedException, ExecutionException { final Map realContents = getContainerToBlobs().get(name); @@ -231,7 +233,7 @@ public class StubBlobStore implements BlobStore { } })); } - return new BoundedTreeSet(contents, prefix, marker, maxResults, + return new ListContainerResponseImpl(contents, prefix, marker, maxResults, truncated); } }; @@ -334,11 +336,12 @@ public class StubBlobStore implements BlobStore { } } - public Future> list() { - return new FutureBase>() { + public Future> list() { + return new FutureBase>() { - public TreeSet get() throws InterruptedException, ExecutionException { - return Sets.newTreeSet(Iterables.transform(getContainerToBlobs().keySet(), + public ListResponse get() throws InterruptedException, + ExecutionException { + return new ListResponseImpl(Iterables.transform(getContainerToBlobs().keySet(), new Function() { public ResourceMetadata apply(String name) { MutableResourceMetadata cmd = create(); @@ -347,7 +350,7 @@ public class StubBlobStore implements BlobStore { return cmd; } - })); + }), null, null, false); } }; diff --git a/blobstore/core/src/test/java/org/jclouds/blobstore/options/ListOptionsTest.java b/blobstore/core/src/test/java/org/jclouds/blobstore/options/ListOptionsTest.java index f7a900305e..15741eae11 100644 --- a/blobstore/core/src/test/java/org/jclouds/blobstore/options/ListOptionsTest.java +++ b/blobstore/core/src/test/java/org/jclouds/blobstore/options/ListOptionsTest.java @@ -23,10 +23,10 @@ */ package org.jclouds.blobstore.options; -import static org.jclouds.blobstore.options.ListOptions.Builder.afterMarker; -import static org.jclouds.blobstore.options.ListOptions.Builder.maxResults; -import static org.jclouds.blobstore.options.ListOptions.Builder.recursive; -import static org.jclouds.blobstore.options.ListOptions.Builder.underPath; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.afterMarker; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.underPath; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -40,33 +40,33 @@ import org.testng.annotations.Test; public class ListOptionsTest { @Test public void testRecursive() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); options.recursive(); assertTrue(options.isRecursive()); } @Test public void testRecursiveStatic() { - ListOptions options = recursive(); + ListContainerOptions options = recursive(); assertTrue(options.isRecursive()); } @Test public void testPath() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); options.underPath("test"); assertEquals(options.getPath(), "test"); } @Test public void testPathStatic() { - ListOptions options = underPath("test"); + ListContainerOptions options = underPath("test"); assertEquals(options.getPath(), "test"); } @Test public void testTwoOptions() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); options.underPath("test").maxResults(1); assertEquals(options.getPath(), "test"); assertEquals(options.getMaxResults(), new Integer(1)); @@ -75,7 +75,7 @@ public class ListOptionsTest { @Test public void testNullPath() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); assertEquals(options.getPath(), null); } @@ -86,7 +86,7 @@ public class ListOptionsTest { @Test public void testMarker() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); options.afterMarker("test"); assertEquals(options.getMarker(), "test"); @@ -94,13 +94,13 @@ public class ListOptionsTest { @Test public void testNullMarker() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); assertEquals(options.getMarker(), null); } @Test public void testMarkerStatic() { - ListOptions options = afterMarker("test"); + ListContainerOptions options = afterMarker("test"); assertEquals(options.getMarker(), "test"); } @@ -111,20 +111,20 @@ public class ListOptionsTest { @Test public void testMaxResults() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); options.maxResults(1000); assertEquals(options.getMaxResults(), new Integer(1000)); } @Test public void testNullMaxResults() { - ListOptions options = new ListOptions(); + ListContainerOptions options = new ListContainerOptions(); assertEquals(options.getMaxResults(), null); } @Test public void testMaxResultsStatic() { - ListOptions options = maxResults(1000); + ListContainerOptions options = maxResults(1000); assertEquals(options.getMaxResults(), new Integer(1000)); } diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java index 688dcd2709..3597133b50 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java @@ -39,7 +39,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; @@ -203,7 +203,7 @@ public interface CloudFilesClient { @QueryParams(keys = "format", values = "json") @ResponseParser(ParseObjectInfoListFromJsonResponse.class) @Path("{container}") - Future> listObjects(@PathParam("container") String container, + Future> listObjects(@PathParam("container") String container, ListContainerOptions... options); @HEAD diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java index ef8d3f179c..38c747f5f1 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/CloudFilesBlobStore.java @@ -24,7 +24,7 @@ package org.jclouds.rackspace.cloudfiles.blobstore; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.blobstore.options.ListOptions.Builder.recursive; +import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import java.util.SortedSet; import java.util.concurrent.Callable; @@ -38,29 +38,29 @@ import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; +import org.jclouds.blobstore.domain.ListResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.domain.internal.ListResponseImpl; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.concurrent.FutureFunctionWrapper; import org.jclouds.http.options.GetOptions; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rackspace.cloudfiles.CloudFilesClient; +import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobToObject; import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobToObjectGetOptions; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ContainerToResourceList; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ContainerToResourceMetadata; -import org.jclouds.rackspace.cloudfiles.blobstore.functions.ListOptionsToListContainerOptions; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ObjectToBlob; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.rackspace.cloudfiles.domain.CFObject; import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo; -import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions; import com.google.common.base.Function; import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; @ConsistencyModel(ConsistencyModels.STRICT) public class CloudFilesBlobStore implements BlobStore { @@ -71,20 +71,20 @@ public class CloudFilesBlobStore implements BlobStore { private final ObjectToBlobMetadata object2BlobMd; private final ObjectToBlob object2Blob; private final BlobToObject blob2Object; - private final ListOptionsToListContainerOptions container2ContainerListOptions; + private final BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions; private final BlobToObjectGetOptions blob2ObjectGetOptions; private final ContainerToResourceMetadata container2ResourceMd; private final ContainerToResourceList container2ResourceList; private final ExecutorService service; @Inject - private CloudFilesBlobStore(CloudFilesClient connection, Blob.Factory blobFactory, LoggerFactory logFactory, - ClearListStrategy clearContainerStrategy, ObjectToBlobMetadata object2BlobMd, - ObjectToBlob object2Blob, BlobToObject blob2Object, - ListOptionsToListContainerOptions container2ContainerListOptions, + private CloudFilesBlobStore(CloudFilesClient connection, Blob.Factory blobFactory, + LoggerFactory logFactory, ClearListStrategy clearContainerStrategy, + ObjectToBlobMetadata object2BlobMd, ObjectToBlob object2Blob, BlobToObject blob2Object, + BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, BlobToObjectGetOptions blob2ObjectGetOptions, - ContainerToResourceMetadata container2ResourceMd, ContainerToResourceList container2ResourceList, - ExecutorService service) { + ContainerToResourceMetadata container2ResourceMd, + ContainerToResourceList container2ResourceList, ExecutorService service) { this.connection = checkNotNull(connection, "connection"); this.blobFactory = checkNotNull(blobFactory, "blobFactory"); this.logFactory = checkNotNull(logFactory, "logFactory"); @@ -150,19 +150,24 @@ public class CloudFilesBlobStore implements BlobStore { return wrapFuture(returnVal, object2Blob); } - public Future> list() { - return wrapFuture(connection.listContainers(), - new Function, SortedSet>() { - public SortedSet apply(SortedSet from) { - return Sets.newTreeSet(Iterables.transform(from, container2ResourceMd)); + public Future> list() { + return wrapFuture( + connection.listContainers(), + new Function, org.jclouds.blobstore.domain.ListResponse>() { + public org.jclouds.blobstore.domain.ListResponse apply( + SortedSet from) { + return new ListResponseImpl(Iterables.transform(from, + container2ResourceMd), null, null, false); } }); } - public Future> list(String container, - ListOptions... optionsList) { - ListContainerOptions httpOptions = container2ContainerListOptions.apply(optionsList); - Future> returnVal = connection.listObjects(container, httpOptions); + public Future> list( + String container, ListContainerOptions... optionsList) { + org.jclouds.rackspace.cloudfiles.options.ListContainerOptions httpOptions = container2ContainerListOptions + .apply(optionsList); + Future> returnVal = connection.listObjects(container, + httpOptions); return wrapFuture(returnVal, container2ResourceList); } diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListOptionsToListContainerOptions.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/BlobStoreListContainerOptionsToListContainerOptions.java similarity index 80% rename from rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListOptionsToListContainerOptions.java rename to rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/BlobStoreListContainerOptionsToListContainerOptions.java index ef5f651700..c533348fa4 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListOptionsToListContainerOptions.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/BlobStoreListContainerOptionsToListContainerOptions.java @@ -25,8 +25,7 @@ package org.jclouds.rackspace.cloudfiles.blobstore.functions; import javax.inject.Singleton; -import org.jclouds.blobstore.options.ListOptions; -import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.common.base.Function; @@ -34,10 +33,12 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class ListOptionsToListContainerOptions implements - Function { - public ListContainerOptions apply(ListOptions[] optionsList) { - ListContainerOptions options = new ListContainerOptions(); +public class BlobStoreListContainerOptionsToListContainerOptions + implements + Function { + public org.jclouds.rackspace.cloudfiles.options.ListContainerOptions apply( + ListContainerOptions[] optionsList) { + org.jclouds.rackspace.cloudfiles.options.ListContainerOptions options = new org.jclouds.rackspace.cloudfiles.options.ListContainerOptions(); if (optionsList.length != 0) { if ((optionsList[0].getPath() == null) && (optionsList[0].isRecursive())) { diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java index 297962bee3..7c7194df64 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java @@ -27,9 +27,9 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.domain.internal.BoundedTreeSet; +import org.jclouds.blobstore.domain.internal.ListContainerResponseImpl; import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo; import com.google.common.base.Function; @@ -40,7 +40,7 @@ import com.google.common.collect.Iterables; */ @Singleton public class ContainerToResourceList implements - Function, BoundedSortedSet> { + Function, ListContainerResponse> { private final ObjectToBlobMetadata object2blobMd; @Inject @@ -48,8 +48,8 @@ public class ContainerToResourceList implements this.object2blobMd = object2blobMd; } - public BoundedSortedSet apply(BoundedSortedSet from) { - return new BoundedTreeSet(Iterables.transform(Iterables.transform(from, + public ListContainerResponse apply(ListContainerResponse from) { + return new ListContainerResponseImpl(Iterables.transform(Iterables.transform(from, object2blobMd), new Function() { public ResourceMetadata apply(BlobMetadata arg0) { return arg0; diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListContainerOptionsToListOptions.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListContainerOptionsToBlobStoreListContainerOptions.java similarity index 79% rename from rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListContainerOptionsToListOptions.java rename to rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListContainerOptionsToBlobStoreListContainerOptions.java index 20fd1b8a57..6f445e52a1 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListContainerOptionsToListOptions.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ListContainerOptionsToBlobStoreListContainerOptions.java @@ -25,8 +25,7 @@ package org.jclouds.rackspace.cloudfiles.blobstore.functions; import javax.inject.Singleton; -import org.jclouds.blobstore.options.ListOptions; -import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import com.google.common.base.Function; @@ -34,10 +33,12 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class ListContainerOptionsToListOptions implements - Function { - public ListOptions apply(ListContainerOptions[] optionsList) { - ListOptions options = new ListOptions(); +public class ListContainerOptionsToBlobStoreListContainerOptions + implements + Function { + public ListContainerOptions apply( + org.jclouds.rackspace.cloudfiles.options.ListContainerOptions[] optionsList) { + ListContainerOptions options = new ListContainerOptions(); if (optionsList.length != 0) { if (optionsList[0].getPath() != null) { options.underPath(optionsList[0].getPath()); diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ResourceToObjectList.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ResourceToObjectList.java index 7ae86888d9..8145bb642a 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ResourceToObjectList.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ResourceToObjectList.java @@ -26,9 +26,9 @@ package org.jclouds.rackspace.cloudfiles.blobstore.functions; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.blobstore.domain.internal.BoundedTreeSet; +import org.jclouds.blobstore.domain.internal.ListContainerResponseImpl; import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo; import com.google.common.base.Function; @@ -39,7 +39,7 @@ import com.google.common.collect.Iterables; */ @Singleton public class ResourceToObjectList implements - Function, BoundedSortedSet> { + Function, ListContainerResponse> { private final ResourceToObjectInfo resource2ObjectMd; @Inject @@ -47,9 +47,9 @@ public class ResourceToObjectList implements this.resource2ObjectMd = resource2ObjectMd; } - public BoundedSortedSet apply(BoundedSortedSet list) { + public ListContainerResponse apply(ListContainerResponse list) { - return new BoundedTreeSet(Iterables.transform(list, + return new ListContainerResponseImpl(Iterables.transform(list, new Function() { public ObjectInfo apply(ResourceMetadata from) { diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponse.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponse.java index e5a9da2533..7df21f6edf 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponse.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponse.java @@ -23,7 +23,6 @@ */ package org.jclouds.rackspace.cloudfiles.functions; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; @@ -32,7 +31,6 @@ import java.util.SortedSet; import javax.inject.Inject; -import org.apache.commons.io.IOUtils; import org.jclouds.http.functions.ParseJson; import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata; @@ -44,23 +42,15 @@ import com.google.gson.reflect.TypeToken; * * @author James Murty */ -public class ParseContainerCDNMetadataListFromJsonResponse extends ParseJson> - { - +public class ParseContainerCDNMetadataListFromJsonResponse extends + ParseJson> { + @Inject public ParseContainerCDNMetadataListFromJsonResponse(Gson gson) { super(gson); } public SortedSet apply(InputStream stream) { - String toParse; - try { - toParse = IOUtils.toString(stream); - } catch (IOException e1) { - throw new RuntimeException(e1); - } - // Ticket #1871 bad quoting on cdn uri - stream = IOUtils.toInputStream(toParse.replaceAll("m,","m\",")); Type listType = new TypeToken>() { }.getType(); try { diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java index 06a7f2d1e2..1328a0f5a2 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java @@ -34,8 +34,8 @@ import java.util.SortedSet; import javax.inject.Inject; -import org.jclouds.blobstore.domain.BoundedSortedSet; -import org.jclouds.blobstore.domain.internal.BoundedTreeSet; +import org.jclouds.blobstore.domain.ListContainerResponse; +import org.jclouds.blobstore.domain.internal.ListContainerResponseImpl; import org.jclouds.http.HttpUtils; import org.jclouds.http.functions.ParseJson; import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo; @@ -55,7 +55,7 @@ import com.google.gson.reflect.TypeToken; * * @author Adrian Cole */ -public class ParseObjectInfoListFromJsonResponse extends ParseJson> +public class ParseObjectInfoListFromJsonResponse extends ParseJson> implements InvocationContext { private GeneratedHttpRequest request; @@ -147,7 +147,7 @@ public class ParseObjectInfoListFromJsonResponse extends ParseJson apply(InputStream stream) { + public ListContainerResponse apply(InputStream stream) { checkState(request != null, "request should be initialized at this point"); checkState(request.getArgs() != null, "request.getArgs() should be initialized at this point"); checkArgument(request.getArgs()[0] instanceof String, "arg[0] must be a container name"); @@ -170,7 +170,7 @@ public class ParseObjectInfoListFromJsonResponse extends ParseJson(returnVal, options.getPath(), marker, options + return new ListContainerResponseImpl(returnVal, options.getPath(), marker, options .getMaxResults(), truncated); } catch (UnsupportedEncodingException e) { diff --git a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java index 085a81aba8..6125b11b6b 100644 --- a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java +++ b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java @@ -42,7 +42,7 @@ import java.util.concurrent.TimeoutException; import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.KeyNotFoundException; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListResponse; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpUtils; @@ -85,6 +85,8 @@ public class CloudFilesClientLiveTest extends BaseBlobStoreIntegrationTest container = context.getApi().listObjects(containerName, + ListResponse container = context.getApi().listObjects(containerName, underPath("")).get(10, TimeUnit.SECONDS); assert !container.isTruncated(); assertEquals(container.size(), 1); diff --git a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesClient.java b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesClient.java index 06df580c29..aff7e66402 100644 --- a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesClient.java +++ b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesClient.java @@ -35,17 +35,17 @@ import java.util.concurrent.Future; import javax.inject.Inject; import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.BoundedSortedSet; +import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.integration.internal.StubBlobStore; import org.jclouds.blobstore.integration.internal.StubBlobStore.FutureBase; -import org.jclouds.blobstore.options.ListOptions; +import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.concurrent.FutureFunctionWrapper; import org.jclouds.http.options.GetOptions; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rackspace.cloudfiles.CloudFilesClient; import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobToObject; -import org.jclouds.rackspace.cloudfiles.blobstore.functions.ListContainerOptionsToListOptions; +import org.jclouds.rackspace.cloudfiles.blobstore.functions.ListContainerOptionsToBlobStoreListContainerOptions; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ObjectToBlob; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ResourceToObjectInfo; import org.jclouds.rackspace.cloudfiles.blobstore.functions.ResourceToObjectList; @@ -56,7 +56,6 @@ import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata; import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo; import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions; -import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -75,7 +74,7 @@ public class StubCloudFilesClient implements CloudFilesClient { private final ObjectToBlob object2Blob; private final BlobToObject blob2Object; private final ResourceToObjectInfo blob2ObjectInfo; - private final ListContainerOptionsToListOptions container2ContainerListOptions; + private final ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions; private final ResourceToObjectList resource2ObjectList; @Inject @@ -84,7 +83,7 @@ public class StubCloudFilesClient implements CloudFilesClient { CFObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo, - ListContainerOptionsToListOptions container2ContainerListOptions, + ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions, ResourceToObjectList resource2ContainerList) { this.blobStore = blobStore; this.logFactory = logFactory; @@ -149,7 +148,7 @@ public class StubCloudFilesClient implements CloudFilesClient { } public Future> listContainers( - ListContainerOptions... options) { + org.jclouds.rackspace.cloudfiles.options.ListContainerOptions... options) { return new FutureBase>() { public SortedSet get() throws InterruptedException, ExecutionException { @@ -164,9 +163,9 @@ public class StubCloudFilesClient implements CloudFilesClient { }; } - public Future> listObjects(String container, - ListContainerOptions... optionsList) { - ListOptions options = container2ContainerListOptions.apply(optionsList); + public Future> listObjects(String container, + org.jclouds.rackspace.cloudfiles.options.ListContainerOptions... optionsList) { + ListContainerOptions options = container2ContainerListOptions.apply(optionsList); return wrapFuture(blobStore.list(container, options), resource2ObjectList); } diff --git a/rackspace/cloudfiles/core/src/test/resources/test_list_cdn.json b/rackspace/cloudfiles/core/src/test/resources/test_list_cdn.json index 5bf462d7d5..bea7be869e 100644 --- a/rackspace/cloudfiles/core/src/test/resources/test_list_cdn.json +++ b/rackspace/cloudfiles/core/src/test/resources/test_list_cdn.json @@ -1,5 +1,5 @@ [ -{"name":"adriancole-blobstore.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"http://c0354712.cdn.cloudfiles.rackspacecloud.com,"referrer_acl":"","useragent_acl":"", "log_retention":"false"}, -{"name":"adriancole-blobstore5","cdn_enabled":"true","ttl":28800,"cdn_uri":"http://c0404671.cdn.cloudfiles.rackspacecloud.com,"referrer_acl":"","useragent_acl":"", "log_retention":"false"}, -{"name":"adriancole-cfcdnint.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"http://c0320431.cdn.cloudfiles.rackspacecloud.com,"referrer_acl":"","useragent_acl":"", "log_retention":"false"} +{"name":"adriancole-blobstore.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"http://c0354712.cdn.cloudfiles.rackspacecloud.com","referrer_acl":"","useragent_acl":"", "log_retention":"false"}, +{"name":"adriancole-blobstore5","cdn_enabled":"true","ttl":28800,"cdn_uri":"http://c0404671.cdn.cloudfiles.rackspacecloud.com","referrer_acl":"","useragent_acl":"", "log_retention":"false"}, +{"name":"adriancole-cfcdnint.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"http://c0320431.cdn.cloudfiles.rackspacecloud.com","referrer_acl":"","useragent_acl":"", "log_retention":"false"} ] \ No newline at end of file