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 15 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 @@ -33,7 +33,7 @@ final class AccountSASPermission {
/**
* Initializes an {@code AccountSASPermission} object with all fields set to false.
*/
private AccountSASPermission() {
public AccountSASPermission() {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class AccountSASResourceType {
/**
* Initializes an {@code AccountSASResourceType} object with all fields set to false.
*/
private AccountSASResourceType() {
public AccountSASResourceType() {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class AccountSASService {
/**
* Initializes an {@code AccountSASService} object with all fields set to false.
*/
private AccountSASService() {
public AccountSASService() {
}

/**
Expand Down
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 @@ -71,7 +71,6 @@
* operation, until {@code .subscribe()} is called on the reactive response. You can simply convert one of these
* responses to a {@link java.util.concurrent.CompletableFuture} object through {@link Mono#toFuture()}.
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class BlobAsyncClient {
private static final int BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE = 4 * Constants.MB;
private static final int BLOB_MAX_DOWNLOAD_BLOCK_SIZE = 100 * Constants.MB;
Expand All @@ -82,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 @@ -98,7 +97,8 @@ public class BlobAsyncClient {
public BlockBlobAsyncClient asBlockBlobAsyncClient() {
return new BlockBlobAsyncClient(new AzureBlobStorageBuilder()
.url(getBlobUrl().toString())
.pipeline(azureBlobStorage.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.build(), snapshot);
}

/**
Expand All @@ -110,7 +110,8 @@ public BlockBlobAsyncClient asBlockBlobAsyncClient() {
public AppendBlobAsyncClient asAppendBlobAsyncClient() {
return new AppendBlobAsyncClient(new AzureBlobStorageBuilder()
.url(getBlobUrl().toString())
.pipeline(azureBlobStorage.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.build(), snapshot);
}

/**
Expand All @@ -122,7 +123,21 @@ public AppendBlobAsyncClient asAppendBlobAsyncClient() {
public PageBlobAsyncClient asPageBlobAsyncClient() {
return new PageBlobAsyncClient(new AzureBlobStorageBuilder()
.url(getBlobUrl().toString())
.pipeline(azureBlobStorage.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.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.httpPipeline())
.build(), snapshot);
}

/**
Expand All @@ -136,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.httpPipeline()));
.pipeline(azureBlobStorage.httpPipeline())
.build());
}

/**
Expand Down Expand Up @@ -555,30 +571,32 @@ public Mono<VoidResponse> setMetadata(Metadata metadata, BlobAccessConditions ac
}

/**
* Creates a read-only snapshot of a blob.
* Creates a read-only snapshot of the blob.
*
* @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.
*
* @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())));
}

/**
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 @@ -45,7 +46,6 @@
* Please refer to the <a href=https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs>Azure
* Docs</a> for more information.
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class BlobClient {
private final BlobAsyncClient blobAsyncClient;

Expand Down Expand Up @@ -88,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 @@ -440,25 +450,28 @@ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessCo
}

/**
* Creates a read-only snapshot of a blob.
* Creates a read-only snapshot of the blob.
*
* @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.
*
* @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 @@ -17,7 +17,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 @@ -90,7 +90,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 @@ -127,7 +127,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 @@ -27,7 +27,7 @@ final class BlobSASPermission {
/**
* Initializes a {@code BlobSASPermission} object with all fields set to false.
*/
private BlobSASPermission() {
public BlobSASPermission() {
}

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

/**
Expand Down Expand Up @@ -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.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.build(), snapshot);
}

/**
Expand Down Expand Up @@ -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.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.build(), snapshot);
}

/**
Expand Down Expand Up @@ -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.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.build(), snapshot);
}

/**
Expand Down Expand Up @@ -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.httpPipeline()), snapshot);
.pipeline(azureBlobStorage.httpPipeline())
.build(), snapshot);
}

/**
Expand All @@ -213,7 +217,8 @@ public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) {
public StorageAsyncClient getStorageAsyncClient() {
return new StorageAsyncClient(new AzureBlobStorageBuilder()
.url(Utility.stripLastPathSegment(getContainerUrl()).toString())
.pipeline(azureBlobStorage.httpPipeline()));
.pipeline(azureBlobStorage.httpPipeline())
.build());
}

/**
Expand Down
Loading