Skip to content

Commit

Permalink
Enable Spotless on Storage (#42766)
Browse files Browse the repository at this point in the history
Enable Spotless on Storage
  • Loading branch information
alzimmermsft authored Nov 1, 2024
1 parent ac46a73 commit 9076361
Show file tree
Hide file tree
Showing 595 changed files with 28,074 additions and 34,167 deletions.
1 change: 0 additions & 1 deletion sdk/storage/azure-storage-blob-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<spotbugs.skip>false</spotbugs.skip>
<spotbugs.excludeFilterFile>spotbugs-exclude.xml</spotbugs.excludeFilterFile>
<doclintMissingInclusion>-</doclintMissingInclusion>
<spotless.skip>true</spotless.skip>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public final class BlobBatch {
* Track the status codes expected for the batching operations here as the batch body does not get parsed in
* Azure Core where this information is maintained.
*/
private static final int[] EXPECTED_DELETE_STATUS_CODES = {202};
private static final int[] EXPECTED_SET_TIER_STATUS_CODES = {200, 202};
private static final int[] EXPECTED_DELETE_STATUS_CODES = { 202 };
private static final int[] EXPECTED_SET_TIER_STATUS_CODES = { 200, 202 };

private static final ClientLogger LOGGER = new ClientLogger(BlobBatch.class);

Expand Down Expand Up @@ -104,8 +104,7 @@ public final class BlobBatch {
batchPipelineBuilder.tracer(pipeline.getTracer());
batchPipelineBuilder.httpClient(pipeline.getHttpClient());

this.blobAsyncClient = new BlobClientBuilder()
.endpoint(accountUrl)
this.blobAsyncClient = new BlobClientBuilder().endpoint(accountUrl)
.blobName("")
.serviceVersion(serviceVersion)
.pipeline(batchPipelineBuilder.build())
Expand Down Expand Up @@ -157,8 +156,8 @@ public Response<Void> deleteBlob(String containerName, String blobName) {
* submitted.
* @throws UnsupportedOperationException If this batch has already added an operation of another type.
*/
public Response<Void> deleteBlob(String containerName, String blobName,
DeleteSnapshotsOptionType deleteOptions, BlobRequestConditions blobRequestConditions) {
public Response<Void> deleteBlob(String containerName, String blobName, DeleteSnapshotsOptionType deleteOptions,
BlobRequestConditions blobRequestConditions) {
return deleteBlobHelper(containerName + "/" + Utility.urlEncode(Utility.urlDecode(blobName)), deleteOptions,
blobRequestConditions);
}
Expand Down Expand Up @@ -212,8 +211,8 @@ public Response<Void> deleteBlob(String blobUrl, DeleteSnapshotsOptionType delet
private Response<Void> deleteBlobHelper(String urlPath, DeleteSnapshotsOptionType deleteOptions,
BlobRequestConditions blobRequestConditions) {
setBatchType(BlobBatchType.DELETE);
return createBatchOperation(blobAsyncClient.deleteWithResponse(deleteOptions, blobRequestConditions),
urlPath, EXPECTED_DELETE_STATUS_CODES);
return createBatchOperation(blobAsyncClient.deleteWithResponse(deleteOptions, blobRequestConditions), urlPath,
EXPECTED_DELETE_STATUS_CODES);
}

/**
Expand Down Expand Up @@ -334,9 +333,8 @@ public Response<Void> setBlobAccessTier(BlobBatchSetBlobAccessTierOptions option
private Response<Void> setBlobAccessTierHelper(String blobPath, AccessTier tier, RehydratePriority priority,
String leaseId, String tagsConditions) {
setBatchType(BlobBatchType.SET_TIER);
return createBatchOperation(blobAsyncClient.setAccessTierWithResponse(
new BlobSetAccessTierOptions(tier)
.setLeaseId(leaseId)
return createBatchOperation(
blobAsyncClient.setAccessTierWithResponse(new BlobSetAccessTierOptions(tier).setLeaseId(leaseId)
.setPriority(priority)
.setTagsConditions(tagsConditions)),
blobPath, EXPECTED_SET_TIER_STATUS_CODES);
Expand Down Expand Up @@ -378,10 +376,12 @@ Mono<BlobBatchOperationInfo> prepareBlobBatchSubmission() {
while (!operations.isEmpty()) {
BlobBatchOperation<?> batchOperation = operations.pop();

batchOperationResponses.add(batchOperation.getResponse()
.contextWrite(Context.of(BATCH_REQUEST_URL_PATH, batchOperation.getRequestUrlPath(),
BATCH_OPERATION_RESPONSE, batchOperation.getBatchOperationResponse(),
BATCH_OPERATION_INFO, operationInfo)));
batchOperationResponses
.add(
batchOperation.getResponse()
.contextWrite(Context.of(BATCH_REQUEST_URL_PATH, batchOperation.getRequestUrlPath(),
BATCH_OPERATION_RESPONSE, batchOperation.getBatchOperationResponse(), BATCH_OPERATION_INFO,
operationInfo)));
}

/*
Expand Down Expand Up @@ -439,8 +439,8 @@ private Mono<HttpResponse> setRequestUrl(HttpPipelineCallContext context, HttpPi
*/
private Mono<HttpResponse> buildBatchOperation(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
BlobBatchOperationInfo operationInfo = (BlobBatchOperationInfo) context.getData(BATCH_OPERATION_INFO).get();
BlobBatchOperationResponse<?> batchOperationResponse =
(BlobBatchOperationResponse<?>) context.getData(BATCH_OPERATION_RESPONSE).get();
BlobBatchOperationResponse<?> batchOperationResponse
= (BlobBatchOperationResponse<?>) context.getData(BATCH_OPERATION_RESPONSE).get();
operationInfo.addBatchOperation(batchOperationResponse, context.getHttpRequest());

return Mono.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public final class BlobBatchAsyncClient {

BlobBatchAsyncClient(String clientUrl, HttpPipeline pipeline, BlobServiceVersion version, boolean containerScoped) {
this.serviceVersion = version;
this.client = new AzureBlobStorageImplBuilder()
.url(clientUrl)
this.client = new AzureBlobStorageImplBuilder().url(clientUrl)
.pipeline(pipeline)
.version(version.getVersion())
.buildClient();
Expand Down Expand Up @@ -147,8 +146,7 @@ public Mono<Void> submitBatch(BlobBatch batch) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> submitBatchWithResponse(BlobBatch batch, boolean throwOnAnyFailure) {
try {
return withContext(context -> submitBatchWithResponse(batch, throwOnAnyFailure,
context));
return withContext(context -> submitBatchWithResponse(batch, throwOnAnyFailure, context));
} catch (RuntimeException ex) {
return monoError(LOGGER, ex);
}
Expand All @@ -158,15 +156,18 @@ Mono<Response<Void>> submitBatchWithResponse(BlobBatch batch, boolean throwOnAny
Context finalContext = context == null ? Context.NONE : context;
return batch.prepareBlobBatchSubmission()
.flatMap(batchOperationInfo -> containerScoped
? client.getContainers().submitBatchWithResponseAsync(null,
batchOperationInfo.getContentLength(), batchOperationInfo.getContentType(),
Flux.fromIterable(batchOperationInfo.getBody()), null, null, finalContext)
.flatMap(response ->
BlobBatchHelper.mapBatchResponse(batchOperationInfo, response, throwOnAnyFailure, LOGGER))
: client.getServices().submitBatchWithResponseAsync(batchOperationInfo.getContentLength(),
batchOperationInfo.getContentType(), Flux.fromIterable(batchOperationInfo.getBody()), null, null, finalContext)
.flatMap(response ->
BlobBatchHelper.mapBatchResponse(batchOperationInfo, response, throwOnAnyFailure, LOGGER)));
? client.getContainers()
.submitBatchWithResponseAsync(null, batchOperationInfo.getContentLength(),
batchOperationInfo.getContentType(), Flux.fromIterable(batchOperationInfo.getBody()), null,
null, finalContext)
.flatMap(response -> BlobBatchHelper.mapBatchResponse(batchOperationInfo, response,
throwOnAnyFailure, LOGGER))
: client.getServices()
.submitBatchWithResponseAsync(batchOperationInfo.getContentLength(),
batchOperationInfo.getContentType(), Flux.fromIterable(batchOperationInfo.getBody()), null,
null, finalContext)
.flatMap(response -> BlobBatchHelper.mapBatchResponse(batchOperationInfo, response,
throwOnAnyFailure, LOGGER)));
}

/**
Expand Down Expand Up @@ -206,8 +207,8 @@ public PagedFlux<Response<Void>> deleteBlobs(List<String> blobUrls, DeleteSnapsh

PagedFlux<Response<Void>> deleteBlobsWithTimeout(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions,
Duration timeout, Context context) {
return new PagedFlux<>(() ->
StorageImplUtils.applyOptionalTimeout(submitDeleteBlobsBatch(blobUrls, deleteOptions, context), timeout));
return new PagedFlux<>(() -> StorageImplUtils
.applyOptionalTimeout(submitDeleteBlobsBatch(blobUrls, deleteOptions, context), timeout));
}

private Mono<PagedResponse<Response<Void>>> submitDeleteBlobsBatch(List<String> blobUrls,
Expand Down Expand Up @@ -251,8 +252,8 @@ public PagedFlux<Response<Void>> setBlobsAccessTier(List<String> blobUrls, Acces

PagedFlux<Response<Void>> setBlobsAccessTierWithTimeout(List<String> blobUrls, AccessTier accessTier,
Duration timeout, Context context) {
return new PagedFlux<>(() ->
StorageImplUtils.applyOptionalTimeout(submitSetTierBatch(blobUrls, accessTier, context), timeout));
return new PagedFlux<>(
() -> StorageImplUtils.applyOptionalTimeout(submitSetTierBatch(blobUrls, accessTier, context), timeout));
}

private Mono<PagedResponse<Response<Void>>> submitSetTierBatch(List<String> blobUrls, AccessTier accessTier,
Expand All @@ -273,8 +274,7 @@ private <T> Mono<PagedResponse<Response<T>>> submitBatchHelper(List<String> blob
responses.add(generator.apply(batch, blobUrl));
}

return submitBatchWithResponse(batch, true, context)
.map(response -> initPagedResponse(responses, response));
return submitBatchWithResponse(batch, true, context).map(response -> initPagedResponse(responses, response));
}

private <T> PagedResponse<Response<T>> initPagedResponse(List<Response<T>> values, Response<?> response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void submitBatch(BlobBatch batch) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> submitBatchWithResponse(BlobBatch batch, boolean throwOnAnyFailure, Duration timeout,
Context context) {
return StorageImplUtils.blockWithOptionalTimeout(client.submitBatchWithResponse(batch,
throwOnAnyFailure, context), timeout);
return StorageImplUtils
.blockWithOptionalTimeout(client.submitBatchWithResponse(batch, throwOnAnyFailure, context), timeout);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
* BlobBatchClients} and {@link BlobBatchAsyncClient BlobBatchAsyncClients} when {@link #buildClient() buildClient} and
* {@link #buildAsyncClient() buildAsyncClient} as called respectively.
*/
@ServiceClientBuilder(serviceClients = {BlobBatchClient.class, BlobBatchAsyncClient.class})
@ServiceClientBuilder(serviceClients = { BlobBatchClient.class, BlobBatchAsyncClient.class })
public final class BlobBatchClientBuilder {
private static final Map<String, String> PROPERTIES =
CoreUtils.getProperties("azure-storage-blob-batch.properties");
private static final Map<String, String> PROPERTIES
= CoreUtils.getProperties("azure-storage-blob-batch.properties");
private static final String SDK_NAME = "name";
private static final String SDK_VERSION = "version";
private static final String CLIENT_NAME = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName");
Expand Down Expand Up @@ -141,8 +141,7 @@ private HttpPipeline addBlobUserAgentModificationPolicy(HttpPipeline pipeline) {
}
}

return new HttpPipelineBuilder()
.httpClient(pipeline.getHttpClient())
return new HttpPipelineBuilder().httpClient(pipeline.getHttpClient())
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.tracer(pipeline.getTracer())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class BlobBatchHelper {
/*
* This pattern matches finding the "Content-Id" of the batch response.
*/
private static final Pattern CONTENT_ID_PATTERN = Pattern
.compile("Content-ID:\\s?(\\d+)", Pattern.CASE_INSENSITIVE);
private static final Pattern CONTENT_ID_PATTERN
= Pattern.compile("Content-ID:\\s?(\\d+)", Pattern.CASE_INSENSITIVE);

/*
* This pattern matches finding the status code of the batch response.
*/
private static final Pattern STATUS_CODE_PATTERN = Pattern
.compile("HTTP/\\d\\.\\d\\s?(\\d+)\\s?\\w+", Pattern.CASE_INSENSITIVE);
private static final Pattern STATUS_CODE_PATTERN
= Pattern.compile("HTTP/\\d\\.\\d\\s?(\\d+)\\s?\\w+", Pattern.CASE_INSENSITIVE);

/*
* The following patterns were previously used in 'String.split' calls. 'String.split' internally compiles the
Expand All @@ -67,8 +67,8 @@ static Mono<SimpleResponse<Void>> mapBatchResponse(BlobBatchOperationInfo batchO
// Split on the boundary [ "multipart/mixed; boundary", "batchresponse_66925647-d0cb-4109-b6d3-28efe3e1e5ed"]
String[] boundaryPieces = contentType.split("=", 2);
if (boundaryPieces.length == 1) {
return Mono.error(logger
.logExceptionAsError(new IllegalStateException("Response doesn't contain a boundary.")));
return Mono
.error(logger.logExceptionAsError(new IllegalStateException("Response doesn't contain a boundary.")));
}

String boundary = boundaryPieces[1];
Expand All @@ -94,9 +94,9 @@ static Mono<SimpleResponse<Void>> mapBatchResponse(BlobBatchOperationInfo batchO
int statusCode = getStatusCode(exceptionSections[1], logger);
HttpHeaders headers = getHttpHeaders(exceptionSections[1]);

sink.error(logger.logExceptionAsError(new BlobStorageException(
headers.getValue(Constants.HeaderConstants.ERROR_CODE_HEADER_NAME),
createHttpResponse(rawResponse.getRequest(), statusCode, headers, body), body)));
sink.error(logger.logExceptionAsError(
new BlobStorageException(headers.getValue(Constants.HeaderConstants.ERROR_CODE_HEADER_NAME),
createHttpResponse(rawResponse.getRequest(), statusCode, headers, body), body)));
}

// Split the batch response body into batch operation responses.
Expand All @@ -110,8 +110,8 @@ static Mono<SimpleResponse<Void>> mapBatchResponse(BlobBatchOperationInfo batchO
String[] subResponseSections = HTTP_DOUBLE_NEWLINE_PATTERN.split(subResponse);

// The first section will contain batching metadata.
BlobBatchOperationResponse<?> batchOperationResponse =
getBatchOperation(batchOperationInfo, subResponseSections[0], logger);
BlobBatchOperationResponse<?> batchOperationResponse
= getBatchOperation(batchOperationInfo, subResponseSections[0], logger);

// The second section will contain status code and header information.
batchOperationResponse.setStatusCode(getStatusCode(subResponseSections[1], logger));
Expand Down Expand Up @@ -185,14 +185,14 @@ private static HttpHeaders getHttpHeaders(String responseMetadata) {
return headers;
}

private static void setBodyOrAddException(BlobBatchOperationResponse<?> batchOperationResponse,
String responseBody, List<BlobStorageException> exceptions, ClientLogger logger) {
private static void setBodyOrAddException(BlobBatchOperationResponse<?> batchOperationResponse, String responseBody,
List<BlobStorageException> exceptions, ClientLogger logger) {
/*
* Currently, no batching operations will return a success body, they will only return a body on an exception.
* For now this will only construct the exception and throw if it should throw on an error.
*/
BlobStorageException exception = new BlobStorageException(responseBody,
batchOperationResponse.asHttpResponse(responseBody), responseBody);
BlobStorageException exception
= new BlobStorageException(responseBody, batchOperationResponse.asHttpResponse(responseBody), responseBody);
logger.logExceptionAsError(exception);
batchOperationResponse.setException(exception);
exceptions.add(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void addBatchOperation(BlobBatchOperationResponse<?> batchOperation, HttpRequest
* 'x-ms-version' used in the batch request. This header is illegal and will fail the batch request if present
* in any operation.
*/
request.getHeaders().stream()
request.getHeaders()
.stream()
.filter(header -> !X_MS_VERSION.equalsIgnoreCase(header.getName()))
.forEach(header -> appendWithNewline(batchRequestBuilder, header.getName() + ": " + header.getValue()));

Expand All @@ -113,8 +114,8 @@ void addBatchOperation(BlobBatchOperationResponse<?> batchOperation, HttpRequest
* Completes the batch by adding the final boundary identifier to the request body.
*/
void finalizeBatchOperations() {
batchOperations.add(ByteBuffer.wrap(
("--" + batchBoundary + "--" + BlobBatchHelper.HTTP_NEWLINE).getBytes(StandardCharsets.UTF_8)));
batchOperations.add(ByteBuffer
.wrap(("--" + batchBoundary + "--" + BlobBatchHelper.HTTP_NEWLINE).getBytes(StandardCharsets.UTF_8)));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
* Enum class used to indicate the batch operation type.
*/
enum BlobBatchType {
DELETE,
SET_TIER
DELETE, SET_TIER
}
Loading

0 comments on commit 9076361

Please sign in to comment.