diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposer.java index 8b12fa8786..b850e4801c 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposer.java @@ -20,6 +20,7 @@ import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.BatchingCallSettings; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; import com.google.api.gax.rpc.OperationCallSettings; @@ -797,6 +798,9 @@ private static TypeNode getCallSettingsTypeHelper( Class callSettingsClazz = isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class; if (protoMethod.isPaged()) { callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class; + } else if (protoMethod.isBatching()) { + callSettingsClazz = + isBuilder ? BatchingCallSettings.Builder.class : BatchingCallSettings.class; } else { switch (protoMethod.stream()) { case CLIENT: diff --git a/src/main/java/com/google/api/generator/gapic/model/GapicServiceConfig.java b/src/main/java/com/google/api/generator/gapic/model/GapicServiceConfig.java index 69f8398417..a707d109a5 100644 --- a/src/main/java/com/google/api/generator/gapic/model/GapicServiceConfig.java +++ b/src/main/java/com/google/api/generator/gapic/model/GapicServiceConfig.java @@ -159,6 +159,14 @@ public boolean hasBatchingSetting(Service service, Method method) { return batchingSettingsTable.containsKey(toName(service, method)); } + public boolean hasBatchingSetting(String protoPakkage, String serviceName, String methodName) { + return batchingSettingsTable.containsKey( + MethodConfig.Name.newBuilder() + .setService(String.format("%s.%s", protoPakkage, serviceName)) + .setMethod(methodName) + .build()); + } + public Optional getLroRetrySetting(Service service, Method method) { return hasLroRetrySetting(service, method) ? Optional.of(lroRetrySettingsTable.get(toName(service, method))) diff --git a/src/main/java/com/google/api/generator/gapic/model/Method.java b/src/main/java/com/google/api/generator/gapic/model/Method.java index 2d78b5f941..006f324904 100644 --- a/src/main/java/com/google/api/generator/gapic/model/Method.java +++ b/src/main/java/com/google/api/generator/gapic/model/Method.java @@ -37,6 +37,8 @@ public enum Stream { public abstract TypeNode outputType(); + public abstract boolean isBatching(); + public abstract boolean isPaged(); @Nullable @@ -70,6 +72,7 @@ public static Builder builder() { .setStream(Stream.NONE) .setMethodSignatures(ImmutableList.of()) .setHttpBindings(ImmutableList.of()) + .setIsBatching(false) .setIsPaged(false); } @@ -104,6 +107,8 @@ public abstract static class Builder { public abstract Builder setMethodSignatures(List> methodSignature); + public abstract Builder setIsBatching(boolean isBatching); + public abstract Builder setIsPaged(boolean isPaged); public abstract Method build(); diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index 24609344e9..86b66bb91a 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -305,7 +305,13 @@ public static List parseService( .setOriginalJavaPackage(originalJavaPackage) .setProtoPakkage(fileDescriptor.getPackage()) .setMethods( - parseMethods(s, pakkage, messageTypes, resourceNames, outputArgResourceNames)) + parseMethods( + s, + pakkage, + messageTypes, + resourceNames, + serviceConfigOpt, + outputArgResourceNames)) .build(); }) .collect(Collectors.toList()); @@ -433,6 +439,7 @@ static List parseMethods( String servicePackage, Map messageTypes, Map resourceNames, + Optional serviceConfigOpt, Set outputArgResourceNames) { List methods = new ArrayList<>(); for (MethodDescriptor protoMethod : serviceDescriptor.getMethods()) { @@ -456,6 +463,15 @@ static List parseMethods( HttpRuleParser.parseHttpBindings(protoMethod, inputMessage, messageTypes); List httpBindings = httpBindingsOpt.isPresent() ? httpBindingsOpt.get() : Collections.emptyList(); + boolean isBatching = + !serviceConfigOpt.isPresent() + ? false + : serviceConfigOpt + .get() + .hasBatchingSetting( + /* protoPakkage */ protoMethod.getFile().getPackage(), + serviceDescriptor.getName(), + protoMethod.getName()); methods.add( methodBuilder @@ -474,6 +490,7 @@ static List parseMethods( resourceNames, outputArgResourceNames)) .setHttpBindings(httpBindings) + .setIsBatching(isBatching) .setIsPaged(parseIsPaged(protoMethod, messageTypes)) .build()); diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java index 1e41473c1a..4315edc1a0 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java @@ -101,7 +101,12 @@ public void parseMethods_basic() { Set outputResourceNames = new HashSet<>(); List methods = Parser.parseMethods( - echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames); + echoService, + ECHO_PACKAGE, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); assertEquals(9, methods.size()); @@ -153,7 +158,12 @@ public void parseMethods_basicLro() { Set outputResourceNames = new HashSet<>(); List methods = Parser.parseMethods( - echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames); + echoService, + ECHO_PACKAGE, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); assertEquals(9, methods.size()); @@ -199,7 +209,12 @@ public void parseMethodSignatures_empty() { List methods = Parser.parseMethods( - echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames); + echoService, + ECHO_PACKAGE, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); assertThat( MethodSignatureParser.parseMethodSignatures( methodDescriptor, @@ -223,7 +238,12 @@ public void parseMethodSignatures_validArgstAndEmptyString() { List methods = Parser.parseMethods( - echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames); + echoService, + ECHO_PACKAGE, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); List> methodArgs = MethodSignatureParser.parseMethodSignatures( methodDescriptor, diff --git a/test/integration/goldens/logging/LoggingSettings.java b/test/integration/goldens/logging/LoggingSettings.java index dc8a40a1b9..0ffa52a7ca 100644 --- a/test/integration/goldens/logging/LoggingSettings.java +++ b/test/integration/goldens/logging/LoggingSettings.java @@ -26,6 +26,7 @@ import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.BatchingCallSettings; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; import com.google.api.gax.rpc.PagedCallSettings; @@ -87,7 +88,7 @@ public UnaryCallSettings deleteLogSettings() { } /** Returns the object with the settings used for calls to writeLogEntries. */ - public UnaryCallSettings + public BatchingCallSettings writeLogEntriesSettings() { return ((LoggingServiceV2StubSettings) getStubSettings()).writeLogEntriesSettings(); } @@ -218,7 +219,7 @@ public UnaryCallSettings.Builder deleteLogSettings() { } /** Returns the builder for the settings used for calls to writeLogEntries. */ - public UnaryCallSettings.Builder + public BatchingCallSettings.Builder writeLogEntriesSettings() { return getStubSettingsBuilder().writeLogEntriesSettings(); }