From ba9415b802c792827f3ad04756cd877d1d997832 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 23 Jun 2022 21:10:11 +0000 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#640) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 --- java-memcache/README.md | 4 +- java-memcache/google-cloud-memcache/pom.xml | 16 + .../memcache/v1/CloudMemcacheClient.java | 37 +- .../memcache/v1/CloudMemcacheSettings.java | 23 +- .../memcache/v1/stub/CloudMemcacheStub.java | 6 +- .../v1/stub/CloudMemcacheStubSettings.java | 53 +- .../HttpJsonCloudMemcacheCallableFactory.java | 105 ++ .../v1/stub/HttpJsonCloudMemcacheStub.java | 622 ++++++++++ .../memcache/v1beta2/CloudMemcacheClient.java | 37 +- .../v1beta2/CloudMemcacheSettings.java | 23 +- .../v1beta2/stub/CloudMemcacheStub.java | 6 +- .../stub/CloudMemcacheStubSettings.java | 53 +- .../HttpJsonCloudMemcacheCallableFactory.java | 105 ++ .../stub/HttpJsonCloudMemcacheStub.java | 694 +++++++++++ .../v1/CloudMemcacheClientHttpJsonTest.java | 892 ++++++++++++++ .../CloudMemcacheClientHttpJsonTest.java | 1039 +++++++++++++++++ .../applyparameters/AsyncApplyParameters.java | 50 + .../AsyncApplyParametersLRO.java | 51 + .../applyparameters/SyncApplyParameters.java | 46 + ...rametersInstancenameListstringBoolean.java | 45 + ...pplyParametersStringListstringBoolean.java | 43 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../createinstance/AsyncCreateInstance.java | 50 + .../AsyncCreateInstanceLRO.java | 50 + .../createinstance/SyncCreateInstance.java | 45 + ...ateInstanceLocationnameInstanceString.java | 42 + ...yncCreateInstanceStringInstanceString.java | 42 + .../deleteinstance/AsyncDeleteInstance.java | 47 + .../AsyncDeleteInstanceLRO.java | 48 + .../deleteinstance/SyncDeleteInstance.java | 42 + .../SyncDeleteInstanceInstancename.java | 38 + .../SyncDeleteInstanceString.java | 38 + .../getinstance/AsyncGetInstance.java | 46 + .../getinstance/SyncGetInstance.java | 43 + .../SyncGetInstanceInstancename.java | 39 + .../getinstance/SyncGetInstanceString.java | 39 + .../listinstances/AsyncListInstances.java | 53 + .../AsyncListInstancesPaged.java | 60 + .../listinstances/SyncListInstances.java | 49 + .../SyncListInstancesLocationname.java | 41 + .../SyncListInstancesString.java | 41 + .../updateinstance/AsyncUpdateInstance.java | 49 + .../AsyncUpdateInstanceLRO.java | 49 + .../updateinstance/SyncUpdateInstance.java | 44 + .../SyncUpdateInstanceInstanceFieldmask.java | 40 + .../AsyncUpdateParameters.java | 51 + .../AsyncUpdateParametersLRO.java | 52 + .../SyncUpdateParameters.java | 47 + ...stancenameFieldmaskMemcacheparameters.java | 47 + ...tersStringFieldmaskMemcacheparameters.java | 46 + .../getinstance/SyncGetInstance.java | 45 + .../getinstance/SyncGetInstance.java | 46 + .../applyparameters/AsyncApplyParameters.java | 50 + .../AsyncApplyParametersLRO.java | 51 + .../applyparameters/SyncApplyParameters.java | 46 + ...rametersInstancenameListstringBoolean.java | 45 + ...pplyParametersStringListstringBoolean.java | 44 + .../AsyncApplySoftwareUpdate.java | 50 + .../AsyncApplySoftwareUpdateLRO.java | 51 + .../SyncApplySoftwareUpdate.java | 46 + ...reUpdateInstancenameListstringBoolean.java | 46 + ...SoftwareUpdateStringListstringBoolean.java | 46 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../createinstance/AsyncCreateInstance.java | 50 + .../AsyncCreateInstanceLRO.java | 50 + .../createinstance/SyncCreateInstance.java | 45 + ...ateInstanceLocationnameStringInstance.java | 44 + ...yncCreateInstanceStringStringInstance.java | 42 + .../deleteinstance/AsyncDeleteInstance.java | 47 + .../AsyncDeleteInstanceLRO.java | 48 + .../deleteinstance/SyncDeleteInstance.java | 42 + .../SyncDeleteInstanceInstancename.java | 38 + .../SyncDeleteInstanceString.java | 38 + .../getinstance/AsyncGetInstance.java | 46 + .../getinstance/SyncGetInstance.java | 43 + .../SyncGetInstanceInstancename.java | 39 + .../getinstance/SyncGetInstanceString.java | 39 + .../listinstances/AsyncListInstances.java | 53 + .../AsyncListInstancesPaged.java | 60 + .../listinstances/SyncListInstances.java | 49 + .../SyncListInstancesLocationname.java | 41 + .../SyncListInstancesString.java | 41 + .../updateinstance/AsyncUpdateInstance.java | 49 + .../AsyncUpdateInstanceLRO.java | 49 + .../updateinstance/SyncUpdateInstance.java | 44 + .../SyncUpdateInstanceFieldmaskInstance.java | 40 + .../AsyncUpdateParameters.java | 51 + .../AsyncUpdateParametersLRO.java | 52 + .../SyncUpdateParameters.java | 47 + ...stancenameFieldmaskMemcacheparameters.java | 47 + ...tersStringFieldmaskMemcacheparameters.java | 46 + .../getinstance/SyncGetInstance.java | 45 + .../getinstance/SyncGetInstance.java | 46 + 97 files changed, 7379 insertions(+), 24 deletions(-) create mode 100644 java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheCallableFactory.java create mode 100644 java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheStub.java create mode 100644 java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheCallableFactory.java create mode 100644 java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheStub.java create mode 100644 java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1/CloudMemcacheClientHttpJsonTest.java create mode 100644 java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClientHttpJsonTest.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetEndpoint.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameInstanceString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceStringInstanceString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/AsyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstances.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstances.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstanceInstanceFieldmask.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcachesettings/getinstance/SyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdate.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdateLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdate.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateInstancenameListstringBoolean.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateStringListstringBoolean.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetEndpoint.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceStringStringInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/AsyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstances.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstances.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesString.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcachesettings/getinstance/SyncGetInstance.java create mode 100644 java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.java diff --git a/java-memcache/README.md b/java-memcache/README.md index be688a0148f3..2607f3c94107 100644 --- a/java-memcache/README.md +++ b/java-memcache/README.md @@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-memcache' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-memcache:2.2.0' +implementation 'com.google.cloud:google-cloud-memcache:2.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-memcache" % "2.2.0" +libraryDependencies += "com.google.cloud" % "google-cloud-memcache" % "2.2.1" ``` ## Authentication diff --git a/java-memcache/google-cloud-memcache/pom.xml b/java-memcache/google-cloud-memcache/pom.xml index 144026efd5f7..40217afae1d0 100644 --- a/java-memcache/google-cloud-memcache/pom.xml +++ b/java-memcache/google-cloud-memcache/pom.xml @@ -61,6 +61,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -83,12 +87,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/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheClient.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheClient.java index ffe210068c3d..2afbbd3a93ba 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheClient.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -30,7 +31,6 @@ import com.google.cloud.memcache.v1.stub.CloudMemcacheStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -120,13 +120,28 @@ * CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); * } * + *

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.
+ * CloudMemcacheSettings cloudMemcacheSettings =
+ *     CloudMemcacheSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudMemcacheSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class CloudMemcacheClient implements BackgroundResource { private final CloudMemcacheSettings settings; private final CloudMemcacheStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of CloudMemcacheClient with default settings. */ public static final CloudMemcacheClient create() throws IOException { @@ -158,13 +173,17 @@ public static final CloudMemcacheClient create(CloudMemcacheStub stub) { protected CloudMemcacheClient(CloudMemcacheSettings settings) throws IOException { this.settings = settings; this.stub = ((CloudMemcacheStubSettings) 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 CloudMemcacheClient(CloudMemcacheStub 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 CloudMemcacheSettings getSettings() { @@ -179,10 +198,18 @@ public CloudMemcacheStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists Instances in a given location. diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheSettings.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheSettings.java index dc798c7d4ea4..528ec1c18719 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheSettings.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/CloudMemcacheSettings.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; @@ -164,11 +165,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudMemcacheStubSettings.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 CloudMemcacheStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudMemcacheStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudMemcacheStubSettings.defaultTransportChannelProvider(); } @@ -178,11 +186,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudMemcacheStubSettings.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); @@ -220,6 +234,11 @@ private static Builder createDefault() { return new Builder(CloudMemcacheStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudMemcacheStubSettings.newHttpJsonBuilder()); + } + public CloudMemcacheStubSettings.Builder getStubSettingsBuilder() { return ((CloudMemcacheStubSettings.Builder) getStubSettings()); } diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStub.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStub.java index a6b58cd5ec8f..6f8fefe744fa 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStub.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStub.java @@ -46,7 +46,11 @@ public abstract class CloudMemcacheStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStubSettings.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStubSettings.java index 5dd82a7b5fc5..b9fbff87c671 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStubSettings.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/CloudMemcacheStubSettings.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; @@ -250,6 +253,11 @@ public CloudMemcacheStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudMemcacheStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudMemcacheStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -282,18 +290,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(CloudMemcacheStubSettings.class)) @@ -301,11 +316,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(CloudMemcacheStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudMemcacheStubSettings.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); @@ -460,6 +494,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 .listInstancesSettings() diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheCallableFactory.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheCallableFactory.java new file mode 100644 index 000000000000..daf9ee31a66b --- /dev/null +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheCallableFactory.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.memcache.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 CloudMemcache service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudMemcacheCallableFactory + 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/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheStub.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheStub.java new file mode 100644 index 000000000000..08ebd97efd02 --- /dev/null +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1/stub/HttpJsonCloudMemcacheStub.java @@ -0,0 +1,622 @@ +/* + * 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.memcache.v1.stub; + +import static com.google.cloud.memcache.v1.CloudMemcacheClient.ListInstancesPagedResponse; + +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.memcache.v1.ApplyParametersRequest; +import com.google.cloud.memcache.v1.CreateInstanceRequest; +import com.google.cloud.memcache.v1.DeleteInstanceRequest; +import com.google.cloud.memcache.v1.GetInstanceRequest; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.ListInstancesRequest; +import com.google.cloud.memcache.v1.ListInstancesResponse; +import com.google.cloud.memcache.v1.OperationMetadata; +import com.google.cloud.memcache.v1.UpdateInstanceRequest; +import com.google.cloud.memcache.v1.UpdateParametersRequest; +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 CloudMemcache service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudMemcacheStub extends CloudMemcacheStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(Instance.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listInstancesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/ListInstances") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/instances", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListInstancesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/GetInstance") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}", + 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(Instance.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/CreateInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/instances", + 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, "instanceId", request.getInstanceId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("instance", request.getInstance())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/UpdateInstance") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{instance.name=projects/*/locations/*/instances/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "instance.name", request.getInstance().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("instance", request.getInstance())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateParametersMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/UpdateParameters") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:updateParameters", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateParametersRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/DeleteInstance") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}", + 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( + (DeleteInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + applyParametersMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1.CloudMemcache/ApplyParameters") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:applyParameters", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ApplyParametersRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listInstancesCallable; + private final UnaryCallable + listInstancesPagedCallable; + private final UnaryCallable getInstanceCallable; + private final UnaryCallable createInstanceCallable; + private final OperationCallable + createInstanceOperationCallable; + private final UnaryCallable updateInstanceCallable; + private final OperationCallable + updateInstanceOperationCallable; + private final UnaryCallable updateParametersCallable; + private final OperationCallable + updateParametersOperationCallable; + private final UnaryCallable deleteInstanceCallable; + private final OperationCallable + deleteInstanceOperationCallable; + private final UnaryCallable applyParametersCallable; + private final OperationCallable + applyParametersOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudMemcacheStub create(CloudMemcacheStubSettings settings) + throws IOException { + return new HttpJsonCloudMemcacheStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudMemcacheStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudMemcacheStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudMemcacheStub, 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 HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonCloudMemcacheCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudMemcacheStub, 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 HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listInstancesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listInstancesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateParametersTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateParametersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings applyParametersTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(applyParametersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listInstancesCallable = + callableFactory.createUnaryCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.listInstancesPagedCallable = + callableFactory.createPagedCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.getInstanceCallable = + callableFactory.createUnaryCallable( + getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); + this.createInstanceCallable = + callableFactory.createUnaryCallable( + createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); + this.createInstanceOperationCallable = + callableFactory.createOperationCallable( + createInstanceTransportSettings, + settings.createInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateInstanceCallable = + callableFactory.createUnaryCallable( + updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); + this.updateInstanceOperationCallable = + callableFactory.createOperationCallable( + updateInstanceTransportSettings, + settings.updateInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateParametersCallable = + callableFactory.createUnaryCallable( + updateParametersTransportSettings, settings.updateParametersSettings(), clientContext); + this.updateParametersOperationCallable = + callableFactory.createOperationCallable( + updateParametersTransportSettings, + settings.updateParametersOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteInstanceCallable = + callableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.deleteInstanceOperationCallable = + callableFactory.createOperationCallable( + deleteInstanceTransportSettings, + settings.deleteInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.applyParametersCallable = + callableFactory.createUnaryCallable( + applyParametersTransportSettings, settings.applyParametersSettings(), clientContext); + this.applyParametersOperationCallable = + callableFactory.createOperationCallable( + applyParametersTransportSettings, + settings.applyParametersOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listInstancesMethodDescriptor); + methodDescriptors.add(getInstanceMethodDescriptor); + methodDescriptors.add(createInstanceMethodDescriptor); + methodDescriptors.add(updateInstanceMethodDescriptor); + methodDescriptors.add(updateParametersMethodDescriptor); + methodDescriptors.add(deleteInstanceMethodDescriptor); + methodDescriptors.add(applyParametersMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listInstancesCallable() { + return listInstancesCallable; + } + + @Override + public UnaryCallable + listInstancesPagedCallable() { + return listInstancesPagedCallable; + } + + @Override + public UnaryCallable getInstanceCallable() { + return getInstanceCallable; + } + + @Override + public UnaryCallable createInstanceCallable() { + return createInstanceCallable; + } + + @Override + public OperationCallable + createInstanceOperationCallable() { + return createInstanceOperationCallable; + } + + @Override + public UnaryCallable updateInstanceCallable() { + return updateInstanceCallable; + } + + @Override + public OperationCallable + updateInstanceOperationCallable() { + return updateInstanceOperationCallable; + } + + @Override + public UnaryCallable updateParametersCallable() { + return updateParametersCallable; + } + + @Override + public OperationCallable + updateParametersOperationCallable() { + return updateParametersOperationCallable; + } + + @Override + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + @Override + public OperationCallable + deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; + } + + @Override + public UnaryCallable applyParametersCallable() { + return applyParametersCallable; + } + + @Override + public OperationCallable + applyParametersOperationCallable() { + return applyParametersOperationCallable; + } + + @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/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClient.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClient.java index f43eac3399cf..30cc7a040891 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClient.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClient.java @@ -20,6 +20,7 @@ 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; @@ -31,7 +32,6 @@ import com.google.cloud.memcache.v1beta2.stub.CloudMemcacheStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -121,6 +121,20 @@ * CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); * } * + *

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.
+ * CloudMemcacheSettings cloudMemcacheSettings =
+ *     CloudMemcacheSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudMemcacheSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -128,7 +142,8 @@ public class CloudMemcacheClient implements BackgroundResource { private final CloudMemcacheSettings settings; private final CloudMemcacheStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of CloudMemcacheClient with default settings. */ public static final CloudMemcacheClient create() throws IOException { @@ -160,13 +175,17 @@ public static final CloudMemcacheClient create(CloudMemcacheStub stub) { protected CloudMemcacheClient(CloudMemcacheSettings settings) throws IOException { this.settings = settings; this.stub = ((CloudMemcacheStubSettings) 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 CloudMemcacheClient(CloudMemcacheStub 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 CloudMemcacheSettings getSettings() { @@ -181,10 +200,18 @@ public CloudMemcacheStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists Instances in a given location. diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheSettings.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheSettings.java index da0e94a6ac8d..51da4ed87208 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheSettings.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/CloudMemcacheSettings.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; @@ -176,11 +177,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudMemcacheStubSettings.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 CloudMemcacheStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudMemcacheStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudMemcacheStubSettings.defaultTransportChannelProvider(); } @@ -190,11 +198,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudMemcacheStubSettings.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); @@ -232,6 +246,11 @@ private static Builder createDefault() { return new Builder(CloudMemcacheStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudMemcacheStubSettings.newHttpJsonBuilder()); + } + public CloudMemcacheStubSettings.Builder getStubSettingsBuilder() { return ((CloudMemcacheStubSettings.Builder) getStubSettings()); } diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStub.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStub.java index 94b69df16d7d..28984f13a414 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStub.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStub.java @@ -49,7 +49,11 @@ public abstract class CloudMemcacheStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStubSettings.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStubSettings.java index 5d76e13b3683..90fb09a66154 100644 --- a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStubSettings.java +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/CloudMemcacheStubSettings.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; @@ -267,6 +270,11 @@ public CloudMemcacheStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudMemcacheStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudMemcacheStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -299,18 +307,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(CloudMemcacheStubSettings.class)) @@ -318,11 +333,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(CloudMemcacheStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudMemcacheStubSettings.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); @@ -492,6 +526,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 .listInstancesSettings() diff --git a/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheCallableFactory.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheCallableFactory.java new file mode 100644 index 000000000000..4f22a9c3aeda --- /dev/null +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheCallableFactory.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.memcache.v1beta2.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 CloudMemcache service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudMemcacheCallableFactory + 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/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheStub.java b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheStub.java new file mode 100644 index 000000000000..f034b57bc9f1 --- /dev/null +++ b/java-memcache/google-cloud-memcache/src/main/java/com/google/cloud/memcache/v1beta2/stub/HttpJsonCloudMemcacheStub.java @@ -0,0 +1,694 @@ +/* + * 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.memcache.v1beta2.stub; + +import static com.google.cloud.memcache.v1beta2.CloudMemcacheClient.ListInstancesPagedResponse; + +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.memcache.v1beta2.ApplyParametersRequest; +import com.google.cloud.memcache.v1beta2.ApplySoftwareUpdateRequest; +import com.google.cloud.memcache.v1beta2.CreateInstanceRequest; +import com.google.cloud.memcache.v1beta2.DeleteInstanceRequest; +import com.google.cloud.memcache.v1beta2.GetInstanceRequest; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.ListInstancesRequest; +import com.google.cloud.memcache.v1beta2.ListInstancesResponse; +import com.google.cloud.memcache.v1beta2.OperationMetadata; +import com.google.cloud.memcache.v1beta2.UpdateInstanceRequest; +import com.google.cloud.memcache.v1beta2.UpdateParametersRequest; +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 CloudMemcache service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudMemcacheStub extends CloudMemcacheStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Instance.getDescriptor()) + .add(Empty.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listInstancesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/ListInstances") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*}/instances", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListInstancesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/GetInstance") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/instances/*}", + 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(Instance.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/CreateInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*}/instances", + 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, "instanceId", request.getInstanceId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("resource", request.getResource())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/UpdateInstance") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{resource.name=projects/*/locations/*/instances/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "resource.name", request.getResource().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("resource", request.getResource())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateParametersMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/UpdateParameters") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/instances/*}:updateParameters", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateParametersRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/DeleteInstance") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/instances/*}", + 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( + (DeleteInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + applyParametersMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/ApplyParameters") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/instances/*}:applyParameters", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ApplyParametersRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + applySoftwareUpdateMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.memcache.v1beta2.CloudMemcache/ApplySoftwareUpdate") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{instance=projects/*/locations/*/instances/*}:applySoftwareUpdate", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "instance", request.getInstance()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearInstance().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ApplySoftwareUpdateRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listInstancesCallable; + private final UnaryCallable + listInstancesPagedCallable; + private final UnaryCallable getInstanceCallable; + private final UnaryCallable createInstanceCallable; + private final OperationCallable + createInstanceOperationCallable; + private final UnaryCallable updateInstanceCallable; + private final OperationCallable + updateInstanceOperationCallable; + private final UnaryCallable updateParametersCallable; + private final OperationCallable + updateParametersOperationCallable; + private final UnaryCallable deleteInstanceCallable; + private final OperationCallable + deleteInstanceOperationCallable; + private final UnaryCallable applyParametersCallable; + private final OperationCallable + applyParametersOperationCallable; + private final UnaryCallable applySoftwareUpdateCallable; + private final OperationCallable + applySoftwareUpdateOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudMemcacheStub create(CloudMemcacheStubSettings settings) + throws IOException { + return new HttpJsonCloudMemcacheStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudMemcacheStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudMemcacheStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudMemcacheStub, 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 HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonCloudMemcacheCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudMemcacheStub, 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 HttpJsonCloudMemcacheStub( + CloudMemcacheStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listInstancesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listInstancesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateParametersTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateParametersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings applyParametersTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(applyParametersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + applySoftwareUpdateTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(applySoftwareUpdateMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listInstancesCallable = + callableFactory.createUnaryCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.listInstancesPagedCallable = + callableFactory.createPagedCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.getInstanceCallable = + callableFactory.createUnaryCallable( + getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); + this.createInstanceCallable = + callableFactory.createUnaryCallable( + createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); + this.createInstanceOperationCallable = + callableFactory.createOperationCallable( + createInstanceTransportSettings, + settings.createInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateInstanceCallable = + callableFactory.createUnaryCallable( + updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); + this.updateInstanceOperationCallable = + callableFactory.createOperationCallable( + updateInstanceTransportSettings, + settings.updateInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateParametersCallable = + callableFactory.createUnaryCallable( + updateParametersTransportSettings, settings.updateParametersSettings(), clientContext); + this.updateParametersOperationCallable = + callableFactory.createOperationCallable( + updateParametersTransportSettings, + settings.updateParametersOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteInstanceCallable = + callableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.deleteInstanceOperationCallable = + callableFactory.createOperationCallable( + deleteInstanceTransportSettings, + settings.deleteInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.applyParametersCallable = + callableFactory.createUnaryCallable( + applyParametersTransportSettings, settings.applyParametersSettings(), clientContext); + this.applyParametersOperationCallable = + callableFactory.createOperationCallable( + applyParametersTransportSettings, + settings.applyParametersOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.applySoftwareUpdateCallable = + callableFactory.createUnaryCallable( + applySoftwareUpdateTransportSettings, + settings.applySoftwareUpdateSettings(), + clientContext); + this.applySoftwareUpdateOperationCallable = + callableFactory.createOperationCallable( + applySoftwareUpdateTransportSettings, + settings.applySoftwareUpdateOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listInstancesMethodDescriptor); + methodDescriptors.add(getInstanceMethodDescriptor); + methodDescriptors.add(createInstanceMethodDescriptor); + methodDescriptors.add(updateInstanceMethodDescriptor); + methodDescriptors.add(updateParametersMethodDescriptor); + methodDescriptors.add(deleteInstanceMethodDescriptor); + methodDescriptors.add(applyParametersMethodDescriptor); + methodDescriptors.add(applySoftwareUpdateMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listInstancesCallable() { + return listInstancesCallable; + } + + @Override + public UnaryCallable + listInstancesPagedCallable() { + return listInstancesPagedCallable; + } + + @Override + public UnaryCallable getInstanceCallable() { + return getInstanceCallable; + } + + @Override + public UnaryCallable createInstanceCallable() { + return createInstanceCallable; + } + + @Override + public OperationCallable + createInstanceOperationCallable() { + return createInstanceOperationCallable; + } + + @Override + public UnaryCallable updateInstanceCallable() { + return updateInstanceCallable; + } + + @Override + public OperationCallable + updateInstanceOperationCallable() { + return updateInstanceOperationCallable; + } + + @Override + public UnaryCallable updateParametersCallable() { + return updateParametersCallable; + } + + @Override + public OperationCallable + updateParametersOperationCallable() { + return updateParametersOperationCallable; + } + + @Override + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + @Override + public OperationCallable + deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; + } + + @Override + public UnaryCallable applyParametersCallable() { + return applyParametersCallable; + } + + @Override + public OperationCallable + applyParametersOperationCallable() { + return applyParametersOperationCallable; + } + + @Override + public UnaryCallable applySoftwareUpdateCallable() { + return applySoftwareUpdateCallable; + } + + @Override + public OperationCallable + applySoftwareUpdateOperationCallable() { + return applySoftwareUpdateOperationCallable; + } + + @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/java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1/CloudMemcacheClientHttpJsonTest.java b/java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1/CloudMemcacheClientHttpJsonTest.java new file mode 100644 index 000000000000..b28966dc8303 --- /dev/null +++ b/java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1/CloudMemcacheClientHttpJsonTest.java @@ -0,0 +1,892 @@ +/* + * 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.memcache.v1; + +import static com.google.cloud.memcache.v1.CloudMemcacheClient.ListInstancesPagedResponse; + +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.memcache.v1.stub.HttpJsonCloudMemcacheStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudMemcacheClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudMemcacheClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudMemcacheStub.getMethodDescriptors(), + CloudMemcacheSettings.getDefaultEndpoint()); + CloudMemcacheSettings settings = + CloudMemcacheSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudMemcacheSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudMemcacheClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listInstancesTest() throws Exception { + Instance responsesElement = Instance.newBuilder().build(); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken("") + .addAllInstances(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getInstancesList().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 listInstancesExceptionTest() 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.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listInstancesTest2() throws Exception { + Instance responsesElement = Instance.newBuilder().build(); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken("") + .addAllInstances(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getInstancesList().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 listInstancesExceptionTest2() 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.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + mockService.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + Instance actualResponse = client.getInstance(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 getInstanceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + + Instance actualResponse = client.getInstance(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 getInstanceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Instance instance = Instance.newBuilder().build(); + String instanceId = "instanceId902024336"; + + Instance actualResponse = client.createInstanceAsync(parent, instance, instanceId).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 createInstanceExceptionTest() 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]"); + Instance instance = Instance.newBuilder().build(); + String instanceId = "instanceId902024336"; + client.createInstanceAsync(parent, instance, instanceId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Instance instance = Instance.newBuilder().build(); + String instanceId = "instanceId902024336"; + + Instance actualResponse = client.createInstanceAsync(parent, instance, instanceId).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 createInstanceExceptionTest2() 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"; + Instance instance = Instance.newBuilder().build(); + String instanceId = "instanceId902024336"; + client.createInstanceAsync(parent, instance, instanceId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + Instance instance = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Instance actualResponse = client.updateInstanceAsync(instance, updateMask).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 updateInstanceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Instance instance = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateInstanceAsync(instance, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateParametersTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + + Instance actualResponse = client.updateParametersAsync(name, updateMask, parameters).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 updateParametersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + client.updateParametersAsync(name, updateMask, parameters).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateParametersTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + + Instance actualResponse = client.updateParametersAsync(name, updateMask, parameters).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 updateParametersExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + client.updateParametersAsync(name, updateMask, parameters).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteInstanceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + client.deleteInstanceAsync(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 deleteInstanceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + client.deleteInstanceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteInstanceTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + + client.deleteInstanceAsync(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 deleteInstanceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + client.deleteInstanceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void applyParametersTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("applyParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + + Instance actualResponse = client.applyParametersAsync(name, nodeIds, applyAll).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 applyParametersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + client.applyParametersAsync(name, nodeIds, applyAll).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void applyParametersTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("applyParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + + Instance actualResponse = client.applyParametersAsync(name, nodeIds, applyAll).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 applyParametersExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + client.applyParametersAsync(name, nodeIds, applyAll).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClientHttpJsonTest.java b/java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClientHttpJsonTest.java new file mode 100644 index 000000000000..1d0e5d13800d --- /dev/null +++ b/java-memcache/google-cloud-memcache/src/test/java/com/google/cloud/memcache/v1beta2/CloudMemcacheClientHttpJsonTest.java @@ -0,0 +1,1039 @@ +/* + * 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.memcache.v1beta2; + +import static com.google.cloud.memcache.v1beta2.CloudMemcacheClient.ListInstancesPagedResponse; + +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.memcache.v1beta2.stub.HttpJsonCloudMemcacheStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudMemcacheClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudMemcacheClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudMemcacheStub.getMethodDescriptors(), + CloudMemcacheSettings.getDefaultEndpoint()); + CloudMemcacheSettings settings = + CloudMemcacheSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudMemcacheSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudMemcacheClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listInstancesTest() throws Exception { + Instance responsesElement = Instance.newBuilder().build(); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken("") + .addAllResources(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResourcesList().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 listInstancesExceptionTest() 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.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listInstancesTest2() throws Exception { + Instance responsesElement = Instance.newBuilder().build(); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken("") + .addAllResources(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResourcesList().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 listInstancesExceptionTest2() 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.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + mockService.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + Instance actualResponse = client.getInstance(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 getInstanceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + + Instance actualResponse = client.getInstance(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 getInstanceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String instanceId = "instanceId902024336"; + Instance resource = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, resource).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 createInstanceExceptionTest() 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 instanceId = "instanceId902024336"; + Instance resource = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, resource).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + String instanceId = "instanceId902024336"; + Instance resource = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, resource).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 createInstanceExceptionTest2() 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 instanceId = "instanceId902024336"; + Instance resource = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, resource).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance resource = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + + Instance actualResponse = client.updateInstanceAsync(updateMask, resource).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 updateInstanceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance resource = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + client.updateInstanceAsync(updateMask, resource).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateParametersTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + + Instance actualResponse = client.updateParametersAsync(name, updateMask, parameters).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 updateParametersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + client.updateParametersAsync(name, updateMask, parameters).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateParametersTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + + Instance actualResponse = client.updateParametersAsync(name, updateMask, parameters).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 updateParametersExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + client.updateParametersAsync(name, updateMask, parameters).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteInstanceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + client.deleteInstanceAsync(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 deleteInstanceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + client.deleteInstanceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteInstanceTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + + client.deleteInstanceAsync(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 deleteInstanceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + client.deleteInstanceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void applyParametersTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("applyParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + + Instance actualResponse = client.applyParametersAsync(name, nodeIds, applyAll).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 applyParametersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + client.applyParametersAsync(name, nodeIds, applyAll).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void applyParametersTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("applyParametersTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + + Instance actualResponse = client.applyParametersAsync(name, nodeIds, applyAll).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 applyParametersExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + client.applyParametersAsync(name, nodeIds, applyAll).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void applySoftwareUpdateTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("applySoftwareUpdateTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName instance = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + + Instance actualResponse = client.applySoftwareUpdateAsync(instance, nodeIds, applyAll).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 applySoftwareUpdateExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InstanceName instance = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + client.applySoftwareUpdateAsync(instance, nodeIds, applyAll).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void applySoftwareUpdateTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .addAllZones(new ArrayList()) + .setNodeCount(1539922066) + .setNodeConfig(Instance.NodeConfig.newBuilder().build()) + .setMemcacheVersion(MemcacheVersion.forNumber(0)) + .setParameters(MemcacheParameters.newBuilder().build()) + .addAllMemcacheNodes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setMemcacheFullVersion("memcacheFullVersion976507452") + .addAllInstanceMessages(new ArrayList()) + .setDiscoveryEndpoint("discoveryEndpoint-1155573915") + .setUpdateAvailable(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("applySoftwareUpdateTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String instance = "projects/project-2526/locations/location-2526/instances/instance-2526"; + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + + Instance actualResponse = client.applySoftwareUpdateAsync(instance, nodeIds, applyAll).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 applySoftwareUpdateExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String instance = "projects/project-2526/locations/location-2526/instances/instance-2526"; + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + client.applySoftwareUpdateAsync(instance, nodeIds, applyAll).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParameters.java new file mode 100644 index 000000000000..1c5992076182 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParameters.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_applyparameters_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.ApplyParametersRequest; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.longrunning.Operation; +import java.util.ArrayList; + +public class AsyncApplyParameters { + + public static void main(String[] args) throws Exception { + asyncApplyParameters(); + } + + public static void asyncApplyParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplyParametersRequest request = + ApplyParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + ApiFuture future = + cloudMemcacheClient.applyParametersCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_applyparameters_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.java new file mode 100644 index 000000000000..7e107bcb6684 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_applyparameters_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1.ApplyParametersRequest; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.OperationMetadata; +import java.util.ArrayList; + +public class AsyncApplyParametersLRO { + + public static void main(String[] args) throws Exception { + asyncApplyParametersLRO(); + } + + public static void asyncApplyParametersLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplyParametersRequest request = + ApplyParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + OperationFuture future = + cloudMemcacheClient.applyParametersOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_applyparameters_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParameters.java new file mode 100644 index 000000000000..4b9feceefcae --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParameters.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_applyparameters_sync] +import com.google.cloud.memcache.v1.ApplyParametersRequest; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import java.util.ArrayList; + +public class SyncApplyParameters { + + public static void main(String[] args) throws Exception { + syncApplyParameters(); + } + + public static void syncApplyParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplyParametersRequest request = + ApplyParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + Instance response = cloudMemcacheClient.applyParametersAsync(request).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_applyparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.java new file mode 100644 index 000000000000..3c387967ba3b --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.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.memcache.v1.samples; + +// [START +// memcache_v1_generated_cloudmemcacheclient_applyparameters_instancenameliststringboolean_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import java.util.ArrayList; +import java.util.List; + +public class SyncApplyParametersInstancenameListstringBoolean { + + public static void main(String[] args) throws Exception { + syncApplyParametersInstancenameListstringBoolean(); + } + + public static void syncApplyParametersInstancenameListstringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + Instance response = cloudMemcacheClient.applyParametersAsync(name, nodeIds, applyAll).get(); + } + } +} +// [END +// memcache_v1_generated_cloudmemcacheclient_applyparameters_instancenameliststringboolean_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.java new file mode 100644 index 000000000000..0603560c5028 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_applyparameters_stringliststringboolean_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import java.util.ArrayList; +import java.util.List; + +public class SyncApplyParametersStringListstringBoolean { + + public static void main(String[] args) throws Exception { + syncApplyParametersStringListstringBoolean(); + } + + public static void syncApplyParametersStringListstringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + Instance response = cloudMemcacheClient.applyParametersAsync(name, nodeIds, applyAll).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_applyparameters_stringliststringboolean_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..23fcd415cc48 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.CloudMemcacheSettings; +import com.google.cloud.memcache.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. + CloudMemcacheSettings cloudMemcacheSettings = + CloudMemcacheSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); + } +} +// [END memcache_v1_generated_cloudmemcacheclient_create_setcredentialsprovider_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..65949753d90f --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_create_setcredentialsprovider1_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.CloudMemcacheSettings; + +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. + CloudMemcacheSettings cloudMemcacheSettings = + CloudMemcacheSettings.newBuilder() + .setTransportChannelProvider( + CloudMemcacheSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); + } +} +// [END memcache_v1_generated_cloudmemcacheclient_create_setcredentialsprovider1_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetEndpoint.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..39af71fcf163 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_create_setendpoint_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.CloudMemcacheSettings; +import com.google.cloud.memcache.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. + CloudMemcacheSettings cloudMemcacheSettings = + CloudMemcacheSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); + } +} +// [END memcache_v1_generated_cloudmemcacheclient_create_setendpoint_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstance.java new file mode 100644 index 000000000000..c39ebe7b196a --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_createinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.CreateInstanceRequest; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; +import com.google.longrunning.Operation; + +public class AsyncCreateInstance { + + public static void main(String[] args) throws Exception { + asyncCreateInstance(); + } + + public static void asyncCreateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + ApiFuture future = + cloudMemcacheClient.createInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_createinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.java new file mode 100644 index 000000000000..edc7256d3a29 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_createinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.CreateInstanceRequest; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; +import com.google.cloud.memcache.v1.OperationMetadata; + +public class AsyncCreateInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncCreateInstanceLRO(); + } + + public static void asyncCreateInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudMemcacheClient.createInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_createinstance_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstance.java new file mode 100644 index 000000000000..923976b6e48a --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_createinstance_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.CreateInstanceRequest; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; + +public class SyncCreateInstance { + + public static void main(String[] args) throws Exception { + syncCreateInstance(); + } + + public static void syncCreateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + Instance response = cloudMemcacheClient.createInstanceAsync(request).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_createinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameInstanceString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameInstanceString.java new file mode 100644 index 000000000000..2bf89199d361 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameInstanceString.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_createinstance_locationnameinstancestring_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; + +public class SyncCreateInstanceLocationnameInstanceString { + + public static void main(String[] args) throws Exception { + syncCreateInstanceLocationnameInstanceString(); + } + + public static void syncCreateInstanceLocationnameInstanceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Instance instance = Instance.newBuilder().build(); + String instanceId = "instanceId902024336"; + Instance response = + cloudMemcacheClient.createInstanceAsync(parent, instance, instanceId).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_createinstance_locationnameinstancestring_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceStringInstanceString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceStringInstanceString.java new file mode 100644 index 000000000000..d2316ff545a6 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/createinstance/SyncCreateInstanceStringInstanceString.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_createinstance_stringinstancestring_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; + +public class SyncCreateInstanceStringInstanceString { + + public static void main(String[] args) throws Exception { + syncCreateInstanceStringInstanceString(); + } + + public static void syncCreateInstanceStringInstanceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Instance instance = Instance.newBuilder().build(); + String instanceId = "instanceId902024336"; + Instance response = + cloudMemcacheClient.createInstanceAsync(parent, instance, instanceId).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_createinstance_stringinstancestring_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.java new file mode 100644 index 000000000000..01a1b63f33b1 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_deleteinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.DeleteInstanceRequest; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.longrunning.Operation; + +public class AsyncDeleteInstance { + + public static void main(String[] args) throws Exception { + asyncDeleteInstance(); + } + + public static void asyncDeleteInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = + cloudMemcacheClient.deleteInstanceCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_deleteinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.java new file mode 100644 index 000000000000..9079cb23bc23 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_deleteinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.DeleteInstanceRequest; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.OperationMetadata; +import com.google.protobuf.Empty; + +public class AsyncDeleteInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteInstanceLRO(); + } + + public static void asyncDeleteInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + OperationFuture future = + cloudMemcacheClient.deleteInstanceOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_deleteinstance_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.java new file mode 100644 index 000000000000..7733e6e179b8 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_deleteinstance_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.DeleteInstanceRequest; +import com.google.cloud.memcache.v1.InstanceName; + +public class SyncDeleteInstance { + + public static void main(String[] args) throws Exception { + syncDeleteInstance(); + } + + public static void syncDeleteInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + cloudMemcacheClient.deleteInstanceAsync(request).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_deleteinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.java new file mode 100644 index 000000000000..83b558dd7991 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_deleteinstance_instancename_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.InstanceName; + +public class SyncDeleteInstanceInstancename { + + public static void main(String[] args) throws Exception { + syncDeleteInstanceInstancename(); + } + + public static void syncDeleteInstanceInstancename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + cloudMemcacheClient.deleteInstanceAsync(name).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_deleteinstance_instancename_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.java new file mode 100644 index 000000000000..15182ba974b8 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_deleteinstance_string_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.InstanceName; + +public class SyncDeleteInstanceString { + + public static void main(String[] args) throws Exception { + syncDeleteInstanceString(); + } + + public static void syncDeleteInstanceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + cloudMemcacheClient.deleteInstanceAsync(name).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_deleteinstance_string_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/AsyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/AsyncGetInstance.java new file mode 100644 index 000000000000..bea5f8ae99c4 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/AsyncGetInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_getinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.GetInstanceRequest; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; + +public class AsyncGetInstance { + + public static void main(String[] args) throws Exception { + asyncGetInstance(); + } + + public static void asyncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudMemcacheClient.getInstanceCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_getinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstance.java new file mode 100644 index 000000000000..bf43198a74b8 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_getinstance_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.GetInstanceRequest; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; + +public class SyncGetInstance { + + public static void main(String[] args) throws Exception { + syncGetInstance(); + } + + public static void syncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + Instance response = cloudMemcacheClient.getInstance(request); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_getinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.java new file mode 100644 index 000000000000..4685fb707020 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_getinstance_instancename_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; + +public class SyncGetInstanceInstancename { + + public static void main(String[] args) throws Exception { + syncGetInstanceInstancename(); + } + + public static void syncGetInstanceInstancename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + Instance response = cloudMemcacheClient.getInstance(name); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_getinstance_instancename_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceString.java new file mode 100644 index 000000000000..cceaefb5cc83 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/getinstance/SyncGetInstanceString.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_getinstance_string_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; + +public class SyncGetInstanceString { + + public static void main(String[] args) throws Exception { + syncGetInstanceString(); + } + + public static void syncGetInstanceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + Instance response = cloudMemcacheClient.getInstance(name); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_getinstance_string_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstances.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstances.java new file mode 100644 index 000000000000..04231a5e6c2e --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstances.java @@ -0,0 +1,53 @@ +/* + * 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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_listinstances_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.ListInstancesRequest; +import com.google.cloud.memcache.v1.LocationName; + +public class AsyncListInstances { + + public static void main(String[] args) throws Exception { + asyncListInstances(); + } + + public static void asyncListInstances() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + cloudMemcacheClient.listInstancesPagedCallable().futureCall(request); + // Do something. + for (Instance element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_listinstances_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java new file mode 100644 index 000000000000..c80ac5069ec1 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java @@ -0,0 +1,60 @@ +/* + * 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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_listinstances_paged_async] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.ListInstancesRequest; +import com.google.cloud.memcache.v1.ListInstancesResponse; +import com.google.cloud.memcache.v1.LocationName; +import com.google.common.base.Strings; + +public class AsyncListInstancesPaged { + + public static void main(String[] args) throws Exception { + asyncListInstancesPaged(); + } + + public static void asyncListInstancesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListInstancesResponse response = cloudMemcacheClient.listInstancesCallable().call(request); + for (Instance element : response.getInstancesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_listinstances_paged_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstances.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstances.java new file mode 100644 index 000000000000..f682638c3739 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstances.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_listinstances_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.ListInstancesRequest; +import com.google.cloud.memcache.v1.LocationName; + +public class SyncListInstances { + + public static void main(String[] args) throws Exception { + syncListInstances(); + } + + public static void syncListInstances() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (Instance element : cloudMemcacheClient.listInstances(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_listinstances_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.java new file mode 100644 index 000000000000..6fc1ffe8519b --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_listinstances_locationname_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; + +public class SyncListInstancesLocationname { + + public static void main(String[] args) throws Exception { + syncListInstancesLocationname(); + } + + public static void syncListInstancesLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Instance element : cloudMemcacheClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_listinstances_locationname_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesString.java new file mode 100644 index 000000000000..9e0823196503 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/listinstances/SyncListInstancesString.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_listinstances_string_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.LocationName; + +public class SyncListInstancesString { + + public static void main(String[] args) throws Exception { + syncListInstancesString(); + } + + public static void syncListInstancesString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Instance element : cloudMemcacheClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_listinstances_string_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java new file mode 100644 index 000000000000..8541acae4a84 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.UpdateInstanceRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateInstance { + + public static void main(String[] args) throws Exception { + asyncUpdateInstance(); + } + + public static void asyncUpdateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + ApiFuture future = + cloudMemcacheClient.updateInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java new file mode 100644 index 000000000000..ca3ec700fa03 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.OperationMetadata; +import com.google.cloud.memcache.v1.UpdateInstanceRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateInstanceLRO(); + } + + public static void asyncUpdateInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudMemcacheClient.updateInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateinstance_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstance.java new file mode 100644 index 000000000000..19b6b26d0bb1 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateinstance_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.UpdateInstanceRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateInstance { + + public static void main(String[] args) throws Exception { + syncUpdateInstance(); + } + + public static void syncUpdateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + Instance response = cloudMemcacheClient.updateInstanceAsync(request).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstanceInstanceFieldmask.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstanceInstanceFieldmask.java new file mode 100644 index 000000000000..6f0bec0c9ee0 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateinstance/SyncUpdateInstanceInstanceFieldmask.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateinstance_instancefieldmask_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.protobuf.FieldMask; + +public class SyncUpdateInstanceInstanceFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateInstanceInstanceFieldmask(); + } + + public static void syncUpdateInstanceInstanceFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + Instance instance = Instance.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance response = cloudMemcacheClient.updateInstanceAsync(instance, updateMask).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateinstance_instancefieldmask_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.java new file mode 100644 index 000000000000..82933ed475ae --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateparameters_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.MemcacheParameters; +import com.google.cloud.memcache.v1.UpdateParametersRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateParameters { + + public static void main(String[] args) throws Exception { + asyncUpdateParameters(); + } + + public static void asyncUpdateParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateParametersRequest request = + UpdateParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setParameters(MemcacheParameters.newBuilder().build()) + .build(); + ApiFuture future = + cloudMemcacheClient.updateParametersCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateparameters_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java new file mode 100644 index 000000000000..3201539954fd --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java @@ -0,0 +1,52 @@ +/* + * 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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateparameters_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.MemcacheParameters; +import com.google.cloud.memcache.v1.OperationMetadata; +import com.google.cloud.memcache.v1.UpdateParametersRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateParametersLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateParametersLRO(); + } + + public static void asyncUpdateParametersLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateParametersRequest request = + UpdateParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setParameters(MemcacheParameters.newBuilder().build()) + .build(); + OperationFuture future = + cloudMemcacheClient.updateParametersOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateparameters_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParameters.java new file mode 100644 index 000000000000..3b85b805e1ab --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParameters.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcacheclient_updateparameters_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.MemcacheParameters; +import com.google.cloud.memcache.v1.UpdateParametersRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateParameters { + + public static void main(String[] args) throws Exception { + syncUpdateParameters(); + } + + public static void syncUpdateParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateParametersRequest request = + UpdateParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setParameters(MemcacheParameters.newBuilder().build()) + .build(); + Instance response = cloudMemcacheClient.updateParametersAsync(request).get(); + } + } +} +// [END memcache_v1_generated_cloudmemcacheclient_updateparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.java new file mode 100644 index 000000000000..b747c64887b0 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.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.memcache.v1.samples; + +// [START +// memcache_v1_generated_cloudmemcacheclient_updateparameters_instancenamefieldmaskmemcacheparameters_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.MemcacheParameters; +import com.google.protobuf.FieldMask; + +public class SyncUpdateParametersInstancenameFieldmaskMemcacheparameters { + + public static void main(String[] args) throws Exception { + syncUpdateParametersInstancenameFieldmaskMemcacheparameters(); + } + + public static void syncUpdateParametersInstancenameFieldmaskMemcacheparameters() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + Instance response = + cloudMemcacheClient.updateParametersAsync(name, updateMask, parameters).get(); + } + } +} +// [END +// memcache_v1_generated_cloudmemcacheclient_updateparameters_instancenamefieldmaskmemcacheparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.java new file mode 100644 index 000000000000..76d6d3955289 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.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.memcache.v1.samples; + +// [START +// memcache_v1_generated_cloudmemcacheclient_updateparameters_stringfieldmaskmemcacheparameters_sync] +import com.google.cloud.memcache.v1.CloudMemcacheClient; +import com.google.cloud.memcache.v1.Instance; +import com.google.cloud.memcache.v1.InstanceName; +import com.google.cloud.memcache.v1.MemcacheParameters; +import com.google.protobuf.FieldMask; + +public class SyncUpdateParametersStringFieldmaskMemcacheparameters { + + public static void main(String[] args) throws Exception { + syncUpdateParametersStringFieldmaskMemcacheparameters(); + } + + public static void syncUpdateParametersStringFieldmaskMemcacheparameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + Instance response = + cloudMemcacheClient.updateParametersAsync(name, updateMask, parameters).get(); + } + } +} +// [END +// memcache_v1_generated_cloudmemcacheclient_updateparameters_stringfieldmaskmemcacheparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcachesettings/getinstance/SyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcachesettings/getinstance/SyncGetInstance.java new file mode 100644 index 000000000000..aacd9011b9ad --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/cloudmemcachesettings/getinstance/SyncGetInstance.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.memcache.v1.samples; + +// [START memcache_v1_generated_cloudmemcachesettings_getinstance_sync] +import com.google.cloud.memcache.v1.CloudMemcacheSettings; +import java.time.Duration; + +public class SyncGetInstance { + + public static void main(String[] args) throws Exception { + syncGetInstance(); + } + + public static void syncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudMemcacheSettings.Builder cloudMemcacheSettingsBuilder = CloudMemcacheSettings.newBuilder(); + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudMemcacheSettings cloudMemcacheSettings = cloudMemcacheSettingsBuilder.build(); + } +} +// [END memcache_v1_generated_cloudmemcachesettings_getinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.java new file mode 100644 index 000000000000..05577f9b5f26 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.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.memcache.v1.stub.samples; + +// [START memcache_v1_generated_cloudmemcachestubsettings_getinstance_sync] +import com.google.cloud.memcache.v1.stub.CloudMemcacheStubSettings; +import java.time.Duration; + +public class SyncGetInstance { + + public static void main(String[] args) throws Exception { + syncGetInstance(); + } + + public static void syncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudMemcacheStubSettings.Builder cloudMemcacheSettingsBuilder = + CloudMemcacheStubSettings.newBuilder(); + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudMemcacheStubSettings cloudMemcacheSettings = cloudMemcacheSettingsBuilder.build(); + } +} +// [END memcache_v1_generated_cloudmemcachestubsettings_getinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParameters.java new file mode 100644 index 000000000000..bd1bbb5ec769 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParameters.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.ApplyParametersRequest; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.longrunning.Operation; +import java.util.ArrayList; + +public class AsyncApplyParameters { + + public static void main(String[] args) throws Exception { + asyncApplyParameters(); + } + + public static void asyncApplyParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplyParametersRequest request = + ApplyParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + ApiFuture future = + cloudMemcacheClient.applyParametersCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.java new file mode 100644 index 000000000000..ae1b842f3d64 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/AsyncApplyParametersLRO.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1beta2.ApplyParametersRequest; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.OperationMetadata; +import java.util.ArrayList; + +public class AsyncApplyParametersLRO { + + public static void main(String[] args) throws Exception { + asyncApplyParametersLRO(); + } + + public static void asyncApplyParametersLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplyParametersRequest request = + ApplyParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + OperationFuture future = + cloudMemcacheClient.applyParametersOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParameters.java new file mode 100644 index 000000000000..0425b703efbf --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParameters.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_sync] +import com.google.cloud.memcache.v1beta2.ApplyParametersRequest; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import java.util.ArrayList; + +public class SyncApplyParameters { + + public static void main(String[] args) throws Exception { + syncApplyParameters(); + } + + public static void syncApplyParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplyParametersRequest request = + ApplyParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + Instance response = cloudMemcacheClient.applyParametersAsync(request).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.java new file mode 100644 index 000000000000..542070abe31a --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersInstancenameListstringBoolean.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_instancenameliststringboolean_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import java.util.ArrayList; +import java.util.List; + +public class SyncApplyParametersInstancenameListstringBoolean { + + public static void main(String[] args) throws Exception { + syncApplyParametersInstancenameListstringBoolean(); + } + + public static void syncApplyParametersInstancenameListstringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + Instance response = cloudMemcacheClient.applyParametersAsync(name, nodeIds, applyAll).get(); + } + } +} +// [END +// memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_instancenameliststringboolean_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.java new file mode 100644 index 000000000000..aae5dc5b7b79 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applyparameters/SyncApplyParametersStringListstringBoolean.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_stringliststringboolean_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import java.util.ArrayList; +import java.util.List; + +public class SyncApplyParametersStringListstringBoolean { + + public static void main(String[] args) throws Exception { + syncApplyParametersStringListstringBoolean(); + } + + public static void syncApplyParametersStringListstringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + Instance response = cloudMemcacheClient.applyParametersAsync(name, nodeIds, applyAll).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applyparameters_stringliststringboolean_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdate.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdate.java new file mode 100644 index 000000000000..a75780296eac --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdate.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.ApplySoftwareUpdateRequest; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.longrunning.Operation; +import java.util.ArrayList; + +public class AsyncApplySoftwareUpdate { + + public static void main(String[] args) throws Exception { + asyncApplySoftwareUpdate(); + } + + public static void asyncApplySoftwareUpdate() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplySoftwareUpdateRequest request = + ApplySoftwareUpdateRequest.newBuilder() + .setInstance(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + ApiFuture future = + cloudMemcacheClient.applySoftwareUpdateCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdateLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdateLRO.java new file mode 100644 index 000000000000..6c960796694f --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/AsyncApplySoftwareUpdateLRO.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1beta2.ApplySoftwareUpdateRequest; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.OperationMetadata; +import java.util.ArrayList; + +public class AsyncApplySoftwareUpdateLRO { + + public static void main(String[] args) throws Exception { + asyncApplySoftwareUpdateLRO(); + } + + public static void asyncApplySoftwareUpdateLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplySoftwareUpdateRequest request = + ApplySoftwareUpdateRequest.newBuilder() + .setInstance(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + OperationFuture future = + cloudMemcacheClient.applySoftwareUpdateOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdate.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdate.java new file mode 100644 index 000000000000..d3f822616bdf --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdate.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_sync] +import com.google.cloud.memcache.v1beta2.ApplySoftwareUpdateRequest; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import java.util.ArrayList; + +public class SyncApplySoftwareUpdate { + + public static void main(String[] args) throws Exception { + syncApplySoftwareUpdate(); + } + + public static void syncApplySoftwareUpdate() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ApplySoftwareUpdateRequest request = + ApplySoftwareUpdateRequest.newBuilder() + .setInstance(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .addAllNodeIds(new ArrayList()) + .setApplyAll(true) + .build(); + Instance response = cloudMemcacheClient.applySoftwareUpdateAsync(request).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateInstancenameListstringBoolean.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateInstancenameListstringBoolean.java new file mode 100644 index 000000000000..384da479dbe3 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateInstancenameListstringBoolean.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_instancenameliststringboolean_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import java.util.ArrayList; +import java.util.List; + +public class SyncApplySoftwareUpdateInstancenameListstringBoolean { + + public static void main(String[] args) throws Exception { + syncApplySoftwareUpdateInstancenameListstringBoolean(); + } + + public static void syncApplySoftwareUpdateInstancenameListstringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName instance = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + Instance response = + cloudMemcacheClient.applySoftwareUpdateAsync(instance, nodeIds, applyAll).get(); + } + } +} +// [END +// memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_instancenameliststringboolean_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateStringListstringBoolean.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateStringListstringBoolean.java new file mode 100644 index 000000000000..1c6ccb8f5c2a --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/applysoftwareupdate/SyncApplySoftwareUpdateStringListstringBoolean.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_stringliststringboolean_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import java.util.ArrayList; +import java.util.List; + +public class SyncApplySoftwareUpdateStringListstringBoolean { + + public static void main(String[] args) throws Exception { + syncApplySoftwareUpdateStringListstringBoolean(); + } + + public static void syncApplySoftwareUpdateStringListstringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String instance = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + List nodeIds = new ArrayList<>(); + boolean applyAll = true; + Instance response = + cloudMemcacheClient.applySoftwareUpdateAsync(instance, nodeIds, applyAll).get(); + } + } +} +// [END +// memcache_v1beta2_generated_cloudmemcacheclient_applysoftwareupdate_stringliststringboolean_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..dfcda128b34e --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.CloudMemcacheSettings; +import com.google.cloud.memcache.v1beta2.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. + CloudMemcacheSettings cloudMemcacheSettings = + CloudMemcacheSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_create_setcredentialsprovider_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..35ae6daaae55 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_create_setcredentialsprovider1_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.CloudMemcacheSettings; + +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. + CloudMemcacheSettings cloudMemcacheSettings = + CloudMemcacheSettings.newBuilder() + .setTransportChannelProvider( + CloudMemcacheSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_create_setcredentialsprovider1_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetEndpoint.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..ebfedbd75252 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_create_setendpoint_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.CloudMemcacheSettings; +import com.google.cloud.memcache.v1beta2.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. + CloudMemcacheSettings cloudMemcacheSettings = + CloudMemcacheSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create(cloudMemcacheSettings); + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_create_setendpoint_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstance.java new file mode 100644 index 000000000000..cd8837a60c1f --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_createinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.CreateInstanceRequest; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; +import com.google.longrunning.Operation; + +public class AsyncCreateInstance { + + public static void main(String[] args) throws Exception { + asyncCreateInstance(); + } + + public static void asyncCreateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setResource(Instance.newBuilder().build()) + .build(); + ApiFuture future = + cloudMemcacheClient.createInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_createinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.java new file mode 100644 index 000000000000..7633cb7ad7e5 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/AsyncCreateInstanceLRO.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_createinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.CreateInstanceRequest; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; +import com.google.cloud.memcache.v1beta2.OperationMetadata; + +public class AsyncCreateInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncCreateInstanceLRO(); + } + + public static void asyncCreateInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setResource(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudMemcacheClient.createInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_createinstance_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstance.java new file mode 100644 index 000000000000..06370d4e645b --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_createinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.CreateInstanceRequest; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class SyncCreateInstance { + + public static void main(String[] args) throws Exception { + syncCreateInstance(); + } + + public static void syncCreateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setResource(Instance.newBuilder().build()) + .build(); + Instance response = cloudMemcacheClient.createInstanceAsync(request).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_createinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java new file mode 100644 index 000000000000..d8c8789a39e1 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceLocationnameStringInstance.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_createinstance_locationnamestringinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class SyncCreateInstanceLocationnameStringInstance { + + public static void main(String[] args) throws Exception { + syncCreateInstanceLocationnameStringInstance(); + } + + public static void syncCreateInstanceLocationnameStringInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String instanceId = "instanceId902024336"; + Instance resource = Instance.newBuilder().build(); + Instance response = + cloudMemcacheClient.createInstanceAsync(parent, instanceId, resource).get(); + } + } +} +// [END +// memcache_v1beta2_generated_cloudmemcacheclient_createinstance_locationnamestringinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceStringStringInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceStringStringInstance.java new file mode 100644 index 000000000000..24ac35626690 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/createinstance/SyncCreateInstanceStringStringInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_createinstance_stringstringinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class SyncCreateInstanceStringStringInstance { + + public static void main(String[] args) throws Exception { + syncCreateInstanceStringStringInstance(); + } + + public static void syncCreateInstanceStringStringInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String instanceId = "instanceId902024336"; + Instance resource = Instance.newBuilder().build(); + Instance response = + cloudMemcacheClient.createInstanceAsync(parent, instanceId, resource).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_createinstance_stringstringinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.java new file mode 100644 index 000000000000..7fe059e2a146 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.DeleteInstanceRequest; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.longrunning.Operation; + +public class AsyncDeleteInstance { + + public static void main(String[] args) throws Exception { + asyncDeleteInstance(); + } + + public static void asyncDeleteInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = + cloudMemcacheClient.deleteInstanceCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.java new file mode 100644 index 000000000000..7c078d3e9193 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/AsyncDeleteInstanceLRO.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.DeleteInstanceRequest; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.OperationMetadata; +import com.google.protobuf.Empty; + +public class AsyncDeleteInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteInstanceLRO(); + } + + public static void asyncDeleteInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + OperationFuture future = + cloudMemcacheClient.deleteInstanceOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.java new file mode 100644 index 000000000000..5455736fa290 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.DeleteInstanceRequest; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class SyncDeleteInstance { + + public static void main(String[] args) throws Exception { + syncDeleteInstance(); + } + + public static void syncDeleteInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + cloudMemcacheClient.deleteInstanceAsync(request).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.java new file mode 100644 index 000000000000..973d2cc2d7e5 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceInstancename.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_instancename_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class SyncDeleteInstanceInstancename { + + public static void main(String[] args) throws Exception { + syncDeleteInstanceInstancename(); + } + + public static void syncDeleteInstanceInstancename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + cloudMemcacheClient.deleteInstanceAsync(name).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_instancename_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.java new file mode 100644 index 000000000000..e1992d61a5f3 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/deleteinstance/SyncDeleteInstanceString.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_string_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class SyncDeleteInstanceString { + + public static void main(String[] args) throws Exception { + syncDeleteInstanceString(); + } + + public static void syncDeleteInstanceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + cloudMemcacheClient.deleteInstanceAsync(name).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_deleteinstance_string_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/AsyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/AsyncGetInstance.java new file mode 100644 index 000000000000..83ab8964ec2d --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/AsyncGetInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_getinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.GetInstanceRequest; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class AsyncGetInstance { + + public static void main(String[] args) throws Exception { + asyncGetInstance(); + } + + public static void asyncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudMemcacheClient.getInstanceCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_getinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstance.java new file mode 100644 index 000000000000..054325eaec69 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_getinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.GetInstanceRequest; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class SyncGetInstance { + + public static void main(String[] args) throws Exception { + syncGetInstance(); + } + + public static void syncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + Instance response = cloudMemcacheClient.getInstance(request); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_getinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.java new file mode 100644 index 000000000000..9bf1c35db303 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceInstancename.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_getinstance_instancename_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class SyncGetInstanceInstancename { + + public static void main(String[] args) throws Exception { + syncGetInstanceInstancename(); + } + + public static void syncGetInstanceInstancename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + Instance response = cloudMemcacheClient.getInstance(name); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_getinstance_instancename_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceString.java new file mode 100644 index 000000000000..da65faaa398f --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/getinstance/SyncGetInstanceString.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_getinstance_string_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; + +public class SyncGetInstanceString { + + public static void main(String[] args) throws Exception { + syncGetInstanceString(); + } + + public static void syncGetInstanceString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + Instance response = cloudMemcacheClient.getInstance(name); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_getinstance_string_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstances.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstances.java new file mode 100644 index 000000000000..12e26eb679d3 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstances.java @@ -0,0 +1,53 @@ +/* + * 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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_listinstances_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.ListInstancesRequest; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class AsyncListInstances { + + public static void main(String[] args) throws Exception { + asyncListInstances(); + } + + public static void asyncListInstances() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + cloudMemcacheClient.listInstancesPagedCallable().futureCall(request); + // Do something. + for (Instance element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_listinstances_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java new file mode 100644 index 000000000000..9f6452aa6873 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/AsyncListInstancesPaged.java @@ -0,0 +1,60 @@ +/* + * 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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_listinstances_paged_async] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.ListInstancesRequest; +import com.google.cloud.memcache.v1beta2.ListInstancesResponse; +import com.google.cloud.memcache.v1beta2.LocationName; +import com.google.common.base.Strings; + +public class AsyncListInstancesPaged { + + public static void main(String[] args) throws Exception { + asyncListInstancesPaged(); + } + + public static void asyncListInstancesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListInstancesResponse response = cloudMemcacheClient.listInstancesCallable().call(request); + for (Instance element : response.getResourcesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_listinstances_paged_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstances.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstances.java new file mode 100644 index 000000000000..0deceafaa03d --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstances.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_listinstances_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.ListInstancesRequest; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class SyncListInstances { + + public static void main(String[] args) throws Exception { + syncListInstances(); + } + + public static void syncListInstances() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (Instance element : cloudMemcacheClient.listInstances(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_listinstances_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.java new file mode 100644 index 000000000000..3c91cf429309 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesLocationname.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_listinstances_locationname_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class SyncListInstancesLocationname { + + public static void main(String[] args) throws Exception { + syncListInstancesLocationname(); + } + + public static void syncListInstancesLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Instance element : cloudMemcacheClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_listinstances_locationname_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesString.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesString.java new file mode 100644 index 000000000000..601afe55cb0a --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/listinstances/SyncListInstancesString.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_listinstances_string_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.LocationName; + +public class SyncListInstancesString { + + public static void main(String[] args) throws Exception { + syncListInstancesString(); + } + + public static void syncListInstancesString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Instance element : cloudMemcacheClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_listinstances_string_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java new file mode 100644 index 000000000000..e21b6d672322 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstance.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.UpdateInstanceRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateInstance { + + public static void main(String[] args) throws Exception { + asyncUpdateInstance(); + } + + public static void asyncUpdateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setResource(Instance.newBuilder().build()) + .build(); + ApiFuture future = + cloudMemcacheClient.updateInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java new file mode 100644 index 000000000000..ee3251ed5eae --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/AsyncUpdateInstanceLRO.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.OperationMetadata; +import com.google.cloud.memcache.v1beta2.UpdateInstanceRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateInstanceLRO(); + } + + public static void asyncUpdateInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setResource(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudMemcacheClient.updateInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstance.java new file mode 100644 index 000000000000..493f7682f5cf --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.UpdateInstanceRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateInstance { + + public static void main(String[] args) throws Exception { + syncUpdateInstance(); + } + + public static void syncUpdateInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setResource(Instance.newBuilder().build()) + .build(); + Instance response = cloudMemcacheClient.updateInstanceAsync(request).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java new file mode 100644 index 000000000000..9e72d00f0588 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_fieldmaskinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.protobuf.FieldMask; + +public class SyncUpdateInstanceFieldmaskInstance { + + public static void main(String[] args) throws Exception { + syncUpdateInstanceFieldmaskInstance(); + } + + public static void syncUpdateInstanceFieldmaskInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance resource = Instance.newBuilder().build(); + Instance response = cloudMemcacheClient.updateInstanceAsync(updateMask, resource).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateinstance_fieldmaskinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.java new file mode 100644 index 000000000000..5dfb74394e0b --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParameters.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.MemcacheParameters; +import com.google.cloud.memcache.v1beta2.UpdateParametersRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateParameters { + + public static void main(String[] args) throws Exception { + asyncUpdateParameters(); + } + + public static void asyncUpdateParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateParametersRequest request = + UpdateParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setParameters(MemcacheParameters.newBuilder().build()) + .build(); + ApiFuture future = + cloudMemcacheClient.updateParametersCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java new file mode 100644 index 000000000000..b0823fbd2127 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/AsyncUpdateParametersLRO.java @@ -0,0 +1,52 @@ +/* + * 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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.MemcacheParameters; +import com.google.cloud.memcache.v1beta2.OperationMetadata; +import com.google.cloud.memcache.v1beta2.UpdateParametersRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateParametersLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateParametersLRO(); + } + + public static void asyncUpdateParametersLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateParametersRequest request = + UpdateParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setParameters(MemcacheParameters.newBuilder().build()) + .build(); + OperationFuture future = + cloudMemcacheClient.updateParametersOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_lro_async] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParameters.java new file mode 100644 index 000000000000..c4de3135dc49 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParameters.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.MemcacheParameters; +import com.google.cloud.memcache.v1beta2.UpdateParametersRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateParameters { + + public static void main(String[] args) throws Exception { + syncUpdateParameters(); + } + + public static void syncUpdateParameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + UpdateParametersRequest request = + UpdateParametersRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setParameters(MemcacheParameters.newBuilder().build()) + .build(); + Instance response = cloudMemcacheClient.updateParametersAsync(request).get(); + } + } +} +// [END memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.java new file mode 100644 index 000000000000..534988893428 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersInstancenameFieldmaskMemcacheparameters.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_instancenamefieldmaskmemcacheparameters_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.MemcacheParameters; +import com.google.protobuf.FieldMask; + +public class SyncUpdateParametersInstancenameFieldmaskMemcacheparameters { + + public static void main(String[] args) throws Exception { + syncUpdateParametersInstancenameFieldmaskMemcacheparameters(); + } + + public static void syncUpdateParametersInstancenameFieldmaskMemcacheparameters() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + Instance response = + cloudMemcacheClient.updateParametersAsync(name, updateMask, parameters).get(); + } + } +} +// [END +// memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_instancenamefieldmaskmemcacheparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.java new file mode 100644 index 000000000000..f41210e7af84 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcacheclient/updateparameters/SyncUpdateParametersStringFieldmaskMemcacheparameters.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.memcache.v1beta2.samples; + +// [START +// memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_stringfieldmaskmemcacheparameters_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheClient; +import com.google.cloud.memcache.v1beta2.Instance; +import com.google.cloud.memcache.v1beta2.InstanceName; +import com.google.cloud.memcache.v1beta2.MemcacheParameters; +import com.google.protobuf.FieldMask; + +public class SyncUpdateParametersStringFieldmaskMemcacheparameters { + + public static void main(String[] args) throws Exception { + syncUpdateParametersStringFieldmaskMemcacheparameters(); + } + + public static void syncUpdateParametersStringFieldmaskMemcacheparameters() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudMemcacheClient cloudMemcacheClient = CloudMemcacheClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + FieldMask updateMask = FieldMask.newBuilder().build(); + MemcacheParameters parameters = MemcacheParameters.newBuilder().build(); + Instance response = + cloudMemcacheClient.updateParametersAsync(name, updateMask, parameters).get(); + } + } +} +// [END +// memcache_v1beta2_generated_cloudmemcacheclient_updateparameters_stringfieldmaskmemcacheparameters_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcachesettings/getinstance/SyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcachesettings/getinstance/SyncGetInstance.java new file mode 100644 index 000000000000..7e9603050965 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/cloudmemcachesettings/getinstance/SyncGetInstance.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.memcache.v1beta2.samples; + +// [START memcache_v1beta2_generated_cloudmemcachesettings_getinstance_sync] +import com.google.cloud.memcache.v1beta2.CloudMemcacheSettings; +import java.time.Duration; + +public class SyncGetInstance { + + public static void main(String[] args) throws Exception { + syncGetInstance(); + } + + public static void syncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudMemcacheSettings.Builder cloudMemcacheSettingsBuilder = CloudMemcacheSettings.newBuilder(); + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudMemcacheSettings cloudMemcacheSettings = cloudMemcacheSettingsBuilder.build(); + } +} +// [END memcache_v1beta2_generated_cloudmemcachesettings_getinstance_sync] diff --git a/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.java b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.java new file mode 100644 index 000000000000..0af8baf6e710 --- /dev/null +++ b/java-memcache/samples/snippets/generated/com/google/cloud/memcache/v1beta2/stub/cloudmemcachestubsettings/getinstance/SyncGetInstance.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.memcache.v1beta2.stub.samples; + +// [START memcache_v1beta2_generated_cloudmemcachestubsettings_getinstance_sync] +import com.google.cloud.memcache.v1beta2.stub.CloudMemcacheStubSettings; +import java.time.Duration; + +public class SyncGetInstance { + + public static void main(String[] args) throws Exception { + syncGetInstance(); + } + + public static void syncGetInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudMemcacheStubSettings.Builder cloudMemcacheSettingsBuilder = + CloudMemcacheStubSettings.newBuilder(); + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudMemcacheSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudMemcacheStubSettings cloudMemcacheSettings = cloudMemcacheSettingsBuilder.build(); + } +} +// [END memcache_v1beta2_generated_cloudmemcachestubsettings_getinstance_sync]