Skip to content

Commit 0ebf4af

Browse files
feat: [cloudfunctions] added helper methods for long running operations, IAM, and locations (#9421)
- [ ] Regenerate this pull request now. docs: clarified that vpcConnector shortname is only returned if the connector is in the same project as the function docs: applied general style guide updates to descriptions PiperOrigin-RevId: 530688922 Source-Link: https://togithub.com/googleapis/googleapis/commit/a540c8aef871694f9489aecb594023817e713d54 Source-Link: https://togithub.com/googleapis/googleapis-gen/commit/dca7c4dd03c0db64c5626c84c7309ce4eee4b967 Copy-Tag: eyJwIjoiamF2YS1mdW5jdGlvbnMvLk93bEJvdC55YW1sIiwiaCI6ImRjYTdjNGRkMDNjMGRiNjRjNTYyNmM4NGM3MzA5Y2U0ZWVlNGI5NjcifQ==
1 parent 5e425bc commit 0ebf4af

37 files changed

+1773
-777
lines changed

java-functions/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
2020
<dependency>
2121
<groupId>com.google.cloud</groupId>
2222
<artifactId>libraries-bom</artifactId>
23-
<version>26.11.0</version>
23+
<version>26.14.0</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -195,7 +195,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
195195
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/java11.html
196196
[stability-image]: https://img.shields.io/badge/stability-stable-green
197197
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-functions.svg
198-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-functions/2.16.0
198+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-functions/2.18.0
199199
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
200200
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
201201
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

java-functions/google-cloud-functions/src/main/java/com/google/cloud/functions/v1/CloudFunctionsServiceClient.java

Lines changed: 209 additions & 20 deletions
Large diffs are not rendered by default.

java-functions/google-cloud-functions/src/main/java/com/google/cloud/functions/v1/CloudFunctionsServiceSettings.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.functions.v1;
1818

1919
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
20+
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;
2021

2122
import com.google.api.core.ApiFunction;
2223
import com.google.api.core.BetaApi;
@@ -32,6 +33,8 @@
3233
import com.google.api.gax.rpc.TransportChannelProvider;
3334
import com.google.api.gax.rpc.UnaryCallSettings;
3435
import com.google.cloud.functions.v1.stub.CloudFunctionsServiceStubSettings;
36+
import com.google.cloud.location.ListLocationsRequest;
37+
import com.google.cloud.location.ListLocationsResponse;
3538
import com.google.iam.v1.GetIamPolicyRequest;
3639
import com.google.iam.v1.Policy;
3740
import com.google.iam.v1.SetIamPolicyRequest;
@@ -165,6 +168,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
165168
return ((CloudFunctionsServiceStubSettings) getStubSettings()).testIamPermissionsSettings();
166169
}
167170

171+
/** Returns the object with the settings used for calls to listLocations. */
172+
public PagedCallSettings<ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
173+
listLocationsSettings() {
174+
return ((CloudFunctionsServiceStubSettings) getStubSettings()).listLocationsSettings();
175+
}
176+
168177
public static final CloudFunctionsServiceSettings create(CloudFunctionsServiceStubSettings stub)
169178
throws IOException {
170179
return new CloudFunctionsServiceSettings.Builder(stub.toBuilder()).build();
@@ -360,6 +369,13 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
360369
return getStubSettingsBuilder().testIamPermissionsSettings();
361370
}
362371

372+
/** Returns the builder for the settings used for calls to listLocations. */
373+
public PagedCallSettings.Builder<
374+
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
375+
listLocationsSettings() {
376+
return getStubSettingsBuilder().listLocationsSettings();
377+
}
378+
363379
@Override
364380
public CloudFunctionsServiceSettings build() throws IOException {
365381
return new CloudFunctionsServiceSettings(this);

java-functions/google-cloud-functions/src/main/java/com/google/cloud/functions/v1/gapic_metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"ListFunctions": {
3535
"methods": ["listFunctions", "listFunctionsPagedCallable", "listFunctionsCallable"]
3636
},
37+
"ListLocations": {
38+
"methods": ["listLocations", "listLocationsPagedCallable", "listLocationsCallable"]
39+
},
3740
"SetIamPolicy": {
3841
"methods": ["setIamPolicy", "setIamPolicyCallable"]
3942
},

java-functions/google-cloud-functions/src/main/java/com/google/cloud/functions/v1/stub/CloudFunctionsServiceStub.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.functions.v1.stub;
1818

1919
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
20+
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;
2021

2122
import com.google.api.gax.core.BackgroundResource;
2223
import com.google.api.gax.rpc.OperationCallable;
@@ -35,6 +36,8 @@
3536
import com.google.cloud.functions.v1.ListFunctionsResponse;
3637
import com.google.cloud.functions.v1.OperationMetadataV1;
3738
import com.google.cloud.functions.v1.UpdateFunctionRequest;
39+
import com.google.cloud.location.ListLocationsRequest;
40+
import com.google.cloud.location.ListLocationsResponse;
3841
import com.google.iam.v1.GetIamPolicyRequest;
3942
import com.google.iam.v1.Policy;
4043
import com.google.iam.v1.SetIamPolicyRequest;
@@ -129,6 +132,15 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
129132
throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()");
130133
}
131134

135+
public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
136+
listLocationsPagedCallable() {
137+
throw new UnsupportedOperationException("Not implemented: listLocationsPagedCallable()");
138+
}
139+
140+
public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
141+
throw new UnsupportedOperationException("Not implemented: listLocationsCallable()");
142+
}
143+
132144
@Override
133145
public abstract void close();
134146
}

java-functions/google-cloud-functions/src/main/java/com/google/cloud/functions/v1/stub/CloudFunctionsServiceStubSettings.java

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.functions.v1.stub;
1818

1919
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
20+
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;
2021

2122
import com.google.api.core.ApiFunction;
2223
import com.google.api.core.ApiFuture;
@@ -61,6 +62,9 @@
6162
import com.google.cloud.functions.v1.ListFunctionsResponse;
6263
import com.google.cloud.functions.v1.OperationMetadataV1;
6364
import com.google.cloud.functions.v1.UpdateFunctionRequest;
65+
import com.google.cloud.location.ListLocationsRequest;
66+
import com.google.cloud.location.ListLocationsResponse;
67+
import com.google.cloud.location.Location;
6468
import com.google.common.collect.ImmutableList;
6569
import com.google.common.collect.ImmutableMap;
6670
import com.google.common.collect.ImmutableSet;
@@ -145,6 +149,9 @@ public class CloudFunctionsServiceStubSettings
145149
private final UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings;
146150
private final UnaryCallSettings<TestIamPermissionsRequest, TestIamPermissionsResponse>
147151
testIamPermissionsSettings;
152+
private final PagedCallSettings<
153+
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
154+
listLocationsSettings;
148155

149156
private static final PagedListDescriptor<
150157
ListFunctionsRequest, ListFunctionsResponse, CloudFunction>
@@ -183,6 +190,42 @@ public Iterable<CloudFunction> extractResources(ListFunctionsResponse payload) {
183190
}
184191
};
185192

193+
private static final PagedListDescriptor<ListLocationsRequest, ListLocationsResponse, Location>
194+
LIST_LOCATIONS_PAGE_STR_DESC =
195+
new PagedListDescriptor<ListLocationsRequest, ListLocationsResponse, Location>() {
196+
@Override
197+
public String emptyToken() {
198+
return "";
199+
}
200+
201+
@Override
202+
public ListLocationsRequest injectToken(ListLocationsRequest payload, String token) {
203+
return ListLocationsRequest.newBuilder(payload).setPageToken(token).build();
204+
}
205+
206+
@Override
207+
public ListLocationsRequest injectPageSize(ListLocationsRequest payload, int pageSize) {
208+
return ListLocationsRequest.newBuilder(payload).setPageSize(pageSize).build();
209+
}
210+
211+
@Override
212+
public Integer extractPageSize(ListLocationsRequest payload) {
213+
return payload.getPageSize();
214+
}
215+
216+
@Override
217+
public String extractNextToken(ListLocationsResponse payload) {
218+
return payload.getNextPageToken();
219+
}
220+
221+
@Override
222+
public Iterable<Location> extractResources(ListLocationsResponse payload) {
223+
return payload.getLocationsList() == null
224+
? ImmutableList.<Location>of()
225+
: payload.getLocationsList();
226+
}
227+
};
228+
186229
private static final PagedListResponseFactory<
187230
ListFunctionsRequest, ListFunctionsResponse, ListFunctionsPagedResponse>
188231
LIST_FUNCTIONS_PAGE_STR_FACT =
@@ -200,6 +243,23 @@ public ApiFuture<ListFunctionsPagedResponse> getFuturePagedResponse(
200243
}
201244
};
202245

246+
private static final PagedListResponseFactory<
247+
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
248+
LIST_LOCATIONS_PAGE_STR_FACT =
249+
new PagedListResponseFactory<
250+
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>() {
251+
@Override
252+
public ApiFuture<ListLocationsPagedResponse> getFuturePagedResponse(
253+
UnaryCallable<ListLocationsRequest, ListLocationsResponse> callable,
254+
ListLocationsRequest request,
255+
ApiCallContext context,
256+
ApiFuture<ListLocationsResponse> futureResponse) {
257+
PageContext<ListLocationsRequest, ListLocationsResponse, Location> pageContext =
258+
PageContext.create(callable, LIST_LOCATIONS_PAGE_STR_DESC, request, context);
259+
return ListLocationsPagedResponse.createAsync(pageContext, futureResponse);
260+
}
261+
};
262+
203263
/** Returns the object with the settings used for calls to listFunctions. */
204264
public PagedCallSettings<ListFunctionsRequest, ListFunctionsResponse, ListFunctionsPagedResponse>
205265
listFunctionsSettings() {
@@ -277,6 +337,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
277337
return testIamPermissionsSettings;
278338
}
279339

340+
/** Returns the object with the settings used for calls to listLocations. */
341+
public PagedCallSettings<ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
342+
listLocationsSettings() {
343+
return listLocationsSettings;
344+
}
345+
280346
public CloudFunctionsServiceStub createStub() throws IOException {
281347
if (getTransportChannelProvider()
282348
.getTransportName()
@@ -397,6 +463,7 @@ protected CloudFunctionsServiceStubSettings(Builder settingsBuilder) throws IOEx
397463
setIamPolicySettings = settingsBuilder.setIamPolicySettings().build();
398464
getIamPolicySettings = settingsBuilder.getIamPolicySettings().build();
399465
testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build();
466+
listLocationsSettings = settingsBuilder.listLocationsSettings().build();
400467
}
401468

402469
/** Builder for CloudFunctionsServiceStubSettings. */
@@ -431,6 +498,9 @@ public static class Builder
431498
private final UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettings;
432499
private final UnaryCallSettings.Builder<TestIamPermissionsRequest, TestIamPermissionsResponse>
433500
testIamPermissionsSettings;
501+
private final PagedCallSettings.Builder<
502+
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
503+
listLocationsSettings;
434504
private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
435505
RETRYABLE_CODE_DEFINITIONS;
436506

@@ -498,6 +568,7 @@ protected Builder(ClientContext clientContext) {
498568
setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
499569
getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
500570
testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
571+
listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT);
501572

502573
unaryMethodSettingsBuilders =
503574
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -511,7 +582,8 @@ protected Builder(ClientContext clientContext) {
511582
generateDownloadUrlSettings,
512583
setIamPolicySettings,
513584
getIamPolicySettings,
514-
testIamPermissionsSettings);
585+
testIamPermissionsSettings,
586+
listLocationsSettings);
515587
initDefaults(this);
516588
}
517589

@@ -532,6 +604,7 @@ protected Builder(CloudFunctionsServiceStubSettings settings) {
532604
setIamPolicySettings = settings.setIamPolicySettings.toBuilder();
533605
getIamPolicySettings = settings.getIamPolicySettings.toBuilder();
534606
testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder();
607+
listLocationsSettings = settings.listLocationsSettings.toBuilder();
535608

536609
unaryMethodSettingsBuilders =
537610
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -545,7 +618,8 @@ protected Builder(CloudFunctionsServiceStubSettings settings) {
545618
generateDownloadUrlSettings,
546619
setIamPolicySettings,
547620
getIamPolicySettings,
548-
testIamPermissionsSettings);
621+
testIamPermissionsSettings,
622+
listLocationsSettings);
549623
}
550624

551625
private static Builder createDefault() {
@@ -630,6 +704,11 @@ private static Builder initDefaults(Builder builder) {
630704
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes"))
631705
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params"));
632706

707+
builder
708+
.listLocationsSettings()
709+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes"))
710+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params"));
711+
633712
builder
634713
.createFunctionOperationSettings()
635714
.setInitialCallSettings(
@@ -805,6 +884,13 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
805884
return testIamPermissionsSettings;
806885
}
807886

887+
/** Returns the builder for the settings used for calls to listLocations. */
888+
public PagedCallSettings.Builder<
889+
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
890+
listLocationsSettings() {
891+
return listLocationsSettings;
892+
}
893+
808894
@Override
809895
public CloudFunctionsServiceStubSettings build() throws IOException {
810896
return new CloudFunctionsServiceStubSettings(this);

java-functions/google-cloud-functions/src/main/java/com/google/cloud/functions/v1/stub/GrpcCloudFunctionsServiceStub.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.functions.v1.stub;
1818

1919
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
20+
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;
2021

2122
import com.google.api.gax.core.BackgroundResource;
2223
import com.google.api.gax.core.BackgroundResourceAggregation;
@@ -39,6 +40,8 @@
3940
import com.google.cloud.functions.v1.ListFunctionsResponse;
4041
import com.google.cloud.functions.v1.OperationMetadataV1;
4142
import com.google.cloud.functions.v1.UpdateFunctionRequest;
43+
import com.google.cloud.location.ListLocationsRequest;
44+
import com.google.cloud.location.ListLocationsResponse;
4245
import com.google.common.collect.ImmutableMap;
4346
import com.google.iam.v1.GetIamPolicyRequest;
4447
import com.google.iam.v1.Policy;
@@ -174,6 +177,17 @@ public class GrpcCloudFunctionsServiceStub extends CloudFunctionsServiceStub {
174177
ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance()))
175178
.build();
176179

180+
private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse>
181+
listLocationsMethodDescriptor =
182+
MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder()
183+
.setType(MethodDescriptor.MethodType.UNARY)
184+
.setFullMethodName("google.cloud.location.Locations/ListLocations")
185+
.setRequestMarshaller(
186+
ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance()))
187+
.setResponseMarshaller(
188+
ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance()))
189+
.build();
190+
177191
private final UnaryCallable<ListFunctionsRequest, ListFunctionsResponse> listFunctionsCallable;
178192
private final UnaryCallable<ListFunctionsRequest, ListFunctionsPagedResponse>
179193
listFunctionsPagedCallable;
@@ -196,6 +210,9 @@ public class GrpcCloudFunctionsServiceStub extends CloudFunctionsServiceStub {
196210
private final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable;
197211
private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
198212
testIamPermissionsCallable;
213+
private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable;
214+
private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
215+
listLocationsPagedCallable;
199216

200217
private final BackgroundResource backgroundResources;
201218
private final GrpcOperationsStub operationsStub;
@@ -354,6 +371,16 @@ protected GrpcCloudFunctionsServiceStub(
354371
return params.build();
355372
})
356373
.build();
374+
GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings =
375+
GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder()
376+
.setMethodDescriptor(listLocationsMethodDescriptor)
377+
.setParamsExtractor(
378+
request -> {
379+
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
380+
params.put("name", String.valueOf(request.getName()));
381+
return params.build();
382+
})
383+
.build();
357384

358385
this.listFunctionsCallable =
359386
callableFactory.createUnaryCallable(
@@ -415,6 +442,12 @@ protected GrpcCloudFunctionsServiceStub(
415442
testIamPermissionsTransportSettings,
416443
settings.testIamPermissionsSettings(),
417444
clientContext);
445+
this.listLocationsCallable =
446+
callableFactory.createUnaryCallable(
447+
listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
448+
this.listLocationsPagedCallable =
449+
callableFactory.createPagedCallable(
450+
listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
418451

419452
this.backgroundResources =
420453
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
@@ -506,6 +539,17 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
506539
return testIamPermissionsCallable;
507540
}
508541

542+
@Override
543+
public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
544+
return listLocationsCallable;
545+
}
546+
547+
@Override
548+
public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
549+
listLocationsPagedCallable() {
550+
return listLocationsPagedCallable;
551+
}
552+
509553
@Override
510554
public final void close() {
511555
try {

0 commit comments

Comments
 (0)