From 303b11a39fb78969d08c764da44fd3d45b024c29 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 2 Aug 2019 13:43:50 -0700 Subject: [PATCH] Blob Create Snapshot Returns a Client (#4472) * Removed raw clients * Added deleteContainer to StorageClient * Merged Blob client builders into BlobClientBuilder * Storage SAS implementation (#4404) * SAS implementation * Fixed some minor formatting issues * Fixed checkstyle problems and test issue * Remove RawClients from Blobs (#4375) Removes RawClients from Storage Blobs * Added getAppendBlob with snapshot to ContainerClient * Updated Storage and Container clients to use AzureBlobStorageImpl to construct clients * Updating unit tests * Fix a snapshot test --- .../storage/blob/AppendBlobAsyncClient.java | 8 ++-- .../azure/storage/blob/BlobAsyncClient.java | 47 +++++++++++++------ .../com/azure/storage/blob/BlobClient.java | 30 ++++++++---- .../azure/storage/blob/BlobClientBuilder.java | 7 +-- .../storage/blob/BlobServiceAsyncClient.java | 9 ++-- .../blob/BlobServiceClientBuilder.java | 37 ++++++--------- .../storage/blob/BlockBlobAsyncClient.java | 8 ++-- .../storage/blob/ContainerAsyncClient.java | 21 +++++---- .../storage/blob/ContainerClientBuilder.java | 37 +++++---------- .../storage/blob/PageBlobAsyncClient.java | 8 ++-- .../java/com/azure/storage/blob/Utility.java | 2 +- .../BlobAsyncClientJavaDocCodeSnippets.java | 6 ++- .../blob/BlobClientJavaDocCodeSnippets.java | 4 +- .../com/azure/storage/blob/BlobAPITest.groovy | 23 ++------- .../storage/blob/ContainerAPITest.groovy | 2 +- .../azure/storage/blob/PageBlobAPITest.groovy | 16 +++---- .../com/azure/storage/blob/SASTest.groovy | 12 ++--- 17 files changed, 142 insertions(+), 135 deletions(-) diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java index af64a840c8cc5..4ddc1d9e46825 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java @@ -6,7 +6,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.AppendBlobAccessConditions; import com.azure.storage.blob.models.AppendBlobItem; import com.azure.storage.blob.models.BlobAccessConditions; @@ -59,10 +59,10 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - AppendBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - super(azureBlobStorageBuilder, snapshot); + AppendBlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + super(azureBlobStorage, snapshot); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index ad598f8a8983b..8f5a863ad38c9 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -81,10 +81,10 @@ public class BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. * - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - BlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - this.azureBlobStorage = azureBlobStorageBuilder.build(); + BlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + this.azureBlobStorage = azureBlobStorage; this.snapshot = snapshot; } @@ -97,7 +97,8 @@ public class BlobAsyncClient { public BlockBlobAsyncClient asBlockBlobAsyncClient() { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -109,7 +110,8 @@ public BlockBlobAsyncClient asBlockBlobAsyncClient() { public AppendBlobAsyncClient asAppendBlobAsyncClient() { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -121,7 +123,21 @@ public AppendBlobAsyncClient asAppendBlobAsyncClient() { public PageBlobAsyncClient asPageBlobAsyncClient() { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); + } + + /** + * Creates a new {@link BlobAsyncClient} linked to the {@code snapshot} of this blob resource. + * + * @param snapshot the identifier for a specific snapshot of this blob + * @return a {@link BlobAsyncClient} used to interact with the specific snapshot. + */ + public BlobAsyncClient getSnapshotClient(String snapshot) { + return new BlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -135,7 +151,8 @@ public ContainerAsyncClient getContainerAsyncClient() { BlobURLParts parts = URLParser.parse(getBlobUrl()); return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s://%s/%s", parts.scheme(), parts.host(), parts.containerName())) - .pipeline(azureBlobStorage.getHttpPipeline())); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build()); } /** @@ -676,7 +693,7 @@ public Mono setMetadata(Metadata metadata, BlobAccessConditions ac } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * *

Code Samples

* @@ -685,14 +702,15 @@ public Mono setMetadata(Metadata metadata, BlobAccessConditions ac *

For more information, see the * Azure Docs

* - * @return A reactive response containing the ID of the new snapshot. + * @return A response containing a {@link BlobAsyncClient} which is used to interact with the created snapshot, use + * {@link BlobAsyncClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Mono> createSnapshot() { + public Mono> createSnapshot() { return this.createSnapshot(null, null); } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * *

Code Samples

* @@ -703,9 +721,10 @@ public Mono> createSnapshot() { * * @param metadata {@link Metadata} * @param accessConditions {@link BlobAccessConditions} - * @return A reactive response containing the ID of the new snapshot. + * @return A response containing a {@link BlobAsyncClient} which is used to interact with the created snapshot, use + * {@link BlobAsyncClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Mono> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { + public Mono> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { metadata = metadata == null ? new Metadata() : metadata; accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; @@ -713,7 +732,7 @@ public Mono> createSnapshot(Metadata metadata, BlobAccessCondit null, null, null, metadata, null, null, null, null, accessConditions.modifiedAccessConditions(), accessConditions.leaseAccessConditions(), Context.NONE)) - .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().snapshot())); + .map(rb -> new SimpleResponse<>(rb, this.getSnapshotClient(rb.deserializedHeaders().snapshot()))); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClient.java index c88bac43c0da4..dfbadaa4ab793 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClient.java @@ -4,6 +4,7 @@ package com.azure.storage.blob; import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; import com.azure.storage.blob.models.AccessTier; import com.azure.storage.blob.models.BlobAccessConditions; @@ -87,6 +88,16 @@ public PageBlobClient asPageBlobClient() { return new PageBlobClient(blobAsyncClient.asPageBlobAsyncClient()); } + /** + * Creates a new {@link BlobClient} linked to the {@code snapshot} of this blob resource. + * + * @param snapshot the identifier for a specific snapshot of this blob + * @return a {@link BlobClient} used to interact with the specific snapshot. + */ + public BlobClient getSnapshotClient(String snapshot) { + return new BlobClient(blobAsyncClient.getSnapshotClient(snapshot)); + } + /** * Initializes a {@link ContainerClient} object pointing to the container this blob is in. This method does not * create a container. It simply constructs the URL to the container and offers access to methods relevant to @@ -559,7 +570,7 @@ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessCo } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * *

Code Samples

* @@ -568,14 +579,15 @@ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessCo *

For more information, see the * Azure Docs

* - * @return The ID of the new snapshot. + * @return A response containing a {@link BlobClient} which is used to interact with the created snapshot, use + * {@link BlobClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Response createSnapshot() { + public Response createSnapshot() { return this.createSnapshot(null, null, null); } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * *

Code Samples

* @@ -587,11 +599,13 @@ public Response createSnapshot() { * @param metadata {@link Metadata} * @param accessConditions {@link BlobAccessConditions} * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. - * @return The ID of the new snapshot. + * @return A response containing a {@link BlobClient} which is used to interact with the created snapshot, use + * {@link BlobClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Response createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) { - Mono> response = blobAsyncClient - .createSnapshot(metadata, accessConditions); + public Response createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) { + Mono> response = blobAsyncClient + .createSnapshot(metadata, accessConditions) + .map(rb -> new SimpleResponse<>(rb, new BlobClient(rb.value()))); return Utility.blockWithOptionalTimeout(response, timeout); } diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java index a4a6d8b97f23a..e58c5a7adeb8e 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java @@ -18,7 +18,7 @@ import com.azure.core.util.configuration.Configuration; import com.azure.core.util.configuration.ConfigurationManager; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; -import com.azure.storage.blob.models.PageRange; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.common.credentials.SASTokenCredential; import com.azure.storage.common.credentials.SharedKeyCredential; import com.azure.storage.common.policy.RequestRetryOptions; @@ -91,7 +91,7 @@ public BlobClientBuilder() { policies = new ArrayList<>(); } - private AzureBlobStorageBuilder buildImpl() { + private AzureBlobStorageImpl buildImpl() { Objects.requireNonNull(endpoint); Objects.requireNonNull(containerName); Objects.requireNonNull(blobName); @@ -126,7 +126,8 @@ private AzureBlobStorageBuilder buildImpl() { return new AzureBlobStorageBuilder() .url(String.format("%s/%s/%s", endpoint, containerName, blobName)) - .pipeline(pipeline); + .pipeline(pipeline) + .build(); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceAsyncClient.java index 4738c234387b1..a8aa7f7b2640f 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceAsyncClient.java @@ -56,10 +56,10 @@ public final class BlobServiceAsyncClient { /** * Package-private constructor for use by {@link BlobServiceClientBuilder}. * - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - BlobServiceAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.azureBlobStorage = azureBlobStorageBuilder.build(); + BlobServiceAsyncClient(AzureBlobStorageImpl azureBlobStorage) { + this.azureBlobStorage = azureBlobStorage; } /** @@ -73,7 +73,8 @@ public final class BlobServiceAsyncClient { public ContainerAsyncClient getContainerAsyncClient(String containerName) { return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getAccountUrl(), containerName).toString()) - .pipeline(azureBlobStorage.getHttpPipeline())); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build()); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceClientBuilder.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceClientBuilder.java index 461739d29865f..220d4331c64fe 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceClientBuilder.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceClientBuilder.java @@ -77,7 +77,17 @@ public BlobServiceClientBuilder() { policies = new ArrayList<>(); } - private AzureBlobStorageBuilder buildImpl() { + /** + * @return a {@link BlobServiceClient} created from the configurations in this builder. + */ + public BlobServiceClient buildClient() { + return new BlobServiceClient(buildAsyncClient()); + } + + /** + * @return a {@link BlobServiceAsyncClient} created from the configurations in this builder. + */ + public BlobServiceAsyncClient buildAsyncClient() { Objects.requireNonNull(endpoint); // Closest to API goes first, closest to wire goes last. @@ -108,29 +118,10 @@ private AzureBlobStorageBuilder buildImpl() { .httpClient(httpClient) .build(); - return new AzureBlobStorageBuilder() + return new BlobServiceAsyncClient(new AzureBlobStorageBuilder() .url(endpoint) - .pipeline(pipeline); - } - - /** - * Creates a {@link BlobServiceClient} based on options set in the Builder. - * - * @return a {@link BlobServiceClient} created from the configurations in this builder. - * @throws NullPointerException If {@code endpoint} is {@code null}. - */ - public BlobServiceClient buildClient() { - return new BlobServiceClient(buildAsyncClient()); - } - - /** - * Creates a {@link BlobServiceAsyncClient} based on options set in the Builder. - * - * @return a {@link BlobServiceAsyncClient} created from the configurations in this builder. - * @throws NullPointerException If {@code endpoint} is {@code null}. - */ - public BlobServiceAsyncClient buildAsyncClient() { - return new BlobServiceAsyncClient(buildImpl()); + .pipeline(pipeline) + .build()); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java index ffb2eddc60b84..1cc6e71232b11 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java @@ -9,7 +9,7 @@ import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.util.FluxUtil; import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; import com.azure.storage.blob.models.BlobRange; @@ -85,10 +85,10 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - super(azureBlobStorageBuilder, snapshot); + BlockBlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + super(azureBlobStorage, snapshot); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index 3e06b364d7853..155c0498f49f0 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -71,10 +71,10 @@ public final class ContainerAsyncClient { /** * Package-private constructor for use by {@link ContainerClientBuilder}. * - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - ContainerAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.azureBlobStorage = azureBlobStorageBuilder.build(); + ContainerAsyncClient(AzureBlobStorageImpl azureBlobStorage) { + this.azureBlobStorage = azureBlobStorage; } /** @@ -107,7 +107,8 @@ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName) { public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName, String snapshot) { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -140,7 +141,8 @@ public PageBlobAsyncClient getPageBlobAsyncClient(String blobName) { public PageBlobAsyncClient getPageBlobAsyncClient(String blobName, String snapshot) { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -173,7 +175,8 @@ public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName) { public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName, String snapshot) { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -202,7 +205,8 @@ public BlobAsyncClient getBlobAsyncClient(String blobName) { public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { return new BlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build(), snapshot); } /** @@ -213,7 +217,8 @@ public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { public BlobServiceAsyncClient getBlobServiceAsyncClient() { return new BlobServiceAsyncClient(new AzureBlobStorageBuilder() .url(Utility.stripLastPathSegment(getContainerUrl()).toString()) - .pipeline(azureBlobStorage.getHttpPipeline())); + .pipeline(azureBlobStorage.getHttpPipeline()) + .build()); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java index 22310e6215515..7ef873aac1b33 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java @@ -79,10 +79,16 @@ public ContainerClientBuilder() { } /** - * Constructs an instance of ContainerAsyncClient based on the configurations stored in the appendBlobClientBuilder. - * @return a new client instance + * @return a {@link ContainerClient} created from the configurations in this builder. */ - private AzureBlobStorageBuilder buildImpl() { + public ContainerClient buildClient() { + return new ContainerClient(buildAsyncClient()); + } + + /** + * @return a {@link ContainerAsyncClient} created from the configurations in this builder. + */ + public ContainerAsyncClient buildAsyncClient() { Objects.requireNonNull(endpoint); Objects.requireNonNull(containerName); @@ -114,29 +120,10 @@ private AzureBlobStorageBuilder buildImpl() { .httpClient(httpClient) .build(); - return new AzureBlobStorageBuilder() + return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s/%s", endpoint, containerName)) - .pipeline(pipeline); - } - - /** - * Creates a {@link ContainerClient} based on options set in the Builder. - * - * @return a {@link ContainerClient} created from the configurations in this builder. - * @throws NullPointerException If {@code endpoint} is {@code null} or {@code containerName} is {@code null}. - */ - public ContainerClient buildClient() { - return new ContainerClient(buildAsyncClient()); - } - - /** - * Creates a {@link ContainerAsyncClient} based on options set in the Builder. - * - * @return a {@link ContainerAsyncClient} created from the configurations in this builder. - * @throws NullPointerException If {@code endpoint} is {@code null} or {@code containerName} is {@code null}. - */ - public ContainerAsyncClient buildAsyncClient() { - return new ContainerAsyncClient(buildImpl()); + .pipeline(pipeline) + .build()); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java index 82e78f762af99..8b1cbd0ca39dc 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java @@ -7,7 +7,7 @@ import com.azure.core.http.rest.SimpleResponse; import com.azure.core.implementation.http.UrlBuilder; import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; import com.azure.storage.blob.models.BlobRange; @@ -65,10 +65,10 @@ public final class PageBlobAsyncClient extends BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - PageBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - super(azureBlobStorageBuilder, snapshot); + PageBlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + super(azureBlobStorage, snapshot); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/Utility.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/Utility.java index 252a5e83bbaf2..d22c2fc6dde21 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/Utility.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/Utility.java @@ -371,7 +371,7 @@ static URL appendToURLPath(URL baseURL, String name) { static URL stripLastPathSegment(URL baseURL) { UrlBuilder url = UrlBuilder.parse(baseURL); - if (url.path() != null || !url.path().contains("/")) { + if (url.path() == null || !url.path().contains("/")) { throw new IllegalArgumentException(String.format("URL %s does not contain path segments", baseURL)); } diff --git a/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobAsyncClientJavaDocCodeSnippets.java b/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobAsyncClientJavaDocCodeSnippets.java index 7f0e2ca99eca7..54d5bc091850b 100644 --- a/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobAsyncClientJavaDocCodeSnippets.java +++ b/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobAsyncClientJavaDocCodeSnippets.java @@ -239,7 +239,8 @@ public void setMetadata() { public void createSnapshot() { // BEGIN: com.azure.storage.blob.BlobAsyncClient.createSnapshot client.createSnapshot() - .subscribe(response -> System.out.printf("Identifier for the snapshot is %s%n", response.value())); + .subscribe(response -> System.out.printf("Identifier for the snapshot is %s%n", + response.value().getSnapshotId())); // END: com.azure.storage.blob.BlobAsyncClient.createSnapshot // BEGIN: com.azure.storage.blob.BlobAsyncClient.createSnapshot#Metadata-BlobAccessConditions @@ -248,7 +249,8 @@ public void createSnapshot() { .leaseAccessConditions(new LeaseAccessConditions().leaseId(leaseId)); client.createSnapshot(snapshotMetadata, accessConditions) - .subscribe(response -> System.out.printf("Identifier for the snapshot is %s%n", response.value())); + .subscribe(response -> System.out.printf("Identifier for the snapshot is %s%n", + response.value().getSnapshotId())); // END: com.azure.storage.blob.BlobAsyncClient.createSnapshot#Metadata-BlobAccessConditions } diff --git a/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobClientJavaDocCodeSnippets.java b/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobClientJavaDocCodeSnippets.java index e19f92dc1a6b9..90a64765f3845 100644 --- a/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobClientJavaDocCodeSnippets.java +++ b/sdk/storage/azure-storage-blob/src/samples/java/com/azure/storage/blob/BlobClientJavaDocCodeSnippets.java @@ -231,7 +231,7 @@ public void setMetadata() { */ public void createSnapshot() { // BEGIN: com.azure.storage.blob.BlobClient.createSnapshot - System.out.printf("Identifier for the snapshot is %s%n", client.createSnapshot().value()); + System.out.printf("Identifier for the snapshot is %s%n", client.createSnapshot().value().getSnapshotId()); // END: com.azure.storage.blob.BlobClient.createSnapshot // BEGIN: com.azure.storage.blob.BlobClient.createSnapshot#Metadata-BlobAccessConditions-Duration @@ -240,7 +240,7 @@ public void createSnapshot() { .leaseAccessConditions(new LeaseAccessConditions().leaseId(leaseId)); System.out.printf("Identifier for the snapshot is %s%n", - client.createSnapshot(snapshotMetadata, accessConditions, timeout).value()); + client.createSnapshot(snapshotMetadata, accessConditions, timeout).value().getSnapshotId()); // END: com.azure.storage.blob.BlobClient.createSnapshot#Metadata-BlobAccessConditions-Duration } diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy index ec294bee15419..4ad895869cba0 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy @@ -236,16 +236,11 @@ class BlobAPITest extends APISpec { ByteArrayOutputStream originalStream = new ByteArrayOutputStream() bu.download(originalStream) - String snapshot = bu.createSnapshot().value() BlockBlobClient bu2 = bu.asBlockBlobClient() + BlobClient bu3 = bu.createSnapshot().value() bu2.upload(new ByteArrayInputStream("ABC".getBytes()), 3) then: - BlobClient bu3 = new BlobClientBuilder() - .endpoint(bu.getBlobUrl().toString()) - .snapshot(snapshot) - .credential(primaryCreds) - .buildBlobClient() ByteArrayOutputStream snapshotStream = new ByteArrayOutputStream() bu3.download(snapshotStream) snapshotStream.toByteArray() == originalStream.toByteArray() @@ -985,12 +980,8 @@ class BlobAPITest extends APISpec { def "Snapshot"() { when: - Response snapshotResponse = bu.createSnapshot() - BlobClient bu2 = new BlobClientBuilder() - .endpoint(bu.getBlobUrl().toString()) - .credential(primaryCreds) - .snapshot(snapshotResponse.value()) - .buildBlobClient() + Response snapshotResponse = bu.createSnapshot() + BlobClient bu2 = snapshotResponse.value() then: bu2.getProperties().statusCode() == 200 @@ -1013,12 +1004,8 @@ class BlobAPITest extends APISpec { metadata.put(key2, value2) } - Response response = bu.createSnapshot(metadata, null, null) - BlobClient bu2 = new BlobClientBuilder() - .endpoint(bu.getBlobUrl().toString()) - .credential(primaryCreds) - .snapshot(response.value()) - .buildBlobClient() + Response response = bu.createSnapshot(metadata, null, null) + BlobClient bu2 = response.value() expect: response.statusCode() == 201 diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy index f82f1d4220eb7..d0027bffbb830 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy @@ -618,7 +618,7 @@ class ContainerAPITest extends APISpec { values.put("foo", "bar") metadataBlob.create(512, null, null, values, null, null) - String snapshotTime = normal.createSnapshot().value() + String snapshotTime = normal.createSnapshot().value().getSnapshotId() BlockBlobClient uncommittedBlob = cu.getBlockBlobClient(uncommittedName) diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy index d0d26275228fa..e34e2cd3dca3e 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy @@ -723,7 +723,7 @@ class PageBlobAPITest extends APISpec { def "Get page ranges diff min"() { setup: - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() when: bu.getPageRangesDiff(null, snapshot).iterator().hasNext() @@ -735,7 +735,7 @@ class PageBlobAPITest extends APISpec { @Unroll def "Get page ranges diff AC"() { setup: - String snapshot = bu.createSnapshot(null, null, null).value() + String snapshot = bu.createSnapshot().value().getSnapshotId() BlobAccessConditions bac = new BlobAccessConditions() .leaseAccessConditions(new LeaseAccessConditions().leaseId(setupBlobLeaseCondition(bu, leaseID))) .modifiedAccessConditions(new ModifiedAccessConditions() @@ -984,7 +984,7 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() Response copyResponse = bu2.copyIncremental(bu.getBlobUrl(), snapshot) String status = copyResponse.value().toString() @@ -1012,7 +1012,7 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() expect: bu2.copyIncremental(bu.getBlobUrl(), snapshot).statusCode() == 202 @@ -1023,7 +1023,7 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() Response copyResponse = bu2.copyIncremental(bu.getBlobUrl(), snapshot) String status = copyResponse.value().toString() @@ -1038,7 +1038,7 @@ class PageBlobAPITest extends APISpec { sleep(1000) } - snapshot = bu.createSnapshot().value() + snapshot = bu.createSnapshot().value().getSnapshotId() match = setupBlobMatchCondition(bu2, match) def mac = new ModifiedAccessConditions() .ifModifiedSince(modified) @@ -1063,9 +1063,9 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() bu2.copyIncremental(bu.getBlobUrl(), snapshot) - snapshot = bu.createSnapshot().value() + snapshot = bu.createSnapshot().value().getSnapshotId() noneMatch = setupBlobMatchCondition(bu2, noneMatch) def mac = new ModifiedAccessConditions() .ifModifiedSince(modified) diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SASTest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SASTest.groovy index 9a7cab385f2e6..45d44751d1a0c 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SASTest.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SASTest.groovy @@ -66,7 +66,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + def snapshotId = bu.createSnapshot().value().getSnapshotId() when: def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) @@ -82,7 +82,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + def snapshotId = bu.createSnapshot().value().getSnapshotId() when: def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) @@ -148,7 +148,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + String snapshotId = bu.createSnapshot().value().getSnapshotId() def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) @@ -296,8 +296,8 @@ class SASTest extends APISpec { String blobName = generateBlobName() BlockBlobClient bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - String snapshotId = bu.createSnapshot().value() - BlockBlobClient snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) + BlockBlobClient snapshotBlob = bu.createSnapshot().value().asBlockBlobClient() + String snapshotId = snapshotBlob.getSnapshotId() BlobSASPermission permissions = new BlobSASPermission() .read(true) @@ -359,7 +359,7 @@ class SASTest extends APISpec { os.toString() == new String(data) and: - def properties = client2.getProperties(null, null).value() + def properties = client2.getProperties().value() then: properties.cacheControl() == "cache"