From dc6c080696ea8a31bf9a99f30464e82443e3b074 Mon Sep 17 00:00:00 2001 From: BenWhitehead Date: Thu, 5 Oct 2023 14:08:06 -0400 Subject: [PATCH] chore: make ParallelCompositeUploadException public (#2245) Tweak public api to be List vs ImmutableList so we are not hard coded against guava. --- .../ParallelCompositeUploadException.java | 28 ++++++++++++++----- ...lelCompositeUploadWritableByteChannel.java | 8 +++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadException.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadException.java index b03348e569..2cc791e16e 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadException.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadException.java @@ -21,28 +21,42 @@ import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.ErrorDetails; import com.google.api.gax.rpc.StatusCode; -import com.google.common.collect.ImmutableList; import io.grpc.Status.Code; +import java.util.List; -final class ParallelCompositeUploadException extends ApiException { +/** + * An exception which provides access to created objects during a Parallel Composite Upload that did + * not finish successfully. + * + *

This exception can occur when calling any method on the {@link + * java.nio.channels.WritableByteChannel} returned from {@link BlobWriteSession#open()}, in which + * case it will be the cause of a {@link StorageException}. + * + *

Similarly, this exception will be the cause of a {@link + * java.util.concurrent.CancellationException} thrown by the {@link BlobWriteSession#getResult()}. + */ +public final class ParallelCompositeUploadException extends ApiException { - private final ApiFuture> createdObjects; + private final ApiFuture> createdObjects; private ParallelCompositeUploadException( Throwable cause, StatusCode statusCode, ErrorDetails errorDetails, - ApiFuture> createdObjects) { + ApiFuture> createdObjects) { super(cause, statusCode, false, errorDetails); this.createdObjects = createdObjects; } - public ApiFuture> getCreatedObjects() { + /** + * A future list of the {@link BlobId}s which were created during the Parallel Composite Upload + * but may not have successfully been cleaned up. + */ + public ApiFuture> getCreatedObjects() { return createdObjects; } - static ParallelCompositeUploadException of( - Throwable t, ApiFuture> createdObjects) { + static ParallelCompositeUploadException of(Throwable t, ApiFuture> createdObjects) { StatusCode statusCode; ErrorDetails errorDetails; diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java index ed33f97553..9ff1ebdb58 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java @@ -431,7 +431,7 @@ private BlobInfo definePart(BlobInfo ultimateObject, PartRange partRange, long o } private ApiFuture asyncCleanupAfterFailure(Throwable originalFailure) { - ApiFuture> pendingAndSuccessfulBlobIds = + ApiFuture> pendingAndSuccessfulBlobIds = getPendingAndSuccessfulBlobIds(exec, pendingParts, successfulParts); return ApiFutures.transformAsync( pendingAndSuccessfulBlobIds, @@ -558,21 +558,21 @@ static ParallelCompositeUploadException buildParallelCompositeUploadException( Executor exec, List> pendingParts, List successfulParts) { - ApiFuture> fCreatedObjects = + ApiFuture> fCreatedObjects = getPendingAndSuccessfulBlobIds(exec, pendingParts, successfulParts); return ParallelCompositeUploadException.of(cause, fCreatedObjects); } @NonNull - private static ApiFuture> getPendingAndSuccessfulBlobIds( + private static ApiFuture> getPendingAndSuccessfulBlobIds( Executor exec, List> pendingParts, List successfulParts) { ApiFuture> successfulList = ApiFutures.successfulAsList(pendingParts); // suppress any failure that might happen when waiting for any pending futures to resolve ApiFuture> catching = ApiFutures.catching(successfulList, Throwable.class, t2 -> ImmutableList.of(), exec); - ApiFuture> fCreatedObjects = + ApiFuture> fCreatedObjects = ApiFutures.transform( catching, l ->