Skip to content

Commit be0453d

Browse files
committed
feat(generator): emit resumable upload settings and HttpJson upload stub
Adds generator support for protocol-specific resumable upload options, independent of any transport stub wiring: - Emit ResumableUploadCallSettings on the generated <Service>Settings and <Service>StubSettings, populated with global timeouts extracted from the service config while bypassing standard unary retries. - Add HttpJsonServiceResumableUploadStubClassComposer, which generates the dedicated REST stub (HttpJson[Service]ResumableUploadStub) for services containing resumable upload RPC methods. - Extract HttpJsonDescriptorComposer out of HttpJsonServiceStubClassComposer and add path prefix support. Pure refactor with no golden changes, reused by the upload stub composer above. Supersedes #14318 and #14320, which are folded in here.
1 parent acc1856 commit be0453d

16 files changed

Lines changed: 2531 additions & 698 deletions

‎sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public class SettingsCommentComposer {
7878
public static final CommentStatement DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT =
7979
toCommentStatement("Returns a builder for the default credentials for this service.");
8080

81+
public static final CommentStatement SET_HTTP_JSON_INTERNAL_HEADER_PROVIDER_METHOD_COMMENT =
82+
toCommentStatement(
83+
"Sets the internal HeaderProvider for HTTP/JSON. Does not change the transport.");
84+
8185
public static final CommentStatement DEFAULT_TRANSPORT_PROVIDER_BUILDER_METHOD_COMMENT =
8286
toCommentStatement("Returns a builder for the default ChannelProvider for this service.");
8387

@@ -130,6 +134,16 @@ public static CommentStatement createCallSettingsGetterComment(
130134
isMethodInternal);
131135
}
132136

137+
private static final String RESUMABLE_UPLOAD_CALL_SETTINGS_DOC_NOTE =
138+
"Note that the settings configured here apply strictly to the initial session initiation"
139+
+ " request, and not to the subsequent data transfer requests.";
140+
141+
public static CommentStatement createResumableUploadCallSettingsGetterComment(
142+
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
143+
return createResumableUploadCallSettingsComment(
144+
CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName, isMethodDeprecated, isMethodInternal);
145+
}
146+
133147
public static CommentStatement createBuilderClassComment(String outerClassName) {
134148
return toCommentStatement(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName));
135149
}
@@ -140,6 +154,30 @@ public static CommentStatement createCallSettingsBuilderGetterComment(
140154
return toCommentStatement(methodComment, isMethodDeprecated, isMethodInternal);
141155
}
142156

157+
public static CommentStatement createResumableUploadCallSettingsBuilderGetterComment(
158+
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
159+
return createResumableUploadCallSettingsComment(
160+
CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN,
161+
javaMethodName,
162+
isMethodDeprecated,
163+
isMethodInternal);
164+
}
165+
166+
private static CommentStatement createResumableUploadCallSettingsComment(
167+
String pattern, String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
168+
JavaDocComment.Builder docBuilder =
169+
JavaDocComment.builder()
170+
.addComment(String.format(pattern, javaMethodName))
171+
.addParagraph(RESUMABLE_UPLOAD_CALL_SETTINGS_DOC_NOTE);
172+
if (isMethodDeprecated) {
173+
docBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
174+
}
175+
if (isMethodInternal) {
176+
docBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING);
177+
}
178+
return CommentStatement.withComment(docBuilder.build());
179+
}
180+
143181
public static List<CommentStatement> createClassHeaderComments(
144182
String configuredClassName,
145183
String defaultHost,

‎sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.gax.rpc.ClientSettings;
2626
import com.google.api.gax.rpc.OperationCallSettings;
2727
import com.google.api.gax.rpc.PagedCallSettings;
28+
import com.google.api.gax.rpc.ResumableUploadCallSettings;
2829
import com.google.api.gax.rpc.ServerStreamingCallSettings;
2930
import com.google.api.gax.rpc.StreamingCallSettings;
3031
import com.google.api.gax.rpc.StubSettings;
@@ -153,7 +154,7 @@ private static List<CommentStatement> createClassHeaderComments(
153154
// list.
154155
List<Method> publicMethods =
155156
service.methods().stream()
156-
.filter(m -> m.isInternalApi() == false)
157+
.filter(m -> !m.isInternalApi() && !m.isResumableUpload())
157158
.collect(Collectors.toList());
158159
Optional<Method> methodOpt =
159160
publicMethods.isEmpty()
@@ -311,12 +312,18 @@ private static List<MethodDefinition> createSettingsGetterMethods(
311312
// Add method header comment statements and annotations.
312313
private static MethodDefinition methodBuilderHelper(
313314
Method protoMethod, MethodDefinition.Builder methodBuilder, String javaMethodName) {
314-
return methodBuilder
315-
.setHeaderCommentStatements(
316-
SettingsCommentComposer.createCallSettingsGetterComment(
315+
CommentStatement commentStatement =
316+
protoMethod.isResumableUpload()
317+
? SettingsCommentComposer.createResumableUploadCallSettingsGetterComment(
318+
getMethodNameFromSettingsVarName(javaMethodName),
319+
protoMethod.isDeprecated(),
320+
protoMethod.isInternalApi())
321+
: SettingsCommentComposer.createCallSettingsGetterComment(
317322
getMethodNameFromSettingsVarName(javaMethodName),
318323
protoMethod.isDeprecated(),
319-
protoMethod.isInternalApi()))
324+
protoMethod.isInternalApi());
325+
return methodBuilder
326+
.setHeaderCommentStatements(commentStatement)
320327
.setAnnotations(createMethodAnnotations(protoMethod))
321328
.build();
322329
}
@@ -794,13 +801,19 @@ private static List<MethodDefinition> createNestedBuilderSettingsGetterMethods(
794801
String javaMethodName = String.format("%sSettings", javaStyleName);
795802
MethodDefinition.Builder methodBuilder =
796803
methodMakerFn.apply(getCallSettingsBuilderType(protoMethod, typeStore), javaMethodName);
804+
CommentStatement commentStatement =
805+
protoMethod.isResumableUpload()
806+
? SettingsCommentComposer.createResumableUploadCallSettingsBuilderGetterComment(
807+
getMethodNameFromSettingsVarName(javaMethodName),
808+
protoMethod.isDeprecated(),
809+
protoMethod.isInternalApi())
810+
: SettingsCommentComposer.createCallSettingsBuilderGetterComment(
811+
getMethodNameFromSettingsVarName(javaMethodName),
812+
protoMethod.isDeprecated(),
813+
protoMethod.isInternalApi());
797814
javaMethods.add(
798815
methodBuilder
799-
.setHeaderCommentStatements(
800-
SettingsCommentComposer.createCallSettingsBuilderGetterComment(
801-
getMethodNameFromSettingsVarName(javaMethodName),
802-
protoMethod.isDeprecated(),
803-
protoMethod.isInternalApi()))
816+
.setHeaderCommentStatements(commentStatement)
804817
.setAnnotations(createMethodAnnotations(protoMethod))
805818
.build());
806819

@@ -856,6 +869,7 @@ private static TypeStore createStaticTypes() {
856869
Operation.class,
857870
OperationCallSettings.class,
858871
PagedCallSettings.class,
872+
ResumableUploadCallSettings.class,
859873
ServerStreamingCallSettings.class,
860874
StreamingCallSettings.class,
861875
StubSettings.class,
@@ -933,7 +947,13 @@ private static TypeNode getCallSettingsTypeHelper(
933947
Method protoMethod, TypeStore typeStore, boolean isBuilder) {
934948
Class<?> callSettingsClazz =
935949
isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class;
936-
if (protoMethod.isPaged()) {
950+
if (protoMethod.isResumableUpload()) {
951+
return TypeNode.withReference(
952+
ConcreteReference.withClazz(
953+
isBuilder
954+
? ResumableUploadCallSettings.Builder.class
955+
: ResumableUploadCallSettings.class));
956+
} else if (protoMethod.isPaged()) {
937957
callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class;
938958
} else if (protoMethod.isBatching()) {
939959
callSettingsClazz =

0 commit comments

Comments
 (0)