diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/ListBlobsInclude.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/ListBlobsInclude.java new file mode 100644 index 0000000000..1964346ef5 --- /dev/null +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/ListBlobsInclude.java @@ -0,0 +1,33 @@ +/* + * 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.azureblob.domain; + +public enum ListBlobsInclude { + COPY, + METADATA, + SNAPSHOTS, + UNCOMMITTEDBLOBS; + + public static ListBlobsInclude fromValue(String symbol) { + return ListBlobsInclude.valueOf(symbol.toUpperCase()); + } + + @Override + public String toString() { + return name().toLowerCase(); + } +} diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/internal/BlobPropertiesImpl.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/internal/BlobPropertiesImpl.java index 27866dbad2..c3c400541d 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/internal/BlobPropertiesImpl.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/internal/BlobPropertiesImpl.java @@ -47,7 +47,7 @@ public class BlobPropertiesImpl implements BlobProperties { private final BaseImmutableContentMetadata contentMetadata; // TODO: should this take Cache-Control as well? - public BlobPropertiesImpl(BlobType type, String name, String container, URI url, Date lastModified, String eTag, + public BlobPropertiesImpl(BlobType type, String name, String container, URI url, @Nullable Date lastModified, @Nullable String eTag, long size, String contentType, @Nullable byte[] contentMD5, @Nullable String contentMetadata, @Nullable String contentLanguage, @Nullable Date currentExpires, LeaseStatus leaseStatus, Map metadata) { @@ -56,8 +56,8 @@ public class BlobPropertiesImpl implements BlobProperties { this.name = checkNotNull(name, "name"); this.container = checkNotNull(container, "container"); this.url = checkNotNull(url, "url"); - this.lastModified = checkNotNull(lastModified, "lastModified"); - this.eTag = checkNotNull(eTag, "eTag"); + this.lastModified = lastModified; + this.eTag = eTag; this.contentMetadata = new BaseImmutableContentMetadata(contentType, size, contentMD5, null, contentLanguage, contentMetadata, currentExpires); this.metadata.putAll(checkNotNull(metadata, "metadata")); diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/options/ListBlobsOptions.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/options/ListBlobsOptions.java index 72128a4dad..895d6a1d04 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/options/ListBlobsOptions.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/options/ListBlobsOptions.java @@ -16,7 +16,13 @@ */ package org.jclouds.azureblob.options; +import java.util.Set; + import org.jclouds.azure.storage.options.ListOptions; +import org.jclouds.azureblob.domain.ListBlobsInclude; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; /** * Contains options supported in the REST API for the List Blobs operation.

@@ -35,6 +41,7 @@ import org.jclouds.azure.storage.options.ListOptions; * @see */ public class ListBlobsOptions extends ListOptions { + private Set datasets; /** * When the request includes this parameter, the operation returns a {@code BlobPrefix} element @@ -94,6 +101,11 @@ public class ListBlobsOptions extends ListOptions { ListBlobsOptions options = new ListBlobsOptions(); return options.maxResults(maxKeys); } + + public static ListBlobsOptions include(Set datasets) { + ListBlobsOptions options = new ListBlobsOptions(); + return options.include(datasets); + } } /** @@ -127,4 +139,14 @@ public class ListBlobsOptions extends ListOptions { public ListBlobsOptions prefix(String prefix) { return (ListBlobsOptions) super.prefix(prefix); } + + public ListBlobsOptions include(Set datasets) { + datasets = ImmutableSet.copyOf(datasets); + this.queryParameters.put("include", Joiner.on(",").join(datasets)); + return this; + } + + public Set getInclude() { + return datasets; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java index bef20c27ea..61f23205cd 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java @@ -31,6 +31,7 @@ import java.net.URI; import java.security.SecureRandom; import java.util.Arrays; import java.util.Date; +import java.util.EnumSet; import java.util.Map; import java.util.Set; @@ -41,6 +42,7 @@ import org.jclouds.azureblob.domain.AzureBlob; import org.jclouds.azureblob.domain.BlobProperties; import org.jclouds.azureblob.domain.ContainerProperties; import org.jclouds.azureblob.domain.ListBlobBlocksResponse; +import org.jclouds.azureblob.domain.ListBlobsInclude; import org.jclouds.azureblob.domain.ListBlobsResponse; import org.jclouds.azureblob.domain.PublicAccess; import org.jclouds.azureblob.options.CopyBlobOptions; @@ -349,11 +351,20 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest { String blockIdA = BaseEncoding.base64().encode((blockBlob + "-" + A).getBytes()); String blockIdB = BaseEncoding.base64().encode((blockBlob + "-" + B).getBytes()); String blockIdC = BaseEncoding.base64().encode((blockBlob + "-" + C).getBytes()); + getApi().createContainer(blockContainer); + getApi().putBlock(blockContainer, blockBlob, blockIdA, Payloads.newByteArrayPayload(A.getBytes())); getApi().putBlock(blockContainer, blockBlob, blockIdB, Payloads.newByteArrayPayload(B.getBytes())); getApi().putBlock(blockContainer, blockBlob, blockIdC, Payloads.newByteArrayPayload(C.getBytes())); + + ListBlobsResponse blobs = getApi().listBlobs(blockContainer); + assertThat(blobs).isEmpty(); + blobs = getApi().listBlobs(blockContainer, new ListBlobsOptions().include(EnumSet.allOf(ListBlobsInclude.class))); + assertThat(blobs).hasSize(1); + getApi().putBlockList(blockContainer, blockBlob, Arrays.asList(blockIdA, blockIdB, blockIdC)); + ListBlobBlocksResponse blocks = getApi().getBlockList(blockContainer, blockBlob); assertEquals(3, blocks.getBlocks().size()); assertEquals(blockIdA, blocks.getBlocks().get(0).getBlockName()); @@ -362,6 +373,7 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest { assertEquals(1, blocks.getBlocks().get(0).getContentLength()); assertEquals(1, blocks.getBlocks().get(1).getContentLength()); assertEquals(1, blocks.getBlocks().get(2).getContentLength()); + getApi().deleteContainer(blockContainer); } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientTest.java index c6fa7234b8..c117d3639f 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientTest.java @@ -24,6 +24,7 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.util.Date; +import java.util.EnumSet; import java.util.Map; import org.jclouds.ContextBuilder; @@ -33,6 +34,7 @@ import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.azureblob.AzureBlobFallbacks.FalseIfContainerAlreadyExists; import org.jclouds.azureblob.domain.AzureBlob; +import org.jclouds.azureblob.domain.ListBlobsInclude; import org.jclouds.azureblob.domain.PublicAccess; import org.jclouds.azureblob.functions.ParseBlobFromHeadersAndHttpContent; import org.jclouds.azureblob.functions.ParseContainerPropertiesFromHeaders; @@ -205,6 +207,20 @@ public class AzureBlobClientTest extends BaseRestAnnotationProcessingTest method = method(AzureBlobClient.class, "listBlobs", String.class, ListBlobsOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("container", new ListBlobsOptions().include(EnumSet.allOf(ListBlobsInclude.class)))); + + assertRequestLineEquals(request, + "GET https://identity.blob.core.windows.net/container?restype=container&comp=list&include=copy,metadata,snapshots,uncommittedblobs HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "x-ms-version: 2013-08-15\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, ContainerNameEnumerationResultsHandler.class); + assertFallbackClassEquals(method, null); + } + public void testListRootBlobs() throws SecurityException, NoSuchMethodException, IOException { Invokable method = method(AzureBlobClient.class, "listBlobs", ListBlobsOptions[].class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());