lib/google/cloud/redis/v1/cloud_redis_client.rb in google-cloud-redis-0.3.0 vs lib/google/cloud/redis/v1/cloud_redis_client.rb in google-cloud-redis-0.4.0
- old
+ new
@@ -27,10 +27,11 @@
require "google/gax/operation"
require "google/longrunning/operations_client"
require "google/cloud/redis/v1/cloud_redis_pb"
require "google/cloud/redis/v1/credentials"
+require "google/cloud/redis/version"
module Google
module Cloud
module Redis
module V1
@@ -193,11 +194,11 @@
end
if credentials.is_a?(Google::Auth::Credentials)
updater_proc = credentials.updater_proc
end
- package_version = Gem.loaded_specs['google-cloud-redis'].version.version
+ package_version = Google::Cloud::Redis::VERSION
google_api_client = "gl-ruby/#{RUBY_VERSION}"
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
google_api_client << " grpc/#{GRPC::VERSION}"
@@ -266,26 +267,42 @@
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"],
+ @import_instance = Google::Gax.create_api_call(
+ @cloud_redis_stub.method(:import_instance),
+ defaults["import_instance"],
exception_transformer: exception_transformer,
params_extractor: proc do |request|
{'name' => request.name}
end
)
+ @export_instance = Google::Gax.create_api_call(
+ @cloud_redis_stub.method(:export_instance),
+ defaults["export_instance"],
+ 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
)
+ @delete_instance = Google::Gax.create_api_call(
+ @cloud_redis_stub.method(:delete_instance),
+ defaults["delete_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
@@ -298,11 +315,11 @@
# available to the project are queried, and the results are aggregated.
#
# @param parent [String]
# Required. The resource name of the instance location using the form:
# `projects/{project_id}/locations/{location_id}`
- # where `location_id` refers to a GCP region
+ # where `location_id` refers to a GCP region.
# @param page_size [Integer]
# The maximum number of resources contained in the underlying API
# response. If page streaming is performed per-resource, this
# parameter does not affect the return value. If page streaming is
# performed per-page, this determines the maximum number of
@@ -354,11 +371,11 @@
# Gets the details of a specific 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
+ # where `location_id` refers to a GCP region.
# @param options [Google::Gax::CallOptions]
# Overrides the default settings for this call, e.g, timeout,
# retries, etc.
# @yield [result, operation] Access the result along with the RPC operation
# @yieldparam result [Google::Cloud::Redis::V1::Instance]
@@ -397,11 +414,11 @@
# is no need to call DeleteOperation.
#
# @param parent [String]
# Required. The resource name of the instance location using the form:
# `projects/{project_id}/locations/{location_id}`
- # where `location_id` refers to a GCP region
+ # where `location_id` refers to a GCP region.
# @param instance_id [String]
# Required. The logical name of the Redis instance in the customer project
# with the following restrictions:
#
# * Must contain only lowercase letters, numbers, and hyphens.
@@ -510,13 +527,12 @@
# cloud_redis_client = Google::Cloud::Redis.new(version: :v1)
# paths_element = "display_name"
# paths_element_2 = "memory_size_gb"
# paths = [paths_element, paths_element_2]
# update_mask = { paths: paths }
- # display_name = "UpdatedDisplayName"
- # memory_size_gb = 4
- # instance = { display_name: display_name, memory_size_gb: memory_size_gb }
+ # display_name = " instance.memory_size_gb=4"
+ # instance = { display_name: display_name }
#
# # Register a callback during the method call.
# operation = cloud_redis_client.update_instance(update_mask, instance) do |op|
# raise op.results.message if op.error?
# op_results = op.results
@@ -561,17 +577,27 @@
)
operation.on_done { |operation| yield(operation) } if block_given?
operation
end
- # Deletes a specific Redis instance. Instance stops serving and data is
- # deleted.
+ # Import a Redis RDB snapshot file from Cloud Storage into a Redis instance.
#
+ # Redis may stop serving during this operation. Instance state will be
+ # IMPORTING for entire operation. When complete, the instance will contain
+ # only data from the imported file.
+ #
+ # The returned operation is automatically deleted after a few hours, so
+ # there is no need to call DeleteOperation.
+ #
# @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
+ # where `location_id` refers to a GCP region.
+ # @param input_config [Google::Cloud::Redis::V1::InputConfig | Hash]
+ # Required. Specify data to be imported.
+ # A hash of the same form as `Google::Cloud::Redis::V1::InputConfig`
+ # can also be provided.
# @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.
@@ -579,12 +605,15 @@
# 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 `input_config`:
+ # input_config = {}
+ #
# # Register a callback during the method call.
- # operation = cloud_redis_client.delete_instance(formatted_name) do |op|
+ # operation = cloud_redis_client.import_instance(formatted_name, input_config) do |op|
# raise op.results.message if op.error?
# op_results = op.results
# # Process the results.
#
# metadata = op.metadata
@@ -606,35 +635,113 @@
#
# # Or block until the operation completes, triggering callbacks on
# # completion.
# operation.wait_until_done!
- def delete_instance \
+ def import_instance \
name,
+ input_config,
options: nil
req = {
- name: name
+ name: name,
+ input_config: input_config
}.delete_if { |_, v| v.nil? }
- req = Google::Gax::to_proto(req, Google::Cloud::Redis::V1::DeleteInstanceRequest)
+ req = Google::Gax::to_proto(req, Google::Cloud::Redis::V1::ImportInstanceRequest)
operation = Google::Gax::Operation.new(
- @delete_instance.call(req, options),
+ @import_instance.call(req, options),
@operations_client,
- Google::Protobuf::Empty,
+ Google::Cloud::Redis::V1::Instance,
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.
+ # Export Redis instance data into a Redis RDB format file in Cloud Storage.
#
+ # Redis will continue serving during this operation.
+ #
+ # The returned operation is automatically deleted after a few hours, so
+ # there is no need to call DeleteOperation.
+ #
# @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
+ # where `location_id` refers to a GCP region.
+ # @param output_config [Google::Cloud::Redis::V1::OutputConfig | Hash]
+ # Required. Specify data to be exported.
+ # A hash of the same form as `Google::Cloud::Redis::V1::OutputConfig`
+ # can also be provided.
+ # @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 `output_config`:
+ # output_config = {}
+ #
+ # # Register a callback during the method call.
+ # operation = cloud_redis_client.export_instance(formatted_name, output_config) 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 export_instance \
+ name,
+ output_config,
+ options: nil
+ req = {
+ name: name,
+ output_config: output_config
+ }.delete_if { |_, v| v.nil? }
+ req = Google::Gax::to_proto(req, Google::Cloud::Redis::V1::ExportInstanceRequest)
+ operation = Google::Gax::Operation.new(
+ @export_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
+ end
+
+ # Initiates a failover of the master node to current replica node for a
+ # specific STANDARD tier Cloud Memorystore for 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,
@@ -688,9 +795,72 @@
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
+ end
+
+ # Deletes a specific Redis instance. Instance stops serving and data is
+ # deleted.
+ #
+ # @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 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]")
+ #
+ # # Register a callback during the method call.
+ # operation = cloud_redis_client.delete_instance(formatted_name) 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 delete_instance \
+ name,
+ options: nil
+ req = {
+ name: name
+ }.delete_if { |_, v| v.nil? }
+ 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