Skip to content

Commit 12c430b

Browse files
committed
feat(gax): retry start upload call and rename ResumableUploadCallSettings to ResumableUploadOptions
1 parent 76cd7d9 commit 12c430b

26 files changed

Lines changed: 286 additions & 304 deletions

‎java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import com.google.api.gax.paging.AbstractPagedListResponse;
2626
import com.google.api.gax.rpc.ApiExceptions;
2727
import com.google.api.gax.rpc.PageContext;
28-
import com.google.api.gax.rpc.ResumableUploadCallSettings;
2928
import com.google.api.gax.rpc.ResumableUploadCallable;
29+
import com.google.api.gax.rpc.ResumableUploadOptions;
3030
import com.google.api.gax.rpc.UnaryCallable;
3131
import com.google.cloud.location.GetLocationRequest;
3232
import com.google.cloud.location.ListLocationsRequest;
@@ -85,7 +85,7 @@
8585
* <td>
8686
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
8787
* <ul>
88-
* <li><p> uploadMedia(UploadMediaRequest request, InputStream payload, ResumableUploadCallSettings callSettings)
88+
* <li><p> uploadMedia(UploadMediaRequest request, InputStream payload, ResumableUploadOptions options)
8989
* </ul>
9090
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
9191
* <ul>
@@ -283,15 +283,13 @@ public ResumableUploadServiceStub getStub() {
283283
*
284284
* @param request The request object containing all of the parameters for the API call.
285285
* @param payload The payload data stream to upload.
286-
* @param callSettings The call settings to apply to this upload, or null to use defaults.
286+
* @param options The options to apply to this upload, or null to use defaults.
287287
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
288288
*/
289289
public final UploadMediaResponse uploadMedia(
290-
UploadMediaRequest request,
291-
InputStream payload,
292-
@Nullable ResumableUploadCallSettings callSettings) {
290+
UploadMediaRequest request, InputStream payload, @Nullable ResumableUploadOptions options) {
293291
return ApiExceptions.callAndTranslateApiException(
294-
uploadMediaCallable().futureCall(request, payload, callSettings));
292+
uploadMediaCallable().futureCall(request, payload, options));
295293
}
296294

297295
// AUTO-GENERATED DOCUMENTATION AND METHOD.

‎java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceSettings.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.api.gax.rpc.ClientContext;
2929
import com.google.api.gax.rpc.ClientSettings;
3030
import com.google.api.gax.rpc.PagedCallSettings;
31-
import com.google.api.gax.rpc.ResumableUploadCallSettings;
3231
import com.google.api.gax.rpc.TransportChannelProvider;
3332
import com.google.api.gax.rpc.UnaryCallSettings;
3433
import com.google.cloud.location.GetLocationRequest;
@@ -104,7 +103,7 @@
104103
public class ResumableUploadServiceSettings extends ClientSettings<ResumableUploadServiceSettings> {
105104

106105
/** Returns the object with the settings used for calls to uploadMedia. */
107-
public ResumableUploadCallSettings uploadMediaSettings() {
106+
public UnaryCallSettings<UploadMediaRequest, UploadMediaResponse> uploadMediaSettings() {
108107
return ((ResumableUploadServiceStubSettings) getStubSettings()).uploadMediaSettings();
109108
}
110109

@@ -249,7 +248,8 @@ public Builder applyToAllUnaryMethods(
249248
}
250249

251250
/** Returns the builder for the settings used for calls to uploadMedia. */
252-
public ResumableUploadCallSettings.Builder uploadMediaSettings() {
251+
public UnaryCallSettings.Builder<UploadMediaRequest, UploadMediaResponse>
252+
uploadMediaSettings() {
253253
return getStubSettingsBuilder().uploadMediaSettings();
254254
}
255255

‎java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStubSettings.java‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import com.google.api.gax.rpc.PagedCallSettings;
4343
import com.google.api.gax.rpc.PagedListDescriptor;
4444
import com.google.api.gax.rpc.PagedListResponseFactory;
45-
import com.google.api.gax.rpc.ResumableUploadCallSettings;
4645
import com.google.api.gax.rpc.StatusCode;
4746
import com.google.api.gax.rpc.StubSettings;
4847
import com.google.api.gax.rpc.TransportChannelProvider;
@@ -61,6 +60,8 @@
6160
import com.google.iam.v1.SetIamPolicyRequest;
6261
import com.google.iam.v1.TestIamPermissionsRequest;
6362
import com.google.iam.v1.TestIamPermissionsResponse;
63+
import com.google.showcase.v1beta1.UploadMediaRequest;
64+
import com.google.showcase.v1beta1.UploadMediaResponse;
6465
import java.io.IOException;
6566
import java.time.Duration;
6667
import java.util.List;
@@ -129,7 +130,7 @@ public class ResumableUploadServiceStubSettings
129130
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
130131
ImmutableList.<String>builder().build();
131132

132-
private final ResumableUploadCallSettings uploadMediaSettings;
133+
private final UnaryCallSettings<UploadMediaRequest, UploadMediaResponse> uploadMediaSettings;
133134
private final PagedCallSettings<
134135
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
135136
listLocationsSettings;
@@ -191,7 +192,7 @@ public ApiFuture<ListLocationsPagedResponse> getFuturePagedResponse(
191192
};
192193

193194
/** Returns the object with the settings used for calls to uploadMedia. */
194-
public ResumableUploadCallSettings uploadMediaSettings() {
195+
public UnaryCallSettings<UploadMediaRequest, UploadMediaResponse> uploadMediaSettings() {
195196
return uploadMediaSettings;
196197
}
197198

@@ -348,7 +349,8 @@ protected LibraryMetadata getLibraryMetadata() {
348349
public static class Builder
349350
extends StubSettings.Builder<ResumableUploadServiceStubSettings, Builder> {
350351
private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders;
351-
private final ResumableUploadCallSettings.Builder uploadMediaSettings;
352+
private final UnaryCallSettings.Builder<UploadMediaRequest, UploadMediaResponse>
353+
uploadMediaSettings;
352354
private final PagedCallSettings.Builder<
353355
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
354356
listLocationsSettings;
@@ -391,7 +393,7 @@ protected Builder() {
391393
protected Builder(@Nullable ClientContext clientContext) {
392394
super(clientContext);
393395

394-
uploadMediaSettings = ResumableUploadCallSettings.newBuilder();
396+
uploadMediaSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
395397
listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT);
396398
getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
397399
setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
@@ -400,6 +402,7 @@ protected Builder(@Nullable ClientContext clientContext) {
400402

401403
unaryMethodSettingsBuilders =
402404
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
405+
uploadMediaSettings,
403406
listLocationsSettings,
404407
getLocationSettings,
405408
setIamPolicySettings,
@@ -420,6 +423,7 @@ protected Builder(ResumableUploadServiceStubSettings settings) {
420423

421424
unaryMethodSettingsBuilders =
422425
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
426+
uploadMediaSettings,
423427
listLocationsSettings,
424428
getLocationSettings,
425429
setIamPolicySettings,
@@ -452,7 +456,10 @@ private static Builder createHttpJsonDefault() {
452456
}
453457

454458
private static Builder initDefaults(Builder builder) {
455-
builder.uploadMediaSettings().setGlobalTimeout(Duration.ofMillis(5000L));
459+
builder
460+
.uploadMediaSettings()
461+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
462+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
456463

457464
builder
458465
.listLocationsSettings()
@@ -505,7 +512,8 @@ public Builder applyToAllUnaryMethods(
505512
}
506513

507514
/** Returns the builder for the settings used for calls to uploadMedia. */
508-
public ResumableUploadCallSettings.Builder uploadMediaSettings() {
515+
public UnaryCallSettings.Builder<UploadMediaRequest, UploadMediaResponse>
516+
uploadMediaSettings() {
509517
return uploadMediaSettings;
510518
}
511519

‎java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITResumableUpload.java‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.google.api.gax.rpc.ResumableUploadCallSettings;
2221
import com.google.api.gax.rpc.ResumableUploadFuture;
22+
import com.google.api.gax.rpc.ResumableUploadOptions;
2323
import com.google.showcase.v1beta1.ResumableUploadServiceClient;
2424
import com.google.showcase.v1beta1.UploadMediaRequest;
2525
import com.google.showcase.v1beta1.UploadMediaResponse;
@@ -41,6 +41,8 @@
4141
class ITResumableUpload {
4242

4343
private static final int SHOWCASE_CHUNK_SIZE = 256 * 1024; // 256KB
44+
private static final ResumableUploadOptions DEFAULT_TEST_OPTIONS =
45+
ResumableUploadOptions.newBuilder().setChunkSize(SHOWCASE_CHUNK_SIZE).build();
4446
private static ResumableUploadServiceClient client;
4547

4648
@BeforeAll
@@ -69,7 +71,7 @@ void testGeneratedClient_uploadMedia_synchronousConvenienceMethod(@TempDir Path
6971
UploadMediaRequest.newBuilder().setName("it-client-sync.txt").build();
7072

7173
try (InputStream stream = Files.newInputStream(file)) {
72-
UploadMediaResponse response = client.uploadMedia(request, stream, null);
74+
UploadMediaResponse response = client.uploadMedia(request, stream, DEFAULT_TEST_OPTIONS);
7375
assertThat(response.getName()).isEqualTo("it-client-sync.txt");
7476
assertThat(response.getSize()).isEqualTo(Files.size(file));
7577
}
@@ -91,7 +93,7 @@ void testGeneratedClient_uploadMediaCallable_asynchronousFutureCall(@TempDir Pat
9193
ResumableUploadFuture<UploadMediaResponse> future =
9294
client
9395
.uploadMediaCallable()
94-
.futureCall(request, stream, (ResumableUploadCallSettings) null);
96+
.futureCall(request, stream, (ResumableUploadOptions) null);
9597

9698
UploadMediaResponse response = future.get(10, TimeUnit.SECONDS);
9799
assertThat(future.isDone()).isTrue();
@@ -112,7 +114,7 @@ void testGeneratedClient_multiChunkUpload(@TempDir Path tempDir) throws Exceptio
112114
UploadMediaRequest.newBuilder().setName("it-client-multi-chunk.txt").build();
113115

114116
try (InputStream stream = Files.newInputStream(file)) {
115-
UploadMediaResponse response = client.uploadMedia(request, stream, null);
117+
UploadMediaResponse response = client.uploadMedia(request, stream, DEFAULT_TEST_OPTIONS);
116118
assertThat(response.getName()).isEqualTo("it-client-multi-chunk.txt");
117119
assertThat(response.getSize()).isEqualTo(Files.size(file));
118120
}
@@ -133,7 +135,8 @@ void testGeneratedClient_grpcClientDelegation_uploadMedia(@TempDir Path tempDir)
133135
try (ResumableUploadServiceClient grpcClient =
134136
TestClientInitializer.createGrpcResumableUploadClient(SHOWCASE_CHUNK_SIZE)) {
135137
try (InputStream stream = Files.newInputStream(file)) {
136-
UploadMediaResponse response = grpcClient.uploadMedia(request, stream, null);
138+
UploadMediaResponse response =
139+
grpcClient.uploadMedia(request, stream, DEFAULT_TEST_OPTIONS);
137140
assertThat(response.getName()).isEqualTo("it-grpc-delegation.txt");
138141
assertThat(response.getSize()).isEqualTo(Files.size(file));
139142
}
@@ -142,7 +145,7 @@ void testGeneratedClient_grpcClientDelegation_uploadMedia(@TempDir Path tempDir)
142145
ResumableUploadFuture<UploadMediaResponse> future =
143146
grpcClient
144147
.uploadMediaCallable()
145-
.futureCall(request, stream, (ResumableUploadCallSettings) null);
148+
.futureCall(request, stream, (ResumableUploadOptions) null);
146149
UploadMediaResponse response = future.get(10, TimeUnit.SECONDS);
147150
assertThat(future.isDone()).isTrue();
148151
assertThat(future.isCancelled()).isFalse();
@@ -155,18 +158,18 @@ void testGeneratedClient_grpcClientDelegation_uploadMedia(@TempDir Path tempDir)
155158
}
156159

157160
@Test
158-
void testGeneratedClient_uploadMedia_withCustomCallSettings(@TempDir Path tempDir)
161+
void testGeneratedClient_uploadMedia_withCustomOptions(@TempDir Path tempDir)
159162
throws Exception {
160163
// 600KB payload with custom per-call 512KB chunk size override (default is 256KB)
161164
int totalBytes = 600 * 1024;
162165
Path file = createTempFile(tempDir, "it-client-custom-call-settings.txt", totalBytes);
163166
UploadMediaRequest request =
164167
UploadMediaRequest.newBuilder().setName("it-client-custom-call-settings.txt").build();
165-
ResumableUploadCallSettings callSettings =
166-
ResumableUploadCallSettings.newBuilder().setChunkSize(512 * 1024).build();
168+
ResumableUploadOptions options =
169+
ResumableUploadOptions.newBuilder().setChunkSize(512 * 1024).build();
167170

168171
try (InputStream stream = Files.newInputStream(file)) {
169-
UploadMediaResponse response = client.uploadMedia(request, stream, callSettings);
172+
UploadMediaResponse response = client.uploadMedia(request, stream, options);
170173
assertThat(response.getName()).isEqualTo("it-client-custom-call-settings.txt");
171174
assertThat(response.getSize()).isEqualTo(Files.size(file));
172175
}

‎java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ public static ResumableUploadServiceClient createHttpJsonResumableUploadClient(i
553553
.setHttpTransport(new NetHttpTransport.Builder().doNotValidateCertificate().build())
554554
.setEndpoint(DEFAULT_HTTPJSON_ENDPOINT)
555555
.build());
556-
settingsBuilder.uploadMediaSettings().setChunkSize(chunkSize);
557556
return ResumableUploadServiceClient.create(settingsBuilder.build());
558557
}
559558

@@ -568,7 +567,6 @@ public static ResumableUploadServiceClient createGrpcResumableUploadClient(int c
568567
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
569568
.build())
570569
.setEndpoint(DEFAULT_HTTPJSON_ENDPOINT);
571-
settingsBuilder.uploadMediaSettings().setChunkSize(chunkSize);
572570
return ResumableUploadServiceClient.create(settingsBuilder.build());
573571
}
574572
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class ServiceClientCommentComposer {
4646
"The request object containing all of the parameters for the API call.";
4747
private static final String PAYLOAD_PARAM_NAME = "payload";
4848
private static final String PAYLOAD_PARAM_DESCRIPTION = "The payload data stream to upload.";
49-
private static final String CALL_SETTINGS_PARAM_NAME = "callSettings";
50-
private static final String CALL_SETTINGS_PARAM_DESCRIPTION =
51-
"The call settings to apply to this upload, or null to use defaults.";
49+
private static final String OPTIONS_PARAM_NAME = "options";
50+
private static final String OPTIONS_PARAM_DESCRIPTION =
51+
"The options to apply to this upload, or null to use defaults.";
5252

5353
// Constants.
5454
private static final String SERVICE_DESCRIPTION_INTRO_STRING =
@@ -214,7 +214,7 @@ public static List<CommentStatement> createRpcMethodHeaderComment(
214214

215215
if (method.isResumableUpload()) {
216216
methodJavadocBuilder.addParam(PAYLOAD_PARAM_NAME, PAYLOAD_PARAM_DESCRIPTION);
217-
methodJavadocBuilder.addParam(CALL_SETTINGS_PARAM_NAME, CALL_SETTINGS_PARAM_DESCRIPTION);
217+
methodJavadocBuilder.addParam(OPTIONS_PARAM_NAME, OPTIONS_PARAM_DESCRIPTION);
218218
}
219219

220220
methodJavadocBuilder.setThrows(API_EXCEPTION_TYPE_NAME, EXCEPTION_CONDITION);

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ public class SettingsCommentComposer {
4141
private static final String CLASS_HEADER_DEFAULT_ADDRESS_PORT_PATTERN =
4242
"The default service address (%s) and default port (%d) are used.";
4343
private static final String CLASS_HEADER_SAMPLE_CODE_PATTERN =
44-
"For example, to set the [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings) of %s:";
44+
"For example, to set the"
45+
+ " [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)"
46+
+ " of %s:";
4547

4648
private static final String CLASS_HEADER_LRO_SAMPLE_CODE_PATTERN =
47-
"To configure the RetrySettings of a Long Running Operation method, create an OperationTimedPollAlgorithm object and update the RPC's polling algorithm. For example, to configure the RetrySettings for %s:";
49+
"To configure the RetrySettings of a Long Running Operation method, create an"
50+
+ " OperationTimedPollAlgorithm object and update the RPC's polling algorithm. For"
51+
+ " example, to configure the RetrySettings for %s:";
4852

4953
private static final String CLASS_HEADER_SAMPLE_CODE_SUFFIX =
50-
"Please refer to the [Client Side Retry Guide](https://docs.cloud.google.com/java/docs/client-retries) for additional support in setting retries.";
54+
"Please refer to the [Client Side Retry"
55+
+ " Guide](https://docs.cloud.google.com/java/docs/client-retries) for additional support"
56+
+ " in setting retries.";
5157

5258
private static final String CLASS_HEADER_BUILDER_DESCRIPTION =
5359
"The builder of this class is recursive, so contained classes are themselves builders. When"
@@ -134,11 +140,6 @@ public static CommentStatement createCallSettingsGetterComment(
134140
isMethodInternal);
135141
}
136142

137-
public static CommentStatement createResumableUploadCallSettingsGetterComment(
138-
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
139-
return createCallSettingsGetterComment(javaMethodName, isMethodDeprecated, isMethodInternal);
140-
}
141-
142143
public static CommentStatement createBuilderClassComment(String outerClassName) {
143144
return toCommentStatement(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName));
144145
}
@@ -149,12 +150,6 @@ public static CommentStatement createCallSettingsBuilderGetterComment(
149150
return toCommentStatement(methodComment, isMethodDeprecated, isMethodInternal);
150151
}
151152

152-
public static CommentStatement createResumableUploadCallSettingsBuilderGetterComment(
153-
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
154-
return createCallSettingsBuilderGetterComment(
155-
javaMethodName, isMethodDeprecated, isMethodInternal);
156-
}
157-
158153
public static List<CommentStatement> createClassHeaderComments(
159154
String configuredClassName,
160155
String defaultHost,

0 commit comments

Comments
 (0)