Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob Create Snapshot Returns a Client #4472

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -676,7 +693,7 @@ public Mono<VoidResponse> setMetadata(Metadata metadata, BlobAccessConditions ac
}

/**
* Creates a read-only snapshot of a blob.
* Creates a read-only snapshot of the blob.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -685,14 +702,15 @@ public Mono<VoidResponse> setMetadata(Metadata metadata, BlobAccessConditions ac
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/snapshot-blob">Azure Docs</a></p>
*
* @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<Response<String>> createSnapshot() {
public Mono<Response<BlobAsyncClient>> createSnapshot() {
return this.createSnapshot(null, null);
}

/**
* Creates a read-only snapshot of a blob.
* Creates a read-only snapshot of the blob.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -703,17 +721,18 @@ public Mono<Response<String>> 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<Response<String>> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) {
public Mono<Response<BlobAsyncClient>> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) {
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;

return postProcessResponse(this.azureBlobStorage.blobs().createSnapshotWithRestResponseAsync(
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())));
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -568,14 +579,15 @@ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessCo
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/snapshot-blob">Azure Docs</a></p>
*
* @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<String> createSnapshot() {
public Response<BlobClient> createSnapshot() {
return this.createSnapshot(null, null, null);
}

/**
* Creates a read-only snapshot of a blob.
* Creates a read-only snapshot of the blob.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -587,11 +599,13 @@ public Response<String> 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<String> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) {
Mono<Response<String>> response = blobAsyncClient
.createSnapshot(metadata, accessConditions);
public Response<BlobClient> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) {
Mono<Response<BlobClient>> response = blobAsyncClient
.createSnapshot(metadata, accessConditions)
.map(rb -> new SimpleResponse<>(rb, new BlobClient(rb.value())));

return Utility.blockWithOptionalTimeout(response, timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +91,7 @@ public BlobClientBuilder() {
policies = new ArrayList<>();
}

private AzureBlobStorageBuilder buildImpl() {
private AzureBlobStorageImpl buildImpl() {
Objects.requireNonNull(endpoint);
Objects.requireNonNull(containerName);
Objects.requireNonNull(blobName);
Expand Down Expand Up @@ -128,7 +128,8 @@ private AzureBlobStorageBuilder buildImpl() {

return new AzureBlobStorageBuilder()
.url(String.format("%s/%s/%s", endpoint, containerName, blobName))
.pipeline(pipeline);
.pipeline(pipeline)
.build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -110,29 +120,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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Loading