Skip to content

Commit

Permalink
Add java-storage implementation for delete buckets API. (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
shilpi23pandey committed Dec 11, 2023
1 parent 84652b2 commit 5229910
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.hadoop.gcsio;

import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageExceptions.createFileNotFoundException;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
Expand Down Expand Up @@ -404,6 +405,36 @@ public void onFailure(Throwable throwable) {
};
}

/** See {@link GoogleCloudStorage#deleteBuckets(List)} for details about expected behavior. */
@Override
public void deleteBuckets(List<String> bucketNames) throws IOException {
logger.atFiner().log("deleteBuckets(%s)", bucketNames);

// Validate all the inputs first.
for (String bucketName : bucketNames) {
checkArgument(!isNullOrEmpty(bucketName), "bucketName must not be null or empty");
}

// Gather exceptions to wrap in a composite exception at the end.
List<IOException> innerExceptions = new ArrayList<>();

for (String bucketName : bucketNames) {
try {
boolean isDeleted = storage.delete(bucketName);
if (!isDeleted) {
innerExceptions.add(createFileNotFoundException(bucketName, null, null));
}
} catch (StorageException e) {
innerExceptions.add(
new IOException(String.format("Error deleting '%s' bucket", bucketName), e));
}
}

if (!innerExceptions.isEmpty()) {
throw GoogleCloudStorageExceptions.createCompositeException(innerExceptions);
}
}

@Override
public SeekableByteChannel open(
StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions) throws IOException {
Expand Down

0 comments on commit 5229910

Please sign in to comment.