diff --git a/google-cloud-redis/pom.xml b/google-cloud-redis/pom.xml index 4ae903db..817e1dc4 100644 --- a/google-cloud-redis/pom.xml +++ b/google-cloud-redis/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -89,12 +93,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisClient.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisClient.java index 55ff5ab0..59c404bc 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisClient.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisClient.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.redis.v1.stub.CloudRedisStubSettings; 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 com.google.protobuf.Timestamp; @@ -122,13 +122,28 @@ * CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); * } * + *

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.
+ * CloudRedisSettings cloudRedisSettings =
+ *     CloudRedisSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudRedisSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class CloudRedisClient implements BackgroundResource { private final CloudRedisSettings settings; private final CloudRedisStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of CloudRedisClient with default settings. */ public static final CloudRedisClient create() throws IOException { @@ -158,13 +173,17 @@ public static final CloudRedisClient create(CloudRedisStub stub) { protected CloudRedisClient(CloudRedisSettings settings) throws IOException { this.settings = settings; this.stub = ((CloudRedisStubSettings) 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 CloudRedisClient(CloudRedisStub 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 CloudRedisSettings getSettings() { @@ -179,10 +198,18 @@ public CloudRedisStub 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 all Redis instances owned by a project in either the specified location (region) or all diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisSettings.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisSettings.java index 34734bc6..35cb5cf7 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisSettings.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/CloudRedisSettings.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; @@ -203,11 +204,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudRedisStubSettings.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 CloudRedisStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudRedisStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudRedisStubSettings.defaultTransportChannelProvider(); } @@ -217,11 +225,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudRedisStubSettings.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); @@ -259,6 +273,11 @@ private static Builder createDefault() { return new Builder(CloudRedisStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudRedisStubSettings.newHttpJsonBuilder()); + } + public CloudRedisStubSettings.Builder getStubSettingsBuilder() { return ((CloudRedisStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStub.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStub.java index 031749a4..05488251 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStub.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStub.java @@ -51,7 +51,11 @@ public abstract class CloudRedisStub 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/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStubSettings.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStubSettings.java index ee259210..7a2e730d 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStubSettings.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/CloudRedisStubSettings.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; @@ -306,6 +309,11 @@ public CloudRedisStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudRedisStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudRedisStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -338,18 +346,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(CloudRedisStubSettings.class)) @@ -357,11 +372,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(CloudRedisStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudRedisStubSettings.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); @@ -562,6 +596,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/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/HttpJsonCloudRedisCallableFactory.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/HttpJsonCloudRedisCallableFactory.java new file mode 100644 index 00000000..9f515870 --- /dev/null +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/HttpJsonCloudRedisCallableFactory.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.redis.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 CloudRedis service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudRedisCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/HttpJsonCloudRedisStub.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/HttpJsonCloudRedisStub.java new file mode 100644 index 00000000..d958da7d --- /dev/null +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1/stub/HttpJsonCloudRedisStub.java @@ -0,0 +1,886 @@ +/* + * 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.redis.v1.stub; + +import static com.google.cloud.redis.v1.CloudRedisClient.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.redis.v1.CreateInstanceRequest; +import com.google.cloud.redis.v1.DeleteInstanceRequest; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.GetInstanceAuthStringRequest; +import com.google.cloud.redis.v1.GetInstanceRequest; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceAuthString; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.v1.ListInstancesResponse; +import com.google.cloud.redis.v1.OperationMetadata; +import com.google.cloud.redis.v1.RescheduleMaintenanceRequest; +import com.google.cloud.redis.v1.UpdateInstanceRequest; +import com.google.cloud.redis.v1.UpgradeInstanceRequest; +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 CloudRedis service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudRedisStub extends CloudRedisStub { + 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.redis.v1.CloudRedis/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, "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.redis.v1.CloudRedis/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 + getInstanceAuthStringMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/GetInstanceAuthString") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}/authString", + 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(InstanceAuthString.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/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.redis.v1.CloudRedis/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 + upgradeInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/UpgradeInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:upgrade", + 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( + (UpgradeInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + importInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/ImportInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:import", + 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( + (ImportInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + exportInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/ExportInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:export", + 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( + (ExportInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + failoverInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/FailoverInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:failover", + 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( + (FailoverInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/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 + rescheduleMaintenanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1.CloudRedis/RescheduleMaintenance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/instances/*}:rescheduleMaintenance", + 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( + (RescheduleMaintenanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listInstancesCallable; + private final UnaryCallable + listInstancesPagedCallable; + private final UnaryCallable getInstanceCallable; + private final UnaryCallable + getInstanceAuthStringCallable; + private final UnaryCallable createInstanceCallable; + private final OperationCallable + createInstanceOperationCallable; + private final UnaryCallable updateInstanceCallable; + private final OperationCallable + updateInstanceOperationCallable; + private final UnaryCallable upgradeInstanceCallable; + private final OperationCallable + upgradeInstanceOperationCallable; + private final UnaryCallable importInstanceCallable; + private final OperationCallable + importInstanceOperationCallable; + private final UnaryCallable exportInstanceCallable; + private final OperationCallable + exportInstanceOperationCallable; + private final UnaryCallable failoverInstanceCallable; + private final OperationCallable + failoverInstanceOperationCallable; + private final UnaryCallable deleteInstanceCallable; + private final OperationCallable + deleteInstanceOperationCallable; + private final UnaryCallable + rescheduleMaintenanceCallable; + private final OperationCallable + rescheduleMaintenanceOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudRedisStub create(CloudRedisStubSettings settings) + throws IOException { + return new HttpJsonCloudRedisStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudRedisStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudRedisStub( + CloudRedisStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudRedisStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudRedisStub( + CloudRedisStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudRedisStub, 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 HttpJsonCloudRedisStub(CloudRedisStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudRedisCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudRedisStub, 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 HttpJsonCloudRedisStub( + CloudRedisStubSettings 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 + getInstanceAuthStringTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getInstanceAuthStringMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings upgradeInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(upgradeInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings exportInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(exportInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings failoverInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(failoverInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + rescheduleMaintenanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(rescheduleMaintenanceMethodDescriptor) + .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.getInstanceAuthStringCallable = + callableFactory.createUnaryCallable( + getInstanceAuthStringTransportSettings, + settings.getInstanceAuthStringSettings(), + 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.upgradeInstanceCallable = + callableFactory.createUnaryCallable( + upgradeInstanceTransportSettings, settings.upgradeInstanceSettings(), clientContext); + this.upgradeInstanceOperationCallable = + callableFactory.createOperationCallable( + upgradeInstanceTransportSettings, + settings.upgradeInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.importInstanceCallable = + callableFactory.createUnaryCallable( + importInstanceTransportSettings, settings.importInstanceSettings(), clientContext); + this.importInstanceOperationCallable = + callableFactory.createOperationCallable( + importInstanceTransportSettings, + settings.importInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.exportInstanceCallable = + callableFactory.createUnaryCallable( + exportInstanceTransportSettings, settings.exportInstanceSettings(), clientContext); + this.exportInstanceOperationCallable = + callableFactory.createOperationCallable( + exportInstanceTransportSettings, + settings.exportInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.failoverInstanceCallable = + callableFactory.createUnaryCallable( + failoverInstanceTransportSettings, settings.failoverInstanceSettings(), clientContext); + this.failoverInstanceOperationCallable = + callableFactory.createOperationCallable( + failoverInstanceTransportSettings, + settings.failoverInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteInstanceCallable = + callableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.deleteInstanceOperationCallable = + callableFactory.createOperationCallable( + deleteInstanceTransportSettings, + settings.deleteInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.rescheduleMaintenanceCallable = + callableFactory.createUnaryCallable( + rescheduleMaintenanceTransportSettings, + settings.rescheduleMaintenanceSettings(), + clientContext); + this.rescheduleMaintenanceOperationCallable = + callableFactory.createOperationCallable( + rescheduleMaintenanceTransportSettings, + settings.rescheduleMaintenanceOperationSettings(), + 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(getInstanceAuthStringMethodDescriptor); + methodDescriptors.add(createInstanceMethodDescriptor); + methodDescriptors.add(updateInstanceMethodDescriptor); + methodDescriptors.add(upgradeInstanceMethodDescriptor); + methodDescriptors.add(importInstanceMethodDescriptor); + methodDescriptors.add(exportInstanceMethodDescriptor); + methodDescriptors.add(failoverInstanceMethodDescriptor); + methodDescriptors.add(deleteInstanceMethodDescriptor); + methodDescriptors.add(rescheduleMaintenanceMethodDescriptor); + 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 + getInstanceAuthStringCallable() { + return getInstanceAuthStringCallable; + } + + @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 upgradeInstanceCallable() { + return upgradeInstanceCallable; + } + + @Override + public OperationCallable + upgradeInstanceOperationCallable() { + return upgradeInstanceOperationCallable; + } + + @Override + public UnaryCallable importInstanceCallable() { + return importInstanceCallable; + } + + @Override + public OperationCallable + importInstanceOperationCallable() { + return importInstanceOperationCallable; + } + + @Override + public UnaryCallable exportInstanceCallable() { + return exportInstanceCallable; + } + + @Override + public OperationCallable + exportInstanceOperationCallable() { + return exportInstanceOperationCallable; + } + + @Override + public UnaryCallable failoverInstanceCallable() { + return failoverInstanceCallable; + } + + @Override + public OperationCallable + failoverInstanceOperationCallable() { + return failoverInstanceOperationCallable; + } + + @Override + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + @Override + public OperationCallable + deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; + } + + @Override + public UnaryCallable rescheduleMaintenanceCallable() { + return rescheduleMaintenanceCallable; + } + + @Override + public OperationCallable + rescheduleMaintenanceOperationCallable() { + return rescheduleMaintenanceOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisClient.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisClient.java index eef75732..884a7d67 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisClient.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisClient.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.redis.v1beta1.stub.CloudRedisStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Any; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; @@ -124,6 +124,20 @@ * CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); * } * + *

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.
+ * CloudRedisSettings cloudRedisSettings =
+ *     CloudRedisSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudRedisSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -131,7 +145,8 @@ public class CloudRedisClient implements BackgroundResource { private final CloudRedisSettings settings; private final CloudRedisStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of CloudRedisClient with default settings. */ public static final CloudRedisClient create() throws IOException { @@ -161,13 +176,17 @@ public static final CloudRedisClient create(CloudRedisStub stub) { protected CloudRedisClient(CloudRedisSettings settings) throws IOException { this.settings = settings; this.stub = ((CloudRedisStubSettings) 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 CloudRedisClient(CloudRedisStub 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 CloudRedisSettings getSettings() { @@ -182,10 +201,18 @@ public CloudRedisStub 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 all Redis instances owned by a project in either the specified location (region) or all diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisSettings.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisSettings.java index 1ec7406b..347d6a82 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisSettings.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/CloudRedisSettings.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; @@ -205,11 +206,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudRedisStubSettings.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 CloudRedisStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudRedisStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudRedisStubSettings.defaultTransportChannelProvider(); } @@ -219,11 +227,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudRedisStubSettings.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); @@ -261,6 +275,11 @@ private static Builder createDefault() { return new Builder(CloudRedisStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudRedisStubSettings.newHttpJsonBuilder()); + } + public CloudRedisStubSettings.Builder getStubSettingsBuilder() { return ((CloudRedisStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStub.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStub.java index 5c9f2594..95ca277c 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStub.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStub.java @@ -53,7 +53,11 @@ public abstract class CloudRedisStub 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/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStubSettings.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStubSettings.java index 9776782e..d123b8b3 100644 --- a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStubSettings.java +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/CloudRedisStubSettings.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; @@ -307,6 +310,11 @@ public CloudRedisStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudRedisStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudRedisStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -339,18 +347,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(CloudRedisStubSettings.class)) @@ -358,11 +373,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(CloudRedisStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudRedisStubSettings.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); @@ -564,6 +598,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/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisCallableFactory.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisCallableFactory.java new file mode 100644 index 00000000..26226344 --- /dev/null +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisCallableFactory.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.redis.v1beta1.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 CloudRedis service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudRedisCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java new file mode 100644 index 00000000..75d73306 --- /dev/null +++ b/google-cloud-redis/src/main/java/com/google/cloud/redis/v1beta1/stub/HttpJsonCloudRedisStub.java @@ -0,0 +1,881 @@ +/* + * 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.redis.v1beta1.stub; + +import static com.google.cloud.redis.v1beta1.CloudRedisClient.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.redis.v1beta1.CreateInstanceRequest; +import com.google.cloud.redis.v1beta1.DeleteInstanceRequest; +import com.google.cloud.redis.v1beta1.ExportInstanceRequest; +import com.google.cloud.redis.v1beta1.FailoverInstanceRequest; +import com.google.cloud.redis.v1beta1.GetInstanceAuthStringRequest; +import com.google.cloud.redis.v1beta1.GetInstanceRequest; +import com.google.cloud.redis.v1beta1.ImportInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceAuthString; +import com.google.cloud.redis.v1beta1.ListInstancesRequest; +import com.google.cloud.redis.v1beta1.ListInstancesResponse; +import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; +import com.google.cloud.redis.v1beta1.UpdateInstanceRequest; +import com.google.cloud.redis.v1beta1.UpgradeInstanceRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +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 CloudRedis service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudRedisStub extends CloudRedisStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(Instance.getDescriptor()) + .add(Any.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listInstancesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/ListInstances") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{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, "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.redis.v1beta1.CloudRedis/GetInstance") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{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 + getInstanceAuthStringMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/GetInstanceAuthString") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/instances/*}/authString", + 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(InstanceAuthString.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/CreateInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{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.redis.v1beta1.CloudRedis/UpdateInstance") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{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 + upgradeInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/UpgradeInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/instances/*}:upgrade", + 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( + (UpgradeInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + importInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/ImportInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/instances/*}:import", + 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( + (ImportInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + exportInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/ExportInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/instances/*}:export", + 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( + (ExportInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + failoverInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/FailoverInstance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/instances/*}:failover", + 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( + (FailoverInstanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteInstanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/DeleteInstance") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{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 + rescheduleMaintenanceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.redis.v1beta1.CloudRedis/RescheduleMaintenance") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/instances/*}:rescheduleMaintenance", + 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( + (RescheduleMaintenanceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listInstancesCallable; + private final UnaryCallable + listInstancesPagedCallable; + private final UnaryCallable getInstanceCallable; + private final UnaryCallable + getInstanceAuthStringCallable; + private final UnaryCallable createInstanceCallable; + private final OperationCallable + createInstanceOperationCallable; + private final UnaryCallable updateInstanceCallable; + private final OperationCallable + updateInstanceOperationCallable; + private final UnaryCallable upgradeInstanceCallable; + private final OperationCallable + upgradeInstanceOperationCallable; + private final UnaryCallable importInstanceCallable; + private final OperationCallable + importInstanceOperationCallable; + private final UnaryCallable exportInstanceCallable; + private final OperationCallable + exportInstanceOperationCallable; + private final UnaryCallable failoverInstanceCallable; + private final OperationCallable + failoverInstanceOperationCallable; + private final UnaryCallable deleteInstanceCallable; + private final OperationCallable + deleteInstanceOperationCallable; + private final UnaryCallable + rescheduleMaintenanceCallable; + private final OperationCallable + rescheduleMaintenanceOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudRedisStub create(CloudRedisStubSettings settings) + throws IOException { + return new HttpJsonCloudRedisStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudRedisStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudRedisStub( + CloudRedisStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudRedisStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudRedisStub( + CloudRedisStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudRedisStub, 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 HttpJsonCloudRedisStub(CloudRedisStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudRedisCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudRedisStub, 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 HttpJsonCloudRedisStub( + CloudRedisStubSettings 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 + getInstanceAuthStringTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getInstanceAuthStringMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings upgradeInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(upgradeInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings exportInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(exportInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings failoverInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(failoverInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteInstanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteInstanceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + rescheduleMaintenanceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(rescheduleMaintenanceMethodDescriptor) + .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.getInstanceAuthStringCallable = + callableFactory.createUnaryCallable( + getInstanceAuthStringTransportSettings, + settings.getInstanceAuthStringSettings(), + 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.upgradeInstanceCallable = + callableFactory.createUnaryCallable( + upgradeInstanceTransportSettings, settings.upgradeInstanceSettings(), clientContext); + this.upgradeInstanceOperationCallable = + callableFactory.createOperationCallable( + upgradeInstanceTransportSettings, + settings.upgradeInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.importInstanceCallable = + callableFactory.createUnaryCallable( + importInstanceTransportSettings, settings.importInstanceSettings(), clientContext); + this.importInstanceOperationCallable = + callableFactory.createOperationCallable( + importInstanceTransportSettings, + settings.importInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.exportInstanceCallable = + callableFactory.createUnaryCallable( + exportInstanceTransportSettings, settings.exportInstanceSettings(), clientContext); + this.exportInstanceOperationCallable = + callableFactory.createOperationCallable( + exportInstanceTransportSettings, + settings.exportInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.failoverInstanceCallable = + callableFactory.createUnaryCallable( + failoverInstanceTransportSettings, settings.failoverInstanceSettings(), clientContext); + this.failoverInstanceOperationCallable = + callableFactory.createOperationCallable( + failoverInstanceTransportSettings, + settings.failoverInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteInstanceCallable = + callableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.deleteInstanceOperationCallable = + callableFactory.createOperationCallable( + deleteInstanceTransportSettings, + settings.deleteInstanceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.rescheduleMaintenanceCallable = + callableFactory.createUnaryCallable( + rescheduleMaintenanceTransportSettings, + settings.rescheduleMaintenanceSettings(), + clientContext); + this.rescheduleMaintenanceOperationCallable = + callableFactory.createOperationCallable( + rescheduleMaintenanceTransportSettings, + settings.rescheduleMaintenanceOperationSettings(), + 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(getInstanceAuthStringMethodDescriptor); + methodDescriptors.add(createInstanceMethodDescriptor); + methodDescriptors.add(updateInstanceMethodDescriptor); + methodDescriptors.add(upgradeInstanceMethodDescriptor); + methodDescriptors.add(importInstanceMethodDescriptor); + methodDescriptors.add(exportInstanceMethodDescriptor); + methodDescriptors.add(failoverInstanceMethodDescriptor); + methodDescriptors.add(deleteInstanceMethodDescriptor); + methodDescriptors.add(rescheduleMaintenanceMethodDescriptor); + 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 + getInstanceAuthStringCallable() { + return getInstanceAuthStringCallable; + } + + @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 upgradeInstanceCallable() { + return upgradeInstanceCallable; + } + + @Override + public OperationCallable + upgradeInstanceOperationCallable() { + return upgradeInstanceOperationCallable; + } + + @Override + public UnaryCallable importInstanceCallable() { + return importInstanceCallable; + } + + @Override + public OperationCallable importInstanceOperationCallable() { + return importInstanceOperationCallable; + } + + @Override + public UnaryCallable exportInstanceCallable() { + return exportInstanceCallable; + } + + @Override + public OperationCallable exportInstanceOperationCallable() { + return exportInstanceOperationCallable; + } + + @Override + public UnaryCallable failoverInstanceCallable() { + return failoverInstanceCallable; + } + + @Override + public OperationCallable + failoverInstanceOperationCallable() { + return failoverInstanceOperationCallable; + } + + @Override + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + @Override + public OperationCallable deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; + } + + @Override + public UnaryCallable rescheduleMaintenanceCallable() { + return rescheduleMaintenanceCallable; + } + + @Override + public OperationCallable + rescheduleMaintenanceOperationCallable() { + return rescheduleMaintenanceOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-redis/src/test/java/com/google/cloud/redis/v1/CloudRedisClientHttpJsonTest.java b/google-cloud-redis/src/test/java/com/google/cloud/redis/v1/CloudRedisClientHttpJsonTest.java new file mode 100644 index 00000000..752b107c --- /dev/null +++ b/google-cloud-redis/src/test/java/com/google/cloud/redis/v1/CloudRedisClientHttpJsonTest.java @@ -0,0 +1,1391 @@ +/* + * 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.redis.v1; + +import static com.google.cloud.redis.v1.CloudRedisClient.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.redis.v1.stub.HttpJsonCloudRedisStub; +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 CloudRedisClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudRedisClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudRedisStub.getMethodDescriptors(), CloudRedisSettings.getDefaultEndpoint()); + CloudRedisSettings settings = + CloudRedisSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudRedisSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudRedisClient.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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .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 getInstanceAuthStringTest() throws Exception { + InstanceAuthString expectedResponse = + InstanceAuthString.newBuilder().setAuthString("authString1994738649").build(); + mockService.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + InstanceAuthString actualResponse = client.getInstanceAuthString(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 getInstanceAuthStringExceptionTest() 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.getInstanceAuthString(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceAuthStringTest2() throws Exception { + InstanceAuthString expectedResponse = + InstanceAuthString.newBuilder().setAuthString("authString1994738649").build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + + InstanceAuthString actualResponse = client.getInstanceAuthString(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 getInstanceAuthStringExceptionTest2() 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.getInstanceAuthString(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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .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 instance = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).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 instance = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, instance).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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .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 instance = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).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 instance = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, instance).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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance instance = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + + Instance actualResponse = client.updateInstanceAsync(updateMask, instance).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 instance = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + client.updateInstanceAsync(updateMask, instance).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void upgradeInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("upgradeInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redisVersion-1972584739"; + + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).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 upgradeInstanceExceptionTest() 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]"); + String redisVersion = "redisVersion-1972584739"; + client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void upgradeInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("upgradeInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + String redisVersion = "redisVersion-1972584739"; + + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).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 upgradeInstanceExceptionTest2() 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"; + String redisVersion = "redisVersion-1972584739"; + client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + + Instance actualResponse = client.importInstanceAsync(name, inputConfig).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 importInstanceExceptionTest() 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"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + client.importInstanceAsync(name, inputConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void exportInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("exportInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + + Instance actualResponse = client.exportInstanceAsync(name, outputConfig).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 exportInstanceExceptionTest() 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"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + client.exportInstanceAsync(name, outputConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void failoverInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).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 failoverInstanceExceptionTest() 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]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + client.failoverInstanceAsync(name, dataProtectionMode).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void failoverInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).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 failoverInstanceExceptionTest2() 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"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + client.failoverInstanceAsync(name, dataProtectionMode).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 rescheduleMaintenanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("rescheduleMaintenanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + Instance actualResponse = + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).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 rescheduleMaintenanceExceptionTest() 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]"); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void rescheduleMaintenanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("rescheduleMaintenanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + Instance actualResponse = + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).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 rescheduleMaintenanceExceptionTest2() 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"; + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/google-cloud-redis/src/test/java/com/google/cloud/redis/v1beta1/CloudRedisClientHttpJsonTest.java b/google-cloud-redis/src/test/java/com/google/cloud/redis/v1beta1/CloudRedisClientHttpJsonTest.java new file mode 100644 index 00000000..81ac5333 --- /dev/null +++ b/google-cloud-redis/src/test/java/com/google/cloud/redis/v1beta1/CloudRedisClientHttpJsonTest.java @@ -0,0 +1,1406 @@ +/* + * 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.redis.v1beta1; + +import static com.google.cloud.redis.v1beta1.CloudRedisClient.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.redis.v1beta1.stub.HttpJsonCloudRedisStub; +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 CloudRedisClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudRedisClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudRedisStub.getMethodDescriptors(), CloudRedisSettings.getDefaultEndpoint()); + CloudRedisSettings settings = + CloudRedisSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudRedisSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudRedisClient.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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .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 getInstanceAuthStringTest() throws Exception { + InstanceAuthString expectedResponse = + InstanceAuthString.newBuilder().setAuthString("authString1994738649").build(); + mockService.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + InstanceAuthString actualResponse = client.getInstanceAuthString(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 getInstanceAuthStringExceptionTest() 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.getInstanceAuthString(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceAuthStringTest2() throws Exception { + InstanceAuthString expectedResponse = + InstanceAuthString.newBuilder().setAuthString("authString1994738649").build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + + InstanceAuthString actualResponse = client.getInstanceAuthString(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 getInstanceAuthStringExceptionTest2() 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.getInstanceAuthString(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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .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 instance = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).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 instance = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, instance).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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .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 instance = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).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 instance = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, instance).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()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance instance = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + + Instance actualResponse = client.updateInstanceAsync(updateMask, instance).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 instance = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + client.updateInstanceAsync(updateMask, instance).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void upgradeInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("upgradeInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redisVersion-1972584739"; + + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).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 upgradeInstanceExceptionTest() 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]"); + String redisVersion = "redisVersion-1972584739"; + client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void upgradeInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("upgradeInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + String redisVersion = "redisVersion-1972584739"; + + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).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 upgradeInstanceExceptionTest2() 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"; + String redisVersion = "redisVersion-1972584739"; + client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + + Instance actualResponse = client.importInstanceAsync(name, inputConfig).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 importInstanceExceptionTest() 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"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + client.importInstanceAsync(name, inputConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void exportInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("exportInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + + Instance actualResponse = client.exportInstanceAsync(name, outputConfig).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 exportInstanceExceptionTest() 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"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + client.exportInstanceAsync(name, outputConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void failoverInstanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).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 failoverInstanceExceptionTest() 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]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + client.failoverInstanceAsync(name, dataProtectionMode).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void failoverInstanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).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 failoverInstanceExceptionTest2() 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"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + client.failoverInstanceAsync(name, dataProtectionMode).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 rescheduleMaintenanceTest() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("rescheduleMaintenanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + Instance actualResponse = + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).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 rescheduleMaintenanceExceptionTest() 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]"); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void rescheduleMaintenanceTest2() throws Exception { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("displayName1714148973") + .putAllLabels(new HashMap()) + .setLocationId("locationId1541836720") + .setAlternativeLocationId("alternativeLocationId1787141949") + .setRedisVersion("redisVersion-1972584739") + .setReservedIpRange("reservedIpRange575015950") + .setSecondaryIpRange("secondaryIpRange-1937131454") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("currentLocationId-1808505335") + .setCreateTime(Timestamp.newBuilder().build()) + .setStatusMessage("statusMessage-958704715") + .putAllRedisConfigs(new HashMap()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorizedNetwork1515554835") + .setPersistenceIamIdentity("persistenceIamIdentity1464017428") + .setAuthEnabled(true) + .addAllServerCaCerts(new ArrayList()) + .setMaintenancePolicy(MaintenancePolicy.newBuilder().build()) + .setMaintenanceSchedule(MaintenanceSchedule.newBuilder().build()) + .setReplicaCount(564075208) + .addAllNodes(new ArrayList()) + .setReadEndpoint("readEndpoint294053195") + .setReadEndpointPort(-1676143102) + .setPersistenceConfig(PersistenceConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("rescheduleMaintenanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + Instance actualResponse = + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).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 rescheduleMaintenanceExceptionTest2() 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"; + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..c7cfca1c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.CloudRedisSettings; +import com.google.cloud.redis.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. + CloudRedisSettings cloudRedisSettings = + CloudRedisSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); + } +} +// [END redis_v1_generated_cloudredisclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..d6e35229 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_create_setcredentialsprovider1_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.CloudRedisSettings; + +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. + CloudRedisSettings cloudRedisSettings = + CloudRedisSettings.newBuilder() + .setTransportChannelProvider( + CloudRedisSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); + } +} +// [END redis_v1_generated_cloudredisclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..122eabb8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_create_setendpoint_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.CloudRedisSettings; +import com.google.cloud.redis.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. + CloudRedisSettings cloudRedisSettings = + CloudRedisSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); + } +} +// [END redis_v1_generated_cloudredisclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/AsyncCreateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/AsyncCreateInstance.java new file mode 100644 index 00000000..a36bd3e1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/AsyncCreateInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_createinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.CreateInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.createInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_createinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/AsyncCreateInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/AsyncCreateInstanceLRO.java new file mode 100644 index 00000000..d5f6c12d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_createinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.CreateInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.LocationName; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.createInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_createinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstance.java new file mode 100644 index 00000000..7c7a3186 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_createinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.CreateInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.createInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_createinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java new file mode 100644 index 00000000..04dc7e04 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstanceLocationnameStringInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_createinstance_locationnamestringinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String instanceId = "instanceId902024336"; + Instance instance = Instance.newBuilder().build(); + Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_createinstance_locationnamestringinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstanceStringStringInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstanceStringStringInstance.java new file mode 100644 index 00000000..bb18df0c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/createinstance/SyncCreateInstanceStringStringInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_createinstance_stringstringinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String instanceId = "instanceId902024336"; + Instance instance = Instance.newBuilder().build(); + Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_createinstance_stringstringinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/AsyncDeleteInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/AsyncDeleteInstance.java new file mode 100644 index 00000000..d021fb93 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/AsyncDeleteInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_deleteinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.DeleteInstanceRequest; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudRedisClient.deleteInstanceCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_deleteinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/AsyncDeleteInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/AsyncDeleteInstanceLRO.java new file mode 100644 index 00000000..d16e1e40 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_deleteinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.DeleteInstanceRequest; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + OperationFuture future = + cloudRedisClient.deleteInstanceOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_deleteinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/SyncDeleteInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/SyncDeleteInstance.java new file mode 100644 index 00000000..8adc4fd3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_deleteinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.DeleteInstanceRequest; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + cloudRedisClient.deleteInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_deleteinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/SyncDeleteInstanceInstancename.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/SyncDeleteInstanceInstancename.java new file mode 100644 index 00000000..1c83619c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_deleteinstance_instancename_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + cloudRedisClient.deleteInstanceAsync(name).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_deleteinstance_instancename_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/SyncDeleteInstanceString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/deleteinstance/SyncDeleteInstanceString.java new file mode 100644 index 00000000..b8820bd8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_deleteinstance_string_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + cloudRedisClient.deleteInstanceAsync(name).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_deleteinstance_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/AsyncExportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/AsyncExportInstance.java new file mode 100644 index 00000000..4e4aa584 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/AsyncExportInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_exportinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.OutputConfig; +import com.google.longrunning.Operation; + +public class AsyncExportInstance { + + public static void main(String[] args) throws Exception { + asyncExportInstance(); + } + + public static void asyncExportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder() + .setName("name3373707") + .setOutputConfig(OutputConfig.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.exportInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_exportinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/AsyncExportInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/AsyncExportInstanceLRO.java new file mode 100644 index 00000000..fde369e6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/AsyncExportInstanceLRO.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_exportinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.OperationMetadata; +import com.google.cloud.redis.v1.OutputConfig; + +public class AsyncExportInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncExportInstanceLRO(); + } + + public static void asyncExportInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder() + .setName("name3373707") + .setOutputConfig(OutputConfig.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.exportInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_exportinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/SyncExportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/SyncExportInstance.java new file mode 100644 index 00000000..093f0ee4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/SyncExportInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_exportinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.OutputConfig; + +public class SyncExportInstance { + + public static void main(String[] args) throws Exception { + syncExportInstance(); + } + + public static void syncExportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder() + .setName("name3373707") + .setOutputConfig(OutputConfig.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.exportInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_exportinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/SyncExportInstanceStringOutputconfig.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/SyncExportInstanceStringOutputconfig.java new file mode 100644 index 00000000..00726e94 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/exportinstance/SyncExportInstanceStringOutputconfig.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_exportinstance_stringoutputconfig_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.OutputConfig; + +public class SyncExportInstanceStringOutputconfig { + + public static void main(String[] args) throws Exception { + syncExportInstanceStringOutputconfig(); + } + + public static void syncExportInstanceStringOutputconfig() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = "name3373707"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + Instance response = cloudRedisClient.exportInstanceAsync(name, outputConfig).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_exportinstance_stringoutputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/AsyncFailoverInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/AsyncFailoverInstance.java new file mode 100644 index 00000000..80772397 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/AsyncFailoverInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_failoverinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.InstanceName; +import com.google.longrunning.Operation; + +public class AsyncFailoverInstance { + + public static void main(String[] args) throws Exception { + asyncFailoverInstance(); + } + + public static void asyncFailoverInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudRedisClient.failoverInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_failoverinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/AsyncFailoverInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/AsyncFailoverInstanceLRO.java new file mode 100644 index 00000000..50290205 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/AsyncFailoverInstanceLRO.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_failoverinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.OperationMetadata; + +public class AsyncFailoverInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncFailoverInstanceLRO(); + } + + public static void asyncFailoverInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + OperationFuture future = + cloudRedisClient.failoverInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_failoverinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstance.java new file mode 100644 index 00000000..f919107b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_failoverinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncFailoverInstance { + + public static void main(String[] args) throws Exception { + syncFailoverInstance(); + } + + public static void syncFailoverInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + Instance response = cloudRedisClient.failoverInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_failoverinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode.java new file mode 100644 index 00000000..8823059b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode.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.redis.v1.samples; + +// [START +// redis_v1_generated_cloudredisclient_failoverinstance_instancenamefailoverinstancerequestdataprotectionmode_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode { + + public static void main(String[] args) throws Exception { + syncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode(); + } + + public static void syncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + Instance response = cloudRedisClient.failoverInstanceAsync(name, dataProtectionMode).get(); + } + } +} +// [END +// redis_v1_generated_cloudredisclient_failoverinstance_instancenamefailoverinstancerequestdataprotectionmode_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode.java new file mode 100644 index 00000000..359a6d8e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/failoverinstance/SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode.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.redis.v1.samples; + +// [START +// redis_v1_generated_cloudredisclient_failoverinstance_stringfailoverinstancerequestdataprotectionmode_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode { + + public static void main(String[] args) throws Exception { + syncFailoverInstanceStringFailoverinstancerequestdataprotectionmode(); + } + + public static void syncFailoverInstanceStringFailoverinstancerequestdataprotectionmode() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + Instance response = cloudRedisClient.failoverInstanceAsync(name, dataProtectionMode).get(); + } + } +} +// [END +// redis_v1_generated_cloudredisclient_failoverinstance_stringfailoverinstancerequestdataprotectionmode_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/AsyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/AsyncGetInstance.java new file mode 100644 index 00000000..f2a07327 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.GetInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudRedisClient.getInstanceCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/SyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/SyncGetInstance.java new file mode 100644 index 00000000..3bdcb704 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.GetInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + Instance response = cloudRedisClient.getInstance(request); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/SyncGetInstanceInstancename.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/SyncGetInstanceInstancename.java new file mode 100644 index 00000000..3bb4b5eb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstance_instancename_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + Instance response = cloudRedisClient.getInstance(name); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstance_instancename_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/SyncGetInstanceString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstance/SyncGetInstanceString.java new file mode 100644 index 00000000..4e8ad48b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstance_string_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + Instance response = cloudRedisClient.getInstance(name); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstance_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/AsyncGetInstanceAuthString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/AsyncGetInstanceAuthString.java new file mode 100644 index 00000000..dbb2ba99 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/AsyncGetInstanceAuthString.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstanceauthstring_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.GetInstanceAuthStringRequest; +import com.google.cloud.redis.v1.InstanceAuthString; +import com.google.cloud.redis.v1.InstanceName; + +public class AsyncGetInstanceAuthString { + + public static void main(String[] args) throws Exception { + asyncGetInstanceAuthString(); + } + + public static void asyncGetInstanceAuthString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceAuthStringRequest request = + GetInstanceAuthStringRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = + cloudRedisClient.getInstanceAuthStringCallable().futureCall(request); + // Do something. + InstanceAuthString response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstanceauthstring_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthString.java new file mode 100644 index 00000000..68e7c5fd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthString.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstanceauthstring_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.GetInstanceAuthStringRequest; +import com.google.cloud.redis.v1.InstanceAuthString; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncGetInstanceAuthString { + + public static void main(String[] args) throws Exception { + syncGetInstanceAuthString(); + } + + public static void syncGetInstanceAuthString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceAuthStringRequest request = + GetInstanceAuthStringRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + InstanceAuthString response = cloudRedisClient.getInstanceAuthString(request); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstanceauthstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringInstancename.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringInstancename.java new file mode 100644 index 00000000..74af0d12 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringInstancename.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstanceauthstring_instancename_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.InstanceAuthString; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncGetInstanceAuthStringInstancename { + + public static void main(String[] args) throws Exception { + syncGetInstanceAuthStringInstancename(); + } + + public static void syncGetInstanceAuthStringInstancename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + InstanceAuthString response = cloudRedisClient.getInstanceAuthString(name); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstanceauthstring_instancename_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringString.java new file mode 100644 index 00000000..f318832e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringString.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_getinstanceauthstring_string_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.InstanceAuthString; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncGetInstanceAuthStringString { + + public static void main(String[] args) throws Exception { + syncGetInstanceAuthStringString(); + } + + public static void syncGetInstanceAuthStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + InstanceAuthString response = cloudRedisClient.getInstanceAuthString(name); + } + } +} +// [END redis_v1_generated_cloudredisclient_getinstanceauthstring_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/AsyncImportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/AsyncImportInstance.java new file mode 100644 index 00000000..3012e27a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/AsyncImportInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_importinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.InputConfig; +import com.google.longrunning.Operation; + +public class AsyncImportInstance { + + public static void main(String[] args) throws Exception { + asyncImportInstance(); + } + + public static void asyncImportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder() + .setName("name3373707") + .setInputConfig(InputConfig.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.importInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_importinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/AsyncImportInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/AsyncImportInstanceLRO.java new file mode 100644 index 00000000..9c29bd06 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/AsyncImportInstanceLRO.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_importinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.InputConfig; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.OperationMetadata; + +public class AsyncImportInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncImportInstanceLRO(); + } + + public static void asyncImportInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder() + .setName("name3373707") + .setInputConfig(InputConfig.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.importInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_importinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/SyncImportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/SyncImportInstance.java new file mode 100644 index 00000000..c79f9b38 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/SyncImportInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_importinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.InputConfig; +import com.google.cloud.redis.v1.Instance; + +public class SyncImportInstance { + + public static void main(String[] args) throws Exception { + syncImportInstance(); + } + + public static void syncImportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder() + .setName("name3373707") + .setInputConfig(InputConfig.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.importInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_importinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/SyncImportInstanceStringInputconfig.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/SyncImportInstanceStringInputconfig.java new file mode 100644 index 00000000..19273c72 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/importinstance/SyncImportInstanceStringInputconfig.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_importinstance_stringinputconfig_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.InputConfig; +import com.google.cloud.redis.v1.Instance; + +public class SyncImportInstanceStringInputconfig { + + public static void main(String[] args) throws Exception { + syncImportInstanceStringInputconfig(); + } + + public static void syncImportInstanceStringInputconfig() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = "name3373707"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + Instance response = cloudRedisClient.importInstanceAsync(name, inputConfig).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_importinstance_stringinputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/AsyncListInstances.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/AsyncListInstances.java new file mode 100644 index 00000000..8dbc9fed --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/AsyncListInstances.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_listinstances_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + cloudRedisClient.listInstancesPagedCallable().futureCall(request); + // Do something. + for (Instance element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1_generated_cloudredisclient_listinstances_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/AsyncListInstancesPaged.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/AsyncListInstancesPaged.java new file mode 100644 index 00000000..d33b6c49 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/AsyncListInstancesPaged.java @@ -0,0 +1,58 @@ +/* + * 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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_listinstances_paged_async] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.v1.ListInstancesResponse; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListInstancesResponse response = cloudRedisClient.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 redis_v1_generated_cloudredisclient_listinstances_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstances.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstances.java new file mode 100644 index 00000000..eee98ebe --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstances.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_listinstances_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Instance element : cloudRedisClient.listInstances(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1_generated_cloudredisclient_listinstances_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstancesLocationname.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstancesLocationname.java new file mode 100644 index 00000000..2c8a14e4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_listinstances_locationname_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1_generated_cloudredisclient_listinstances_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstancesString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/listinstances/SyncListInstancesString.java new file mode 100644 index 00000000..880787c9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_listinstances_string_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1_generated_cloudredisclient_listinstances_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenance.java new file mode 100644 index 00000000..552c9a90 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_reschedulemaintenance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.RescheduleMaintenanceRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Timestamp; + +public class AsyncRescheduleMaintenance { + + public static void main(String[] args) throws Exception { + asyncRescheduleMaintenance(); + } + + public static void asyncRescheduleMaintenance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + RescheduleMaintenanceRequest request = + RescheduleMaintenanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .build(); + ApiFuture future = + cloudRedisClient.rescheduleMaintenanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_reschedulemaintenance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenanceLRO.java new file mode 100644 index 00000000..0a969adb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenanceLRO.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_reschedulemaintenance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.OperationMetadata; +import com.google.cloud.redis.v1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public class AsyncRescheduleMaintenanceLRO { + + public static void main(String[] args) throws Exception { + asyncRescheduleMaintenanceLRO(); + } + + public static void asyncRescheduleMaintenanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + RescheduleMaintenanceRequest request = + RescheduleMaintenanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.rescheduleMaintenanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_reschedulemaintenance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenance.java new file mode 100644 index 00000000..b89b517a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_reschedulemaintenance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public class SyncRescheduleMaintenance { + + public static void main(String[] args) throws Exception { + syncRescheduleMaintenance(); + } + + public static void syncRescheduleMaintenance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + RescheduleMaintenanceRequest request = + RescheduleMaintenanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.rescheduleMaintenanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_reschedulemaintenance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp.java new file mode 100644 index 00000000..576d7262 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp.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.redis.v1.samples; + +// [START +// redis_v1_generated_cloudredisclient_reschedulemaintenance_instancenamereschedulemaintenancerequestrescheduletypetimestamp_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public +class SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp { + + public static void main(String[] args) throws Exception { + syncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp(); + } + + public static void + syncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Instance response = + cloudRedisClient.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + } + } +} +// [END +// redis_v1_generated_cloudredisclient_reschedulemaintenance_instancenamereschedulemaintenancerequestrescheduletypetimestamp_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp.java new file mode 100644 index 00000000..1f4e63b2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp.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.redis.v1.samples; + +// [START +// redis_v1_generated_cloudredisclient_reschedulemaintenance_stringreschedulemaintenancerequestrescheduletypetimestamp_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public class SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp { + + public static void main(String[] args) throws Exception { + syncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp(); + } + + public static void + syncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Instance response = + cloudRedisClient.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + } + } +} +// [END +// redis_v1_generated_cloudredisclient_reschedulemaintenance_stringreschedulemaintenancerequestrescheduletypetimestamp_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/AsyncUpdateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/AsyncUpdateInstance.java new file mode 100644 index 00000000..0d73b70e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/AsyncUpdateInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_updateinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.updateInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_updateinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/AsyncUpdateInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/AsyncUpdateInstanceLRO.java new file mode 100644 index 00000000..ea7bf5f0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_updateinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.OperationMetadata; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.updateInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_updateinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/SyncUpdateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/SyncUpdateInstance.java new file mode 100644 index 00000000..7460eb1e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_updateinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.updateInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_updateinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java new file mode 100644 index 00000000..e78ddd19 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_updateinstance_fieldmaskinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance instance = Instance.newBuilder().build(); + Instance response = cloudRedisClient.updateInstanceAsync(updateMask, instance).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_updateinstance_fieldmaskinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/AsyncUpgradeInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/AsyncUpgradeInstance.java new file mode 100644 index 00000000..27287237 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/AsyncUpgradeInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_upgradeinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.UpgradeInstanceRequest; +import com.google.longrunning.Operation; + +public class AsyncUpgradeInstance { + + public static void main(String[] args) throws Exception { + asyncUpgradeInstance(); + } + + public static void asyncUpgradeInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setRedisVersion("redisVersion-1972584739") + .build(); + ApiFuture future = cloudRedisClient.upgradeInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_upgradeinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/AsyncUpgradeInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/AsyncUpgradeInstanceLRO.java new file mode 100644 index 00000000..cc95739f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/AsyncUpgradeInstanceLRO.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_upgradeinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.OperationMetadata; +import com.google.cloud.redis.v1.UpgradeInstanceRequest; + +public class AsyncUpgradeInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncUpgradeInstanceLRO(); + } + + public static void asyncUpgradeInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setRedisVersion("redisVersion-1972584739") + .build(); + OperationFuture future = + cloudRedisClient.upgradeInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_upgradeinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstance.java new file mode 100644 index 00000000..e3daecf4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstance.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_upgradeinstance_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; +import com.google.cloud.redis.v1.UpgradeInstanceRequest; + +public class SyncUpgradeInstance { + + public static void main(String[] args) throws Exception { + syncUpgradeInstance(); + } + + public static void syncUpgradeInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setRedisVersion("redisVersion-1972584739") + .build(); + Instance response = cloudRedisClient.upgradeInstanceAsync(request).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_upgradeinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceInstancenameString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceInstancenameString.java new file mode 100644 index 00000000..aef01d2b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceInstancenameString.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_upgradeinstance_instancenamestring_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncUpgradeInstanceInstancenameString { + + public static void main(String[] args) throws Exception { + syncUpgradeInstanceInstancenameString(); + } + + public static void syncUpgradeInstanceInstancenameString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redisVersion-1972584739"; + Instance response = cloudRedisClient.upgradeInstanceAsync(name, redisVersion).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_upgradeinstance_instancenamestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceStringString.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceStringString.java new file mode 100644 index 00000000..ccb937ac --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceStringString.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.redis.v1.samples; + +// [START redis_v1_generated_cloudredisclient_upgradeinstance_stringstring_sync] +import com.google.cloud.redis.v1.CloudRedisClient; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.InstanceName; + +public class SyncUpgradeInstanceStringString { + + public static void main(String[] args) throws Exception { + syncUpgradeInstanceStringString(); + } + + public static void syncUpgradeInstanceStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + String redisVersion = "redisVersion-1972584739"; + Instance response = cloudRedisClient.upgradeInstanceAsync(name, redisVersion).get(); + } + } +} +// [END redis_v1_generated_cloudredisclient_upgradeinstance_stringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/cloudredissettings/getinstance/SyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredissettings/getinstance/SyncGetInstance.java new file mode 100644 index 00000000..069a43ad --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/cloudredissettings/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.redis.v1.samples; + +// [START redis_v1_generated_cloudredissettings_getinstance_sync] +import com.google.cloud.redis.v1.CloudRedisSettings; +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. + CloudRedisSettings.Builder cloudRedisSettingsBuilder = CloudRedisSettings.newBuilder(); + cloudRedisSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudRedisSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudRedisSettings cloudRedisSettings = cloudRedisSettingsBuilder.build(); + } +} +// [END redis_v1_generated_cloudredissettings_getinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1/stub/cloudredisstubsettings/getinstance/SyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1/stub/cloudredisstubsettings/getinstance/SyncGetInstance.java new file mode 100644 index 00000000..a5129fc0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1/stub/cloudredisstubsettings/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.redis.v1.stub.samples; + +// [START redis_v1_generated_cloudredisstubsettings_getinstance_sync] +import com.google.cloud.redis.v1.stub.CloudRedisStubSettings; +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. + CloudRedisStubSettings.Builder cloudRedisSettingsBuilder = CloudRedisStubSettings.newBuilder(); + cloudRedisSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudRedisSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudRedisStubSettings cloudRedisSettings = cloudRedisSettingsBuilder.build(); + } +} +// [END redis_v1_generated_cloudredisstubsettings_getinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..cfd9fc80 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.CloudRedisSettings; +import com.google.cloud.redis.v1beta1.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. + CloudRedisSettings cloudRedisSettings = + CloudRedisSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); + } +} +// [END redis_v1beta1_generated_cloudredisclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..61ca0b73 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_create_setcredentialsprovider1_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.CloudRedisSettings; + +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. + CloudRedisSettings cloudRedisSettings = + CloudRedisSettings.newBuilder() + .setTransportChannelProvider( + CloudRedisSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); + } +} +// [END redis_v1beta1_generated_cloudredisclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..b6234a30 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_create_setendpoint_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.CloudRedisSettings; +import com.google.cloud.redis.v1beta1.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. + CloudRedisSettings cloudRedisSettings = + CloudRedisSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudRedisClient cloudRedisClient = CloudRedisClient.create(cloudRedisSettings); + } +} +// [END redis_v1beta1_generated_cloudredisclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/AsyncCreateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/AsyncCreateInstance.java new file mode 100644 index 00000000..59c4f0fd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/AsyncCreateInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_createinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.CreateInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.createInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_createinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/AsyncCreateInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/AsyncCreateInstanceLRO.java new file mode 100644 index 00000000..8a8154c4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_createinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.CreateInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.LocationName; +import com.google.protobuf.Any; + +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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.createInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_createinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstance.java new file mode 100644 index 00000000..fedb0e4d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_createinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.CreateInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setInstanceId("instanceId902024336") + .setInstance(Instance.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.createInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_createinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstanceLocationnameStringInstance.java new file mode 100644 index 00000000..55af3c16 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstanceLocationnameStringInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_createinstance_locationnamestringinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String instanceId = "instanceId902024336"; + Instance instance = Instance.newBuilder().build(); + Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_createinstance_locationnamestringinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstanceStringStringInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstanceStringStringInstance.java new file mode 100644 index 00000000..1e777a70 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/createinstance/SyncCreateInstanceStringStringInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_createinstance_stringstringinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String instanceId = "instanceId902024336"; + Instance instance = Instance.newBuilder().build(); + Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_createinstance_stringstringinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/AsyncDeleteInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/AsyncDeleteInstance.java new file mode 100644 index 00000000..b7fb20b6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/AsyncDeleteInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_deleteinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.DeleteInstanceRequest; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudRedisClient.deleteInstanceCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_deleteinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/AsyncDeleteInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/AsyncDeleteInstanceLRO.java new file mode 100644 index 00000000..ddb78118 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_deleteinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.DeleteInstanceRequest; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.protobuf.Any; +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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + OperationFuture future = + cloudRedisClient.deleteInstanceOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_deleteinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/SyncDeleteInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/SyncDeleteInstance.java new file mode 100644 index 00000000..0aa52407 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_deleteinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.DeleteInstanceRequest; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + cloudRedisClient.deleteInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_deleteinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/SyncDeleteInstanceInstancename.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/SyncDeleteInstanceInstancename.java new file mode 100644 index 00000000..fd859e1e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_deleteinstance_instancename_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + cloudRedisClient.deleteInstanceAsync(name).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_deleteinstance_instancename_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/SyncDeleteInstanceString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/deleteinstance/SyncDeleteInstanceString.java new file mode 100644 index 00000000..ce8e43b2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_deleteinstance_string_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + cloudRedisClient.deleteInstanceAsync(name).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_deleteinstance_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/AsyncExportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/AsyncExportInstance.java new file mode 100644 index 00000000..ad57c58e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/AsyncExportInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_exportinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.ExportInstanceRequest; +import com.google.cloud.redis.v1beta1.OutputConfig; +import com.google.longrunning.Operation; + +public class AsyncExportInstance { + + public static void main(String[] args) throws Exception { + asyncExportInstance(); + } + + public static void asyncExportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder() + .setName("name3373707") + .setOutputConfig(OutputConfig.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.exportInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_exportinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/AsyncExportInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/AsyncExportInstanceLRO.java new file mode 100644 index 00000000..8534bf3e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/AsyncExportInstanceLRO.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_exportinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.ExportInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.OutputConfig; +import com.google.protobuf.Any; + +public class AsyncExportInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncExportInstanceLRO(); + } + + public static void asyncExportInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder() + .setName("name3373707") + .setOutputConfig(OutputConfig.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.exportInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_exportinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/SyncExportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/SyncExportInstance.java new file mode 100644 index 00000000..3f2cc0e5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/SyncExportInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_exportinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.ExportInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.OutputConfig; + +public class SyncExportInstance { + + public static void main(String[] args) throws Exception { + syncExportInstance(); + } + + public static void syncExportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder() + .setName("name3373707") + .setOutputConfig(OutputConfig.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.exportInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_exportinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/SyncExportInstanceStringOutputconfig.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/SyncExportInstanceStringOutputconfig.java new file mode 100644 index 00000000..d2b36f90 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/exportinstance/SyncExportInstanceStringOutputconfig.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_exportinstance_stringoutputconfig_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.OutputConfig; + +public class SyncExportInstanceStringOutputconfig { + + public static void main(String[] args) throws Exception { + syncExportInstanceStringOutputconfig(); + } + + public static void syncExportInstanceStringOutputconfig() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = "name3373707"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + Instance response = cloudRedisClient.exportInstanceAsync(name, outputConfig).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_exportinstance_stringoutputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/AsyncFailoverInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/AsyncFailoverInstance.java new file mode 100644 index 00000000..908d016b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/AsyncFailoverInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_failoverinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.FailoverInstanceRequest; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.longrunning.Operation; + +public class AsyncFailoverInstance { + + public static void main(String[] args) throws Exception { + asyncFailoverInstance(); + } + + public static void asyncFailoverInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudRedisClient.failoverInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_failoverinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/AsyncFailoverInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/AsyncFailoverInstanceLRO.java new file mode 100644 index 00000000..9424f430 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/AsyncFailoverInstanceLRO.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_failoverinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.FailoverInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.protobuf.Any; + +public class AsyncFailoverInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncFailoverInstanceLRO(); + } + + public static void asyncFailoverInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + OperationFuture future = + cloudRedisClient.failoverInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_failoverinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstance.java new file mode 100644 index 00000000..845c470c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_failoverinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.FailoverInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncFailoverInstance { + + public static void main(String[] args) throws Exception { + syncFailoverInstance(); + } + + public static void syncFailoverInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + Instance response = cloudRedisClient.failoverInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_failoverinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode.java new file mode 100644 index 00000000..8f6a549c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode.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.redis.v1beta1.samples; + +// [START +// redis_v1beta1_generated_cloudredisclient_failoverinstance_instancenamefailoverinstancerequestdataprotectionmode_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.FailoverInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode { + + public static void main(String[] args) throws Exception { + syncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode(); + } + + public static void syncFailoverInstanceInstancenameFailoverinstancerequestdataprotectionmode() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + Instance response = cloudRedisClient.failoverInstanceAsync(name, dataProtectionMode).get(); + } + } +} +// [END +// redis_v1beta1_generated_cloudredisclient_failoverinstance_instancenamefailoverinstancerequestdataprotectionmode_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode.java new file mode 100644 index 00000000..d5c14d25 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/failoverinstance/SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode.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.redis.v1beta1.samples; + +// [START +// redis_v1beta1_generated_cloudredisclient_failoverinstance_stringfailoverinstancerequestdataprotectionmode_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.FailoverInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncFailoverInstanceStringFailoverinstancerequestdataprotectionmode { + + public static void main(String[] args) throws Exception { + syncFailoverInstanceStringFailoverinstancerequestdataprotectionmode(); + } + + public static void syncFailoverInstanceStringFailoverinstancerequestdataprotectionmode() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + Instance response = cloudRedisClient.failoverInstanceAsync(name, dataProtectionMode).get(); + } + } +} +// [END +// redis_v1beta1_generated_cloudredisclient_failoverinstance_stringfailoverinstancerequestdataprotectionmode_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/AsyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/AsyncGetInstance.java new file mode 100644 index 00000000..b2147500 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.GetInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = cloudRedisClient.getInstanceCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/SyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/SyncGetInstance.java new file mode 100644 index 00000000..d68e0527 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.GetInstanceRequest; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + Instance response = cloudRedisClient.getInstance(request); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/SyncGetInstanceInstancename.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/SyncGetInstanceInstancename.java new file mode 100644 index 00000000..97b59905 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstance_instancename_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + Instance response = cloudRedisClient.getInstance(name); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstance_instancename_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/SyncGetInstanceString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstance/SyncGetInstanceString.java new file mode 100644 index 00000000..92ff58b9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstance_string_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + Instance response = cloudRedisClient.getInstance(name); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstance_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/AsyncGetInstanceAuthString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/AsyncGetInstanceAuthString.java new file mode 100644 index 00000000..1adc8483 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/AsyncGetInstanceAuthString.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.GetInstanceAuthStringRequest; +import com.google.cloud.redis.v1beta1.InstanceAuthString; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class AsyncGetInstanceAuthString { + + public static void main(String[] args) throws Exception { + asyncGetInstanceAuthString(); + } + + public static void asyncGetInstanceAuthString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceAuthStringRequest request = + GetInstanceAuthStringRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + ApiFuture future = + cloudRedisClient.getInstanceAuthStringCallable().futureCall(request); + // Do something. + InstanceAuthString response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthString.java new file mode 100644 index 00000000..44666a4c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthString.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.GetInstanceAuthStringRequest; +import com.google.cloud.redis.v1beta1.InstanceAuthString; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncGetInstanceAuthString { + + public static void main(String[] args) throws Exception { + syncGetInstanceAuthString(); + } + + public static void syncGetInstanceAuthString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + GetInstanceAuthStringRequest request = + GetInstanceAuthStringRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .build(); + InstanceAuthString response = cloudRedisClient.getInstanceAuthString(request); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringInstancename.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringInstancename.java new file mode 100644 index 00000000..9aab155d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringInstancename.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_instancename_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.InstanceAuthString; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncGetInstanceAuthStringInstancename { + + public static void main(String[] args) throws Exception { + syncGetInstanceAuthStringInstancename(); + } + + public static void syncGetInstanceAuthStringInstancename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + InstanceAuthString response = cloudRedisClient.getInstanceAuthString(name); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_instancename_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringString.java new file mode 100644 index 00000000..b9ffffca --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/getinstanceauthstring/SyncGetInstanceAuthStringString.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_string_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.InstanceAuthString; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncGetInstanceAuthStringString { + + public static void main(String[] args) throws Exception { + syncGetInstanceAuthStringString(); + } + + public static void syncGetInstanceAuthStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + InstanceAuthString response = cloudRedisClient.getInstanceAuthString(name); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_getinstanceauthstring_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/AsyncImportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/AsyncImportInstance.java new file mode 100644 index 00000000..cdf2776d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/AsyncImportInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_importinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.ImportInstanceRequest; +import com.google.cloud.redis.v1beta1.InputConfig; +import com.google.longrunning.Operation; + +public class AsyncImportInstance { + + public static void main(String[] args) throws Exception { + asyncImportInstance(); + } + + public static void asyncImportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder() + .setName("name3373707") + .setInputConfig(InputConfig.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.importInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_importinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/AsyncImportInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/AsyncImportInstanceLRO.java new file mode 100644 index 00000000..74e69879 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/AsyncImportInstanceLRO.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_importinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.ImportInstanceRequest; +import com.google.cloud.redis.v1beta1.InputConfig; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.protobuf.Any; + +public class AsyncImportInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncImportInstanceLRO(); + } + + public static void asyncImportInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder() + .setName("name3373707") + .setInputConfig(InputConfig.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.importInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_importinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/SyncImportInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/SyncImportInstance.java new file mode 100644 index 00000000..4482b680 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/SyncImportInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_importinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.ImportInstanceRequest; +import com.google.cloud.redis.v1beta1.InputConfig; +import com.google.cloud.redis.v1beta1.Instance; + +public class SyncImportInstance { + + public static void main(String[] args) throws Exception { + syncImportInstance(); + } + + public static void syncImportInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder() + .setName("name3373707") + .setInputConfig(InputConfig.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.importInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_importinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/SyncImportInstanceStringInputconfig.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/SyncImportInstanceStringInputconfig.java new file mode 100644 index 00000000..bc0092ca --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/importinstance/SyncImportInstanceStringInputconfig.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_importinstance_stringinputconfig_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.InputConfig; +import com.google.cloud.redis.v1beta1.Instance; + +public class SyncImportInstanceStringInputconfig { + + public static void main(String[] args) throws Exception { + syncImportInstanceStringInputconfig(); + } + + public static void syncImportInstanceStringInputconfig() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = "name3373707"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + Instance response = cloudRedisClient.importInstanceAsync(name, inputConfig).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_importinstance_stringinputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/AsyncListInstances.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/AsyncListInstances.java new file mode 100644 index 00000000..f4d15eb7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/AsyncListInstances.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_listinstances_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.ListInstancesRequest; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + cloudRedisClient.listInstancesPagedCallable().futureCall(request); + // Do something. + for (Instance element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_listinstances_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/AsyncListInstancesPaged.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/AsyncListInstancesPaged.java new file mode 100644 index 00000000..4fda4467 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/AsyncListInstancesPaged.java @@ -0,0 +1,58 @@ +/* + * 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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_listinstances_paged_async] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.ListInstancesRequest; +import com.google.cloud.redis.v1beta1.ListInstancesResponse; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListInstancesResponse response = cloudRedisClient.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 redis_v1beta1_generated_cloudredisclient_listinstances_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstances.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstances.java new file mode 100644 index 00000000..c76dc3b7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstances.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_listinstances_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.ListInstancesRequest; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Instance element : cloudRedisClient.listInstances(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_listinstances_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstancesLocationname.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstancesLocationname.java new file mode 100644 index 00000000..3b16874b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_listinstances_locationname_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_listinstances_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstancesString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/listinstances/SyncListInstancesString.java new file mode 100644 index 00000000..fd896631 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_listinstances_string_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_listinstances_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenance.java new file mode 100644 index 00000000..6da21f92 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Timestamp; + +public class AsyncRescheduleMaintenance { + + public static void main(String[] args) throws Exception { + asyncRescheduleMaintenance(); + } + + public static void asyncRescheduleMaintenance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + RescheduleMaintenanceRequest request = + RescheduleMaintenanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .build(); + ApiFuture future = + cloudRedisClient.rescheduleMaintenanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenanceLRO.java new file mode 100644 index 00000000..2e4486d4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/AsyncRescheduleMaintenanceLRO.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; +import com.google.protobuf.Any; +import com.google.protobuf.Timestamp; + +public class AsyncRescheduleMaintenanceLRO { + + public static void main(String[] args) throws Exception { + asyncRescheduleMaintenanceLRO(); + } + + public static void asyncRescheduleMaintenanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + RescheduleMaintenanceRequest request = + RescheduleMaintenanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.rescheduleMaintenanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenance.java new file mode 100644 index 00000000..e5aa6c34 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public class SyncRescheduleMaintenance { + + public static void main(String[] args) throws Exception { + syncRescheduleMaintenance(); + } + + public static void syncRescheduleMaintenance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + RescheduleMaintenanceRequest request = + RescheduleMaintenanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.rescheduleMaintenanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp.java new file mode 100644 index 00000000..18b55fd0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp.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.redis.v1beta1.samples; + +// [START +// redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_instancenamereschedulemaintenancerequestrescheduletypetimestamp_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public +class SyncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp { + + public static void main(String[] args) throws Exception { + syncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp(); + } + + public static void + syncRescheduleMaintenanceInstancenameReschedulemaintenancerequestrescheduletypeTimestamp() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Instance response = + cloudRedisClient.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + } + } +} +// [END +// redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_instancenamereschedulemaintenancerequestrescheduletypetimestamp_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp.java new file mode 100644 index 00000000..a244632e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/reschedulemaintenance/SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp.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.redis.v1beta1.samples; + +// [START +// redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_stringreschedulemaintenancerequestrescheduletypetimestamp_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest; +import com.google.protobuf.Timestamp; + +public class SyncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp { + + public static void main(String[] args) throws Exception { + syncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp(); + } + + public static void + syncRescheduleMaintenanceStringReschedulemaintenancerequestrescheduletypeTimestamp() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + RescheduleMaintenanceRequest.RescheduleType rescheduleType = + RescheduleMaintenanceRequest.RescheduleType.forNumber(0); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Instance response = + cloudRedisClient.rescheduleMaintenanceAsync(name, rescheduleType, scheduleTime).get(); + } + } +} +// [END +// redis_v1beta1_generated_cloudredisclient_reschedulemaintenance_stringreschedulemaintenancerequestrescheduletypetimestamp_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/AsyncUpdateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/AsyncUpdateInstance.java new file mode 100644 index 00000000..a8250d4d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/AsyncUpdateInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_updateinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + ApiFuture future = cloudRedisClient.updateInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_updateinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/AsyncUpdateInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/AsyncUpdateInstanceLRO.java new file mode 100644 index 00000000..b8702e6a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_updateinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.UpdateInstanceRequest; +import com.google.protobuf.Any; +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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + OperationFuture future = + cloudRedisClient.updateInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_updateinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/SyncUpdateInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/SyncUpdateInstance.java new file mode 100644 index 00000000..3e2e71b8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_updateinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder() + .setUpdateMask(FieldMask.newBuilder().build()) + .setInstance(Instance.newBuilder().build()) + .build(); + Instance response = cloudRedisClient.updateInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_updateinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/updateinstance/SyncUpdateInstanceFieldmaskInstance.java new file mode 100644 index 00000000..2580dcde --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_updateinstance_fieldmaskinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.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 (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance instance = Instance.newBuilder().build(); + Instance response = cloudRedisClient.updateInstanceAsync(updateMask, instance).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_updateinstance_fieldmaskinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/AsyncUpgradeInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/AsyncUpgradeInstance.java new file mode 100644 index 00000000..e94e34c9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/AsyncUpgradeInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_upgradeinstance_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.UpgradeInstanceRequest; +import com.google.longrunning.Operation; + +public class AsyncUpgradeInstance { + + public static void main(String[] args) throws Exception { + asyncUpgradeInstance(); + } + + public static void asyncUpgradeInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setRedisVersion("redisVersion-1972584739") + .build(); + ApiFuture future = cloudRedisClient.upgradeInstanceCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_upgradeinstance_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/AsyncUpgradeInstanceLRO.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/AsyncUpgradeInstanceLRO.java new file mode 100644 index 00000000..daae237f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/AsyncUpgradeInstanceLRO.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_upgradeinstance_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.UpgradeInstanceRequest; +import com.google.protobuf.Any; + +public class AsyncUpgradeInstanceLRO { + + public static void main(String[] args) throws Exception { + asyncUpgradeInstanceLRO(); + } + + public static void asyncUpgradeInstanceLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setRedisVersion("redisVersion-1972584739") + .build(); + OperationFuture future = + cloudRedisClient.upgradeInstanceOperationCallable().futureCall(request); + // Do something. + Instance response = future.get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_upgradeinstance_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstance.java new file mode 100644 index 00000000..2860730b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstance.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_upgradeinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; +import com.google.cloud.redis.v1beta1.UpgradeInstanceRequest; + +public class SyncUpgradeInstance { + + public static void main(String[] args) throws Exception { + syncUpgradeInstance(); + } + + public static void syncUpgradeInstance() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setRedisVersion("redisVersion-1972584739") + .build(); + Instance response = cloudRedisClient.upgradeInstanceAsync(request).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_upgradeinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceInstancenameString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceInstancenameString.java new file mode 100644 index 00000000..20bc73d1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceInstancenameString.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_upgradeinstance_instancenamestring_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncUpgradeInstanceInstancenameString { + + public static void main(String[] args) throws Exception { + syncUpgradeInstanceInstancenameString(); + } + + public static void syncUpgradeInstanceInstancenameString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redisVersion-1972584739"; + Instance response = cloudRedisClient.upgradeInstanceAsync(name, redisVersion).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_upgradeinstance_instancenamestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceStringString.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceStringString.java new file mode 100644 index 00000000..d5e491b2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredisclient/upgradeinstance/SyncUpgradeInstanceStringString.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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredisclient_upgradeinstance_stringstring_sync] +import com.google.cloud.redis.v1beta1.CloudRedisClient; +import com.google.cloud.redis.v1beta1.Instance; +import com.google.cloud.redis.v1beta1.InstanceName; + +public class SyncUpgradeInstanceStringString { + + public static void main(String[] args) throws Exception { + syncUpgradeInstanceStringString(); + } + + public static void syncUpgradeInstanceStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { + String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString(); + String redisVersion = "redisVersion-1972584739"; + Instance response = cloudRedisClient.upgradeInstanceAsync(name, redisVersion).get(); + } + } +} +// [END redis_v1beta1_generated_cloudredisclient_upgradeinstance_stringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredissettings/getinstance/SyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredissettings/getinstance/SyncGetInstance.java new file mode 100644 index 00000000..83c80354 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/cloudredissettings/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.redis.v1beta1.samples; + +// [START redis_v1beta1_generated_cloudredissettings_getinstance_sync] +import com.google.cloud.redis.v1beta1.CloudRedisSettings; +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. + CloudRedisSettings.Builder cloudRedisSettingsBuilder = CloudRedisSettings.newBuilder(); + cloudRedisSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudRedisSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudRedisSettings cloudRedisSettings = cloudRedisSettingsBuilder.build(); + } +} +// [END redis_v1beta1_generated_cloudredissettings_getinstance_sync] diff --git a/samples/snippets/generated/com/google/cloud/redis/v1beta1/stub/cloudredisstubsettings/getinstance/SyncGetInstance.java b/samples/snippets/generated/com/google/cloud/redis/v1beta1/stub/cloudredisstubsettings/getinstance/SyncGetInstance.java new file mode 100644 index 00000000..3721e359 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/redis/v1beta1/stub/cloudredisstubsettings/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.redis.v1beta1.stub.samples; + +// [START redis_v1beta1_generated_cloudredisstubsettings_getinstance_sync] +import com.google.cloud.redis.v1beta1.stub.CloudRedisStubSettings; +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. + CloudRedisStubSettings.Builder cloudRedisSettingsBuilder = CloudRedisStubSettings.newBuilder(); + cloudRedisSettingsBuilder + .getInstanceSettings() + .setRetrySettings( + cloudRedisSettingsBuilder + .getInstanceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudRedisStubSettings cloudRedisSettings = cloudRedisSettingsBuilder.build(); + } +} +// [END redis_v1beta1_generated_cloudredisstubsettings_getinstance_sync]