diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index a79f0627..a454a61e 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,5 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:2567a120ce90fadb6201999b87d649d9f67459de28815ad239bce9ebfaa18a74 -# created: 2022-05-19T15:12:45.278246753Z + digest: sha256:6d4e3a15c62cfdcb823d60e16da7521e7c6fc00eba07c8ff12e4de9924a57d28 +# created: 2022-06-29T23:17:33.110417661Z diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 6f09d695..dd5626f3 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -11,7 +11,6 @@ branchProtectionRules: - dependencies (8) - dependencies (11) - lint - - clirr - units (8) - units (11) - 'Kokoro - Test: Integration' @@ -26,7 +25,6 @@ branchProtectionRules: - dependencies (8) - dependencies (11) - lint - - clirr - units (7) - units (8) - units (11) diff --git a/.kokoro/common.sh b/.kokoro/common.sh index ace89f45..f8f957af 100644 --- a/.kokoro/common.sh +++ b/.kokoro/common.sh @@ -55,4 +55,6 @@ function retry_with_backoff { ## Helper functionss function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; } function msg() { println "$*" >&2; } -function println() { printf '%s\n' "$(now) $*"; } \ No newline at end of file +function println() { printf '%s\n' "$(now) $*"; } + +## Helper comment to trigger updated repo dependency release \ No newline at end of file diff --git a/.kokoro/release/stage.sh b/.kokoro/release/stage.sh index 77dc4e8f..1dba8de1 100755 --- a/.kokoro/release/stage.sh +++ b/.kokoro/release/stage.sh @@ -32,6 +32,7 @@ retry_with_backoff 3 10 \ mvn clean deploy -B \ --settings ${MAVEN_SETTINGS_FILE} \ -DskipTests=true \ + -Dclirr.skip=true \ -DperformRelease=true \ -Dgpg.executable=gpg \ -Dgpg.passphrase=${GPG_PASSPHRASE} \ @@ -42,4 +43,4 @@ then mvn nexus-staging:release -B \ -DperformRelease=true \ --settings=settings.xml -fi \ No newline at end of file +fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c84f0fa..b73edfb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [2.3.0](https://github.com/googleapis/java-vpcaccess/compare/v2.2.1...v2.3.0) (2022-07-01) + + +### Features + +* Enable REST transport for most of Java and Go clients ([908b1f6](https://github.com/googleapis/java-vpcaccess/commit/908b1f61e9e3c4110317375a7fb142a9b7619a0e)) + + +### Bug Fixes + +* update gapic-generator-java with mock service generation fixes ([#206](https://github.com/googleapis/java-vpcaccess/issues/206)) ([908b1f6](https://github.com/googleapis/java-vpcaccess/commit/908b1f61e9e3c4110317375a7fb142a9b7619a0e)) + ## [2.2.1](https://github.com/googleapis/java-vpcaccess/compare/v2.2.0...v2.2.1) (2022-06-23) diff --git a/README.md b/README.md index 8f899f49..f8b0ab39 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-vpcaccess - 2.2.0 + 2.2.1 ``` @@ -27,13 +27,13 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-vpcaccess:2.2.0' +implementation 'com.google.cloud:google-cloud-vpcaccess:2.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-vpcaccess" % "2.2.0" +libraryDependencies += "com.google.cloud" % "google-cloud-vpcaccess" % "2.2.1" ``` ## Authentication diff --git a/google-cloud-vpcaccess-bom/pom.xml b/google-cloud-vpcaccess-bom/pom.xml index 7d5782e4..290cdce5 100644 --- a/google-cloud-vpcaccess-bom/pom.xml +++ b/google-cloud-vpcaccess-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-vpcaccess-bom - 2.2.1 + 2.3.0 pom com.google.cloud @@ -56,17 +56,17 @@ com.google.cloud google-cloud-vpcaccess - 2.2.1 + 2.3.0 com.google.api.grpc grpc-google-cloud-vpcaccess-v1 - 2.2.1 + 2.3.0 com.google.api.grpc proto-google-cloud-vpcaccess-v1 - 2.2.1 + 2.3.0 diff --git a/google-cloud-vpcaccess/pom.xml b/google-cloud-vpcaccess/pom.xml index bd7c41bc..d4db5d71 100644 --- a/google-cloud-vpcaccess/pom.xml +++ b/google-cloud-vpcaccess/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-vpcaccess - 2.2.1 + 2.3.0 jar Google Serverless VPC Access https://github.com/googleapis/java-vpcaccess @@ -11,7 +11,7 @@ com.google.cloud google-cloud-vpcaccess-parent - 2.2.1 + 2.3.0 google-cloud-vpcaccess @@ -58,6 +58,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -77,12 +81,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-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClient.java b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClient.java index 70d1472a..e2057d60 100644 --- a/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClient.java +++ b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClient.java @@ -18,7 +18,9 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; 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 +32,6 @@ import com.google.cloud.vpcaccess.v1.stub.VpcAccessServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -106,13 +107,29 @@ * VpcAccessServiceClient.create(vpcAccessServiceSettings); * } * + *

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.
+ * VpcAccessServiceSettings vpcAccessServiceSettings =
+ *     VpcAccessServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             VpcAccessServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * VpcAccessServiceClient vpcAccessServiceClient =
+ *     VpcAccessServiceClient.create(vpcAccessServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class VpcAccessServiceClient implements BackgroundResource { private final VpcAccessServiceSettings settings; private final VpcAccessServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of VpcAccessServiceClient with default settings. */ public static final VpcAccessServiceClient create() throws IOException { @@ -144,13 +161,17 @@ public static final VpcAccessServiceClient create(VpcAccessServiceStub stub) { protected VpcAccessServiceClient(VpcAccessServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((VpcAccessServiceStubSettings) 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 VpcAccessServiceClient(VpcAccessServiceStub 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 VpcAccessServiceSettings getSettings() { @@ -165,10 +186,19 @@ public VpcAccessServiceStub 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. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Creates a Serverless VPC Access connector, returns an operation. diff --git a/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceSettings.java b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceSettings.java index dad3d315..b0207fa7 100644 --- a/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceSettings.java +++ b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceSettings.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; @@ -133,11 +134,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return VpcAccessServiceStubSettings.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 VpcAccessServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return VpcAccessServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return VpcAccessServiceStubSettings.defaultTransportChannelProvider(); } @@ -147,11 +155,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return VpcAccessServiceStubSettings.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); @@ -189,6 +203,11 @@ private static Builder createDefault() { return new Builder(VpcAccessServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(VpcAccessServiceStubSettings.newHttpJsonBuilder()); + } + public VpcAccessServiceStubSettings.Builder getStubSettingsBuilder() { return ((VpcAccessServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/HttpJsonVpcAccessServiceCallableFactory.java b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/HttpJsonVpcAccessServiceCallableFactory.java new file mode 100644 index 00000000..77821620 --- /dev/null +++ b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/HttpJsonVpcAccessServiceCallableFactory.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.vpcaccess.v1.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 VpcAccessService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonVpcAccessServiceCallableFactory + 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-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/HttpJsonVpcAccessServiceStub.java b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/HttpJsonVpcAccessServiceStub.java new file mode 100644 index 00000000..f610e4c6 --- /dev/null +++ b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/HttpJsonVpcAccessServiceStub.java @@ -0,0 +1,412 @@ +/* + * 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.vpcaccess.v1.stub; + +import static com.google.cloud.vpcaccess.v1.VpcAccessServiceClient.ListConnectorsPagedResponse; + +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.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.CreateConnectorRequest; +import com.google.cloud.vpcaccess.v1.DeleteConnectorRequest; +import com.google.cloud.vpcaccess.v1.GetConnectorRequest; +import com.google.cloud.vpcaccess.v1.ListConnectorsRequest; +import com.google.cloud.vpcaccess.v1.ListConnectorsResponse; +import com.google.cloud.vpcaccess.v1.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +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 VpcAccessService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonVpcAccessServiceStub extends VpcAccessServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(Connector.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + createConnectorMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.vpcaccess.v1.VpcAccessService/CreateConnector") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/connectors", + 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, "connectorId", request.getConnectorId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("connector", request.getConnector())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateConnectorRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + getConnectorMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.vpcaccess.v1.VpcAccessService/GetConnector") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/connectors/*}", + 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(Connector.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listConnectorsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.vpcaccess.v1.VpcAccessService/ListConnectors") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/connectors", + 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()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListConnectorsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteConnectorMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.vpcaccess.v1.VpcAccessService/DeleteConnector") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/connectors/*}", + 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(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteConnectorRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable createConnectorCallable; + private final OperationCallable + createConnectorOperationCallable; + private final UnaryCallable getConnectorCallable; + private final UnaryCallable listConnectorsCallable; + private final UnaryCallable + listConnectorsPagedCallable; + private final UnaryCallable deleteConnectorCallable; + private final OperationCallable + deleteConnectorOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonVpcAccessServiceStub create(VpcAccessServiceStubSettings settings) + throws IOException { + return new HttpJsonVpcAccessServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonVpcAccessServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonVpcAccessServiceStub( + VpcAccessServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonVpcAccessServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonVpcAccessServiceStub( + VpcAccessServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonVpcAccessServiceStub, 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 HttpJsonVpcAccessServiceStub( + VpcAccessServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonVpcAccessServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonVpcAccessServiceStub, 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 HttpJsonVpcAccessServiceStub( + VpcAccessServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings createConnectorTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createConnectorMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getConnectorTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getConnectorMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listConnectorsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listConnectorsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteConnectorTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteConnectorMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createConnectorCallable = + callableFactory.createUnaryCallable( + createConnectorTransportSettings, settings.createConnectorSettings(), clientContext); + this.createConnectorOperationCallable = + callableFactory.createOperationCallable( + createConnectorTransportSettings, + settings.createConnectorOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getConnectorCallable = + callableFactory.createUnaryCallable( + getConnectorTransportSettings, settings.getConnectorSettings(), clientContext); + this.listConnectorsCallable = + callableFactory.createUnaryCallable( + listConnectorsTransportSettings, settings.listConnectorsSettings(), clientContext); + this.listConnectorsPagedCallable = + callableFactory.createPagedCallable( + listConnectorsTransportSettings, settings.listConnectorsSettings(), clientContext); + this.deleteConnectorCallable = + callableFactory.createUnaryCallable( + deleteConnectorTransportSettings, settings.deleteConnectorSettings(), clientContext); + this.deleteConnectorOperationCallable = + callableFactory.createOperationCallable( + deleteConnectorTransportSettings, + settings.deleteConnectorOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createConnectorMethodDescriptor); + methodDescriptors.add(getConnectorMethodDescriptor); + methodDescriptors.add(listConnectorsMethodDescriptor); + methodDescriptors.add(deleteConnectorMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable createConnectorCallable() { + return createConnectorCallable; + } + + @Override + public OperationCallable + createConnectorOperationCallable() { + return createConnectorOperationCallable; + } + + @Override + public UnaryCallable getConnectorCallable() { + return getConnectorCallable; + } + + @Override + public UnaryCallable listConnectorsCallable() { + return listConnectorsCallable; + } + + @Override + public UnaryCallable + listConnectorsPagedCallable() { + return listConnectorsPagedCallable; + } + + @Override + public UnaryCallable deleteConnectorCallable() { + return deleteConnectorCallable; + } + + @Override + public OperationCallable + deleteConnectorOperationCallable() { + return deleteConnectorOperationCallable; + } + + @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-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStub.java b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStub.java index 675ea276..18d84e28 100644 --- a/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStub.java +++ b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStub.java @@ -43,7 +43,11 @@ public abstract class VpcAccessServiceStub 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-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStubSettings.java b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStubSettings.java index af516c9f..01827378 100644 --- a/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStubSettings.java +++ b/google-cloud-vpcaccess/src/main/java/com/google/cloud/vpcaccess/v1/stub/VpcAccessServiceStubSettings.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; @@ -207,6 +210,11 @@ public VpcAccessServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcVpcAccessServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonVpcAccessServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -239,18 +247,25 @@ 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(VpcAccessServiceStubSettings.class)) @@ -258,11 +273,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil 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(VpcAccessServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return VpcAccessServiceStubSettings.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); @@ -381,6 +415,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 .createConnectorSettings() diff --git a/google-cloud-vpcaccess/src/test/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClientHttpJsonTest.java b/google-cloud-vpcaccess/src/test/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClientHttpJsonTest.java new file mode 100644 index 00000000..e2487409 --- /dev/null +++ b/google-cloud-vpcaccess/src/test/java/com/google/cloud/vpcaccess/v1/VpcAccessServiceClientHttpJsonTest.java @@ -0,0 +1,490 @@ +/* + * 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.vpcaccess.v1; + +import static com.google.cloud.vpcaccess.v1.VpcAccessServiceClient.ListConnectorsPagedResponse; + +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.vpcaccess.v1.stub.HttpJsonVpcAccessServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +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 VpcAccessServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static VpcAccessServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonVpcAccessServiceStub.getMethodDescriptors(), + VpcAccessServiceSettings.getDefaultEndpoint()); + VpcAccessServiceSettings settings = + VpcAccessServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + VpcAccessServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = VpcAccessServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createConnectorTest() throws Exception { + Connector expectedResponse = + Connector.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .setNetwork("network1843485230") + .setIpCidrRange("ipCidrRange-866375486") + .setMinThroughput(2064735799) + .setMaxThroughput(1407819749) + .addAllConnectedProjects(new ArrayList()) + .setSubnet(Connector.Subnet.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createConnectorTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String connectorId = "connectorId1724784200"; + Connector connector = Connector.newBuilder().build(); + + Connector actualResponse = client.createConnectorAsync(parent, connectorId, connector).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 createConnectorExceptionTest() 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]"); + String connectorId = "connectorId1724784200"; + Connector connector = Connector.newBuilder().build(); + client.createConnectorAsync(parent, connectorId, connector).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createConnectorTest2() throws Exception { + Connector expectedResponse = + Connector.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .setNetwork("network1843485230") + .setIpCidrRange("ipCidrRange-866375486") + .setMinThroughput(2064735799) + .setMaxThroughput(1407819749) + .addAllConnectedProjects(new ArrayList()) + .setSubnet(Connector.Subnet.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createConnectorTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + String connectorId = "connectorId1724784200"; + Connector connector = Connector.newBuilder().build(); + + Connector actualResponse = client.createConnectorAsync(parent, connectorId, connector).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 createConnectorExceptionTest2() 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"; + String connectorId = "connectorId1724784200"; + Connector connector = Connector.newBuilder().build(); + client.createConnectorAsync(parent, connectorId, connector).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getConnectorTest() throws Exception { + Connector expectedResponse = + Connector.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .setNetwork("network1843485230") + .setIpCidrRange("ipCidrRange-866375486") + .setMinThroughput(2064735799) + .setMaxThroughput(1407819749) + .addAllConnectedProjects(new ArrayList()) + .setSubnet(Connector.Subnet.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ConnectorName name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]"); + + Connector actualResponse = client.getConnector(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 getConnectorExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ConnectorName name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]"); + client.getConnector(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getConnectorTest2() throws Exception { + Connector expectedResponse = + Connector.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .setNetwork("network1843485230") + .setIpCidrRange("ipCidrRange-866375486") + .setMinThroughput(2064735799) + .setMaxThroughput(1407819749) + .addAllConnectedProjects(new ArrayList()) + .setSubnet(Connector.Subnet.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-698/locations/location-698/connectors/connector-698"; + + Connector actualResponse = client.getConnector(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 getConnectorExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-698/locations/location-698/connectors/connector-698"; + client.getConnector(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listConnectorsTest() throws Exception { + Connector responsesElement = Connector.newBuilder().build(); + ListConnectorsResponse expectedResponse = + ListConnectorsResponse.newBuilder() + .setNextPageToken("") + .addAllConnectors(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListConnectorsPagedResponse pagedListResponse = client.listConnectors(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getConnectorsList().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 listConnectorsExceptionTest() 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.listConnectors(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listConnectorsTest2() throws Exception { + Connector responsesElement = Connector.newBuilder().build(); + ListConnectorsResponse expectedResponse = + ListConnectorsResponse.newBuilder() + .setNextPageToken("") + .addAllConnectors(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListConnectorsPagedResponse pagedListResponse = client.listConnectors(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getConnectorsList().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 listConnectorsExceptionTest2() 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.listConnectors(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteConnectorTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteConnectorTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ConnectorName name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]"); + + client.deleteConnectorAsync(name).get(); + + 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 deleteConnectorExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ConnectorName name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]"); + client.deleteConnectorAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteConnectorTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteConnectorTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-698/locations/location-698/connectors/connector-698"; + + client.deleteConnectorAsync(name).get(); + + 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 deleteConnectorExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-698/locations/location-698/connectors/connector-698"; + client.deleteConnectorAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/grpc-google-cloud-vpcaccess-v1/pom.xml b/grpc-google-cloud-vpcaccess-v1/pom.xml index 823d4d0a..46122cea 100644 --- a/grpc-google-cloud-vpcaccess-v1/pom.xml +++ b/grpc-google-cloud-vpcaccess-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-vpcaccess-v1 - 2.2.1 + 2.3.0 grpc-google-cloud-vpcaccess-v1 GRPC library for google-cloud-vpcaccess com.google.cloud google-cloud-vpcaccess-parent - 2.2.1 + 2.3.0 diff --git a/pom.xml b/pom.xml index 132d185b..e16b9d1e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-vpcaccess-parent pom - 2.2.1 + 2.3.0 Google Serverless VPC Access Parent https://github.com/googleapis/java-vpcaccess @@ -60,17 +60,17 @@ com.google.cloud google-cloud-vpcaccess - 2.2.1 + 2.3.0 com.google.api.grpc grpc-google-cloud-vpcaccess-v1 - 2.2.1 + 2.3.0 com.google.api.grpc proto-google-cloud-vpcaccess-v1 - 2.2.1 + 2.3.0 diff --git a/proto-google-cloud-vpcaccess-v1/pom.xml b/proto-google-cloud-vpcaccess-v1/pom.xml index a105832d..0de24205 100644 --- a/proto-google-cloud-vpcaccess-v1/pom.xml +++ b/proto-google-cloud-vpcaccess-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-vpcaccess-v1 - 2.2.1 + 2.3.0 proto-google-cloud-vpcaccess-v1 Proto library for google-cloud-vpcaccess com.google.cloud google-cloud-vpcaccess-parent - 2.2.1 + 2.3.0 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 67dd3a76..c6319c77 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -29,7 +29,7 @@ com.google.cloud google-cloud-vpcaccess - 2.2.0 + 2.2.1 diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index b6e6e37d..19a37984 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,7 +28,7 @@ com.google.cloud google-cloud-vpcaccess - 2.2.0 + 2.2.1 diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/stub/vpcaccessservicestubsettings/getconnector/SyncGetConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/stub/vpcaccessservicestubsettings/getconnector/SyncGetConnector.java new file mode 100644 index 00000000..9799e917 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/stub/vpcaccessservicestubsettings/getconnector/SyncGetConnector.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.vpcaccess.v1.stub.samples; + +// [START vpcaccess_v1_generated_vpcaccessservicestubsettings_getconnector_sync] +import com.google.cloud.vpcaccess.v1.stub.VpcAccessServiceStubSettings; +import java.time.Duration; + +public class SyncGetConnector { + + public static void main(String[] args) throws Exception { + syncGetConnector(); + } + + public static void syncGetConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + VpcAccessServiceStubSettings.Builder vpcAccessServiceSettingsBuilder = + VpcAccessServiceStubSettings.newBuilder(); + vpcAccessServiceSettingsBuilder + .getConnectorSettings() + .setRetrySettings( + vpcAccessServiceSettingsBuilder + .getConnectorSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + VpcAccessServiceStubSettings vpcAccessServiceSettings = vpcAccessServiceSettingsBuilder.build(); + } +} +// [END vpcaccess_v1_generated_vpcaccessservicestubsettings_getconnector_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..c5ddbed1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,42 @@ +/* + * 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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceSettings; +import com.google.cloud.vpcaccess.v1.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. + VpcAccessServiceSettings vpcAccessServiceSettings = + VpcAccessServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + VpcAccessServiceClient vpcAccessServiceClient = + VpcAccessServiceClient.create(vpcAccessServiceSettings); + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..5338ec9a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetCredentialsProvider1.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceSettings; + +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. + VpcAccessServiceSettings vpcAccessServiceSettings = + VpcAccessServiceSettings.newBuilder() + .setTransportChannelProvider( + VpcAccessServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + VpcAccessServiceClient vpcAccessServiceClient = + VpcAccessServiceClient.create(vpcAccessServiceSettings); + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..124ac839 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/create/SyncCreateSetEndpoint.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_create_setendpoint_sync] +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceSettings; +import com.google.cloud.vpcaccess.v1.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. + VpcAccessServiceSettings vpcAccessServiceSettings = + VpcAccessServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + VpcAccessServiceClient vpcAccessServiceClient = + VpcAccessServiceClient.create(vpcAccessServiceSettings); + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/AsyncCreateConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/AsyncCreateConnector.java new file mode 100644 index 00000000..d96f2ec5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/AsyncCreateConnector.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.CreateConnectorRequest; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.longrunning.Operation; + +public class AsyncCreateConnector { + + public static void main(String[] args) throws Exception { + asyncCreateConnector(); + } + + public static void asyncCreateConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + CreateConnectorRequest request = + CreateConnectorRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setConnectorId("connectorId1724784200") + .setConnector(Connector.newBuilder().build()) + .build(); + ApiFuture future = + vpcAccessServiceClient.createConnectorCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/AsyncCreateConnectorLRO.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/AsyncCreateConnectorLRO.java new file mode 100644 index 00000000..a3a3803c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/AsyncCreateConnectorLRO.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.CreateConnectorRequest; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.OperationMetadata; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class AsyncCreateConnectorLRO { + + public static void main(String[] args) throws Exception { + asyncCreateConnectorLRO(); + } + + public static void asyncCreateConnectorLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + CreateConnectorRequest request = + CreateConnectorRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setConnectorId("connectorId1724784200") + .setConnector(Connector.newBuilder().build()) + .build(); + OperationFuture future = + vpcAccessServiceClient.createConnectorOperationCallable().futureCall(request); + // Do something. + Connector response = future.get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnector.java new file mode 100644 index 00000000..63ccd15a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnector.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.CreateConnectorRequest; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncCreateConnector { + + public static void main(String[] args) throws Exception { + syncCreateConnector(); + } + + public static void syncCreateConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + CreateConnectorRequest request = + CreateConnectorRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setConnectorId("connectorId1724784200") + .setConnector(Connector.newBuilder().build()) + .build(); + Connector response = vpcAccessServiceClient.createConnectorAsync(request).get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnectorLocationnameStringConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnectorLocationnameStringConnector.java new file mode 100644 index 00000000..d559f65e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnectorLocationnameStringConnector.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.vpcaccess.v1.samples; + +// [START +// vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_locationnamestringconnector_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncCreateConnectorLocationnameStringConnector { + + public static void main(String[] args) throws Exception { + syncCreateConnectorLocationnameStringConnector(); + } + + public static void syncCreateConnectorLocationnameStringConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String connectorId = "connectorId1724784200"; + Connector connector = Connector.newBuilder().build(); + Connector response = + vpcAccessServiceClient.createConnectorAsync(parent, connectorId, connector).get(); + } + } +} +// [END +// vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_locationnamestringconnector_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnectorStringStringConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnectorStringStringConnector.java new file mode 100644 index 00000000..4c5f042d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/createconnector/SyncCreateConnectorStringStringConnector.java @@ -0,0 +1,42 @@ +/* + * 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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_stringstringconnector_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncCreateConnectorStringStringConnector { + + public static void main(String[] args) throws Exception { + syncCreateConnectorStringStringConnector(); + } + + public static void syncCreateConnectorStringStringConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String connectorId = "connectorId1724784200"; + Connector connector = Connector.newBuilder().build(); + Connector response = + vpcAccessServiceClient.createConnectorAsync(parent, connectorId, connector).get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_createconnector_stringstringconnector_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/AsyncDeleteConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/AsyncDeleteConnector.java new file mode 100644 index 00000000..d7514e97 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/AsyncDeleteConnector.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.DeleteConnectorRequest; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteConnector { + + public static void main(String[] args) throws Exception { + asyncDeleteConnector(); + } + + public static void asyncDeleteConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + DeleteConnectorRequest request = + DeleteConnectorRequest.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .build(); + ApiFuture future = + vpcAccessServiceClient.deleteConnectorCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/AsyncDeleteConnectorLRO.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/AsyncDeleteConnectorLRO.java new file mode 100644 index 00000000..9e9c310e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/AsyncDeleteConnectorLRO.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.DeleteConnectorRequest; +import com.google.cloud.vpcaccess.v1.OperationMetadata; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.protobuf.Empty; + +public class AsyncDeleteConnectorLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteConnectorLRO(); + } + + public static void asyncDeleteConnectorLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + DeleteConnectorRequest request = + DeleteConnectorRequest.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .build(); + OperationFuture future = + vpcAccessServiceClient.deleteConnectorOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnector.java new file mode 100644 index 00000000..b13ba891 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnector.java @@ -0,0 +1,42 @@ +/* + * 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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_sync] +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.DeleteConnectorRequest; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncDeleteConnector { + + public static void main(String[] args) throws Exception { + syncDeleteConnector(); + } + + public static void syncDeleteConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + DeleteConnectorRequest request = + DeleteConnectorRequest.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .build(); + vpcAccessServiceClient.deleteConnectorAsync(request).get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnectorConnectorname.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnectorConnectorname.java new file mode 100644 index 00000000..aaf23ca9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnectorConnectorname.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_connectorname_sync] +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncDeleteConnectorConnectorname { + + public static void main(String[] args) throws Exception { + syncDeleteConnectorConnectorname(); + } + + public static void syncDeleteConnectorConnectorname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + ConnectorName name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]"); + vpcAccessServiceClient.deleteConnectorAsync(name).get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_connectorname_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnectorString.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnectorString.java new file mode 100644 index 00000000..a3832c58 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/deleteconnector/SyncDeleteConnectorString.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_string_sync] +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncDeleteConnectorString { + + public static void main(String[] args) throws Exception { + syncDeleteConnectorString(); + } + + public static void syncDeleteConnectorString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + String name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString(); + vpcAccessServiceClient.deleteConnectorAsync(name).get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_deleteconnector_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/AsyncGetConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/AsyncGetConnector.java new file mode 100644 index 00000000..2d0b641c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/AsyncGetConnector.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.GetConnectorRequest; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class AsyncGetConnector { + + public static void main(String[] args) throws Exception { + asyncGetConnector(); + } + + public static void asyncGetConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + GetConnectorRequest request = + GetConnectorRequest.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .build(); + ApiFuture future = + vpcAccessServiceClient.getConnectorCallable().futureCall(request); + // Do something. + Connector response = future.get(); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnector.java new file mode 100644 index 00000000..44dceafc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnector.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.GetConnectorRequest; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncGetConnector { + + public static void main(String[] args) throws Exception { + syncGetConnector(); + } + + public static void syncGetConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + GetConnectorRequest request = + GetConnectorRequest.newBuilder() + .setName(ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString()) + .build(); + Connector response = vpcAccessServiceClient.getConnector(request); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnectorConnectorname.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnectorConnectorname.java new file mode 100644 index 00000000..58cadaed --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnectorConnectorname.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_connectorname_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncGetConnectorConnectorname { + + public static void main(String[] args) throws Exception { + syncGetConnectorConnectorname(); + } + + public static void syncGetConnectorConnectorname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + ConnectorName name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]"); + Connector response = vpcAccessServiceClient.getConnector(name); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_connectorname_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnectorString.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnectorString.java new file mode 100644 index 00000000..503a67d9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/getconnector/SyncGetConnectorString.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_string_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ConnectorName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncGetConnectorString { + + public static void main(String[] args) throws Exception { + syncGetConnectorString(); + } + + public static void syncGetConnectorString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + String name = ConnectorName.of("[PROJECT]", "[LOCATION]", "[CONNECTOR]").toString(); + Connector response = vpcAccessServiceClient.getConnector(name); + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_getconnector_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/AsyncListConnectors.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/AsyncListConnectors.java new file mode 100644 index 00000000..576dfa5f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/AsyncListConnectors.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ListConnectorsRequest; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class AsyncListConnectors { + + public static void main(String[] args) throws Exception { + asyncListConnectors(); + } + + public static void asyncListConnectors() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + ListConnectorsRequest request = + ListConnectorsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + vpcAccessServiceClient.listConnectorsPagedCallable().futureCall(request); + // Do something. + for (Connector element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/AsyncListConnectorsPaged.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/AsyncListConnectorsPaged.java new file mode 100644 index 00000000..e55b250d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/AsyncListConnectorsPaged.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_paged_async] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ListConnectorsRequest; +import com.google.cloud.vpcaccess.v1.ListConnectorsResponse; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; +import com.google.common.base.Strings; + +public class AsyncListConnectorsPaged { + + public static void main(String[] args) throws Exception { + asyncListConnectorsPaged(); + } + + public static void asyncListConnectorsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + ListConnectorsRequest request = + ListConnectorsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListConnectorsResponse response = + vpcAccessServiceClient.listConnectorsCallable().call(request); + for (Connector element : response.getConnectorsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectors.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectors.java new file mode 100644 index 00000000..12912ffc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectors.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.ListConnectorsRequest; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncListConnectors { + + public static void main(String[] args) throws Exception { + syncListConnectors(); + } + + public static void syncListConnectors() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + ListConnectorsRequest request = + ListConnectorsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Connector element : vpcAccessServiceClient.listConnectors(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectorsLocationname.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectorsLocationname.java new file mode 100644 index 00000000..b0e17d16 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectorsLocationname.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_locationname_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncListConnectorsLocationname { + + public static void main(String[] args) throws Exception { + syncListConnectorsLocationname(); + } + + public static void syncListConnectorsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Connector element : vpcAccessServiceClient.listConnectors(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectorsString.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectorsString.java new file mode 100644 index 00000000..8ff76ba0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessserviceclient/listconnectors/SyncListConnectorsString.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_string_sync] +import com.google.cloud.vpcaccess.v1.Connector; +import com.google.cloud.vpcaccess.v1.LocationName; +import com.google.cloud.vpcaccess.v1.VpcAccessServiceClient; + +public class SyncListConnectorsString { + + public static void main(String[] args) throws Exception { + syncListConnectorsString(); + } + + public static void syncListConnectorsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (VpcAccessServiceClient vpcAccessServiceClient = VpcAccessServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Connector element : vpcAccessServiceClient.listConnectors(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END vpcaccess_v1_generated_vpcaccessserviceclient_listconnectors_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessservicesettings/getconnector/SyncGetConnector.java b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessservicesettings/getconnector/SyncGetConnector.java new file mode 100644 index 00000000..35a0a98c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/vpcaccess/v1/vpcaccessservicesettings/getconnector/SyncGetConnector.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.vpcaccess.v1.samples; + +// [START vpcaccess_v1_generated_vpcaccessservicesettings_getconnector_sync] +import com.google.cloud.vpcaccess.v1.VpcAccessServiceSettings; +import java.time.Duration; + +public class SyncGetConnector { + + public static void main(String[] args) throws Exception { + syncGetConnector(); + } + + public static void syncGetConnector() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + VpcAccessServiceSettings.Builder vpcAccessServiceSettingsBuilder = + VpcAccessServiceSettings.newBuilder(); + vpcAccessServiceSettingsBuilder + .getConnectorSettings() + .setRetrySettings( + vpcAccessServiceSettingsBuilder + .getConnectorSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + VpcAccessServiceSettings vpcAccessServiceSettings = vpcAccessServiceSettingsBuilder.build(); + } +} +// [END vpcaccess_v1_generated_vpcaccessservicesettings_getconnector_sync] diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 4833207f..76472255 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -28,7 +28,7 @@ com.google.cloud google-cloud-vpcaccess - 2.2.0 + 2.2.1 diff --git a/versions.txt b/versions.txt index 1b0ab142..6e1bdb93 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -google-cloud-vpcaccess:2.2.1:2.2.1 -grpc-google-cloud-vpcaccess-v1:2.2.1:2.2.1 -proto-google-cloud-vpcaccess-v1:2.2.1:2.2.1 +google-cloud-vpcaccess:2.3.0:2.3.0 +grpc-google-cloud-vpcaccess-v1:2.3.0:2.3.0 +proto-google-cloud-vpcaccess-v1:2.3.0:2.3.0