You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2016/06/13 23:28:26 UTC

[3/3] jclouds git commit: JCLOUDS-1125: Azure list other blobs

JCLOUDS-1125: Azure list other blobs

Some BlobProperties fields become nullable due to these new blob types.


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/61ab28cc
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/61ab28cc
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/61ab28cc

Branch: refs/heads/master
Commit: 61ab28cc50afa75abf026f7a382f2a2f736637bf
Parents: c1ce819
Author: Andrew Gaul <ga...@apache.org>
Authored: Fri Jun 10 18:31:39 2016 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Mon Jun 13 16:26:43 2016 -0700

----------------------------------------------------------------------
 .../azureblob/domain/ListBlobsInclude.java      | 33 ++++++++++++++++++++
 .../domain/internal/BlobPropertiesImpl.java     |  6 ++--
 .../azureblob/options/ListBlobsOptions.java     | 22 +++++++++++++
 .../azureblob/AzureBlobClientLiveTest.java      | 12 +++++++
 .../jclouds/azureblob/AzureBlobClientTest.java  | 16 ++++++++++
 5 files changed, 86 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/61ab28cc/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/ListBlobsInclude.java
----------------------------------------------------------------------
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 0000000..1964346
--- /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();
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/61ab28cc/providers/azureblob/src/main/java/org/jclouds/azureblob/domain/internal/BlobPropertiesImpl.java
----------------------------------------------------------------------
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 27866db..c3c4005 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<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"));

http://git-wip-us.apache.org/repos/asf/jclouds/blob/61ab28cc/providers/azureblob/src/main/java/org/jclouds/azureblob/options/ListBlobsOptions.java
----------------------------------------------------------------------
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 72128a4..895d6a1 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. <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;
+   }
 }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/61ab28cc/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java
----------------------------------------------------------------------
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 bef20c2..61f2320 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);
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds/blob/61ab28cc/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientTest.java
----------------------------------------------------------------------
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 c6fa723..c117d36 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<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());