Skip to content

Commit

Permalink
Revert "Blobs Sync Stack Migration (#40812)" (#41819)
Browse files Browse the repository at this point in the history
This reverts commit 37d8cdc.
  • Loading branch information
ibrahimrabab authored Sep 12, 2024
1 parent 038071f commit ac9ee63
Show file tree
Hide file tree
Showing 35 changed files with 2,824 additions and 17,575 deletions.
3 changes: 0 additions & 3 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,6 @@ unreleased_com.azure:azure-json;1.3.0

unreleased_com.azure:azure-core-amqp;2.10.0-beta.1

unreleased_com.azure:azure-core;1.52.0-beta.1
unreleased_com.azure:azure-core-http-okhttp;1.13.0-beta.1

# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
# version and set the version to the released beta. Released beta dependencies are only valid
# for dependency versions. These entries are specifically for when we've released a beta for
Expand Down
7 changes: 0 additions & 7 deletions sdk/storage/azure-storage-blob/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@
<suppress files="com.azure.storage.blob.implementation.util.ModelHelper.java" checks="com.azure.tools.checkstyle.checks.JavadocThrowsChecks" />
<suppress files="com.azure.storage.blob.implementation.AzureBlobStorageImplBuilder.java" checks="com.azure.tools.checkstyle.checks.ServiceClientBuilderCheck" />
<suppress files="com.azure.storage.blob.BlobClient.java" checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" />
<suppress files="com.azure.storage.blob.specialized.BlobLeaseClient.java" checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" />
<suppress files="com.azure.storage.blob.specialized.BlobLeaseAsyncClient.java" checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" />
<suppress files="com.azure.storage.blob.specialized.BlobInputStream.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.specialized.BlobOutputStream.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.implementation.AppendBlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.implementation.PageBlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.implementation.ServicesImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.implementation.BlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.implementation.BlockBlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="com.azure.storage.blob.implementation.ContainersImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
</suppressions>
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.52.0-beta.1</version><!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
<version>1.51.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down Expand Up @@ -182,7 +182,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<version>1.13.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-http-okhttp;dependency} -->
<version>1.12.2</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
5 changes: 0 additions & 5 deletions sdk/storage/azure-storage-blob/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Class name="com.azure.storage.blob.implementation.util.BlobSasImplUtil" />
<Class name="com.azure.storage.blob.models.CustomerProvidedKey" />
<Class name="com.azure.storage.blob.specialized.BlobAsyncClientBase" />
<Class name="com.azure.storage.blob.specialized.BlobClientBase" />
</Or>
</Match>
<Match>
Expand Down Expand Up @@ -186,8 +185,4 @@
<Class name="com.azure.storage.blob.sas.BlobServiceSasSignatureValues" />
</Or>
</Match>
<Match>
<Bug pattern="MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR" />
<Class name="com.azure.storage.blob.specialized.BlobClientBase" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.blob.implementation.models.EncryptionScope;
import com.azure.storage.blob.implementation.util.ModelHelper;
import com.azure.storage.blob.models.AccessTier;
import com.azure.storage.blob.models.CpkInfo;
import com.azure.storage.blob.models.CustomerProvidedKey;
import com.azure.storage.blob.options.BlobParallelUploadOptions;
import com.azure.storage.blob.models.BlobRequestConditions;
Expand All @@ -35,8 +32,6 @@

import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -66,26 +61,19 @@ public class BlobClient extends BlobClientBase {
/**
* The block size to use if none is specified in parallel operations.
*/
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = 4 * Constants.MB;
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = BlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;

/**
* The number of buffers to use if none is specied on the buffered upload method.
*/
public static final int BLOB_DEFAULT_NUMBER_OF_BUFFERS = 8;
public static final int BLOB_DEFAULT_NUMBER_OF_BUFFERS = BlobAsyncClient.BLOB_DEFAULT_NUMBER_OF_BUFFERS;
/**
* If a blob is known to be greater than 100MB, using a larger block size will trigger some server-side
* optimizations. If the block size is not set and the size of the blob is known to be greater than 100MB, this
* value will be used.
*/
public static final int BLOB_DEFAULT_HTBB_UPLOAD_BLOCK_SIZE = 8 * Constants.MB;
public static final int BLOB_DEFAULT_HTBB_UPLOAD_BLOCK_SIZE = BlobAsyncClient.BLOB_DEFAULT_HTBB_UPLOAD_BLOCK_SIZE;

/**
* The default block size used in {@link FluxUtil#readFile(AsynchronousFileChannel)}.
* This is to make sure we're using same size when using {@link BinaryData#fromFile(Path, int)}
* and {@link BinaryData#fromFile(Path, Long, Long, int)}
* to represent the content.
*/
private static final int DEFAULT_FILE_READ_CHUNK_SIZE = 1024 * 64;
private final BlobAsyncClient client;

private BlockBlobClient blockBlobClient;
Expand All @@ -101,31 +89,6 @@ protected BlobClient(BlobAsyncClient client) {
this.client = client;
}

/**
* Protected constructor for use by {@link BlobClientBuilder}.
*
* @param client the async blob client
* @param pipeline The pipeline used to send and receive service requests.
* @param url The endpoint where to send service requests.
* @param serviceVersion The version of the service to receive requests.
* @param accountName The storage account name.
* @param containerName The container name.
* @param blobName The blob name.
* @param snapshot The snapshot identifier for the blob, pass {@code null} to interact with the blob directly.
* @param customerProvidedKey Customer provided key used during encryption of the blob's data on the server, pass
* {@code null} to allow the service to use its own encryption.
* @param encryptionScope Encryption scope used during encryption of the blob's data on the server, pass
* {@code null} to allow the service to use its own encryption.
* @param versionId The version identifier for the blob, pass {@code null} to interact with the latest blob version.
*/
protected BlobClient(BlobAsyncClient client, HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion,
String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey,
EncryptionScope encryptionScope, String versionId) {
super(client, pipeline, url, serviceVersion, accountName, containerName, blobName, snapshot, customerProvidedKey,
encryptionScope, versionId);
this.client = client;
}

/**
* Creates a new {@link BlobClient} linked to the {@code snapshot} of this blob resource.
*
Expand All @@ -134,11 +97,7 @@ protected BlobClient(BlobAsyncClient client, HttpPipeline pipeline, String url,
*/
@Override
public BlobClient getSnapshotClient(String snapshot) {
BlobAsyncClient asyncClient = new BlobAsyncClient(getHttpPipeline(), getAccountUrl(), getServiceVersion(),
getAccountName(), getContainerName(), getBlobName(), snapshot, getCustomerProvidedKey(),
encryptionScope, getVersionId());
return new BlobClient(asyncClient, getHttpPipeline(), getAccountUrl(), getServiceVersion(), getAccountName(),
getContainerName(), getBlobName(), snapshot, getCustomerProvidedKey(), encryptionScope, getVersionId());
return new BlobClient(client.getSnapshotClient(snapshot));
}

/**
Expand All @@ -150,11 +109,7 @@ public BlobClient getSnapshotClient(String snapshot) {
*/
@Override
public BlobClient getVersionClient(String versionId) {
BlobAsyncClient asyncClient = new BlobAsyncClient(getHttpPipeline(), getAccountUrl(), getServiceVersion(),
getAccountName(), getContainerName(), getBlobName(), getSnapshotId(), getCustomerProvidedKey(),
encryptionScope, versionId);
return new BlobClient(asyncClient, getHttpPipeline(), getAccountUrl(), getServiceVersion(), getAccountName(),
getContainerName(), getBlobName(), getSnapshotId(), getCustomerProvidedKey(), encryptionScope, versionId);
return new BlobClient(client.getVersionClient(versionId));
}

/**
Expand All @@ -165,13 +120,7 @@ public BlobClient getVersionClient(String versionId) {
*/
@Override
public BlobClient getEncryptionScopeClient(String encryptionScope) {
EncryptionScope finalEncryptionScope = null;
if (encryptionScope != null) {
finalEncryptionScope = new EncryptionScope().setEncryptionScope(encryptionScope);
}
return new BlobClient(this.client.getEncryptionScopeAsyncClient(encryptionScope), getHttpPipeline(),
getAccountUrl(), getServiceVersion(), getAccountName(), getContainerName(), getBlobName(), getSnapshotId(),
getCustomerProvidedKey(), finalEncryptionScope, getVersionId());
return new BlobClient(client.getEncryptionScopeAsyncClient(encryptionScope));
}

/**
Expand All @@ -183,16 +132,7 @@ public BlobClient getEncryptionScopeClient(String encryptionScope) {
*/
@Override
public BlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey) {
CpkInfo finalCustomerProvidedKey = null;
if (customerProvidedKey != null) {
finalCustomerProvidedKey = new CpkInfo()
.setEncryptionKey(customerProvidedKey.getKey())
.setEncryptionKeySha256(customerProvidedKey.getKeySha256())
.setEncryptionAlgorithm(customerProvidedKey.getEncryptionAlgorithm());
}
return new BlobClient(this.client.getCustomerProvidedKeyAsyncClient(customerProvidedKey), getHttpPipeline(),
getAccountUrl(), getServiceVersion(), getAccountName(), getContainerName(), getBlobName(), getSnapshotId(),
finalCustomerProvidedKey, encryptionScope, getVersionId());
return new BlobClient(client.getCustomerProvidedKeyAsyncClient(customerProvidedKey));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,7 @@ public BlobClientBuilder() {
* and {@link #retryOptions(RequestRetryOptions)} have been set.
*/
public BlobClient buildClient() {
Objects.requireNonNull(blobName, "'blobName' cannot be null.");
Objects.requireNonNull(endpoint, "'endpoint' cannot be null");

BuilderHelper.httpsValidation(customerProvidedKey, "customer provided key", endpoint, LOGGER);

if (Objects.nonNull(customerProvidedKey) && Objects.nonNull(encryptionScope)) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("Customer provided key and encryption "
+ "scope cannot both be set"));
}

/*
Implicit and explicit root container access are functionally equivalent, but explicit references are easier
to read and debug.
*/
String blobContainerName = CoreUtils.isNullOrEmpty(containerName) ? BlobContainerClient.ROOT_CONTAINER_NAME
: containerName;

BlobServiceVersion serviceVersion = version != null ? version : BlobServiceVersion.getLatest();

BlobAsyncClient asyncClient = buildAsyncClient();

return new BlobClient(asyncClient, asyncClient.getHttpPipeline(), endpoint, serviceVersion, accountName,
blobContainerName, blobName, snapshot, customerProvidedKey, encryptionScope, versionId);
return new BlobClient(buildAsyncClient());
}

/**
Expand Down Expand Up @@ -193,17 +171,13 @@ public BlobAsyncClient buildAsyncClient() {

BlobServiceVersion serviceVersion = version != null ? version : BlobServiceVersion.getLatest();

HttpPipeline pipeline = constructPipeline();

return new BlobAsyncClient(pipeline, endpoint, serviceVersion, accountName, blobContainerName, blobName,
snapshot, customerProvidedKey, encryptionScope, versionId);
}

private HttpPipeline constructPipeline() {
return (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline(
HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline(
storageSharedKeyCredential, tokenCredential, azureSasCredential, sasToken,
endpoint, retryOptions, coreRetryOptions, logOptions,
clientOptions, httpClient, perCallPolicies, perRetryPolicies, configuration, audience, LOGGER);

return new BlobAsyncClient(pipeline, endpoint, serviceVersion, accountName, blobContainerName, blobName,
snapshot, customerProvidedKey, encryptionScope, versionId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.net.URI;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -314,19 +315,6 @@ public String getEncryptionScope() {
return encryptionScope.getEncryptionScope();
}

/**
* Gets the {@link EncryptionScope} used to encrypt this blob's content on the server.
*
* @return the encryption scope used for encryption.
*/
BlobContainerEncryptionScope getBlobContainerEncryptionScope() {
if (blobContainerEncryptionScope == null) {
return null;
}
return blobContainerEncryptionScope;
}


/**
* Gets if the container this client represents exists in the cloud.
*
Expand Down Expand Up @@ -577,7 +565,7 @@ public Mono<Response<Void>> deleteWithResponse(BlobRequestConditions requestCond
Mono<Response<Void>> deleteWithResponse(BlobRequestConditions requestConditions, Context context) {
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;

if (!ModelHelper.validateNoETag(requestConditions)) {
if (!validateNoETag(requestConditions)) {
// Throwing is preferred to Mono.error because this will error out immediately instead of waiting until
// subscription.
throw LOGGER.logExceptionAsError(
Expand Down Expand Up @@ -803,7 +791,7 @@ Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata,
BlobRequestConditions requestConditions, Context context) {
context = context == null ? Context.NONE : context;
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
if (!ModelHelper.validateNoETag(requestConditions) || requestConditions.getIfUnmodifiedSince() != null) {
if (!validateNoETag(requestConditions) || requestConditions.getIfUnmodifiedSince() != null) {
// Throwing is preferred to Mono.error because this will error out immediately instead of waiting until
// subscription.
throw LOGGER.logExceptionAsError(new UnsupportedOperationException(
Expand Down Expand Up @@ -973,19 +961,36 @@ Mono<Response<Void>> setAccessPolicyWithResponse(PublicAccessType accessType,
List<BlobSignedIdentifier> identifiers, BlobRequestConditions requestConditions, Context context) {
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;

if (!ModelHelper.validateNoETag(requestConditions)) {
if (!validateNoETag(requestConditions)) {
// Throwing is preferred to Mono.error because this will error out immediately instead of waiting until
// subscription.
throw LOGGER.logExceptionAsError(
new UnsupportedOperationException("ETag access conditions are not supported for this API."));
}

List<BlobSignedIdentifier> finalIdentifiers = ModelHelper.truncateTimeForBlobSignedIdentifier(identifiers);
/*
We truncate to seconds because the service only supports nanoseconds or seconds, but doing an
OffsetDateTime.now will only give back milliseconds (more precise fields are zeroed and not serialized). This
allows for proper serialization with no real detriment to users as sub-second precision on active time for
signed identifiers is not really necessary.
*/
if (identifiers != null) {
for (BlobSignedIdentifier identifier : identifiers) {
if (identifier.getAccessPolicy() != null && identifier.getAccessPolicy().getStartsOn() != null) {
identifier.getAccessPolicy().setStartsOn(
identifier.getAccessPolicy().getStartsOn().truncatedTo(ChronoUnit.SECONDS));
}
if (identifier.getAccessPolicy() != null && identifier.getAccessPolicy().getExpiresOn() != null) {
identifier.getAccessPolicy().setExpiresOn(
identifier.getAccessPolicy().getExpiresOn().truncatedTo(ChronoUnit.SECONDS));
}
}
}
context = context == null ? Context.NONE : context;

return this.azureBlobStorage.getContainers().setAccessPolicyNoCustomHeadersWithResponseAsync(containerName,
null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), null, finalIdentifiers, context);
requestConditions.getIfUnmodifiedSince(), null, identifiers, context);
}

/**
Expand Down Expand Up @@ -1720,6 +1725,13 @@ public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureV
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
}

private static boolean validateNoETag(BlobRequestConditions modifiedRequestConditions) {
if (modifiedRequestConditions == null) {
return true;
}
return modifiedRequestConditions.getIfMatch() == null && modifiedRequestConditions.getIfNoneMatch() == null;
}

// private boolean validateNoTime(BlobRequestConditions modifiedRequestConditions) {
// if (modifiedRequestConditions == null) {
// return true;
Expand Down
Loading

0 comments on commit ac9ee63

Please sign in to comment.