feat: implement GrpcStorageImpl#delete(String, BucketSourceOption)
feat: introduce delete bucket for gRPC
@@ -25,6 +25,7 @@ import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.Page;
+import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.BaseService;
@@ -43,6 +44,7 @@ import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.storage.v2.BucketName;
import com.google.storage.v2.CreateBucketRequest;
+import com.google.storage.v2.DeleteBucketRequest;
import com.google.storage.v2.DeleteHmacKeyRequest;
import com.google.storage.v2.GetBucketRequest;
import com.google.storage.v2.GetObjectRequest;
@@ -333,7 +335,29 @@ final class GrpcStorageImpl extends BaseService<StorageOptions> implements Stora
@Override
public boolean delete(String bucket, BucketSourceOption... options) {
- return todo();
+ final Map<StorageRpc.Option, ?> optionsMap = StorageImpl.optionMap(options);
+ DeleteBucketRequest.Builder bucketRequestBuilder =
+ DeleteBucketRequest.newBuilder()
+ .setName(BucketName.format(this.getOptions().getProjectId(), bucket));
+ ifNonNull(
+ (Long) optionsMap.get(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH),
+ bucketRequestBuilder::setIfMetagenerationNotMatch);
+ ifNonNull(
+ (Long) optionsMap.get(StorageRpc.Option.IF_METAGENERATION_MATCH),
+ bucketRequestBuilder::setIfMetagenerationNotMatch);
+ DeleteBucketRequest req = bucketRequestBuilder.build();
+ try {
+ Retrying.run(
+ getOptions(),
+ retryAlgorithmManager.getFor(req),
+ () -> grpcStorageStub.deleteBucketCallable().call(req),
+ Decoder.identity());
+ return true;
+ } catch (ApiException e) {
+ // TODO: We should throw a StorageException instead of ApiException when making the
+ // deleteBucketCallable().call(req)
+ return false;
+ }
}
@Override
