Skip to content

Commit

Permalink
chore: make ParallelCompositeUploadException public (#2245)
Browse files Browse the repository at this point in the history
Tweak public api to be List vs ImmutableList so we are not hard coded against guava.
  • Loading branch information
BenWhitehead authored Oct 5, 2023
1 parent 1adc736 commit dc6c080
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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}.
*
* <p>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<ImmutableList<BlobId>> createdObjects;
private final ApiFuture<List<BlobId>> createdObjects;

private ParallelCompositeUploadException(
Throwable cause,
StatusCode statusCode,
ErrorDetails errorDetails,
ApiFuture<ImmutableList<BlobId>> createdObjects) {
ApiFuture<List<BlobId>> createdObjects) {
super(cause, statusCode, false, errorDetails);
this.createdObjects = createdObjects;
}

public ApiFuture<ImmutableList<BlobId>> 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<List<BlobId>> getCreatedObjects() {
return createdObjects;
}

static ParallelCompositeUploadException of(
Throwable t, ApiFuture<ImmutableList<BlobId>> createdObjects) {
static ParallelCompositeUploadException of(Throwable t, ApiFuture<List<BlobId>> createdObjects) {
StatusCode statusCode;
ErrorDetails errorDetails;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private BlobInfo definePart(BlobInfo ultimateObject, PartRange partRange, long o
}

private <R> ApiFuture<R> asyncCleanupAfterFailure(Throwable originalFailure) {
ApiFuture<ImmutableList<BlobId>> pendingAndSuccessfulBlobIds =
ApiFuture<List<BlobId>> pendingAndSuccessfulBlobIds =
getPendingAndSuccessfulBlobIds(exec, pendingParts, successfulParts);
return ApiFutures.transformAsync(
pendingAndSuccessfulBlobIds,
Expand Down Expand Up @@ -558,21 +558,21 @@ static ParallelCompositeUploadException buildParallelCompositeUploadException(
Executor exec,
List<ApiFuture<BlobInfo>> pendingParts,
List<BlobId> successfulParts) {
ApiFuture<ImmutableList<BlobId>> fCreatedObjects =
ApiFuture<List<BlobId>> fCreatedObjects =
getPendingAndSuccessfulBlobIds(exec, pendingParts, successfulParts);

return ParallelCompositeUploadException.of(cause, fCreatedObjects);
}

@NonNull
private static ApiFuture<ImmutableList<BlobId>> getPendingAndSuccessfulBlobIds(
private static ApiFuture<List<BlobId>> getPendingAndSuccessfulBlobIds(
Executor exec, List<ApiFuture<BlobInfo>> pendingParts, List<BlobId> successfulParts) {
ApiFuture<List<BlobInfo>> successfulList = ApiFutures.successfulAsList(pendingParts);
// suppress any failure that might happen when waiting for any pending futures to resolve
ApiFuture<List<BlobInfo>> catching =
ApiFutures.catching(successfulList, Throwable.class, t2 -> ImmutableList.of(), exec);

ApiFuture<ImmutableList<BlobId>> fCreatedObjects =
ApiFuture<List<BlobId>> fCreatedObjects =
ApiFutures.transform(
catching,
l ->
Expand Down

0 comments on commit dc6c080

Please sign in to comment.