lib/google/cloud/redis/v1/cloud_redis_client.rb in google-cloud-redis-0.2.3 vs lib/google/cloud/redis/v1/cloud_redis_client.rb in google-cloud-redis-0.3.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright 2018 Google LLC
+# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -45,11 +45,11 @@
# * Each project has a collection of available locations, named: `/locations/*`
# * Each location has a collection of Redis instances, named: `/instances/*`
# * As such, Redis instances are resources of the form:
# `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
#
- # Note that location_id must be refering to a GCP `region`; for example:
+ # Note that location_id must be referring to a GCP `region`; for example:
# * `projects/redpepper-1290/locations/us-central1/instances/my-redis`
#
# @!attribute [r] cloud_redis_stub
# @return [Google::Cloud::Redis::V1::CloudRedis::Stub]
class CloudRedisClient
@@ -86,33 +86,22 @@
class OperationsClient < Google::Longrunning::OperationsClient
self::SERVICE_ADDRESS = CloudRedisClient::SERVICE_ADDRESS
self::GRPC_INTERCEPTORS = CloudRedisClient::GRPC_INTERCEPTORS
end
- LOCATION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
- "projects/{project}/locations/{location}"
- )
-
- private_constant :LOCATION_PATH_TEMPLATE
-
INSTANCE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
"projects/{project}/locations/{location}/instances/{instance}"
)
private_constant :INSTANCE_PATH_TEMPLATE
- # Returns a fully-qualified location resource name string.
- # @param project [String]
- # @param location [String]
- # @return [String]
- def self.location_path project, location
- LOCATION_PATH_TEMPLATE.render(
- :"project" => project,
- :"location" => location
- )
- end
+ LOCATION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
+ "projects/{project}/locations/{location}"
+ )
+ private_constant :LOCATION_PATH_TEMPLATE
+
# Returns a fully-qualified instance resource name string.
# @param project [String]
# @param location [String]
# @param instance [String]
# @return [String]
@@ -122,10 +111,21 @@
:"location" => location,
:"instance" => instance
)
end
+ # Returns a fully-qualified location resource name string.
+ # @param project [String]
+ # @param location [String]
+ # @return [String]
+ def self.location_path project, location
+ LOCATION_PATH_TEMPLATE.render(
+ :"project" => project,
+ :"location" => location
+ )
+ end
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
# Provides the means for authenticating requests made by the client. This parameter can
# be many types.
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
# authenticating requests made by this client.
@@ -237,32 +237,55 @@
)
@list_instances = Google::Gax.create_api_call(
@cloud_redis_stub.method(:list_instances),
defaults["list_instances"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@get_instance = Google::Gax.create_api_call(
@cloud_redis_stub.method(:get_instance),
defaults["get_instance"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@create_instance = Google::Gax.create_api_call(
@cloud_redis_stub.method(:create_instance),
defaults["create_instance"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@update_instance = Google::Gax.create_api_call(
@cloud_redis_stub.method(:update_instance),
defaults["update_instance"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'instance.name' => request.instance.name}
+ end
)
@delete_instance = Google::Gax.create_api_call(
@cloud_redis_stub.method(:delete_instance),
defaults["delete_instance"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
+ @failover_instance = Google::Gax.create_api_call(
+ @cloud_redis_stub.method(:failover_instance),
+ defaults["failover_instance"],
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
+ )
end
# Service calls
# Lists all Redis instances owned by a project in either the specified
@@ -594,9 +617,80 @@
req = Google::Gax::to_proto(req, Google::Cloud::Redis::V1::DeleteInstanceRequest)
operation = Google::Gax::Operation.new(
@delete_instance.call(req, options),
@operations_client,
Google::Protobuf::Empty,
+ Google::Cloud::Redis::V1::OperationMetadata,
+ call_options: options
+ )
+ operation.on_done { |operation| yield(operation) } if block_given?
+ operation
+ end
+
+ # Failover the master role to current replica node against a specific
+ # STANDARD tier redis instance.
+ #
+ # @param name [String]
+ # Required. Redis instance resource name using the form:
+ # `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
+ # where `location_id` refers to a GCP region
+ # @param data_protection_mode [Google::Cloud::Redis::V1::FailoverInstanceRequest::DataProtectionMode]
+ # Optional. Available data protection modes that the user can choose. If it's
+ # unspecified, data protection mode will be LIMITED_DATA_LOSS by default.
+ # @param options [Google::Gax::CallOptions]
+ # Overrides the default settings for this call, e.g, timeout,
+ # retries, etc.
+ # @return [Google::Gax::Operation]
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
+ # @example
+ # require "google/cloud/redis"
+ #
+ # cloud_redis_client = Google::Cloud::Redis.new(version: :v1)
+ # formatted_name = Google::Cloud::Redis::V1::CloudRedisClient.instance_path("[PROJECT]", "[LOCATION]", "[INSTANCE]")
+ #
+ # # TODO: Initialize `data_protection_mode`:
+ # data_protection_mode = :DATA_PROTECTION_MODE_UNSPECIFIED
+ #
+ # # Register a callback during the method call.
+ # operation = cloud_redis_client.failover_instance(formatted_name, data_protection_mode) do |op|
+ # raise op.results.message if op.error?
+ # op_results = op.results
+ # # Process the results.
+ #
+ # metadata = op.metadata
+ # # Process the metadata.
+ # end
+ #
+ # # Or use the return value to register a callback.
+ # operation.on_done do |op|
+ # raise op.results.message if op.error?
+ # op_results = op.results
+ # # Process the results.
+ #
+ # metadata = op.metadata
+ # # Process the metadata.
+ # end
+ #
+ # # Manually reload the operation.
+ # operation.reload!
+ #
+ # # Or block until the operation completes, triggering callbacks on
+ # # completion.
+ # operation.wait_until_done!
+
+ def failover_instance \
+ name,
+ data_protection_mode,
+ options: nil
+ req = {
+ name: name,
+ data_protection_mode: data_protection_mode
+ }.delete_if { |_, v| v.nil? }
+ req = Google::Gax::to_proto(req, Google::Cloud::Redis::V1::FailoverInstanceRequest)
+ operation = Google::Gax::Operation.new(
+ @failover_instance.call(req, options),
+ @operations_client,
+ Google::Cloud::Redis::V1::Instance,
Google::Cloud::Redis::V1::OperationMetadata,
call_options: options
)
operation.on_done { |operation| yield(operation) } if block_given?
operation