Skip to content

Commit f8ccd2a

Browse files
lqiu96renovate-botblakeli0meltsufinsuztomo
authored
fix: Allow custom HttpRules for REST LROs (#1288)
* fix: Allow custom http bindings for LROs * fix: Update generator and GAX to support custom HTTP Bindings for operations * fix: Use static Map for custom Operation REST Http Bindings * chore: Update golden test cases * chore: Update showcase tests * chore: Update golden ITs * chore: Add back origin HttpJsonOperationStub.create() methods * fix(deps): update dependency com.google.auth:google-auth-library-bom to v1.15.0 (#1278) * doc: Update DEVELOPMENT.md for local development. (#1237) * chore: Create a default mapping in OperationStub * chore: Do not generate custom bindings if there are none * chore: Update golden units * chore: Update all test cases * chore: Fix format issues * fix: remove constant operation binding field * chore: Clean up code * chore: Resolve sonar comments * chore: DEVELOPMENT.md formatting fix (#1289) * ci: use java-shared-dependencies in google-cloud-java repository for downstream test (#1291) * ci: use java-shared-dependencies in google-cloud-java * No need to modify google-cloud-jar-parent * fix(java): initialize netty-shaded at run-time and add reflection configurations for netty classes (#1290) * fix(java): initialize netty-shaded at run-time and add reflection configurations for netty classes * ci(showcase): disable rest_numeric_enum for showcase testing (#1284) * ci(showcase): disable rest_numeric_enum feature in showcase tests * chore(main): release 2.15.0 (#1269) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * chore(main): release 2.15.1-SNAPSHOT (#1292) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * chore: Pin Bazel version to 5.2.0 (#1304) Pin Bazel version to 5.2.0 as googleapis already updated to 5.2.0 * build(deps): bump cryptography from 38.0.3 to 39.0.1 in /.kokoro (#1297) Bumps [cryptography](https://github.com/pyca/cryptography) from 38.0.3 to 39.0.1. - [Release notes](https://github.com/pyca/cryptography/releases) - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](pyca/cryptography@38.0.3...39.0.1) --- updated-dependencies: - dependency-name: cryptography dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mridula <[email protected]> * chore: (cleanup) removing unused files (#1265) * chore: (cleanup) removing unused files * chore: working on comments * chore: removing unused Gradle files in api-common-java, gax-java, java-common-protos, and java-iam (#1305) The build is Maven or Bazel. The Gradle files in the recently migrated repositories (api-common-java, gax-java, java-common-protos, and java-iam) are not used. Note that this pull request is not touching rules_java_gapic/resources/gradle which is still used to generate Gradle files for self-service client libraries. * chore: updated gax-java contribution doc (#1334) Removing unnecessary files * fix: use pkg_tar from rules_pkg (#1303) * chore: Fix pre-commit. (#1294) * chore: update CONTRIBUTING.md (#1346) * fix(deps): update dependency io.grpc:grpc-bom to v1.53.0 (#1345) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [io.grpc:grpc-bom](https://togithub.com/grpc/grpc-java) | `1.52.1` -> `1.53.0` | [![age](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.53.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.53.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.53.0/compatibility-slim/1.52.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/io.grpc:grpc-bom/1.53.0/confidence-slim/1.52.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>grpc/grpc-java</summary> ### [`v1.53.0`](https://togithub.com/grpc/grpc-java/releases/tag/v1.53.0) [Compare Source](https://togithub.com/grpc/grpc-java/compare/v1.52.1...v1.53.0) ##### New Features - googleapis: Allow user set c2p bootstrap config ([#&#8203;9856](https://togithub.com/grpc/grpc-java/issues/9856)) - xds: Add contain and stringMatcher in `RouteConfiguration` ([#&#8203;9845](https://togithub.com/grpc/grpc-java/issues/9845)) - core: Add `grpc-previous-rpc-attempts` to the initial response metadata ([#&#8203;9686](https://togithub.com/grpc/grpc-java/issues/9686)) - servlet: Implement gRPC server as a Servlet ([#&#8203;8596](https://togithub.com/grpc/grpc-java/issues/8596)) - authz: Implement static authorization server interceptor ([#&#8203;8934](https://togithub.com/grpc/grpc-java/issues/8934)) ##### Examples - servlet: Add servlet example ([#&#8203;8596](https://togithub.com/grpc/grpc-java/issues/8596)) ##### Bug Fixes - xds: Update xds error handling logic. Specifically: - When the ads stream is closed only send errors to subscribers that haven't yet gotten results - Timers to detect missing resources don’t start until the adsStream is ready ([#&#8203;9745](https://togithub.com/grpc/grpc-java/issues/9745)) - Call subscriber onError callback when xds client fails to connect to server ([#&#8203;9827](https://togithub.com/grpc/grpc-java/issues/9827)) - core: Delay retriable stream master listener close until all sub streams are closed. This fixes the call executor lifecycle and prevents potential `RejectedExecutionException`. ([#&#8203;9754](https://togithub.com/grpc/grpc-java/issues/9754)) - core: Free unused `MessageProducer` in `RetriableStream` ([#&#8203;9853](https://togithub.com/grpc/grpc-java/issues/9853)), fixing a Netty buffer memory leak for cancelled RPCs - api: Fail with `NullPointerException` when a Metadata.Marshaller returns null bytes ([#&#8203;9781](https://togithub.com/grpc/grpc-java/issues/9781)). This would previously cause a `NullPointerException` later during the RPC. Now the return value of the Marshaller is checked immediately, to help find the broken Marshaller ##### Behavior Changes - xds: Disallow duplicate addresses in the RingHashLB. ([#&#8203;9776](https://togithub.com/grpc/grpc-java/issues/9776)) - xds: EDS weight sums are allowed up to max unsigned int (was max signed int) ([#&#8203;9765](https://togithub.com/grpc/grpc-java/issues/9765)) - xds: Drop xds v2 support ([#&#8203;9760](https://togithub.com/grpc/grpc-java/issues/9760)) ##### Dependencies - JUnit upgraded to 4.13.2 - bazel: Dropped support for Bazel 4. We track the two most recent major versions of Bazel, Bazel 5 and 6. Bazel 4 may still work, but we are no longer testing it - bazel: Include Tomcat annotations dependency for `@Generated` as used by autovalue ([#&#8203;9762](https://togithub.com/grpc/grpc-java/issues/9762)). Necessary for building xds and rls on Java 9+ - bazel: Export deps from Maven Central-specific stand-in targets ([#&#8203;9780](https://togithub.com/grpc/grpc-java/issues/9780)). Some Maven Central artifacts are a combination of multiple Bazel targets, like grpc-core is composed of //core:inprocess, //core:internal, //core:util, //api. There is a “//core:core_maven” target used by maven_install that uses the other targets. Previously the target used `runtime_deps` to discourage their use by Bazel users, but that could cause compilation failures from lack of hjars. These targets now use `exports` ##### Acknowledgement [@&#8203;cpovirk](https://togithub.com/cpovirk) [@&#8203;niloc132](https://togithub.com/niloc132) [@&#8203;stephenh](https://togithub.com/stephenh) [@&#8203;olderwei](https://togithub.com/olderwei) [@&#8203;pandaapo](https://togithub.com/pandaapo) [@&#8203;panxuefeng](https://togithub.com/panxuefeng) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTQuMCIsInVwZGF0ZWRJblZlciI6IjM0LjEyNS4xIn0=--> * chore(deps): update dependency org.apache.maven.plugins:maven-deploy-plugin to v3.1.0 (#1340) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [org.apache.maven.plugins:maven-deploy-plugin](https://maven.apache.org/plugins/) | `3.0.0` -> `3.1.0` | [![age](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.0/compatibility-slim/3.0.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.0/confidence-slim/3.0.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTQuMCIsInVwZGF0ZWRJblZlciI6IjM0LjEyNS4xIn0=--> * chore(deps): update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.0.0-m9 (#1350) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [org.apache.maven.plugins:maven-surefire-plugin](https://maven.apache.org/surefire/) | `3.0.0-M8` -> `3.0.0-M9` | [![age](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M9/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M9/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M9/compatibility-slim/3.0.0-M8)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M9/confidence-slim/3.0.0-M8)](https://docs.renovatebot.com/merge-confidence/) | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-generator-java). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMjUuMSIsInVwZGF0ZWRJblZlciI6IjM0LjEyNS4xIn0=--> * chore: add rules_pkg to renovate bot ignoreDeps (#1349) Following up on https://togithub.com/googleapis/gapic-generator-java/pull/1338, suppressing renovate PRs for the `rules_pkg` dependency since it will need to align with version used in googleapis. * chore: fix renovate bot ignoreDeps (#1353) Fixes #1352, from missed separator in #1349's changes. * fix(batcher): exceptions in unaryCaller bubble up (#1166) Co-authored-by: Blake Li <[email protected]> * fix(deps): update dependency com.google.auth:google-auth-library-bom to v1.16.0 (#1355) * chore(deps): update dependency org.apache.maven.plugins:maven-javadoc-plugin to v3.5.0 (#1356) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [org.apache.maven.plugins:maven-javadoc-plugin](https://maven.apache.org/plugins/) | `3.4.1` -> `3.5.0` | [![age](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.5.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.5.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.5.0/compatibility-slim/3.4.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.5.0/confidence-slim/3.4.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-generator-java). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMjUuMSIsInVwZGF0ZWRJblZlciI6IjM0LjEyNS4xIn0=--> * chore(main): release 2.15.1 (#1339) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Emily Wang <[email protected]> * chore: refactoring README and DEVELOPMENT.md (#1351) Thank you for opening a Pull Request! For general contributing guidelines, please refer to [contributing guide](https://togithub.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md) - The old file https://togithub.com/googleapis/gapic-generator-java/blob/main/gapic-generator-java/DEVELOPMENT.md was last touched in mid December. I'm replacing the content with the latest at the root. - Removing the root DEVELOPMENT.md in favor of the file above. - Adding index of the modules at the root README.md - Moving showcase testing guide to showcase/README.md. * chore(main): release 2.15.2-SNAPSHOT (#1358) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * chore: renovate to group Protobuf artifacts (#1362) Copying packageGroup configuration from https://togithub.com/googleapis/synthtool/blob/master/synthtool/gcp/templates/java_library/renovate.json This should avoid separate pull requests for Protobuf: https://togithub.com/googleapis/gapic-generator-java/pull/1155 and https://togithub.com/googleapis/gapic-generator-java/pull/1154 * chore: README.md to explain service_config.proto (#1361) * chore: README.md to explain service_config.proto * add link * chore: Telling owlbot to ignore these files & it's a monorepo (#1372) * chore: Telling owlbot to ignore these files & it's a monorepo * fix: Change the default scope of gax from implementation to api in auto-generated gradle files for self-service client libraries. (#1374) * chore: Update variable name * chore: Fix format issues * fix: Use HttpRule as Value for Custom Bindings * fix: Use HttpRule as Value for Custom Bindings * chore: Add comments * chore: Update tests * fix(deps): update dependency com.google.auth:google-auth-library-bom to v1.15.0 (#1278) * doc: Update DEVELOPMENT.md for local development. (#1237) * chore: Add tests * chore: Cleanup files * chore: Format the files * chore: Add NoCredentialsProvider * chore: Fix sonar comments * chore: Add serviceyaml file for parsing for rest showcase tests * chore: Use service yaml file in test * chore: Fix Echo showcase test * chore: Clean up tests * chore: Sort the map entry to get a consistent ordering for the test * chore: Update showcase and integration tests * chore: Resolve sonar comments * chore: Update comments * chore: Remove a few public constructors * chore: test ci * chore: Remove the cache for java 8 * chore: Update from PR feedback * chore: Update comments * chore: Fix sonar issue * chore: Fix comment * chore: Update to have multiple additional_bindings * chore: Update grpcrest golden test to include httprule * chore: HttpJsonOperationsStub's MethodDescriptors are not static * chore: Add unit tests for HttpJson Operations logic * chore: Resolve lint issues * chore: Clean up test code * chore: Resolve pr comments * chore: Add VisibleForTesting annotation --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Mend Renovate <[email protected]> Co-authored-by: Blake Li <[email protected]> Co-authored-by: Mike Eltsufin <[email protected]> Co-authored-by: Tomo Suzuki <[email protected]> Co-authored-by: Mridula <[email protected]> Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Deepankar Dixit <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]> Co-authored-by: Joe Wang <[email protected]> Co-authored-by: Emily Wang <[email protected]> Co-authored-by: Diego Alonso Marquez Palacios <[email protected]>
1 parent 84036c7 commit f8ccd2a

File tree

17 files changed

+1528
-139
lines changed

17 files changed

+1528
-139
lines changed

.github/workflows/ci-maven.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ jobs:
106106
with:
107107
java-version: 8
108108
distribution: temurin
109-
cache: maven
110109
- run: java -version
111110
- name: Run tests in Java 8 with the source compiled in Java 11 for gapic-generator-java
112111
shell: bash

DEVELOPMENT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ for gapic-generator-java's Bazel build.
3838

3939
```sh
4040
mvn fmt:format
41-
```
41+
```

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractTransportServiceStubClassComposer.java

+2
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ protected List<MethodDefinition> createConstructorMethods(
649649
if (generateOperationsStubLogic(service)) {
650650
secondCtorExprs.addAll(
651651
createOperationsStubInitExpr(
652+
context,
652653
service,
653654
thisExpr,
654655
operationsStubClassVarExpr,
@@ -758,6 +759,7 @@ protected List<MethodDefinition> createConstructorMethods(
758759
}
759760

760761
protected List<Expr> createOperationsStubInitExpr(
762+
GapicContext context,
761763
Service service,
762764
Expr thisExpr,
763765
VariableExpr operationsStubClassVarExpr,

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java

+115-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.api.generator.gapic.composer.rest;
1616

17+
import com.google.api.HttpRule;
1718
import com.google.api.core.InternalApi;
1819
import com.google.api.gax.httpjson.ApiMethodDescriptor;
1920
import com.google.api.gax.httpjson.ApiMethodDescriptor.MethodType;
@@ -63,6 +64,7 @@
6364
import com.google.common.annotations.VisibleForTesting;
6465
import com.google.common.collect.BiMap;
6566
import com.google.common.collect.ImmutableList;
67+
import com.google.common.collect.ImmutableMap;
6668
import com.google.protobuf.TypeRegistry;
6769
import java.util.ArrayList;
6870
import java.util.Arrays;
@@ -73,10 +75,10 @@
7375
import java.util.Set;
7476
import java.util.function.BiFunction;
7577
import java.util.function.Function;
78+
import java.util.function.Predicate;
7679
import java.util.stream.Collectors;
7780

7881
public class HttpJsonServiceStubClassComposer extends AbstractTransportServiceStubClassComposer {
79-
8082
private static final HttpJsonServiceStubClassComposer INSTANCE =
8183
new HttpJsonServiceStubClassComposer();
8284

@@ -89,6 +91,7 @@ public class HttpJsonServiceStubClassComposer extends AbstractTransportServiceSt
8991
.setType(FIXED_REST_TYPESTORE.get(TypeRegistry.class.getSimpleName()))
9092
.build())
9193
.build();
94+
private static final String LRO_NAME_PREFIX = "google.longrunning.Operations";
9295

9396
protected HttpJsonServiceStubClassComposer() {
9497
super(RestContext.instance());
@@ -109,7 +112,9 @@ private static TypeStore createStaticTypes() {
109112
HttpJsonCallSettings.class,
110113
HttpJsonOperationSnapshot.class,
111114
HttpJsonStubCallableFactory.class,
115+
HttpRule.class,
112116
Map.class,
117+
ImmutableMap.class,
113118
ProtoMessageRequestFormatter.class,
114119
ProtoMessageResponseParser.class,
115120
ProtoRestSerializer.class,
@@ -1075,6 +1080,7 @@ private List<Expr> getMethodTypeExpr(Method protoMethod) {
10751080

10761081
@Override
10771082
protected List<Expr> createOperationsStubInitExpr(
1083+
GapicContext context,
10781084
Service service,
10791085
Expr thisExpr,
10801086
VariableExpr operationsStubClassVarExpr,
@@ -1089,6 +1095,47 @@ protected List<Expr> createOperationsStubInitExpr(
10891095
arguments.add(TYPE_REGISTRY_VAR_EXPR);
10901096
}
10911097

1098+
// If the Service contains custom HttpRules for Operations, we pass a map of the custom rules to
1099+
// the Operations Client
1100+
Map<String, HttpRule> operationCustomHttpRules = parseOperationsCustomHttpRules(context);
1101+
if (operationCustomHttpRules.size() > 0) {
1102+
Expr operationCustomHttpBindingsBuilderExpr =
1103+
MethodInvocationExpr.builder()
1104+
.setStaticReferenceType(FIXED_REST_TYPESTORE.get(ImmutableMap.class.getSimpleName()))
1105+
.setMethodName("builder")
1106+
.setGenerics(
1107+
Arrays.asList(
1108+
TypeNode.STRING.reference(),
1109+
FIXED_REST_TYPESTORE.get(HttpRule.class.getSimpleName()).reference()))
1110+
.build();
1111+
1112+
// Sorting is done to ensure consistent ordering of the entries in the Custom HttpRule Map
1113+
for (String selector :
1114+
operationCustomHttpRules.keySet().stream().sorted().collect(Collectors.toList())) {
1115+
HttpRule httpRule = operationCustomHttpRules.get(selector);
1116+
Expr httpRuleBuilderExpr = createHttpRuleExpr(httpRule, true);
1117+
1118+
operationCustomHttpBindingsBuilderExpr =
1119+
MethodInvocationExpr.builder()
1120+
.setExprReferenceExpr(operationCustomHttpBindingsBuilderExpr)
1121+
.setMethodName("put")
1122+
.setArguments(
1123+
Arrays.asList(
1124+
ValueExpr.withValue(StringObjectValue.withValue(selector)),
1125+
httpRuleBuilderExpr))
1126+
.build();
1127+
}
1128+
1129+
operationCustomHttpBindingsBuilderExpr =
1130+
MethodInvocationExpr.builder()
1131+
.setExprReferenceExpr(operationCustomHttpBindingsBuilderExpr)
1132+
.setMethodName("build")
1133+
.setReturnType(FIXED_REST_TYPESTORE.get(ImmutableMap.class.getSimpleName()))
1134+
.build();
1135+
1136+
arguments.add(operationCustomHttpBindingsBuilderExpr);
1137+
}
1138+
10921139
return Collections.singletonList(
10931140
AssignmentExpr.builder()
10941141
.setVariableExpr(
@@ -1103,6 +1150,73 @@ protected List<Expr> createOperationsStubInitExpr(
11031150
.build());
11041151
}
11051152

1153+
/* Build an Expr that creates an HttpRule. Creates a builder and adds the http verb, custom path, and any additional bindings. `additional_bindings` can only be nested one layer deep, so we only check once */
1154+
private Expr createHttpRuleExpr(HttpRule httpRule, boolean checkAdditionalBindings) {
1155+
Expr httpRuleBuilderExpr =
1156+
MethodInvocationExpr.builder()
1157+
.setStaticReferenceType(FIXED_REST_TYPESTORE.get(HttpRule.class.getSimpleName()))
1158+
.setMethodName("newBuilder")
1159+
.build();
1160+
1161+
httpRuleBuilderExpr =
1162+
MethodInvocationExpr.builder()
1163+
.setExprReferenceExpr(httpRuleBuilderExpr)
1164+
// toLowerCase as the PatternCase result is all uppercase
1165+
.setMethodName(setMethodFormat(httpRule.getPatternCase().toString().toLowerCase()))
1166+
.setArguments(
1167+
ValueExpr.withValue(
1168+
StringObjectValue.withValue(getOperationsURIValueFromHttpRule(httpRule))))
1169+
.setReturnType(FIXED_REST_TYPESTORE.get(HttpRule.class.getSimpleName()))
1170+
.build();
1171+
1172+
if (checkAdditionalBindings) {
1173+
for (HttpRule additionalBindings : httpRule.getAdditionalBindingsList()) {
1174+
httpRuleBuilderExpr =
1175+
MethodInvocationExpr.builder()
1176+
.setExprReferenceExpr(httpRuleBuilderExpr)
1177+
.setMethodName("addAdditionalBindings")
1178+
.setArguments(Arrays.asList(createHttpRuleExpr(additionalBindings, false)))
1179+
.build();
1180+
}
1181+
}
1182+
1183+
httpRuleBuilderExpr =
1184+
MethodInvocationExpr.builder()
1185+
.setExprReferenceExpr(httpRuleBuilderExpr)
1186+
.setMethodName("build")
1187+
.setReturnType(FIXED_REST_TYPESTORE.get(HttpRule.class.getSimpleName()))
1188+
.build();
1189+
return httpRuleBuilderExpr;
1190+
}
1191+
1192+
/* Parses the Service Yaml file's for custom HttpRules. Filter the HttpRules for ones that match Operations */
1193+
Map<String, HttpRule> parseOperationsCustomHttpRules(GapicContext context) {
1194+
Predicate<HttpRule> predicate = x -> x.getSelector().contains(LRO_NAME_PREFIX);
1195+
com.google.api.Service service = context.serviceYamlProto();
1196+
if (service == null || service.getHttp() == null) {
1197+
return ImmutableMap.of();
1198+
}
1199+
return service.getHttp().getRulesList().stream()
1200+
.filter(predicate)
1201+
.collect(Collectors.toMap(HttpRule::getSelector, x -> x));
1202+
}
1203+
1204+
/* This is meant to be used for the OperationsClient Mixin OperationsClient's RPCs are mapped to GET/POST/DELETE and this function only expects those HttpVerbs to be used */
1205+
String getOperationsURIValueFromHttpRule(HttpRule httpRule) {
1206+
switch (httpRule.getPatternCase().getNumber()) {
1207+
case 2:
1208+
return httpRule.getGet();
1209+
case 4:
1210+
return httpRule.getPost();
1211+
case 5:
1212+
return httpRule.getDelete();
1213+
default:
1214+
throw new IllegalArgumentException(
1215+
"Operations HttpRule should only contain GET/POST/DELETE. Invalid: "
1216+
+ httpRule.getSelector());
1217+
}
1218+
}
1219+
11061220
@Override
11071221
protected List<Statement> createLongRunningClient(Service service, TypeStore typeStore) {
11081222
Method pollingMethod = service.operationPollingMethod();

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/GrpcRestTestProtoLoader.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.api.generator.gapic.composer.grpcrest;
1616

17+
import static com.google.common.truth.Truth.assertThat;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertTrue;
1920

@@ -26,6 +27,7 @@
2627
import com.google.api.generator.gapic.model.Transport;
2728
import com.google.api.generator.gapic.protoparser.Parser;
2829
import com.google.api.generator.gapic.protoparser.ServiceConfigParser;
30+
import com.google.api.generator.gapic.protoparser.ServiceYamlParser;
2931
import com.google.longrunning.OperationsProto;
3032
import com.google.protobuf.Descriptors.FileDescriptor;
3133
import com.google.protobuf.Descriptors.ServiceDescriptor;
@@ -58,6 +60,13 @@ public GapicContext parseShowcaseEcho() {
5860
ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0);
5961
assertEquals("Echo", echoServiceDescriptor.getName());
6062

63+
String serviceYamlFileName = "echo_v1beta1.yaml";
64+
Path serviceYamlPath = Paths.get(getTestFilesDirectory(), serviceYamlFileName);
65+
Optional<com.google.api.Service> serviceYamlOpt =
66+
ServiceYamlParser.parse(serviceYamlPath.toString());
67+
assertThat(serviceYamlOpt.isPresent()).isTrue();
68+
com.google.api.Service service = serviceYamlOpt.get();
69+
6170
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
6271
messageTypes.putAll(Parser.parseMessages(OperationsProto.getDescriptor()));
6372
messageTypes.putAll(Parser.parseMessages(StructProto.getDescriptor()));
@@ -66,7 +75,7 @@ public GapicContext parseShowcaseEcho() {
6675
Set<ResourceName> outputResourceNames = new HashSet<>();
6776
List<Service> services =
6877
Parser.parseService(
69-
echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
78+
echoFileDescriptor, messageTypes, resourceNames, serviceYamlOpt, outputResourceNames);
7079

7180
String jsonFilename = "showcase_grpc_service_config.json";
7281
Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename);
@@ -79,6 +88,7 @@ public GapicContext parseShowcaseEcho() {
7988
.setResourceNames(resourceNames)
8089
.setServices(services)
8190
.setServiceConfig(config)
91+
.setServiceYamlProto(service)
8292
.setHelperResourceNames(outputResourceNames)
8393
.setTransport(getTransport())
8494
.build();

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/HttpJsonEchoStub.golden

+52-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.google.showcase.grpcrest.v1beta1.stub;
33
import static com.google.showcase.grpcrest.v1beta1.EchoClient.PagedExpandPagedResponse;
44
import static com.google.showcase.grpcrest.v1beta1.EchoClient.SimplePagedExpandPagedResponse;
55

6+
import com.google.api.HttpRule;
67
import com.google.api.core.BetaApi;
78
import com.google.api.core.InternalApi;
89
import com.google.api.gax.core.BackgroundResource;
@@ -21,6 +22,7 @@ import com.google.api.gax.rpc.ClientContext;
2122
import com.google.api.gax.rpc.OperationCallable;
2223
import com.google.api.gax.rpc.ServerStreamingCallable;
2324
import com.google.api.gax.rpc.UnaryCallable;
25+
import com.google.common.collect.ImmutableMap;
2426
import com.google.longrunning.Operation;
2527
import com.google.protobuf.TypeRegistry;
2628
import com.google.showcase.grpcrest.v1beta1.BlockRequest;
@@ -382,7 +384,56 @@ public class HttpJsonEchoStub extends EchoStub {
382384
throws IOException {
383385
this.callableFactory = callableFactory;
384386
this.httpJsonOperationsStub =
385-
HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry);
387+
HttpJsonOperationsStub.create(
388+
clientContext,
389+
callableFactory,
390+
typeRegistry,
391+
ImmutableMap.<String, HttpRule>builder()
392+
.put(
393+
"google.longrunning.Operations.CancelOperation",
394+
HttpRule.newBuilder()
395+
.setPost("/v1beta1/{name=operations/**}:cancel")
396+
.addAdditionalBindings(
397+
HttpRule.newBuilder()
398+
.setPost("/v1beta2/{name=operations/**}:cancel")
399+
.build())
400+
.addAdditionalBindings(
401+
HttpRule.newBuilder()
402+
.setPost("/v1beta3/{name=operations/**}:cancel")
403+
.build())
404+
.build())
405+
.put(
406+
"google.longrunning.Operations.DeleteOperation",
407+
HttpRule.newBuilder()
408+
.setDelete("/v1beta1/{name=operations/**}")
409+
.addAdditionalBindings(
410+
HttpRule.newBuilder()
411+
.setDelete("/v1beta2/{name=operations/**}")
412+
.build())
413+
.addAdditionalBindings(
414+
HttpRule.newBuilder()
415+
.setDelete("/v1beta3/{name=operations/**}")
416+
.build())
417+
.build())
418+
.put(
419+
"google.longrunning.Operations.GetOperation",
420+
HttpRule.newBuilder()
421+
.setGet("/v1beta1/{name=operations/**}")
422+
.addAdditionalBindings(
423+
HttpRule.newBuilder().setGet("/v1beta2/{name=operations/**}").build())
424+
.addAdditionalBindings(
425+
HttpRule.newBuilder().setGet("/v1beta3/{name=operations/**}").build())
426+
.build())
427+
.put(
428+
"google.longrunning.Operations.ListOperations",
429+
HttpRule.newBuilder()
430+
.setGet("/v1beta1/operations")
431+
.addAdditionalBindings(
432+
HttpRule.newBuilder().setGet("/v1beta2/operations").build())
433+
.addAdditionalBindings(
434+
HttpRule.newBuilder().setGet("/v1beta3/operations").build())
435+
.build())
436+
.build());
386437

387438
HttpJsonCallSettings<EchoRequest, EchoResponse> echoTransportSettings =
388439
HttpJsonCallSettings.<EchoRequest, EchoResponse>newBuilder()

0 commit comments

Comments
 (0)