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

Added back support for container undelete. #15344

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 12.9.0-beta.1 (Unreleased)
- Added support for the 2019-02-10 service version.
- Added support to specify Arrow Output Serialization when querying a blob.
- Added support to undelete a container.

- Fixed a bug where the TokenCredential scope would be incorrect for custom URLs.
- Fixed a bug where Default Azure Credential would not work with Azurite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.azure.storage.blob.models.PublicAccessType;
import com.azure.storage.blob.models.StorageAccountInfo;
import com.azure.storage.blob.models.UserDelegationKey;
import com.azure.storage.blob.options.UndeleteBlobContainerOptions;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.implementation.AccountSasImplUtil;
import com.azure.storage.common.implementation.Constants;
Expand Down Expand Up @@ -428,15 +429,12 @@ private Mono<PagedResponse<TaggedBlobItem>> findBlobsByTags(
*/
private List<ListBlobContainersIncludeType> toIncludeTypes(BlobContainerListDetails blobContainerListDetails) {
boolean hasDetails = blobContainerListDetails != null
&& blobContainerListDetails.getRetrieveMetadata();
// Add back for container soft delete.
// boolean hasDetails = blobContainerListDetails != null
// && (blobContainerListDetails.getRetrieveMetadata() || blobContainerListDetails.getRetrieveDeleted());
&& (blobContainerListDetails.getRetrieveMetadata() || blobContainerListDetails.getRetrieveDeleted());
if (hasDetails) {
List<ListBlobContainersIncludeType> flags = new ArrayList<>(2);
// if (blobContainerListDetails.getRetrieveDeleted()) {
// flags.add(ListBlobContainersIncludeType.DELETED);
// }
if (blobContainerListDetails.getRetrieveDeleted()) {
flags.add(ListBlobContainersIncludeType.DELETED);
}
if (blobContainerListDetails.getRetrieveMetadata()) {
flags.add(ListBlobContainersIncludeType.METADATA);
}
Expand Down Expand Up @@ -849,14 +847,13 @@ private void throwOnAnonymousAccess() {
* @return A {@link Mono} containing a {@link BlobContainerAsyncClient} used
* to interact with the restored container.
*/
/*
public Mono<BlobContainerAsyncClient> undeleteBlobContainer(
String deletedContainerName, String deletedContainerVersion) {
return this.undeleteBlobContainerWithResponse(
new UndeleteBlobContainerOptions(deletedContainerName, deletedContainerVersion)
return this.undeleteBlobContainerWithResponse(new UndeleteBlobContainerOptions(deletedContainerName,
deletedContainerVersion)
).flatMap(FluxUtil::toMono);
}
*/


/**
* Restores a previously deleted container. The restored container
Expand All @@ -877,13 +874,10 @@ public Mono<BlobContainerAsyncClient> undeleteBlobContainer(
* @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains a {@link
* BlobContainerAsyncClient} used to interact with the restored container.
*/
/*
public Mono<Response<BlobContainerAsyncClient>> undeleteBlobContainerWithResponse(
UndeleteBlobContainerOptions options) {
try {
return withContext(context ->
undeleteBlobContainerWithResponse(
options, context));
return withContext(context -> undeleteBlobContainerWithResponse(options, context));
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
Expand All @@ -903,5 +897,5 @@ Mono<Response<BlobContainerAsyncClient>> undeleteBlobContainerWithResponse(
.map(response -> new SimpleResponse<>(response,
getBlobContainerAsyncClient(finalDestinationContainerName)));
}
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.azure.storage.blob.models.PublicAccessType;
import com.azure.storage.blob.models.StorageAccountInfo;
import com.azure.storage.blob.models.UserDelegationKey;
import com.azure.storage.blob.options.UndeleteBlobContainerOptions;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.common.sas.AccountSasSignatureValues;
Expand Down Expand Up @@ -450,13 +451,11 @@ public String generateAccountSas(AccountSasSignatureValues accountSasSignatureVa
* @param deletedContainerVersion The version of the previously deleted container.
* @return The {@link BlobContainerClient} used to interact with the restored container.
*/
/*
public BlobContainerClient undeleteBlobContainer(String deletedContainerName, String deletedContainerVersion) {
return this.undeleteBlobContainerWithResponse(
new UndeleteBlobContainerOptions(deletedContainerName, deletedContainerVersion), null,
Context.NONE).getValue();
}
*/

/**
* Restores a previously deleted container. The restored container
Expand All @@ -479,14 +478,12 @@ public BlobContainerClient undeleteBlobContainer(String deletedContainerName, St
* @return A {@link Response} whose {@link Response#getValue() value} contains the {@link BlobContainerClient} used
* to interact with the restored container.
*/
/*
public Response<BlobContainerClient> undeleteBlobContainerWithResponse(
UndeleteBlobContainerOptions options, Duration timeout, Context context) {
Mono<Response<BlobContainerClient>> response =
this.blobServiceAsyncClient.undeleteBlobContainerWithResponse(options, context)
.map(r -> new SimpleResponse<>(r, getBlobContainerClient(r.getValue().getBlobContainerName())));

return blockWithOptionalTimeout(response, timeout);
return StorageImplUtils.blockWithOptionalTimeout(response, timeout);
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Fluent
public final class BlobContainerListDetails {
private boolean retrieveMetadata;
// private boolean retrieveDeleted;
private boolean retrieveDeleted;

/**
* Constructs an unpopulated {@link BlobContainerListDetails}.
Expand Down Expand Up @@ -47,24 +47,20 @@ public BlobContainerListDetails setRetrieveMetadata(boolean retrieveMetadata) {
*
* @return a flag indicating whether deleted containers should be returned
*/
/*
private boolean getRetrieveDeleted() {
public boolean getRetrieveDeleted() {
return this.retrieveDeleted;
}
*/

/**
* Whether deleted containers should be returned.
*
* @param retrieveDeleted Flag indicating whether deleted containers should be returned.
* @return the updated ContainerListDetails object
*/
/*
private BlobContainerListDetails setRetrieveDeleted(boolean retrieveDeleted) {
public BlobContainerListDetails setRetrieveDeleted(boolean retrieveDeleted) {
this.retrieveDeleted = retrieveDeleted;
return this;
}
*/

/**
* @return the listing flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.storage.blob;

import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.storage.blob.models.BlobAnalyticsLogging;
import com.azure.storage.blob.models.BlobContainerListDetails;
Expand All @@ -12,10 +13,12 @@
import com.azure.storage.blob.options.FindBlobsOptions;
import com.azure.storage.blob.models.ListBlobContainersOptions;
import com.azure.storage.blob.models.PublicAccessType;
import com.azure.storage.blob.options.UndeleteBlobContainerOptions;
import com.azure.storage.common.sas.AccountSasPermission;
import com.azure.storage.common.sas.AccountSasResourceType;
import com.azure.storage.common.sas.AccountSasService;
import com.azure.storage.common.sas.AccountSasSignatureValues;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -276,42 +279,41 @@ public void generateAccountSas() {
// END: com.azure.storage.blob.BlobServiceAsyncClient.generateAccountSas#AccountSasSignatureValues
}

// Add back for container soft delete
// /**
// * Code snippet for {@link BlobServiceAsyncClient#undeleteBlobContainer(String, String)}.
// */
// public void undeleteBlobContainer() {
// // BEGIN: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainer#String-String
// ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
// listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
// client.listBlobContainers(listBlobContainersOptions).flatMap(
// deletedContainer -> {
// Mono<BlobContainerAsyncClient> blobContainerClient = client.undeleteBlobContainer(
// deletedContainer.getName(), deletedContainer.getVersion());
// return blobContainerClient;
// }
// ).then().block();
// // END: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainer#String-String
// }
//
// /**
// * Code snippet for
// * {@link BlobServiceAsyncClient#undeleteBlobContainerWithResponse(UndeleteBlobContainerOptions)}.
// */
// public void undeleteBlobContainerWithResponseWithRename() {
// Context context = new Context("Key", "Value");
// // BEGIN: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions
// ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
// listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
// client.listBlobContainers(listBlobContainersOptions).flatMap(
// deletedContainer -> {
// Mono<BlobContainerAsyncClient> blobContainerClient = client.undeleteBlobContainerWithResponse(
// new UndeleteBlobContainerOptions(deletedContainer.getName(), deletedContainer.getVersion())
// .setDestinationContainerName(deletedContainer.getName() + "V2"))
// .map(Response::getValue);
// return blobContainerClient;
// }
// ).then().block();
// // END: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions
// }
/**
* Code snippet for {@link BlobServiceAsyncClient#undeleteBlobContainer(String, String)}.
*/
public void undeleteBlobContainer() {
// BEGIN: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainer#String-String
ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
client.listBlobContainers(listBlobContainersOptions).flatMap(
deletedContainer -> {
Mono<BlobContainerAsyncClient> blobContainerClient = client.undeleteBlobContainer(
deletedContainer.getName(), deletedContainer.getVersion());
return blobContainerClient;
}
).then().block();
// END: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainer#String-String
}

/**
* Code snippet for
* {@link BlobServiceAsyncClient#undeleteBlobContainerWithResponse(UndeleteBlobContainerOptions)}.
*/
public void undeleteBlobContainerWithResponseWithRename() {
Context context = new Context("Key", "Value");
// BEGIN: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions
ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
client.listBlobContainers(listBlobContainersOptions).flatMap(
deletedContainer -> {
Mono<BlobContainerAsyncClient> blobContainerClient = client.undeleteBlobContainerWithResponse(
new UndeleteBlobContainerOptions(deletedContainer.getName(), deletedContainer.getVersion())
.setDestinationContainerName(deletedContainer.getName() + "V2"))
.map(Response::getValue);
return blobContainerClient;
}
).then().block();
// END: com.azure.storage.blob.BlobServiceAsyncClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.azure.storage.blob.models.ListBlobContainersOptions;
import com.azure.storage.blob.models.PublicAccessType;
import com.azure.storage.blob.models.StorageAccountInfo;
import com.azure.storage.blob.options.UndeleteBlobContainerOptions;
import com.azure.storage.common.sas.AccountSasPermission;
import com.azure.storage.common.sas.AccountSasResourceType;
import com.azure.storage.common.sas.AccountSasService;
Expand Down Expand Up @@ -283,40 +284,39 @@ public void generateAccountSas() {
// END: com.azure.storage.blob.BlobServiceClient.generateAccountSas#AccountSasSignatureValues
}

// Add back for container soft delete
// /**
// * Code snippet for {@link BlobServiceClient#undeleteBlobContainer(String, String)}.
// */
// public void undeleteBlobContainer() {
// // BEGIN: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainer#String-String
// ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
// listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
// client.listBlobContainers(listBlobContainersOptions, null).forEach(
// deletedContainer -> {
// BlobContainerClient blobContainerClient = client.undeleteBlobContainer(
// deletedContainer.getName(), deletedContainer.getVersion());
// }
// );
// // END: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainer#String-String
// }
//
// /**
// * Code snippet for {@link BlobServiceClient#undeleteBlobContainerWithResponse(UndeleteBlobContainerOptions,
// * Duration, Context)}.
// */
// public void undeleteBlobContainerWithResponseWithRename() {
// Context context = new Context("Key", "Value");
// // BEGIN: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions-Duration-Context
// ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
// listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
// client.listBlobContainers(listBlobContainersOptions, null).forEach(
// deletedContainer -> {
// BlobContainerClient blobContainerClient = client.undeleteBlobContainerWithResponse(
// new UndeleteBlobContainerOptions(deletedContainer.getName(), deletedContainer.getVersion())
// .setDestinationContainerName(deletedContainer.getName() + "V2"), timeout,
// context).getValue();
// }
// );
// // END: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions-Duration-Context
// }
/**
* Code snippet for {@link BlobServiceClient#undeleteBlobContainer(String, String)}.
*/
public void undeleteBlobContainer() {
// BEGIN: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainer#String-String
ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
client.listBlobContainers(listBlobContainersOptions, null).forEach(
deletedContainer -> {
BlobContainerClient blobContainerClient = client.undeleteBlobContainer(
deletedContainer.getName(), deletedContainer.getVersion());
}
);
// END: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainer#String-String
}

/**
* Code snippet for {@link BlobServiceClient#undeleteBlobContainerWithResponse(UndeleteBlobContainerOptions,
* Duration, Context)}.
*/
public void undeleteBlobContainerWithResponseWithRename() {
Context context = new Context("Key", "Value");
// BEGIN: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions-Duration-Context
ListBlobContainersOptions listBlobContainersOptions = new ListBlobContainersOptions();
listBlobContainersOptions.getDetails().setRetrieveDeleted(true);
client.listBlobContainers(listBlobContainersOptions, null).forEach(
deletedContainer -> {
BlobContainerClient blobContainerClient = client.undeleteBlobContainerWithResponse(
new UndeleteBlobContainerOptions(deletedContainer.getName(), deletedContainer.getVersion())
.setDestinationContainerName(deletedContainer.getName() + "V2"), timeout,
context).getValue();
}
);
// END: com.azure.storage.blob.BlobServiceClient.undeleteBlobContainerWithResponse#UndeleteBlobContainerOptions-Duration-Context
}
}
Loading