mirror of https://github.com/apache/jclouds.git
JCLOUDS-1125: Azure list other blobs
Some BlobProperties fields become nullable due to these new blob types.
This commit is contained in:
parent
c1ce819f61
commit
61ab28cc50
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<String, String> 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"));
|
||||
|
|
|
@ -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. <h2>
|
||||
|
@ -35,6 +41,7 @@ import org.jclouds.azure.storage.options.ListOptions;
|
|||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179466.aspx" />
|
||||
*/
|
||||
public class ListBlobsOptions extends ListOptions {
|
||||
private Set<String> 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<ListBlobsInclude> 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<ListBlobsInclude> datasets) {
|
||||
datasets = ImmutableSet.copyOf(datasets);
|
||||
this.queryParameters.put("include", Joiner.on(",").join(datasets));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<String> getInclude() {
|
||||
return datasets;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<AzureB
|
|||
assertFallbackClassEquals(method, null);
|
||||
}
|
||||
|
||||
public void testListBlobsWithOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = method(AzureBlobClient.class, "listBlobs", String.class, ListBlobsOptions[].class);
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> 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());
|
||||
|
|
Loading…
Reference in New Issue