Skip to content

Commit

Permalink
feat: [cloudfunctions] added helper methods for long running operatio…
Browse files Browse the repository at this point in the history
…ns, 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://github.com/googleapis/googleapis/commit/a540c8aef871694f9489aecb594023817e713d54

Source-Link: https://github.com/googleapis/googleapis-gen/commit/dca7c4dd03c0db64c5626c84c7309ce4eee4b967
Copy-Tag: eyJwIjoiamF2YS1mdW5jdGlvbnMvLk93bEJvdC55YW1sIiwiaCI6ImRjYTdjNGRkMDNjMGRiNjRjNTYyNmM4NGM3MzA5Y2U0ZWVlNGI5NjcifQ==
  • Loading branch information
gcf-owl-bot[bot] authored May 10, 2023
1 parent 5e425bc commit 0ebf4af
Show file tree
Hide file tree
Showing 37 changed files with 1,773 additions and 777 deletions.
4 changes: 2 additions & 2 deletions java-functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.11.0</version>
<version>26.14.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -195,7 +195,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-functions.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-functions/2.16.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-functions/2.18.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.functions.v1;

import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;

import com.google.api.core.ApiFunction;
import com.google.api.core.BetaApi;
Expand All @@ -32,6 +33,8 @@
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.functions.v1.stub.CloudFunctionsServiceStubSettings;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
Expand Down Expand Up @@ -165,6 +168,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
return ((CloudFunctionsServiceStubSettings) getStubSettings()).testIamPermissionsSettings();
}

/** Returns the object with the settings used for calls to listLocations. */
public PagedCallSettings<ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings() {
return ((CloudFunctionsServiceStubSettings) getStubSettings()).listLocationsSettings();
}

public static final CloudFunctionsServiceSettings create(CloudFunctionsServiceStubSettings stub)
throws IOException {
return new CloudFunctionsServiceSettings.Builder(stub.toBuilder()).build();
Expand Down Expand Up @@ -360,6 +369,13 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
return getStubSettingsBuilder().testIamPermissionsSettings();
}

/** Returns the builder for the settings used for calls to listLocations. */
public PagedCallSettings.Builder<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings() {
return getStubSettingsBuilder().listLocationsSettings();
}

@Override
public CloudFunctionsServiceSettings build() throws IOException {
return new CloudFunctionsServiceSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"ListFunctions": {
"methods": ["listFunctions", "listFunctionsPagedCallable", "listFunctionsCallable"]
},
"ListLocations": {
"methods": ["listLocations", "listLocationsPagedCallable", "listLocationsCallable"]
},
"SetIamPolicy": {
"methods": ["setIamPolicy", "setIamPolicyCallable"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.functions.v1.stub;

import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;

import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.OperationCallable;
Expand All @@ -35,6 +36,8 @@
import com.google.cloud.functions.v1.ListFunctionsResponse;
import com.google.cloud.functions.v1.OperationMetadataV1;
import com.google.cloud.functions.v1.UpdateFunctionRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
Expand Down Expand Up @@ -129,6 +132,15 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()");
}

public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable() {
throw new UnsupportedOperationException("Not implemented: listLocationsPagedCallable()");
}

public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
throw new UnsupportedOperationException("Not implemented: listLocationsCallable()");
}

@Override
public abstract void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.functions.v1.stub;

import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;

import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
Expand Down Expand Up @@ -61,6 +62,9 @@
import com.google.cloud.functions.v1.ListFunctionsResponse;
import com.google.cloud.functions.v1.OperationMetadataV1;
import com.google.cloud.functions.v1.UpdateFunctionRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.cloud.location.Location;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -145,6 +149,9 @@ public class CloudFunctionsServiceStubSettings
private final UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings;
private final UnaryCallSettings<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsSettings;
private final PagedCallSettings<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings;

private static final PagedListDescriptor<
ListFunctionsRequest, ListFunctionsResponse, CloudFunction>
Expand Down Expand Up @@ -183,6 +190,42 @@ public Iterable<CloudFunction> extractResources(ListFunctionsResponse payload) {
}
};

private static final PagedListDescriptor<ListLocationsRequest, ListLocationsResponse, Location>
LIST_LOCATIONS_PAGE_STR_DESC =
new PagedListDescriptor<ListLocationsRequest, ListLocationsResponse, Location>() {
@Override
public String emptyToken() {
return "";
}

@Override
public ListLocationsRequest injectToken(ListLocationsRequest payload, String token) {
return ListLocationsRequest.newBuilder(payload).setPageToken(token).build();
}

@Override
public ListLocationsRequest injectPageSize(ListLocationsRequest payload, int pageSize) {
return ListLocationsRequest.newBuilder(payload).setPageSize(pageSize).build();
}

@Override
public Integer extractPageSize(ListLocationsRequest payload) {
return payload.getPageSize();
}

@Override
public String extractNextToken(ListLocationsResponse payload) {
return payload.getNextPageToken();
}

@Override
public Iterable<Location> extractResources(ListLocationsResponse payload) {
return payload.getLocationsList() == null
? ImmutableList.<Location>of()
: payload.getLocationsList();
}
};

private static final PagedListResponseFactory<
ListFunctionsRequest, ListFunctionsResponse, ListFunctionsPagedResponse>
LIST_FUNCTIONS_PAGE_STR_FACT =
Expand All @@ -200,6 +243,23 @@ public ApiFuture<ListFunctionsPagedResponse> getFuturePagedResponse(
}
};

private static final PagedListResponseFactory<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
LIST_LOCATIONS_PAGE_STR_FACT =
new PagedListResponseFactory<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>() {
@Override
public ApiFuture<ListLocationsPagedResponse> getFuturePagedResponse(
UnaryCallable<ListLocationsRequest, ListLocationsResponse> callable,
ListLocationsRequest request,
ApiCallContext context,
ApiFuture<ListLocationsResponse> futureResponse) {
PageContext<ListLocationsRequest, ListLocationsResponse, Location> pageContext =
PageContext.create(callable, LIST_LOCATIONS_PAGE_STR_DESC, request, context);
return ListLocationsPagedResponse.createAsync(pageContext, futureResponse);
}
};

/** Returns the object with the settings used for calls to listFunctions. */
public PagedCallSettings<ListFunctionsRequest, ListFunctionsResponse, ListFunctionsPagedResponse>
listFunctionsSettings() {
Expand Down Expand Up @@ -277,6 +337,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
return testIamPermissionsSettings;
}

/** Returns the object with the settings used for calls to listLocations. */
public PagedCallSettings<ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings() {
return listLocationsSettings;
}

public CloudFunctionsServiceStub createStub() throws IOException {
if (getTransportChannelProvider()
.getTransportName()
Expand Down Expand Up @@ -397,6 +463,7 @@ protected CloudFunctionsServiceStubSettings(Builder settingsBuilder) throws IOEx
setIamPolicySettings = settingsBuilder.setIamPolicySettings().build();
getIamPolicySettings = settingsBuilder.getIamPolicySettings().build();
testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build();
listLocationsSettings = settingsBuilder.listLocationsSettings().build();
}

/** Builder for CloudFunctionsServiceStubSettings. */
Expand Down Expand Up @@ -431,6 +498,9 @@ public static class Builder
private final UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettings;
private final UnaryCallSettings.Builder<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsSettings;
private final PagedCallSettings.Builder<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings;
private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
RETRYABLE_CODE_DEFINITIONS;

Expand Down Expand Up @@ -498,6 +568,7 @@ protected Builder(ClientContext clientContext) {
setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT);

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
Expand All @@ -511,7 +582,8 @@ protected Builder(ClientContext clientContext) {
generateDownloadUrlSettings,
setIamPolicySettings,
getIamPolicySettings,
testIamPermissionsSettings);
testIamPermissionsSettings,
listLocationsSettings);
initDefaults(this);
}

Expand All @@ -532,6 +604,7 @@ protected Builder(CloudFunctionsServiceStubSettings settings) {
setIamPolicySettings = settings.setIamPolicySettings.toBuilder();
getIamPolicySettings = settings.getIamPolicySettings.toBuilder();
testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder();
listLocationsSettings = settings.listLocationsSettings.toBuilder();

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
Expand All @@ -545,7 +618,8 @@ protected Builder(CloudFunctionsServiceStubSettings settings) {
generateDownloadUrlSettings,
setIamPolicySettings,
getIamPolicySettings,
testIamPermissionsSettings);
testIamPermissionsSettings,
listLocationsSettings);
}

private static Builder createDefault() {
Expand Down Expand Up @@ -630,6 +704,11 @@ private static Builder initDefaults(Builder builder) {
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params"));

builder
.listLocationsSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params"));

builder
.createFunctionOperationSettings()
.setInitialCallSettings(
Expand Down Expand Up @@ -805,6 +884,13 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
return testIamPermissionsSettings;
}

/** Returns the builder for the settings used for calls to listLocations. */
public PagedCallSettings.Builder<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings() {
return listLocationsSettings;
}

@Override
public CloudFunctionsServiceStubSettings build() throws IOException {
return new CloudFunctionsServiceStubSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.functions.v1.stub;

import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
import static com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListLocationsPagedResponse;

import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
Expand All @@ -39,6 +40,8 @@
import com.google.cloud.functions.v1.ListFunctionsResponse;
import com.google.cloud.functions.v1.OperationMetadataV1;
import com.google.cloud.functions.v1.UpdateFunctionRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.common.collect.ImmutableMap;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
Expand Down Expand Up @@ -174,6 +177,17 @@ public class GrpcCloudFunctionsServiceStub extends CloudFunctionsServiceStub {
ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance()))
.build();

private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse>
listLocationsMethodDescriptor =
MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.location.Locations/ListLocations")
.setRequestMarshaller(
ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance()))
.build();

private final UnaryCallable<ListFunctionsRequest, ListFunctionsResponse> listFunctionsCallable;
private final UnaryCallable<ListFunctionsRequest, ListFunctionsPagedResponse>
listFunctionsPagedCallable;
Expand All @@ -196,6 +210,9 @@ public class GrpcCloudFunctionsServiceStub extends CloudFunctionsServiceStub {
private final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable;
private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsCallable;
private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable;
private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable;

private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
Expand Down Expand Up @@ -354,6 +371,16 @@ protected GrpcCloudFunctionsServiceStub(
return params.build();
})
.build();
GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings =
GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder()
.setMethodDescriptor(listLocationsMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
})
.build();

this.listFunctionsCallable =
callableFactory.createUnaryCallable(
Expand Down Expand Up @@ -415,6 +442,12 @@ protected GrpcCloudFunctionsServiceStub(
testIamPermissionsTransportSettings,
settings.testIamPermissionsSettings(),
clientContext);
this.listLocationsCallable =
callableFactory.createUnaryCallable(
listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
this.listLocationsPagedCallable =
callableFactory.createPagedCallable(
listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);

this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
Expand Down Expand Up @@ -506,6 +539,17 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
return testIamPermissionsCallable;
}

@Override
public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
return listLocationsCallable;
}

@Override
public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable() {
return listLocationsPagedCallable;
}

@Override
public final void close() {
try {
Expand Down
Loading

0 comments on commit 0ebf4af

Please sign in to comment.