diff --git a/README.md b/README.md index 3937952..eeccc93 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-run - 0.2.0 + 0.2.1 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-run:0.2.0' +implementation 'com.google.cloud:google-cloud-run:0.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-run" % "0.2.0" +libraryDependencies += "com.google.cloud" % "google-cloud-run" % "0.2.1" ``` ## Authentication diff --git a/google-cloud-run/pom.xml b/google-cloud-run/pom.xml index a63be06..d5d495f 100644 --- a/google-cloud-run/pom.xml +++ b/google-cloud-run/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -81,12 +85,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsClient.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsClient.java index a2f96dc..66c447e 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsClient.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -30,7 +31,6 @@ import com.google.cloud.run.v2.stub.RevisionsStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -100,13 +100,28 @@ * RevisionsClient revisionsClient = RevisionsClient.create(revisionsSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * RevisionsSettings revisionsSettings =
+ *     RevisionsSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             RevisionsSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * RevisionsClient revisionsClient = RevisionsClient.create(revisionsSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class RevisionsClient implements BackgroundResource { private final RevisionsSettings settings; private final RevisionsStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of RevisionsClient with default settings. */ public static final RevisionsClient create() throws IOException { @@ -136,13 +151,17 @@ public static final RevisionsClient create(RevisionsStub stub) { protected RevisionsClient(RevisionsSettings settings) throws IOException { this.settings = settings; this.stub = ((RevisionsStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected RevisionsClient(RevisionsStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final RevisionsSettings getSettings() { @@ -157,10 +176,18 @@ public RevisionsStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Gets information about a Revision. diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsSettings.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsSettings.java index 2b6cfcf..c89ef86 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsSettings.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/RevisionsSettings.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -118,11 +119,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return RevisionsStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return RevisionsStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return RevisionsStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return RevisionsStubSettings.defaultTransportChannelProvider(); } @@ -132,11 +140,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return RevisionsStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -174,6 +188,11 @@ private static Builder createDefault() { return new Builder(RevisionsStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(RevisionsStubSettings.newHttpJsonBuilder()); + } + public RevisionsStubSettings.Builder getStubSettingsBuilder() { return ((RevisionsStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesClient.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesClient.java index 0b771f6..0d10699 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesClient.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -35,7 +36,6 @@ import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -105,13 +105,28 @@ * ServicesClient servicesClient = ServicesClient.create(servicesSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * ServicesSettings servicesSettings =
+ *     ServicesSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             ServicesSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * ServicesClient servicesClient = ServicesClient.create(servicesSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class ServicesClient implements BackgroundResource { private final ServicesSettings settings; private final ServicesStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of ServicesClient with default settings. */ public static final ServicesClient create() throws IOException { @@ -141,13 +156,17 @@ public static final ServicesClient create(ServicesStub stub) { protected ServicesClient(ServicesSettings settings) throws IOException { this.settings = settings; this.stub = ((ServicesStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected ServicesClient(ServicesStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final ServicesSettings getSettings() { @@ -162,10 +181,18 @@ public ServicesStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Creates a new Service in a given project and location. diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesSettings.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesSettings.java index 569d60e..9433cf1 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesSettings.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/ServicesSettings.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -161,11 +162,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return ServicesStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return ServicesStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return ServicesStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return ServicesStubSettings.defaultTransportChannelProvider(); } @@ -175,11 +183,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return ServicesStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -217,6 +231,11 @@ private static Builder createDefault() { return new Builder(ServicesStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(ServicesStubSettings.newHttpJsonBuilder()); + } + public ServicesStubSettings.Builder getStubSettingsBuilder() { return ((ServicesStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonRevisionsCallableFactory.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonRevisionsCallableFactory.java new file mode 100644 index 0000000..aea8d91 --- /dev/null +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonRevisionsCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Revisions service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonRevisionsCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonRevisionsStub.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonRevisionsStub.java new file mode 100644 index 0000000..c01acd4 --- /dev/null +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonRevisionsStub.java @@ -0,0 +1,339 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.stub; + +import static com.google.cloud.run.v2.RevisionsClient.ListRevisionsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.run.v2.DeleteRevisionRequest; +import com.google.cloud.run.v2.GetRevisionRequest; +import com.google.cloud.run.v2.ListRevisionsRequest; +import com.google.cloud.run.v2.ListRevisionsResponse; +import com.google.cloud.run.v2.Revision; +import com.google.longrunning.Operation; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Revisions service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonRevisionsStub extends RevisionsStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder().add(Revision.getDescriptor()).build(); + + private static final ApiMethodDescriptor + getRevisionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Revisions/GetRevision") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/services/*/revisions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Revision.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listRevisionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Revisions/ListRevisions") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*/services/*}/revisions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam( + fields, "showDeleted", request.getShowDeleted()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListRevisionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteRevisionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Revisions/DeleteRevision") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/services/*/revisions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "etag", request.getEtag()); + serializer.putQueryParam( + fields, "validateOnly", request.getValidateOnly()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteRevisionRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable getRevisionCallable; + private final UnaryCallable listRevisionsCallable; + private final UnaryCallable + listRevisionsPagedCallable; + private final UnaryCallable deleteRevisionCallable; + private final OperationCallable + deleteRevisionOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonRevisionsStub create(RevisionsStubSettings settings) + throws IOException { + return new HttpJsonRevisionsStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonRevisionsStub create(ClientContext clientContext) throws IOException { + return new HttpJsonRevisionsStub( + RevisionsStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonRevisionsStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonRevisionsStub( + RevisionsStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonRevisionsStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonRevisionsStub(RevisionsStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonRevisionsCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonRevisionsStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonRevisionsStub( + RevisionsStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings getRevisionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getRevisionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listRevisionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listRevisionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteRevisionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteRevisionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.getRevisionCallable = + callableFactory.createUnaryCallable( + getRevisionTransportSettings, settings.getRevisionSettings(), clientContext); + this.listRevisionsCallable = + callableFactory.createUnaryCallable( + listRevisionsTransportSettings, settings.listRevisionsSettings(), clientContext); + this.listRevisionsPagedCallable = + callableFactory.createPagedCallable( + listRevisionsTransportSettings, settings.listRevisionsSettings(), clientContext); + this.deleteRevisionCallable = + callableFactory.createUnaryCallable( + deleteRevisionTransportSettings, settings.deleteRevisionSettings(), clientContext); + this.deleteRevisionOperationCallable = + callableFactory.createOperationCallable( + deleteRevisionTransportSettings, + settings.deleteRevisionOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(getRevisionMethodDescriptor); + methodDescriptors.add(listRevisionsMethodDescriptor); + methodDescriptors.add(deleteRevisionMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable getRevisionCallable() { + return getRevisionCallable; + } + + @Override + public UnaryCallable listRevisionsCallable() { + return listRevisionsCallable; + } + + @Override + public UnaryCallable + listRevisionsPagedCallable() { + return listRevisionsPagedCallable; + } + + @Override + public UnaryCallable deleteRevisionCallable() { + return deleteRevisionCallable; + } + + @Override + public OperationCallable + deleteRevisionOperationCallable() { + return deleteRevisionOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonServicesCallableFactory.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonServicesCallableFactory.java new file mode 100644 index 0000000..50fd833 --- /dev/null +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonServicesCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Services service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonServicesCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonServicesStub.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonServicesStub.java new file mode 100644 index 0000000..e339e7d --- /dev/null +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/HttpJsonServicesStub.java @@ -0,0 +1,641 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.stub; + +import static com.google.cloud.run.v2.ServicesClient.ListServicesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.run.v2.CreateServiceRequest; +import com.google.cloud.run.v2.DeleteServiceRequest; +import com.google.cloud.run.v2.GetServiceRequest; +import com.google.cloud.run.v2.ListServicesRequest; +import com.google.cloud.run.v2.ListServicesResponse; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.UpdateServiceRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Services service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonServicesStub extends ServicesStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder().add(Service.getDescriptor()).build(); + + private static final ApiMethodDescriptor + createServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/CreateService") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*}/services", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "serviceId", request.getServiceId()); + serializer.putQueryParam( + fields, "validateOnly", request.getValidateOnly()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("service", request.getService())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor getServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/GetService") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/services/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Service.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/ListServices") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*}/services", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam( + fields, "showDeleted", request.getShowDeleted()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListServicesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/UpdateService") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{service.name=projects/*/locations/*/services/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "service.name", request.getService().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "allowMissing", request.getAllowMissing()); + serializer.putQueryParam( + fields, "validateOnly", request.getValidateOnly()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("service", request.getService())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/DeleteService") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/services/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "etag", request.getEtag()); + serializer.putQueryParam( + fields, "validateOnly", request.getValidateOnly()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{resource=projects/*/locations/*/services/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "options", request.getOptions()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{resource=projects/*/locations/*/services/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.run.v2.Services/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{resource=projects/*/locations/*/services/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createServiceCallable; + private final OperationCallable + createServiceOperationCallable; + private final UnaryCallable getServiceCallable; + private final UnaryCallable listServicesCallable; + private final UnaryCallable + listServicesPagedCallable; + private final UnaryCallable updateServiceCallable; + private final OperationCallable + updateServiceOperationCallable; + private final UnaryCallable deleteServiceCallable; + private final OperationCallable + deleteServiceOperationCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonServicesStub create(ServicesStubSettings settings) + throws IOException { + return new HttpJsonServicesStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonServicesStub create(ClientContext clientContext) throws IOException { + return new HttpJsonServicesStub( + ServicesStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonServicesStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonServicesStub( + ServicesStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonServicesStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonServicesStub(ServicesStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonServicesCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonServicesStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonServicesStub( + ServicesStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings createServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createServiceCallable = + callableFactory.createUnaryCallable( + createServiceTransportSettings, settings.createServiceSettings(), clientContext); + this.createServiceOperationCallable = + callableFactory.createOperationCallable( + createServiceTransportSettings, + settings.createServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getServiceCallable = + callableFactory.createUnaryCallable( + getServiceTransportSettings, settings.getServiceSettings(), clientContext); + this.listServicesCallable = + callableFactory.createUnaryCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.listServicesPagedCallable = + callableFactory.createPagedCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.updateServiceCallable = + callableFactory.createUnaryCallable( + updateServiceTransportSettings, settings.updateServiceSettings(), clientContext); + this.updateServiceOperationCallable = + callableFactory.createOperationCallable( + updateServiceTransportSettings, + settings.updateServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteServiceCallable = + callableFactory.createUnaryCallable( + deleteServiceTransportSettings, settings.deleteServiceSettings(), clientContext); + this.deleteServiceOperationCallable = + callableFactory.createOperationCallable( + deleteServiceTransportSettings, + settings.deleteServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createServiceMethodDescriptor); + methodDescriptors.add(getServiceMethodDescriptor); + methodDescriptors.add(listServicesMethodDescriptor); + methodDescriptors.add(updateServiceMethodDescriptor); + methodDescriptors.add(deleteServiceMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable createServiceCallable() { + return createServiceCallable; + } + + @Override + public OperationCallable + createServiceOperationCallable() { + return createServiceOperationCallable; + } + + @Override + public UnaryCallable getServiceCallable() { + return getServiceCallable; + } + + @Override + public UnaryCallable listServicesCallable() { + return listServicesCallable; + } + + @Override + public UnaryCallable listServicesPagedCallable() { + return listServicesPagedCallable; + } + + @Override + public UnaryCallable updateServiceCallable() { + return updateServiceCallable; + } + + @Override + public OperationCallable + updateServiceOperationCallable() { + return updateServiceOperationCallable; + } + + @Override + public UnaryCallable deleteServiceCallable() { + return deleteServiceCallable; + } + + @Override + public OperationCallable + deleteServiceOperationCallable() { + return deleteServiceOperationCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStub.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStub.java index a0cb6a8..7f41e3c 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStub.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStub.java @@ -40,7 +40,11 @@ public abstract class RevisionsStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable getRevisionCallable() { diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStubSettings.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStubSettings.java index 7caabae..af7f5b1 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStubSettings.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/RevisionsStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -187,6 +190,11 @@ public RevisionsStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcRevisionsStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonRevisionsStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -219,29 +227,54 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(RevisionsStubSettings.class)) .setTransportToken( GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(RevisionsStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return RevisionsStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -336,6 +369,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .getRevisionSettings() diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStub.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStub.java index 48ef344..8a7a3e5 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStub.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStub.java @@ -47,7 +47,11 @@ public abstract class ServicesStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public OperationCallable diff --git a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStubSettings.java b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStubSettings.java index dba2cba..2abf68f 100644 --- a/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStubSettings.java +++ b/google-cloud-run/src/main/java/com/google/cloud/run/v2/stub/ServicesStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -242,6 +245,11 @@ public ServicesStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcServicesStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonServicesStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -274,29 +282,54 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(ServicesStubSettings.class)) .setTransportToken( GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(ServicesStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ServicesStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -469,6 +502,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .createServiceSettings() diff --git a/google-cloud-run/src/test/java/com/google/cloud/run/v2/RevisionsClientHttpJsonTest.java b/google-cloud-run/src/test/java/com/google/cloud/run/v2/RevisionsClientHttpJsonTest.java new file mode 100644 index 0000000..a9757ce --- /dev/null +++ b/google-cloud-run/src/test/java/com/google/cloud/run/v2/RevisionsClientHttpJsonTest.java @@ -0,0 +1,474 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2; + +import static com.google.cloud.run.v2.RevisionsClient.ListRevisionsPagedResponse; + +import com.google.api.LaunchStage; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.run.v2.stub.HttpJsonRevisionsStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Duration; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class RevisionsClientHttpJsonTest { + private static MockHttpService mockService; + private static RevisionsClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonRevisionsStub.getMethodDescriptors(), RevisionsSettings.getDefaultEndpoint()); + RevisionsSettings settings = + RevisionsSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + RevisionsSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = RevisionsClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void getRevisionTest() throws Exception { + Revision expectedResponse = + Revision.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setLaunchStage(LaunchStage.forNumber(0)) + .setService(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setScaling(RevisionScaling.newBuilder().build()) + .setVpcAccess(VpcAccess.newBuilder().build()) + .setMaxInstanceRequestConcurrency(117250100) + .setTimeout(Duration.newBuilder().build()) + .setServiceAccount("serviceAccount1079137720") + .addAllContainers(new ArrayList()) + .addAllVolumes(new ArrayList()) + .setExecutionEnvironment(ExecutionEnvironment.forNumber(0)) + .setEncryptionKey("encryptionKey-36224036") + .setReconciling(true) + .addAllConditions(new ArrayList()) + .setObservedGeneration(900833007) + .setLogUri("logUri-1097354360") + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + RevisionName name = RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]"); + + Revision actualResponse = client.getRevision(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRevisionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RevisionName name = RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]"); + client.getRevision(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRevisionTest2() throws Exception { + Revision expectedResponse = + Revision.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setLaunchStage(LaunchStage.forNumber(0)) + .setService(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setScaling(RevisionScaling.newBuilder().build()) + .setVpcAccess(VpcAccess.newBuilder().build()) + .setMaxInstanceRequestConcurrency(117250100) + .setTimeout(Duration.newBuilder().build()) + .setServiceAccount("serviceAccount1079137720") + .addAllContainers(new ArrayList()) + .addAllVolumes(new ArrayList()) + .setExecutionEnvironment(ExecutionEnvironment.forNumber(0)) + .setEncryptionKey("encryptionKey-36224036") + .setReconciling(true) + .addAllConditions(new ArrayList()) + .setObservedGeneration(900833007) + .setLogUri("logUri-1097354360") + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-7778/locations/location-7778/services/service-7778/revisions/revision-7778"; + + Revision actualResponse = client.getRevision(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRevisionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-7778/locations/location-7778/services/service-7778/revisions/revision-7778"; + client.getRevision(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRevisionsTest() throws Exception { + Revision responsesElement = Revision.newBuilder().build(); + ListRevisionsResponse expectedResponse = + ListRevisionsResponse.newBuilder() + .setNextPageToken("") + .addAllRevisions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ServiceName parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + + ListRevisionsPagedResponse pagedListResponse = client.listRevisions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRevisionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRevisionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ServiceName parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + client.listRevisions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRevisionsTest2() throws Exception { + Revision responsesElement = Revision.newBuilder().build(); + ListRevisionsResponse expectedResponse = + ListRevisionsResponse.newBuilder() + .setNextPageToken("") + .addAllRevisions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-4913/locations/location-4913/services/service-4913"; + + ListRevisionsPagedResponse pagedListResponse = client.listRevisions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRevisionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRevisionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-4913/locations/location-4913/services/service-4913"; + client.listRevisions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRevisionTest() throws Exception { + Revision expectedResponse = + Revision.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setLaunchStage(LaunchStage.forNumber(0)) + .setService(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setScaling(RevisionScaling.newBuilder().build()) + .setVpcAccess(VpcAccess.newBuilder().build()) + .setMaxInstanceRequestConcurrency(117250100) + .setTimeout(Duration.newBuilder().build()) + .setServiceAccount("serviceAccount1079137720") + .addAllContainers(new ArrayList()) + .addAllVolumes(new ArrayList()) + .setExecutionEnvironment(ExecutionEnvironment.forNumber(0)) + .setEncryptionKey("encryptionKey-36224036") + .setReconciling(true) + .addAllConditions(new ArrayList()) + .setObservedGeneration(900833007) + .setLogUri("logUri-1097354360") + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRevisionTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RevisionName name = RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]"); + + Revision actualResponse = client.deleteRevisionAsync(name).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRevisionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RevisionName name = RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]"); + client.deleteRevisionAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRevisionTest2() throws Exception { + Revision expectedResponse = + Revision.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setLaunchStage(LaunchStage.forNumber(0)) + .setService(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setScaling(RevisionScaling.newBuilder().build()) + .setVpcAccess(VpcAccess.newBuilder().build()) + .setMaxInstanceRequestConcurrency(117250100) + .setTimeout(Duration.newBuilder().build()) + .setServiceAccount("serviceAccount1079137720") + .addAllContainers(new ArrayList()) + .addAllVolumes(new ArrayList()) + .setExecutionEnvironment(ExecutionEnvironment.forNumber(0)) + .setEncryptionKey("encryptionKey-36224036") + .setReconciling(true) + .addAllConditions(new ArrayList()) + .setObservedGeneration(900833007) + .setLogUri("logUri-1097354360") + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRevisionTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-7778/locations/location-7778/services/service-7778/revisions/revision-7778"; + + Revision actualResponse = client.deleteRevisionAsync(name).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRevisionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-7778/locations/location-7778/services/service-7778/revisions/revision-7778"; + client.deleteRevisionAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/google-cloud-run/src/test/java/com/google/cloud/run/v2/ServicesClientHttpJsonTest.java b/google-cloud-run/src/test/java/com/google/cloud/run/v2/ServicesClientHttpJsonTest.java new file mode 100644 index 0000000..2806f80 --- /dev/null +++ b/google-cloud-run/src/test/java/com/google/cloud/run/v2/ServicesClientHttpJsonTest.java @@ -0,0 +1,963 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2; + +import static com.google.cloud.run.v2.ServicesClient.ListServicesPagedResponse; + +import com.google.api.LaunchStage; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.run.v2.stub.HttpJsonServicesStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class ServicesClientHttpJsonTest { + private static MockHttpService mockService; + private static ServicesClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonServicesStub.getMethodDescriptors(), ServicesSettings.getDefaultEndpoint()); + ServicesSettings settings = + ServicesSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + ServicesSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ServicesClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createServiceTest() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Service service = Service.newBuilder().build(); + String serviceId = "serviceId-194185552"; + + Service actualResponse = client.createServiceAsync(parent, service, serviceId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Service service = Service.newBuilder().build(); + String serviceId = "serviceId-194185552"; + client.createServiceAsync(parent, service, serviceId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createServiceTest2() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Service service = Service.newBuilder().build(); + String serviceId = "serviceId-194185552"; + + Service actualResponse = client.createServiceAsync(parent, service, serviceId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createServiceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Service service = Service.newBuilder().build(); + String serviceId = "serviceId-194185552"; + client.createServiceAsync(parent, service, serviceId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getServiceTest() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + ServiceName name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + + Service actualResponse = client.getService(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ServiceName name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + client.getService(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getServiceTest2() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-7842/locations/location-7842/services/service-7842"; + + Service actualResponse = client.getService(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getServiceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-7842/locations/location-7842/services/service-7842"; + client.getService(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listServicesTest() throws Exception { + Service responsesElement = Service.newBuilder().build(); + ListServicesResponse expectedResponse = + ListServicesResponse.newBuilder() + .setNextPageToken("") + .addAllServices(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListServicesPagedResponse pagedListResponse = client.listServices(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listServices(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listServicesTest2() throws Exception { + Service responsesElement = Service.newBuilder().build(); + ListServicesResponse expectedResponse = + ListServicesResponse.newBuilder() + .setNextPageToken("") + .addAllServices(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListServicesPagedResponse pagedListResponse = client.listServices(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listServicesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listServices(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateServiceTest() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + Service service = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + + Service actualResponse = client.updateServiceAsync(service).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Service service = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + client.updateServiceAsync(service).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteServiceTest() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ServiceName name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + + Service actualResponse = client.deleteServiceAsync(name).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ServiceName name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + client.deleteServiceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteServiceTest2() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setDescription("description-1724546052") + .setUid("uid115792") + .setGeneration(305703192) + .putAllLabels(new HashMap()) + .putAllAnnotations(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDeleteTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastModifier("lastModifier1959003021") + .setClient("client-1357712437") + .setClientVersion("clientVersion771880589") + .setIngress(IngressTraffic.forNumber(0)) + .setLaunchStage(LaunchStage.forNumber(0)) + .setBinaryAuthorization(BinaryAuthorization.newBuilder().build()) + .setTemplate(RevisionTemplate.newBuilder().build()) + .addAllTraffic(new ArrayList()) + .setObservedGeneration(900833007) + .setTerminalCondition(Condition.newBuilder().build()) + .addAllConditions(new ArrayList()) + .setLatestReadyRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setLatestCreatedRevision( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .addAllTrafficStatuses(new ArrayList()) + .setUri("uri116076") + .setReconciling(true) + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-7842/locations/location-7842/services/service-7842"; + + Service actualResponse = client.deleteServiceAsync(name).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteServiceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-7842/locations/location-7842/services/service-7842"; + client.deleteServiceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000..54315a1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.RevisionsSettings; +import com.google.cloud.run.v2.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + RevisionsSettings revisionsSettings = + RevisionsSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + RevisionsClient revisionsClient = RevisionsClient.create(revisionsSettings); + } +} +// [END run_v2_generated_revisionsclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000..6a6936b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_create_setcredentialsprovider1_sync] +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.RevisionsSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + RevisionsSettings revisionsSettings = + RevisionsSettings.newBuilder() + .setTransportChannelProvider( + RevisionsSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + RevisionsClient revisionsClient = RevisionsClient.create(revisionsSettings); + } +} +// [END run_v2_generated_revisionsclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000..5255169 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_create_setendpoint_sync] +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.RevisionsSettings; +import com.google.cloud.run.v2.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + RevisionsSettings revisionsSettings = + RevisionsSettings.newBuilder().setEndpoint(myEndpoint).build(); + RevisionsClient revisionsClient = RevisionsClient.create(revisionsSettings); + } +} +// [END run_v2_generated_revisionsclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/AsyncDeleteRevision.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/AsyncDeleteRevision.java new file mode 100644 index 0000000..9c007e8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/AsyncDeleteRevision.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_deleterevision_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.DeleteRevisionRequest; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteRevision { + + public static void main(String[] args) throws Exception { + asyncDeleteRevision(); + } + + public static void asyncDeleteRevision() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + DeleteRevisionRequest request = + DeleteRevisionRequest.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setValidateOnly(true) + .setEtag("etag3123477") + .build(); + ApiFuture future = revisionsClient.deleteRevisionCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END run_v2_generated_revisionsclient_deleterevision_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/AsyncDeleteRevisionLRO.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/AsyncDeleteRevisionLRO.java new file mode 100644 index 0000000..f870bc2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/AsyncDeleteRevisionLRO.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_deleterevision_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.run.v2.DeleteRevisionRequest; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class AsyncDeleteRevisionLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteRevisionLRO(); + } + + public static void asyncDeleteRevisionLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + DeleteRevisionRequest request = + DeleteRevisionRequest.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setValidateOnly(true) + .setEtag("etag3123477") + .build(); + OperationFuture future = + revisionsClient.deleteRevisionOperationCallable().futureCall(request); + // Do something. + Revision response = future.get(); + } + } +} +// [END run_v2_generated_revisionsclient_deleterevision_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevision.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevision.java new file mode 100644 index 0000000..cd3fb73 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevision.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_deleterevision_sync] +import com.google.cloud.run.v2.DeleteRevisionRequest; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class SyncDeleteRevision { + + public static void main(String[] args) throws Exception { + syncDeleteRevision(); + } + + public static void syncDeleteRevision() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + DeleteRevisionRequest request = + DeleteRevisionRequest.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .setValidateOnly(true) + .setEtag("etag3123477") + .build(); + Revision response = revisionsClient.deleteRevisionAsync(request).get(); + } + } +} +// [END run_v2_generated_revisionsclient_deleterevision_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevisionRevisionname.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevisionRevisionname.java new file mode 100644 index 0000000..c2f323f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevisionRevisionname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_deleterevision_revisionname_sync] +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class SyncDeleteRevisionRevisionname { + + public static void main(String[] args) throws Exception { + syncDeleteRevisionRevisionname(); + } + + public static void syncDeleteRevisionRevisionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + RevisionName name = RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]"); + Revision response = revisionsClient.deleteRevisionAsync(name).get(); + } + } +} +// [END run_v2_generated_revisionsclient_deleterevision_revisionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevisionString.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevisionString.java new file mode 100644 index 0000000..e7ad444 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/deleterevision/SyncDeleteRevisionString.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_deleterevision_string_sync] +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class SyncDeleteRevisionString { + + public static void main(String[] args) throws Exception { + syncDeleteRevisionString(); + } + + public static void syncDeleteRevisionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + String name = + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString(); + Revision response = revisionsClient.deleteRevisionAsync(name).get(); + } + } +} +// [END run_v2_generated_revisionsclient_deleterevision_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/AsyncGetRevision.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/AsyncGetRevision.java new file mode 100644 index 0000000..7622bf1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/AsyncGetRevision.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_getrevision_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.GetRevisionRequest; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class AsyncGetRevision { + + public static void main(String[] args) throws Exception { + asyncGetRevision(); + } + + public static void asyncGetRevision() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + GetRevisionRequest request = + GetRevisionRequest.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .build(); + ApiFuture future = revisionsClient.getRevisionCallable().futureCall(request); + // Do something. + Revision response = future.get(); + } + } +} +// [END run_v2_generated_revisionsclient_getrevision_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevision.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevision.java new file mode 100644 index 0000000..f65d388 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevision.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_getrevision_sync] +import com.google.cloud.run.v2.GetRevisionRequest; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class SyncGetRevision { + + public static void main(String[] args) throws Exception { + syncGetRevision(); + } + + public static void syncGetRevision() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + GetRevisionRequest request = + GetRevisionRequest.newBuilder() + .setName( + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString()) + .build(); + Revision response = revisionsClient.getRevision(request); + } + } +} +// [END run_v2_generated_revisionsclient_getrevision_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevisionRevisionname.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevisionRevisionname.java new file mode 100644 index 0000000..1eb7745 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevisionRevisionname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_getrevision_revisionname_sync] +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class SyncGetRevisionRevisionname { + + public static void main(String[] args) throws Exception { + syncGetRevisionRevisionname(); + } + + public static void syncGetRevisionRevisionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + RevisionName name = RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]"); + Revision response = revisionsClient.getRevision(name); + } + } +} +// [END run_v2_generated_revisionsclient_getrevision_revisionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevisionString.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevisionString.java new file mode 100644 index 0000000..761d750 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/getrevision/SyncGetRevisionString.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_getrevision_string_sync] +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionName; +import com.google.cloud.run.v2.RevisionsClient; + +public class SyncGetRevisionString { + + public static void main(String[] args) throws Exception { + syncGetRevisionString(); + } + + public static void syncGetRevisionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + String name = + RevisionName.of("[PROJECT]", "[LOCATION]", "[SERVICE]", "[REVISION]").toString(); + Revision response = revisionsClient.getRevision(name); + } + } +} +// [END run_v2_generated_revisionsclient_getrevision_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/AsyncListRevisions.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/AsyncListRevisions.java new file mode 100644 index 0000000..fe797d7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/AsyncListRevisions.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_listrevisions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.ListRevisionsRequest; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.ServiceName; + +public class AsyncListRevisions { + + public static void main(String[] args) throws Exception { + asyncListRevisions(); + } + + public static void asyncListRevisions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + ListRevisionsRequest request = + ListRevisionsRequest.newBuilder() + .setParent(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setShowDeleted(true) + .build(); + ApiFuture future = revisionsClient.listRevisionsPagedCallable().futureCall(request); + // Do something. + for (Revision element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_revisionsclient_listrevisions_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/AsyncListRevisionsPaged.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/AsyncListRevisionsPaged.java new file mode 100644 index 0000000..bafc415 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/AsyncListRevisionsPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_listrevisions_paged_async] +import com.google.cloud.run.v2.ListRevisionsRequest; +import com.google.cloud.run.v2.ListRevisionsResponse; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.ServiceName; +import com.google.common.base.Strings; + +public class AsyncListRevisionsPaged { + + public static void main(String[] args) throws Exception { + asyncListRevisionsPaged(); + } + + public static void asyncListRevisionsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + ListRevisionsRequest request = + ListRevisionsRequest.newBuilder() + .setParent(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setShowDeleted(true) + .build(); + while (true) { + ListRevisionsResponse response = revisionsClient.listRevisionsCallable().call(request); + for (Revision element : response.getRevisionsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END run_v2_generated_revisionsclient_listrevisions_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisions.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisions.java new file mode 100644 index 0000000..227c054 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisions.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_listrevisions_sync] +import com.google.cloud.run.v2.ListRevisionsRequest; +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.ServiceName; + +public class SyncListRevisions { + + public static void main(String[] args) throws Exception { + syncListRevisions(); + } + + public static void syncListRevisions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + ListRevisionsRequest request = + ListRevisionsRequest.newBuilder() + .setParent(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setShowDeleted(true) + .build(); + for (Revision element : revisionsClient.listRevisions(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_revisionsclient_listrevisions_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisionsServicename.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisionsServicename.java new file mode 100644 index 0000000..1af4902 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisionsServicename.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_listrevisions_servicename_sync] +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.ServiceName; + +public class SyncListRevisionsServicename { + + public static void main(String[] args) throws Exception { + syncListRevisionsServicename(); + } + + public static void syncListRevisionsServicename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + ServiceName parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + for (Revision element : revisionsClient.listRevisions(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_revisionsclient_listrevisions_servicename_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisionsString.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisionsString.java new file mode 100644 index 0000000..7599d48 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionsclient/listrevisions/SyncListRevisionsString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionsclient_listrevisions_string_sync] +import com.google.cloud.run.v2.Revision; +import com.google.cloud.run.v2.RevisionsClient; +import com.google.cloud.run.v2.ServiceName; + +public class SyncListRevisionsString { + + public static void main(String[] args) throws Exception { + syncListRevisionsString(); + } + + public static void syncListRevisionsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (RevisionsClient revisionsClient = RevisionsClient.create()) { + String parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString(); + for (Revision element : revisionsClient.listRevisions(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_revisionsclient_listrevisions_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/revisionssettings/getrevision/SyncGetRevision.java b/samples/snippets/generated/com/google/cloud/run/v2/revisionssettings/getrevision/SyncGetRevision.java new file mode 100644 index 0000000..93ca1ed --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/revisionssettings/getrevision/SyncGetRevision.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_revisionssettings_getrevision_sync] +import com.google.cloud.run.v2.RevisionsSettings; +import java.time.Duration; + +public class SyncGetRevision { + + public static void main(String[] args) throws Exception { + syncGetRevision(); + } + + public static void syncGetRevision() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + RevisionsSettings.Builder revisionsSettingsBuilder = RevisionsSettings.newBuilder(); + revisionsSettingsBuilder + .getRevisionSettings() + .setRetrySettings( + revisionsSettingsBuilder + .getRevisionSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + RevisionsSettings revisionsSettings = revisionsSettingsBuilder.build(); + } +} +// [END run_v2_generated_revisionssettings_getrevision_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000..64a046f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.run.v2.ServicesClient; +import com.google.cloud.run.v2.ServicesSettings; +import com.google.cloud.run.v2.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + ServicesSettings servicesSettings = + ServicesSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + ServicesClient servicesClient = ServicesClient.create(servicesSettings); + } +} +// [END run_v2_generated_servicesclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000..655c0fa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_create_setcredentialsprovider1_sync] +import com.google.cloud.run.v2.ServicesClient; +import com.google.cloud.run.v2.ServicesSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + ServicesSettings servicesSettings = + ServicesSettings.newBuilder() + .setTransportChannelProvider( + ServicesSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + ServicesClient servicesClient = ServicesClient.create(servicesSettings); + } +} +// [END run_v2_generated_servicesclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000..68f0b75 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_create_setendpoint_sync] +import com.google.cloud.run.v2.ServicesClient; +import com.google.cloud.run.v2.ServicesSettings; +import com.google.cloud.run.v2.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + ServicesSettings servicesSettings = + ServicesSettings.newBuilder().setEndpoint(myEndpoint).build(); + ServicesClient servicesClient = ServicesClient.create(servicesSettings); + } +} +// [END run_v2_generated_servicesclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/AsyncCreateService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/AsyncCreateService.java new file mode 100644 index 0000000..684ceee --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/AsyncCreateService.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_createservice_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.CreateServiceRequest; +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; +import com.google.longrunning.Operation; + +public class AsyncCreateService { + + public static void main(String[] args) throws Exception { + asyncCreateService(); + } + + public static void asyncCreateService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + CreateServiceRequest request = + CreateServiceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setService(Service.newBuilder().build()) + .setServiceId("serviceId-194185552") + .setValidateOnly(true) + .build(); + ApiFuture future = servicesClient.createServiceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_createservice_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/AsyncCreateServiceLRO.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/AsyncCreateServiceLRO.java new file mode 100644 index 0000000..eda3f56 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/AsyncCreateServiceLRO.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_createservice_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.run.v2.CreateServiceRequest; +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class AsyncCreateServiceLRO { + + public static void main(String[] args) throws Exception { + asyncCreateServiceLRO(); + } + + public static void asyncCreateServiceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + CreateServiceRequest request = + CreateServiceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setService(Service.newBuilder().build()) + .setServiceId("serviceId-194185552") + .setValidateOnly(true) + .build(); + OperationFuture future = + servicesClient.createServiceOperationCallable().futureCall(request); + // Do something. + Service response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_createservice_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateService.java new file mode 100644 index 0000000..0120811 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateService.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_createservice_sync] +import com.google.cloud.run.v2.CreateServiceRequest; +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncCreateService { + + public static void main(String[] args) throws Exception { + syncCreateService(); + } + + public static void syncCreateService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + CreateServiceRequest request = + CreateServiceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setService(Service.newBuilder().build()) + .setServiceId("serviceId-194185552") + .setValidateOnly(true) + .build(); + Service response = servicesClient.createServiceAsync(request).get(); + } + } +} +// [END run_v2_generated_servicesclient_createservice_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateServiceLocationnameServiceString.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateServiceLocationnameServiceString.java new file mode 100644 index 0000000..e7b4335 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateServiceLocationnameServiceString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_createservice_locationnameservicestring_sync] +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncCreateServiceLocationnameServiceString { + + public static void main(String[] args) throws Exception { + syncCreateServiceLocationnameServiceString(); + } + + public static void syncCreateServiceLocationnameServiceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Service service = Service.newBuilder().build(); + String serviceId = "serviceId-194185552"; + Service response = servicesClient.createServiceAsync(parent, service, serviceId).get(); + } + } +} +// [END run_v2_generated_servicesclient_createservice_locationnameservicestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateServiceStringServiceString.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateServiceStringServiceString.java new file mode 100644 index 0000000..54db6fc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/createservice/SyncCreateServiceStringServiceString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_createservice_stringservicestring_sync] +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncCreateServiceStringServiceString { + + public static void main(String[] args) throws Exception { + syncCreateServiceStringServiceString(); + } + + public static void syncCreateServiceStringServiceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Service service = Service.newBuilder().build(); + String serviceId = "serviceId-194185552"; + Service response = servicesClient.createServiceAsync(parent, service, serviceId).get(); + } + } +} +// [END run_v2_generated_servicesclient_createservice_stringservicestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/AsyncDeleteService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/AsyncDeleteService.java new file mode 100644 index 0000000..cfd782f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/AsyncDeleteService.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_deleteservice_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.DeleteServiceRequest; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteService { + + public static void main(String[] args) throws Exception { + asyncDeleteService(); + } + + public static void asyncDeleteService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + DeleteServiceRequest request = + DeleteServiceRequest.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setValidateOnly(true) + .setEtag("etag3123477") + .build(); + ApiFuture future = servicesClient.deleteServiceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_deleteservice_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/AsyncDeleteServiceLRO.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/AsyncDeleteServiceLRO.java new file mode 100644 index 0000000..1314ce4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/AsyncDeleteServiceLRO.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_deleteservice_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.run.v2.DeleteServiceRequest; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class AsyncDeleteServiceLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteServiceLRO(); + } + + public static void asyncDeleteServiceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + DeleteServiceRequest request = + DeleteServiceRequest.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setValidateOnly(true) + .setEtag("etag3123477") + .build(); + OperationFuture future = + servicesClient.deleteServiceOperationCallable().futureCall(request); + // Do something. + Service response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_deleteservice_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteService.java new file mode 100644 index 0000000..395e53c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_deleteservice_sync] +import com.google.cloud.run.v2.DeleteServiceRequest; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncDeleteService { + + public static void main(String[] args) throws Exception { + syncDeleteService(); + } + + public static void syncDeleteService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + DeleteServiceRequest request = + DeleteServiceRequest.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setValidateOnly(true) + .setEtag("etag3123477") + .build(); + Service response = servicesClient.deleteServiceAsync(request).get(); + } + } +} +// [END run_v2_generated_servicesclient_deleteservice_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteServiceServicename.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteServiceServicename.java new file mode 100644 index 0000000..1e5ef0e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteServiceServicename.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_deleteservice_servicename_sync] +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncDeleteServiceServicename { + + public static void main(String[] args) throws Exception { + syncDeleteServiceServicename(); + } + + public static void syncDeleteServiceServicename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + ServiceName name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + Service response = servicesClient.deleteServiceAsync(name).get(); + } + } +} +// [END run_v2_generated_servicesclient_deleteservice_servicename_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteServiceString.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteServiceString.java new file mode 100644 index 0000000..9fb75e7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/deleteservice/SyncDeleteServiceString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_deleteservice_string_sync] +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncDeleteServiceString { + + public static void main(String[] args) throws Exception { + syncDeleteServiceString(); + } + + public static void syncDeleteServiceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + String name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString(); + Service response = servicesClient.deleteServiceAsync(name).get(); + } + } +} +// [END run_v2_generated_servicesclient_deleteservice_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getiampolicy/AsyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000..cf87a0a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_getiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = servicesClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_getiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getiampolicy/SyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000..8a8bfc8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_getiampolicy_sync] +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = servicesClient.getIamPolicy(request); + } + } +} +// [END run_v2_generated_servicesclient_getiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/AsyncGetService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/AsyncGetService.java new file mode 100644 index 0000000..1587af0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/AsyncGetService.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_getservice_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.GetServiceRequest; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class AsyncGetService { + + public static void main(String[] args) throws Exception { + asyncGetService(); + } + + public static void asyncGetService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + GetServiceRequest request = + GetServiceRequest.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .build(); + ApiFuture future = servicesClient.getServiceCallable().futureCall(request); + // Do something. + Service response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_getservice_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetService.java new file mode 100644 index 0000000..950891e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetService.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_getservice_sync] +import com.google.cloud.run.v2.GetServiceRequest; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncGetService { + + public static void main(String[] args) throws Exception { + syncGetService(); + } + + public static void syncGetService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + GetServiceRequest request = + GetServiceRequest.newBuilder() + .setName(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .build(); + Service response = servicesClient.getService(request); + } + } +} +// [END run_v2_generated_servicesclient_getservice_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetServiceServicename.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetServiceServicename.java new file mode 100644 index 0000000..72ddd61 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetServiceServicename.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_getservice_servicename_sync] +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncGetServiceServicename { + + public static void main(String[] args) throws Exception { + syncGetServiceServicename(); + } + + public static void syncGetServiceServicename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + ServiceName name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]"); + Service response = servicesClient.getService(name); + } + } +} +// [END run_v2_generated_servicesclient_getservice_servicename_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetServiceString.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetServiceString.java new file mode 100644 index 0000000..8503f6f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/getservice/SyncGetServiceString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_getservice_string_sync] +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncGetServiceString { + + public static void main(String[] args) throws Exception { + syncGetServiceString(); + } + + public static void syncGetServiceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + String name = ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString(); + Service response = servicesClient.getService(name); + } + } +} +// [END run_v2_generated_servicesclient_getservice_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/AsyncListServices.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/AsyncListServices.java new file mode 100644 index 0000000..f605a8c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/AsyncListServices.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_listservices_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.ListServicesRequest; +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class AsyncListServices { + + public static void main(String[] args) throws Exception { + asyncListServices(); + } + + public static void asyncListServices() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setShowDeleted(true) + .build(); + ApiFuture future = servicesClient.listServicesPagedCallable().futureCall(request); + // Do something. + for (Service element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_servicesclient_listservices_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/AsyncListServicesPaged.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/AsyncListServicesPaged.java new file mode 100644 index 0000000..26da4f1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/AsyncListServicesPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_listservices_paged_async] +import com.google.cloud.run.v2.ListServicesRequest; +import com.google.cloud.run.v2.ListServicesResponse; +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; +import com.google.common.base.Strings; + +public class AsyncListServicesPaged { + + public static void main(String[] args) throws Exception { + asyncListServicesPaged(); + } + + public static void asyncListServicesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setShowDeleted(true) + .build(); + while (true) { + ListServicesResponse response = servicesClient.listServicesCallable().call(request); + for (Service element : response.getServicesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END run_v2_generated_servicesclient_listservices_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServices.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServices.java new file mode 100644 index 0000000..8316c98 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServices.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_listservices_sync] +import com.google.cloud.run.v2.ListServicesRequest; +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncListServices { + + public static void main(String[] args) throws Exception { + syncListServices(); + } + + public static void syncListServices() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setShowDeleted(true) + .build(); + for (Service element : servicesClient.listServices(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_servicesclient_listservices_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServicesLocationname.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServicesLocationname.java new file mode 100644 index 0000000..b3808ee --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServicesLocationname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_listservices_locationname_sync] +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncListServicesLocationname { + + public static void main(String[] args) throws Exception { + syncListServicesLocationname(); + } + + public static void syncListServicesLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Service element : servicesClient.listServices(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_servicesclient_listservices_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServicesString.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServicesString.java new file mode 100644 index 0000000..855d5ec --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/listservices/SyncListServicesString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_listservices_string_sync] +import com.google.cloud.run.v2.LocationName; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncListServicesString { + + public static void main(String[] args) throws Exception { + syncListServicesString(); + } + + public static void syncListServicesString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Service element : servicesClient.listServices(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END run_v2_generated_servicesclient_listservices_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/setiampolicy/AsyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000..439cd5e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_setiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = servicesClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_setiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/setiampolicy/SyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000..e033009 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_setiampolicy_sync] +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = servicesClient.setIamPolicy(request); + } + } +} +// [END run_v2_generated_servicesclient_setiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/testiampermissions/AsyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000..c143cd9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_testiampermissions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + servicesClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_testiampermissions_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/testiampermissions/SyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000..c7d2cf6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_testiampermissions_sync] +import com.google.cloud.run.v2.ServiceName; +import com.google.cloud.run.v2.ServicesClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(ServiceName.of("[PROJECT]", "[LOCATION]", "[SERVICE]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = servicesClient.testIamPermissions(request); + } + } +} +// [END run_v2_generated_servicesclient_testiampermissions_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/AsyncUpdateService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/AsyncUpdateService.java new file mode 100644 index 0000000..cca0236 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/AsyncUpdateService.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_updateservice_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; +import com.google.cloud.run.v2.UpdateServiceRequest; +import com.google.longrunning.Operation; + +public class AsyncUpdateService { + + public static void main(String[] args) throws Exception { + asyncUpdateService(); + } + + public static void asyncUpdateService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + UpdateServiceRequest request = + UpdateServiceRequest.newBuilder() + .setService(Service.newBuilder().build()) + .setValidateOnly(true) + .setAllowMissing(true) + .build(); + ApiFuture future = servicesClient.updateServiceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_updateservice_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/AsyncUpdateServiceLRO.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/AsyncUpdateServiceLRO.java new file mode 100644 index 0000000..1b1a8ca --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/AsyncUpdateServiceLRO.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_updateservice_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; +import com.google.cloud.run.v2.UpdateServiceRequest; + +public class AsyncUpdateServiceLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateServiceLRO(); + } + + public static void asyncUpdateServiceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + UpdateServiceRequest request = + UpdateServiceRequest.newBuilder() + .setService(Service.newBuilder().build()) + .setValidateOnly(true) + .setAllowMissing(true) + .build(); + OperationFuture future = + servicesClient.updateServiceOperationCallable().futureCall(request); + // Do something. + Service response = future.get(); + } + } +} +// [END run_v2_generated_servicesclient_updateservice_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/SyncUpdateService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/SyncUpdateService.java new file mode 100644 index 0000000..6c15866 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/SyncUpdateService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_updateservice_sync] +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; +import com.google.cloud.run.v2.UpdateServiceRequest; + +public class SyncUpdateService { + + public static void main(String[] args) throws Exception { + syncUpdateService(); + } + + public static void syncUpdateService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + UpdateServiceRequest request = + UpdateServiceRequest.newBuilder() + .setService(Service.newBuilder().build()) + .setValidateOnly(true) + .setAllowMissing(true) + .build(); + Service response = servicesClient.updateServiceAsync(request).get(); + } + } +} +// [END run_v2_generated_servicesclient_updateservice_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/SyncUpdateServiceService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/SyncUpdateServiceService.java new file mode 100644 index 0000000..a44fef7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicesclient/updateservice/SyncUpdateServiceService.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicesclient_updateservice_service_sync] +import com.google.cloud.run.v2.Service; +import com.google.cloud.run.v2.ServicesClient; + +public class SyncUpdateServiceService { + + public static void main(String[] args) throws Exception { + syncUpdateServiceService(); + } + + public static void syncUpdateServiceService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (ServicesClient servicesClient = ServicesClient.create()) { + Service service = Service.newBuilder().build(); + Service response = servicesClient.updateServiceAsync(service).get(); + } + } +} +// [END run_v2_generated_servicesclient_updateservice_service_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/servicessettings/getservice/SyncGetService.java b/samples/snippets/generated/com/google/cloud/run/v2/servicessettings/getservice/SyncGetService.java new file mode 100644 index 0000000..52c440d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/servicessettings/getservice/SyncGetService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.samples; + +// [START run_v2_generated_servicessettings_getservice_sync] +import com.google.cloud.run.v2.ServicesSettings; +import java.time.Duration; + +public class SyncGetService { + + public static void main(String[] args) throws Exception { + syncGetService(); + } + + public static void syncGetService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + ServicesSettings.Builder servicesSettingsBuilder = ServicesSettings.newBuilder(); + servicesSettingsBuilder + .getServiceSettings() + .setRetrySettings( + servicesSettingsBuilder + .getServiceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + ServicesSettings servicesSettings = servicesSettingsBuilder.build(); + } +} +// [END run_v2_generated_servicessettings_getservice_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/stub/revisionsstubsettings/getrevision/SyncGetRevision.java b/samples/snippets/generated/com/google/cloud/run/v2/stub/revisionsstubsettings/getrevision/SyncGetRevision.java new file mode 100644 index 0000000..55abff2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/stub/revisionsstubsettings/getrevision/SyncGetRevision.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.stub.samples; + +// [START run_v2_generated_revisionsstubsettings_getrevision_sync] +import com.google.cloud.run.v2.stub.RevisionsStubSettings; +import java.time.Duration; + +public class SyncGetRevision { + + public static void main(String[] args) throws Exception { + syncGetRevision(); + } + + public static void syncGetRevision() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + RevisionsStubSettings.Builder revisionsSettingsBuilder = RevisionsStubSettings.newBuilder(); + revisionsSettingsBuilder + .getRevisionSettings() + .setRetrySettings( + revisionsSettingsBuilder + .getRevisionSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + RevisionsStubSettings revisionsSettings = revisionsSettingsBuilder.build(); + } +} +// [END run_v2_generated_revisionsstubsettings_getrevision_sync] diff --git a/samples/snippets/generated/com/google/cloud/run/v2/stub/servicesstubsettings/getservice/SyncGetService.java b/samples/snippets/generated/com/google/cloud/run/v2/stub/servicesstubsettings/getservice/SyncGetService.java new file mode 100644 index 0000000..f6585a6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/run/v2/stub/servicesstubsettings/getservice/SyncGetService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.run.v2.stub.samples; + +// [START run_v2_generated_servicesstubsettings_getservice_sync] +import com.google.cloud.run.v2.stub.ServicesStubSettings; +import java.time.Duration; + +public class SyncGetService { + + public static void main(String[] args) throws Exception { + syncGetService(); + } + + public static void syncGetService() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + ServicesStubSettings.Builder servicesSettingsBuilder = ServicesStubSettings.newBuilder(); + servicesSettingsBuilder + .getServiceSettings() + .setRetrySettings( + servicesSettingsBuilder + .getServiceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + ServicesStubSettings servicesSettings = servicesSettingsBuilder.build(); + } +} +// [END run_v2_generated_servicesstubsettings_getservice_sync]