Skip to content

Commit ac9ee63

Browse files
authored
Revert "Blobs Sync Stack Migration (#40812)" (#41819)
This reverts commit 37d8cdc.
1 parent 038071f commit ac9ee63

35 files changed

+2824
-17575
lines changed

eng/versioning/version_client.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ unreleased_com.azure:azure-json;1.3.0
492492

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

495-
unreleased_com.azure:azure-core;1.52.0-beta.1
496-
unreleased_com.azure:azure-core-http-okhttp;1.13.0-beta.1
497-
498495
# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
499496
# version and set the version to the released beta. Released beta dependencies are only valid
500497
# for dependency versions. These entries are specifically for when we've released a beta for

sdk/storage/azure-storage-blob/checkstyle-suppressions.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@
3535
<suppress files="com.azure.storage.blob.implementation.util.ModelHelper.java" checks="com.azure.tools.checkstyle.checks.JavadocThrowsChecks" />
3636
<suppress files="com.azure.storage.blob.implementation.AzureBlobStorageImplBuilder.java" checks="com.azure.tools.checkstyle.checks.ServiceClientBuilderCheck" />
3737
<suppress files="com.azure.storage.blob.BlobClient.java" checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" />
38-
<suppress files="com.azure.storage.blob.specialized.BlobLeaseClient.java" checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" />
3938
<suppress files="com.azure.storage.blob.specialized.BlobLeaseAsyncClient.java" checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" />
4039
<suppress files="com.azure.storage.blob.specialized.BlobInputStream.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
4140
<suppress files="com.azure.storage.blob.specialized.BlobOutputStream.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
42-
<suppress files="com.azure.storage.blob.implementation.AppendBlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
43-
<suppress files="com.azure.storage.blob.implementation.PageBlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
44-
<suppress files="com.azure.storage.blob.implementation.ServicesImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
45-
<suppress files="com.azure.storage.blob.implementation.BlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
46-
<suppress files="com.azure.storage.blob.implementation.BlockBlobsImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
47-
<suppress files="com.azure.storage.blob.implementation.ContainersImpl.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
4841
</suppressions>

sdk/storage/azure-storage-blob/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>com.azure</groupId>
7272
<artifactId>azure-core</artifactId>
73-
<version>1.52.0-beta.1</version><!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
73+
<version>1.51.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
7474
</dependency>
7575
<dependency>
7676
<groupId>com.azure</groupId>
@@ -182,7 +182,7 @@
182182
<dependency>
183183
<groupId>com.azure</groupId>
184184
<artifactId>azure-core-http-okhttp</artifactId>
185-
<version>1.13.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-http-okhttp;dependency} -->
185+
<version>1.12.2</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
186186
<scope>test</scope>
187187
</dependency>
188188
<dependency>

sdk/storage/azure-storage-blob/spotbugs-exclude.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<Class name="com.azure.storage.blob.implementation.util.BlobSasImplUtil" />
99
<Class name="com.azure.storage.blob.models.CustomerProvidedKey" />
1010
<Class name="com.azure.storage.blob.specialized.BlobAsyncClientBase" />
11-
<Class name="com.azure.storage.blob.specialized.BlobClientBase" />
1211
</Or>
1312
</Match>
1413
<Match>
@@ -186,8 +185,4 @@
186185
<Class name="com.azure.storage.blob.sas.BlobServiceSasSignatureValues" />
187186
</Or>
188187
</Match>
189-
<Match>
190-
<Bug pattern="MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR" />
191-
<Class name="com.azure.storage.blob.specialized.BlobClientBase" />
192-
</Match>
193188
</FindBugsFilter>

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClient.java

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
import com.azure.core.annotation.ReturnType;
77
import com.azure.core.annotation.ServiceClient;
88
import com.azure.core.annotation.ServiceMethod;
9-
import com.azure.core.http.HttpPipeline;
109
import com.azure.core.http.rest.Response;
1110
import com.azure.core.util.BinaryData;
1211
import com.azure.core.util.Context;
1312
import com.azure.core.util.FluxUtil;
1413
import com.azure.core.util.logging.ClientLogger;
15-
import com.azure.storage.blob.implementation.models.EncryptionScope;
1614
import com.azure.storage.blob.implementation.util.ModelHelper;
1715
import com.azure.storage.blob.models.AccessTier;
18-
import com.azure.storage.blob.models.CpkInfo;
1916
import com.azure.storage.blob.models.CustomerProvidedKey;
2017
import com.azure.storage.blob.options.BlobParallelUploadOptions;
2118
import com.azure.storage.blob.models.BlobRequestConditions;
@@ -35,8 +32,6 @@
3532

3633
import java.io.InputStream;
3734
import java.io.UncheckedIOException;
38-
import java.nio.channels.AsynchronousFileChannel;
39-
import java.nio.file.Path;
4035
import java.time.Duration;
4136
import java.util.Map;
4237
import java.util.Objects;
@@ -66,26 +61,19 @@ public class BlobClient extends BlobClientBase {
6661
/**
6762
* The block size to use if none is specified in parallel operations.
6863
*/
69-
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = 4 * Constants.MB;
64+
public static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = BlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;
7065

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

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

9179
private BlockBlobClient blockBlobClient;
@@ -101,31 +89,6 @@ protected BlobClient(BlobAsyncClient client) {
10189
this.client = client;
10290
}
10391

104-
/**
105-
* Protected constructor for use by {@link BlobClientBuilder}.
106-
*
107-
* @param client the async blob client
108-
* @param pipeline The pipeline used to send and receive service requests.
109-
* @param url The endpoint where to send service requests.
110-
* @param serviceVersion The version of the service to receive requests.
111-
* @param accountName The storage account name.
112-
* @param containerName The container name.
113-
* @param blobName The blob name.
114-
* @param snapshot The snapshot identifier for the blob, pass {@code null} to interact with the blob directly.
115-
* @param customerProvidedKey Customer provided key used during encryption of the blob's data on the server, pass
116-
* {@code null} to allow the service to use its own encryption.
117-
* @param encryptionScope Encryption scope used during encryption of the blob's data on the server, pass
118-
* {@code null} to allow the service to use its own encryption.
119-
* @param versionId The version identifier for the blob, pass {@code null} to interact with the latest blob version.
120-
*/
121-
protected BlobClient(BlobAsyncClient client, HttpPipeline pipeline, String url, BlobServiceVersion serviceVersion,
122-
String accountName, String containerName, String blobName, String snapshot, CpkInfo customerProvidedKey,
123-
EncryptionScope encryptionScope, String versionId) {
124-
super(client, pipeline, url, serviceVersion, accountName, containerName, blobName, snapshot, customerProvidedKey,
125-
encryptionScope, versionId);
126-
this.client = client;
127-
}
128-
12992
/**
13093
* Creates a new {@link BlobClient} linked to the {@code snapshot} of this blob resource.
13194
*
@@ -134,11 +97,7 @@ protected BlobClient(BlobAsyncClient client, HttpPipeline pipeline, String url,
13497
*/
13598
@Override
13699
public BlobClient getSnapshotClient(String snapshot) {
137-
BlobAsyncClient asyncClient = new BlobAsyncClient(getHttpPipeline(), getAccountUrl(), getServiceVersion(),
138-
getAccountName(), getContainerName(), getBlobName(), snapshot, getCustomerProvidedKey(),
139-
encryptionScope, getVersionId());
140-
return new BlobClient(asyncClient, getHttpPipeline(), getAccountUrl(), getServiceVersion(), getAccountName(),
141-
getContainerName(), getBlobName(), snapshot, getCustomerProvidedKey(), encryptionScope, getVersionId());
100+
return new BlobClient(client.getSnapshotClient(snapshot));
142101
}
143102

144103
/**
@@ -150,11 +109,7 @@ public BlobClient getSnapshotClient(String snapshot) {
150109
*/
151110
@Override
152111
public BlobClient getVersionClient(String versionId) {
153-
BlobAsyncClient asyncClient = new BlobAsyncClient(getHttpPipeline(), getAccountUrl(), getServiceVersion(),
154-
getAccountName(), getContainerName(), getBlobName(), getSnapshotId(), getCustomerProvidedKey(),
155-
encryptionScope, versionId);
156-
return new BlobClient(asyncClient, getHttpPipeline(), getAccountUrl(), getServiceVersion(), getAccountName(),
157-
getContainerName(), getBlobName(), getSnapshotId(), getCustomerProvidedKey(), encryptionScope, versionId);
112+
return new BlobClient(client.getVersionClient(versionId));
158113
}
159114

160115
/**
@@ -165,13 +120,7 @@ public BlobClient getVersionClient(String versionId) {
165120
*/
166121
@Override
167122
public BlobClient getEncryptionScopeClient(String encryptionScope) {
168-
EncryptionScope finalEncryptionScope = null;
169-
if (encryptionScope != null) {
170-
finalEncryptionScope = new EncryptionScope().setEncryptionScope(encryptionScope);
171-
}
172-
return new BlobClient(this.client.getEncryptionScopeAsyncClient(encryptionScope), getHttpPipeline(),
173-
getAccountUrl(), getServiceVersion(), getAccountName(), getContainerName(), getBlobName(), getSnapshotId(),
174-
getCustomerProvidedKey(), finalEncryptionScope, getVersionId());
123+
return new BlobClient(client.getEncryptionScopeAsyncClient(encryptionScope));
175124
}
176125

177126
/**
@@ -183,16 +132,7 @@ public BlobClient getEncryptionScopeClient(String encryptionScope) {
183132
*/
184133
@Override
185134
public BlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey) {
186-
CpkInfo finalCustomerProvidedKey = null;
187-
if (customerProvidedKey != null) {
188-
finalCustomerProvidedKey = new CpkInfo()
189-
.setEncryptionKey(customerProvidedKey.getKey())
190-
.setEncryptionKeySha256(customerProvidedKey.getKeySha256())
191-
.setEncryptionAlgorithm(customerProvidedKey.getEncryptionAlgorithm());
192-
}
193-
return new BlobClient(this.client.getCustomerProvidedKeyAsyncClient(customerProvidedKey), getHttpPipeline(),
194-
getAccountUrl(), getServiceVersion(), getAccountName(), getContainerName(), getBlobName(), getSnapshotId(),
195-
finalCustomerProvidedKey, encryptionScope, getVersionId());
135+
return new BlobClient(client.getCustomerProvidedKeyAsyncClient(customerProvidedKey));
196136
}
197137

198138
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,7 @@ public BlobClientBuilder() {
127127
* and {@link #retryOptions(RequestRetryOptions)} have been set.
128128
*/
129129
public BlobClient buildClient() {
130-
Objects.requireNonNull(blobName, "'blobName' cannot be null.");
131-
Objects.requireNonNull(endpoint, "'endpoint' cannot be null");
132-
133-
BuilderHelper.httpsValidation(customerProvidedKey, "customer provided key", endpoint, LOGGER);
134-
135-
if (Objects.nonNull(customerProvidedKey) && Objects.nonNull(encryptionScope)) {
136-
throw LOGGER.logExceptionAsError(new IllegalArgumentException("Customer provided key and encryption "
137-
+ "scope cannot both be set"));
138-
}
139-
140-
/*
141-
Implicit and explicit root container access are functionally equivalent, but explicit references are easier
142-
to read and debug.
143-
*/
144-
String blobContainerName = CoreUtils.isNullOrEmpty(containerName) ? BlobContainerClient.ROOT_CONTAINER_NAME
145-
: containerName;
146-
147-
BlobServiceVersion serviceVersion = version != null ? version : BlobServiceVersion.getLatest();
148-
149-
BlobAsyncClient asyncClient = buildAsyncClient();
150-
151-
return new BlobClient(asyncClient, asyncClient.getHttpPipeline(), endpoint, serviceVersion, accountName,
152-
blobContainerName, blobName, snapshot, customerProvidedKey, encryptionScope, versionId);
130+
return new BlobClient(buildAsyncClient());
153131
}
154132

155133
/**
@@ -193,17 +171,13 @@ public BlobAsyncClient buildAsyncClient() {
193171

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

196-
HttpPipeline pipeline = constructPipeline();
197-
198-
return new BlobAsyncClient(pipeline, endpoint, serviceVersion, accountName, blobContainerName, blobName,
199-
snapshot, customerProvidedKey, encryptionScope, versionId);
200-
}
201-
202-
private HttpPipeline constructPipeline() {
203-
return (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline(
174+
HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline(
204175
storageSharedKeyCredential, tokenCredential, azureSasCredential, sasToken,
205176
endpoint, retryOptions, coreRetryOptions, logOptions,
206177
clientOptions, httpClient, perCallPolicies, perRetryPolicies, configuration, audience, LOGGER);
178+
179+
return new BlobAsyncClient(pipeline, endpoint, serviceVersion, accountName, blobContainerName, blobName,
180+
snapshot, customerProvidedKey, encryptionScope, versionId);
207181
}
208182

209183
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobContainerAsyncClient.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.net.URI;
5757
import java.time.Duration;
5858
import java.time.OffsetDateTime;
59+
import java.time.temporal.ChronoUnit;
5960
import java.util.ArrayList;
6061
import java.util.Collections;
6162
import java.util.List;
@@ -314,19 +315,6 @@ public String getEncryptionScope() {
314315
return encryptionScope.getEncryptionScope();
315316
}
316317

317-
/**
318-
* Gets the {@link EncryptionScope} used to encrypt this blob's content on the server.
319-
*
320-
* @return the encryption scope used for encryption.
321-
*/
322-
BlobContainerEncryptionScope getBlobContainerEncryptionScope() {
323-
if (blobContainerEncryptionScope == null) {
324-
return null;
325-
}
326-
return blobContainerEncryptionScope;
327-
}
328-
329-
330318
/**
331319
* Gets if the container this client represents exists in the cloud.
332320
*
@@ -577,7 +565,7 @@ public Mono<Response<Void>> deleteWithResponse(BlobRequestConditions requestCond
577565
Mono<Response<Void>> deleteWithResponse(BlobRequestConditions requestConditions, Context context) {
578566
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
579567

580-
if (!ModelHelper.validateNoETag(requestConditions)) {
568+
if (!validateNoETag(requestConditions)) {
581569
// Throwing is preferred to Mono.error because this will error out immediately instead of waiting until
582570
// subscription.
583571
throw LOGGER.logExceptionAsError(
@@ -803,7 +791,7 @@ Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata,
803791
BlobRequestConditions requestConditions, Context context) {
804792
context = context == null ? Context.NONE : context;
805793
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
806-
if (!ModelHelper.validateNoETag(requestConditions) || requestConditions.getIfUnmodifiedSince() != null) {
794+
if (!validateNoETag(requestConditions) || requestConditions.getIfUnmodifiedSince() != null) {
807795
// Throwing is preferred to Mono.error because this will error out immediately instead of waiting until
808796
// subscription.
809797
throw LOGGER.logExceptionAsError(new UnsupportedOperationException(
@@ -973,19 +961,36 @@ Mono<Response<Void>> setAccessPolicyWithResponse(PublicAccessType accessType,
973961
List<BlobSignedIdentifier> identifiers, BlobRequestConditions requestConditions, Context context) {
974962
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
975963

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

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

986991
return this.azureBlobStorage.getContainers().setAccessPolicyNoCustomHeadersWithResponseAsync(containerName,
987992
null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
988-
requestConditions.getIfUnmodifiedSince(), null, finalIdentifiers, context);
993+
requestConditions.getIfUnmodifiedSince(), null, identifiers, context);
989994
}
990995

991996
/**
@@ -1720,6 +1725,13 @@ public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureV
17201725
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
17211726
}
17221727

1728+
private static boolean validateNoETag(BlobRequestConditions modifiedRequestConditions) {
1729+
if (modifiedRequestConditions == null) {
1730+
return true;
1731+
}
1732+
return modifiedRequestConditions.getIfMatch() == null && modifiedRequestConditions.getIfNoneMatch() == null;
1733+
}
1734+
17231735
// private boolean validateNoTime(BlobRequestConditions modifiedRequestConditions) {
17241736
// if (modifiedRequestConditions == null) {
17251737
// return true;

0 commit comments

Comments
 (0)