lib/google/cloud/memcache/v1beta2/cloud_memcache/client.rb in google-cloud-memcache-v1beta2-0.1.2 vs lib/google/cloud/memcache/v1beta2/cloud_memcache/client.rb in google-cloud-memcache-v1beta2-0.2.0

- old
+ new

@@ -38,11 +38,11 @@ # * Each location has a collection of Memcached instances, named: # `/instances/*` # * As such, Memcached 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 a GCP `region`; for example: # * `projects/my-memcached-project/locations/us-central1/instances/my-memcached` # class Client include Paths @@ -72,11 +72,11 @@ @configure ||= begin namespace = ["Google", "Cloud", "Memcache", "V1beta2"] parent_config = while namespace.any? parent_name = namespace.join "::" parent_const = const_get parent_name - break parent_const.configure if parent_const&.respond_to? :configure + break parent_const.configure if parent_const.respond_to? :configure namespace.pop end default_config = Client::Configuration.new parent_config default_config.rpcs.list_instances.timeout = 1200.0 @@ -91,10 +91,12 @@ default_config.rpcs.delete_instance.timeout = 1200.0 default_config.rpcs.apply_parameters.timeout = 1200.0 + default_config.rpcs.apply_software_update.timeout = 1200.0 + default_config end yield @configure if block_given? @configure end @@ -152,11 +154,17 @@ # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials - credentials ||= Credentials.default scope: @config.scope + # Use self-signed JWT if the scope and endpoint are unchanged from default, + # but only if the default endpoint does not have a region prefix. + enable_self_signed_jwt = @config.scope == Client.configure.scope && + @config.endpoint == Client.configure.endpoint && + !@config.endpoint.split(".").first.include?("-") + credentials ||= Credentials.default scope: @config.scope, + enable_self_signed_jwt: enable_self_signed_jwt if credentials.is_a?(String) || credentials.is_a?(Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = @config.quota_project @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id @@ -183,11 +191,11 @@ attr_reader :operations_client # Service calls ## - # Lists Instances in a given project and location. + # Lists Instances in a given location. # # @overload list_instances(request, options = nil) # Pass arguments to `list_instances` via a request object, either of type # {::Google::Cloud::Memcache::V1beta2::ListInstancesRequest} or an equivalent Hash. # @@ -208,20 +216,19 @@ # where `location_id` refers to a GCP region # @param page_size [::Integer] # The maximum number of items to return. # # If not specified, a default value of 1000 will be used by the service. - # Regardless of the page_size value, the response may include a partial list - # and a caller should only rely on response's - # [next_page_token][CloudMemcache.ListInstancesResponse.next_page_token] + # Regardless of the `page_size` value, the response may include a partial + # list and a caller should only rely on response's + # {::Google::Cloud::Memcache::V1beta2::ListInstancesResponse#next_page_token `next_page_token`} # to determine if there are more instances left to be queried. # @param page_token [::String] - # The next_page_token value returned from a previous List request, - # if any. + # The `next_page_token` value returned from a previous List request, if any. # @param filter [::String] # List filter. For example, exclude all Memcached instances with name as - # my-instance by specifying "name != my-instance". + # my-instance by specifying `"name != my-instance"`. # @param order_by [::String] # Sort results. Supported values are "name", "name desc" or "" (unsorted). # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Memcache::V1beta2::Instance>] @@ -336,11 +343,11 @@ rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## - # Creates a new Instance in a given project and location. + # Creates a new Instance in a given location. # # @overload create_instance(request, options = nil) # Pass arguments to `create_instance` via a request object, either of type # {::Google::Cloud::Memcache::V1beta2::CreateInstanceRequest} or an equivalent Hash. # @@ -365,11 +372,13 @@ # # * Must contain only lowercase letters, numbers, and hyphens. # * Must start with a letter. # * Must be between 1-40 characters. # * Must end with a number or a letter. - # * Must be unique within the user project / location + # * Must be unique within the user project / location. + # + # If any of the above are not met, the API raises an invalid argument error. # @param resource [::Google::Cloud::Memcache::V1beta2::Instance, ::Hash] # Required. A Memcached [Instance] resource # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] @@ -435,11 +444,11 @@ # least one keyword argument is required. To specify no parameters, or to keep all # the default parameter values, pass an empty Hash as a request object (see above). # # @param update_mask [::Google::Protobuf::FieldMask, ::Hash] # Required. Mask of fields to update. - # * `displayName` + # * `displayName` # @param resource [::Google::Cloud::Memcache::V1beta2::Instance, ::Hash] # Required. A Memcached [Instance] resource. # Only fields specified in update_mask are updated. # # @yield [response, operation] Access the result along with the RPC operation @@ -487,13 +496,14 @@ rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## - # Updates the defined Memcached Parameters for an existing Instance. + # Updates the defined Memcached parameters for an existing instance. # This method only stages the parameters, it must be followed by - # ApplyParameters to apply the parameters to nodes of the Memcached Instance. + # `ApplyParameters` to apply the parameters to nodes of the Memcached + # instance. # # @overload update_parameters(request, options = nil) # Pass arguments to `update_parameters` via a request object, either of type # {::Google::Cloud::Memcache::V1beta2::UpdateParametersRequest} or an equivalent Hash. # @@ -579,11 +589,11 @@ # Pass arguments to `delete_instance` via keyword arguments. Note that at # least one keyword argument is required. To specify no parameters, or to keep all # the default parameter values, pass an empty Hash as a request object (see above). # # @param name [::String] - # Memcached instance resource name in the format: + # Required. Memcached instance resource name in the format: # `projects/{project_id}/locations/{location_id}/instances/{instance_id}` # where `location_id` refers to a GCP region # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] @@ -630,12 +640,12 @@ rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## - # ApplyParameters will update current set of Parameters to the set of - # specified nodes of the Memcached Instance. + # `ApplyParameters` restarts the set of specified nodes in order to update + # them to the current set of parameters for the Memcached Instance. # # @overload apply_parameters(request, options = nil) # Pass arguments to `apply_parameters` via a request object, either of type # {::Google::Cloud::Memcache::V1beta2::ApplyParametersRequest} or an equivalent Hash. # @@ -652,15 +662,15 @@ # # @param name [::String] # Required. Resource name of the Memcached instance for which parameter group updates # should be applied. # @param node_ids [::Array<::String>] - # Nodes to which we should apply the instance-level parameter group. + # Nodes to which the instance-level parameter group is applied. # @param apply_all [::Boolean] # Whether to apply instance-level parameter group to all nodes. If set to - # true, will explicitly restrict users from specifying any nodes, and apply - # parameter group updates to all nodes within the instance. + # true, users are restricted from specifying individual nodes, and + # `ApplyParameters` updates all nodes within the instance. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # @@ -705,10 +715,85 @@ rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## + # Updates software on the selected nodes of the Instance. + # + # @overload apply_software_update(request, options = nil) + # Pass arguments to `apply_software_update` via a request object, either of type + # {::Google::Cloud::Memcache::V1beta2::ApplySoftwareUpdateRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::Memcache::V1beta2::ApplySoftwareUpdateRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. + # + # @overload apply_software_update(instance: nil, node_ids: nil, apply_all: nil) + # Pass arguments to `apply_software_update` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param instance [::String] + # Required. Resource name of the Memcached instance for which software update should be + # applied. + # @param node_ids [::Array<::String>] + # Nodes to which we should apply the update to. Note all the selected nodes + # are updated in parallel. + # @param apply_all [::Boolean] + # Whether to apply the update to all nodes. If set to + # true, will explicitly restrict users from specifying any nodes, and apply + # software update to all nodes (where applicable) within the instance. + # + # @yield [response, operation] Access the result along with the RPC operation + # @yieldparam response [::Gapic::Operation] + # @yieldparam operation [::GRPC::ActiveCall::Operation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the RPC is aborted. + # + def apply_software_update request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Memcache::V1beta2::ApplySoftwareUpdateRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + metadata = @config.rpcs.apply_software_update.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::Memcache::V1beta2::VERSION + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + header_params = { + "instance" => request.instance + } + request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + metadata[:"x-goog-request-params"] ||= request_params_header + + options.apply_defaults timeout: @config.rpcs.apply_software_update.timeout, + metadata: metadata, + retry_policy: @config.rpcs.apply_software_update.retry_policy + options.apply_defaults metadata: @config.metadata, + retry_policy: @config.retry_policy + + @cloud_memcache_stub.call_rpc :apply_software_update, request, options: options do |response, operation| + response = ::Gapic::Operation.new response, @operations_client, options: options + yield response, operation if block_given? + return response + end + rescue ::GRPC::BadStatus => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## # Configuration class for the CloudMemcache API. # # This class represents the configuration for CloudMemcache, # providing control over timeouts, retry behavior, logging, transport # parameters, and other low-level controls. Certain parameters can also be @@ -789,18 +874,18 @@ class Configuration extend ::Gapic::Config config_attr :endpoint, "memcache.googleapis.com", ::String config_attr :credentials, nil do |value| - allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil] + allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil] allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC allowed.any? { |klass| klass === value } end config_attr :scope, nil, ::String, ::Array, nil config_attr :lib_name, nil, ::String, nil config_attr :lib_version, nil, ::String, nil - config_attr(:channel_args, { "grpc.service_config_disable_resolution"=>1 }, ::Hash, nil) + config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil) config_attr :interceptors, nil, ::Array, nil config_attr :timeout, nil, ::Numeric, nil config_attr :metadata, nil, ::Hash, nil config_attr :retry_policy, nil, ::Hash, ::Proc, nil config_attr :quota_project, nil, ::String, nil @@ -817,11 +902,11 @@ # @return [Rpcs] # def rpcs @rpcs ||= begin parent_rpcs = nil - parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config&.respond_to?(:rpcs) + parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs) Rpcs.new parent_rpcs end end ## @@ -829,11 +914,11 @@ # # Includes fields providing the configuration for each RPC in this service. # Each configuration object is of type `Gapic::Config::Method` and includes # the following configuration fields: # - # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds + # * `timeout` (*type:* `Numeric`) - The call timeout in seconds # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields # include the following keys: # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. @@ -875,26 +960,33 @@ ## # RPC-specific configuration for `apply_parameters` # @return [::Gapic::Config::Method] # attr_reader :apply_parameters + ## + # RPC-specific configuration for `apply_software_update` + # @return [::Gapic::Config::Method] + # + attr_reader :apply_software_update # @private def initialize parent_rpcs = nil - list_instances_config = parent_rpcs&.list_instances if parent_rpcs&.respond_to? :list_instances + list_instances_config = parent_rpcs.list_instances if parent_rpcs.respond_to? :list_instances @list_instances = ::Gapic::Config::Method.new list_instances_config - get_instance_config = parent_rpcs&.get_instance if parent_rpcs&.respond_to? :get_instance + get_instance_config = parent_rpcs.get_instance if parent_rpcs.respond_to? :get_instance @get_instance = ::Gapic::Config::Method.new get_instance_config - create_instance_config = parent_rpcs&.create_instance if parent_rpcs&.respond_to? :create_instance + create_instance_config = parent_rpcs.create_instance if parent_rpcs.respond_to? :create_instance @create_instance = ::Gapic::Config::Method.new create_instance_config - update_instance_config = parent_rpcs&.update_instance if parent_rpcs&.respond_to? :update_instance + update_instance_config = parent_rpcs.update_instance if parent_rpcs.respond_to? :update_instance @update_instance = ::Gapic::Config::Method.new update_instance_config - update_parameters_config = parent_rpcs&.update_parameters if parent_rpcs&.respond_to? :update_parameters + update_parameters_config = parent_rpcs.update_parameters if parent_rpcs.respond_to? :update_parameters @update_parameters = ::Gapic::Config::Method.new update_parameters_config - delete_instance_config = parent_rpcs&.delete_instance if parent_rpcs&.respond_to? :delete_instance + delete_instance_config = parent_rpcs.delete_instance if parent_rpcs.respond_to? :delete_instance @delete_instance = ::Gapic::Config::Method.new delete_instance_config - apply_parameters_config = parent_rpcs&.apply_parameters if parent_rpcs&.respond_to? :apply_parameters + apply_parameters_config = parent_rpcs.apply_parameters if parent_rpcs.respond_to? :apply_parameters @apply_parameters = ::Gapic::Config::Method.new apply_parameters_config + apply_software_update_config = parent_rpcs.apply_software_update if parent_rpcs.respond_to? :apply_software_update + @apply_software_update = ::Gapic::Config::Method.new apply_software_update_config yield self if block_given? end end end