forked from googleapis/java-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add support for partial success in ListBuckets for grpc #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dhriti07
wants to merge
9
commits into
nidhiii-27:list-buckets
Choose a base branch
from
Dhriti07:pr-3404-merge
base: list-buckets
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a0adf4
feat: adding support for grpc partial list buckets
8907f91
Cleaning up after merge and formatting fixes
21d0483
more cleanup
6e2b21b
Merge branch 'list-buckets' into pr-3404-merge
Dhriti07 f14fb68
cleanup
cb2a934
Adding more tests
7b6079d
Resolving comments
4168e9d
Merge branch 'list-buckets' into pr-3404-merge
Dhriti07 d0f3f90
Updating according to base pr test changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,26 +454,37 @@ public Page<Bucket> list(BucketListOption... options) { | |
| Opts<BucketListOpt> opts = Opts.unwrap(options).prepend(defaultOpts).prepend(ALL_BUCKET_FIELDS); | ||
| GrpcCallContext grpcCallContext = | ||
| opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); | ||
| ListBucketsRequest request = | ||
| ListBucketsRequest.Builder builder = | ||
| defaultProjectId | ||
| .get() | ||
| .listBuckets() | ||
| .andThen(opts.listBucketsRequest()) | ||
| .apply(ListBucketsRequest.newBuilder()) | ||
| .build(); | ||
| try { | ||
| GrpcCallContext merge = Utils.merge(grpcCallContext, Retrying.newCallContext()); | ||
| return retrier.run( | ||
| retryAlgorithmManager.getFor(request), | ||
| () -> storageClient.listBucketsPagedCallable().call(request, merge), | ||
| resp -> | ||
| new TransformingPageDecorator<>( | ||
| resp.getPage(), | ||
| syntaxDecoders.bucket.andThen(opts.clearBucketFields()), | ||
| retrier, | ||
| retryAlgorithmManager.getFor(request))); | ||
| } catch (Exception e) { | ||
| throw StorageException.coalesce(e); | ||
| .apply(ListBucketsRequest.newBuilder()); | ||
|
|
||
| final ListBucketsRequest request = builder.build(); | ||
| if (!request.getReturnPartialSuccess()) { | ||
| try { | ||
| GrpcCallContext merge = Utils.merge(grpcCallContext, Retrying.newCallContext()); | ||
| return retrier.run( | ||
| retryAlgorithmManager.getFor(request), | ||
| () -> storageClient.listBucketsPagedCallable().call(request, merge), | ||
| resp -> | ||
| new TransformingPageDecorator<>( | ||
| resp.getPage(), | ||
| syntaxDecoders.bucket.andThen(opts.clearBucketFields()), | ||
| retrier, | ||
| retryAlgorithmManager.getFor(request))); | ||
| } catch (Exception e) { | ||
| throw StorageException.coalesce(e); | ||
| } | ||
| } else { | ||
| // New logic for partial success | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove redundant comment |
||
| try { | ||
| com.google.storage.v2.ListBucketsResponse response = listBuckets(grpcCallContext, request); | ||
| return new ListBucketsWithPartialSuccessPage(grpcCallContext, request, response, opts); | ||
| } catch (Exception e) { | ||
| throw StorageException.coalesce(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1619,6 +1630,79 @@ public Iterable<Blob> getValues() { | |
| } | ||
| } | ||
|
|
||
| private final class ListBucketsWithPartialSuccessPage implements Page<Bucket> { | ||
|
|
||
| private final GrpcCallContext ctx; | ||
| private final ListBucketsRequest req; | ||
| private final com.google.storage.v2.ListBucketsResponse resp; | ||
| private final Opts<BucketListOpt> opts; | ||
|
|
||
| private ListBucketsWithPartialSuccessPage( | ||
| GrpcCallContext ctx, | ||
| ListBucketsRequest req, | ||
| com.google.storage.v2.ListBucketsResponse resp, | ||
| Opts<BucketListOpt> opts) { | ||
| this.ctx = ctx; | ||
| this.req = req; | ||
| this.resp = resp; | ||
| this.opts = opts; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasNextPage() { | ||
| return !resp.getNextPageToken().isEmpty(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getNextPageToken() { | ||
| return resp.getNextPageToken(); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Bucket> getNextPage() { | ||
| if (!hasNextPage()) { | ||
| return null; | ||
| } | ||
| ListBucketsRequest nextPageReq = | ||
| req.toBuilder().setPageToken(resp.getNextPageToken()).build(); | ||
| try { | ||
| com.google.storage.v2.ListBucketsResponse nextPageResp = | ||
| listBuckets(ctx, nextPageReq); | ||
| return new ListBucketsWithPartialSuccessPage(ctx, nextPageReq, nextPageResp, opts); | ||
| } catch (Exception e) { | ||
| throw StorageException.coalesce(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<Bucket> getValues() { | ||
| Decoder<com.google.storage.v2.Bucket, Bucket> bucketDecoder = | ||
| syntaxDecoders.bucket.andThen(opts.clearBucketFields()); | ||
| Stream<Bucket> reachable = resp.getBucketsList().stream().map(bucketDecoder::decode); | ||
| Stream<Bucket> unreachable = | ||
| resp.getUnreachableList().stream() | ||
| .map( | ||
| name -> { | ||
| String encoded = bucketNameCodec.encode(name); | ||
| return BucketInfo.newBuilder(encoded) | ||
| .setIsUnreachable(true) | ||
| .build() | ||
| .asBucket(GrpcStorageImpl.this); | ||
| }); | ||
| return Streams.concat(reachable, unreachable).collect(ImmutableList.toImmutableList()); | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<Bucket> iterateAll() { | ||
| Page<Bucket> curr = this; | ||
| return () -> | ||
| streamIterate(curr, p -> p != null && p.hasNextPage(), Page::getNextPage) | ||
| .filter(Objects::nonNull) | ||
| .flatMap(p -> StreamSupport.stream(p.getValues().spliterator(), false)) | ||
| .iterator(); | ||
| } | ||
| } | ||
|
|
||
| static final class TransformingPageDecorator< | ||
| RequestT, | ||
| ResponseT, | ||
|
|
@@ -1858,6 +1942,15 @@ private SourceObject sourceObjectEncode(SourceBlob from) { | |
| return to.build(); | ||
| } | ||
|
|
||
| private com.google.storage.v2.ListBucketsResponse listBuckets( | ||
| GrpcCallContext grpcCallContext, ListBucketsRequest request) { | ||
| GrpcCallContext merge = Utils.merge(grpcCallContext, Retrying.newCallContext()); | ||
| return retrier.run( | ||
| retryAlgorithmManager.getFor(request), | ||
| () -> storageClient.listBucketsCallable().call(request, merge), | ||
| Decoder.identity()); | ||
| } | ||
|
|
||
| private com.google.storage.v2.Bucket getBucketWithDefaultAcls(String bucketName) { | ||
| Fields fields = | ||
| UnifiedOpts.fields( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for breaking this to new line, rather than keeping it above as ListBucketRequest