Class: RightScale::ApiClient

Inherits:
BaseRetryClient show all
Defined in:
lib/right_agent/clients/api_client.rb

Overview

HTTP interface to RightApi for use when mapping actor-based requests to API requests

Constant Summary collapse

API_VERSION =

RightApi API version for use in X-API-Version header

"1.5"
MAX_AUDIT_SUMMARY_LENGTH =

Maximum length of an audit summary as enforced by RightApi

255
DEFAULT_OPEN_TIMEOUT =

Default time to wait for HTTP connection to open

2
DEFAULT_REQUEST_TIMEOUT =

Default time to wait for response from request, which is chosen to be 5 seconds greater than the response timeout inside the RightNet router

35
API_MAP =

Map from actor-based request paths to RightApi HTTP verb and path; only requests whose type matches an entry in this hash will be routed to the RightApi; all others will be routed to RightNet

{
"/auditor/create_entry"              => [:post, "/audit_entries"],
"/auditor/update_entry"              => [:post, "/audit_entries/:id/append"],
"/booter/declare"                    => [:post, "/right_net/booter/declare"],
"/booter/get_repositories"           => [:get,  "/right_net/booter/get_repositories"],
"/booter/get_boot_bundle"            => [:get,  "/right_net/booter/get_boot_bundle"],
"/booter/get_decommission_bundle"    => [:get,  "/right_net/booter/get_decommission_bundle"],
"/booter/get_missing_attributes"     => [:get,  "/right_net/booter/get_missing_attributes"],
"/booter/get_login_policy"           => [:get,  "/right_net/booter/get_login_policy"],
"/forwarder/schedule_right_script"   => [:post, "/right_net/scheduler/bundle_right_script"],
"/forwarder/schedule_recipe"         => [:post, "/right_net/scheduler/bundle_recipe"],
"/forwarder/shutdown"                => [:post, "/right_net/scheduler/shutdown"],
"/key_server/retrieve_public_keys"   => [:get,  "/right_net/key_server/retrieve_public_keys"],
"/router/ping"                       => [:get,  "/health-check"],
# Currently cannot use RightApi for query_tags because it does not support server
# tag scoping by account or deployment like the router does
#"/router/query_tags"                 => [:post, "/tags/by_tag"],
"/router/add_tags"                   => [:post, "/tags/multi_add"],
"/router/delete_tags"                => [:post, "/tags/multi_delete"],
"/state_recorder/record"             => [:put,  "/right_net/state_recorder/record"],
"/storage_valet/get_planned_volumes" => [:get,  "/right_net/storage_valet/get_planned_volumes"],
"/storage_valet/attach_volume"       => [:post, "/right_net/storage_valet/attach_volume"],
"/storage_valet/detach_volume"       => [:post, "/right_net/storage_valet/detach_volume"],
"/updater/update_inputs"             => [:post, "/right_net/scheduler/update_inputs"],
"/vault/read_documents"              => [:get,  "/right_net/vault/read_documents"] }
AUDIT_FILTER_PARAMS =

Symbols for audit request parameters whose values are to be hidden when logging

["detail", "text"]

Constants inherited from BaseRetryClient

BaseRetryClient::DEFAULT_RECONNECT_INTERVAL, BaseRetryClient::DEFAULT_RETRY_INTERVALS, BaseRetryClient::DEFAULT_RETRY_TIMEOUT, BaseRetryClient::PERMITTED_STATE_TRANSITIONS

Instance Attribute Summary collapse

Attributes inherited from BaseRetryClient

#state

Instance Method Summary collapse

Methods inherited from BaseRetryClient

#close, #communicated, #init, #stats, #status

Constructor Details

#initialize(auth_client, options) ⇒ ApiClient

Create RightApi client of specified type

Parameters:

  • auth_client (AuthClient)

    providing authorization session for HTTP requests

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :open_timeout (Numeric)

    maximum wait for connection; defaults to DEFAULT_OPEN_TIMEOUT

  • :request_timeout (Numeric)

    maximum wait for response; defaults to DEFAULT_REQUEST_TIMEOUT

  • :retry_timeout (Numeric)

    maximum before stop retrying; defaults to DEFAULT_RETRY_TIMEOUT

  • :retry_intervals (Array)

    between successive retries; defaults to DEFAULT_RETRY_INTERVALS

  • :retry_enabled (Boolean)

    for requests that fail to connect or that return a retry result

  • :reconnect_interval (Numeric)

    for reconnect attempts after lose connectivity

Raises:

  • (ArgumentError)

    auth client does not support this client type



88
89
90
# File 'lib/right_agent/clients/api_client.rb', line 88

def initialize(auth_client, options)
  init(:api, auth_client, options.merge(:server_name => "RightApi", :api_version => API_VERSION))
end

Instance Attribute Details

#self_hrefObject (readonly)

Resource href for this agent



74
75
76
# File 'lib/right_agent/clients/api_client.rb', line 74

def self_href
  @self_href
end

Instance Method Details

#push(type, payload, target, options = {}) ⇒ NilClass

Route a request to a single target or multiple targets with no response expected Persist the request en route to reduce the chance of it being lost at the expense of some additional network overhead Enqueue the request if the target is not currently available Never automatically retry the request if there is the possibility of it being duplicated Set time-to-live to be forever

Parameters:

  • type (String)

    of request as path specifying actor and action

  • payload (Hash, NilClass)

    for request

  • target (String, Hash, NilClass)

    for request, which may be identity of specific target, hash for selecting potentially multiple targets, or nil if routing solely using type; hash may contain:

    String

    :agent_id serialized identity of specific target

    Array

    :tags that must all be associated with a target for it to be selected

    Hash

    :scope for restricting routing which may contain:

    Integer

    :account id that agents must be associated with to be included

    Integer

    :shard id that agents must be in to be included, or if value is

    Packet::GLOBAL, ones with no shard id
    
    Symbol

    :selector for picking from qualified targets: :any or :all;

    defaults to :any
    
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :request_uuid (String)

    uniquely identifying this request; defaults to randomly generated

  • :time_to_live (Numeric)

    seconds before request expires and is to be ignored; non-positive value or nil means never expire

Returns:

  • (NilClass)

    always nil since there is no expected response to the request

Raises:



126
127
128
# File 'lib/right_agent/clients/api_client.rb', line 126

def push(type, payload, target, options = {})
  map_request(type, payload, options)
end

#request(type, payload, target, options = {}) ⇒ Result, NilClass

Route a request to a single target with a response expected Automatically retry the request if a response is not received in a reasonable amount of time or if there is a non-delivery response indicating the target is not currently available Timeout the request if a response is not received in time, typically configured to 30 sec Because of retries there is the possibility of duplicated requests, and these are detected and discarded automatically for non-idempotent actions Allow the request to expire per the agent’s configured time-to-live, typically 1 minute

Parameters:

  • type (String)

    of request as path specifying actor and action

  • payload (Hash, NilClass)

    for request

  • target (String, Hash, NilClass)

    for request, which may be identity of specific target, hash for selecting targets of which one is picked randomly, or nil if routing solely using type; hash may contain:

    String

    :agent_id serialized identity of specific target

    Array

    :tags that must all be associated with a target for it to be selected

    Hash

    :scope for restricting routing which may contain:

    Integer

    :account id that agents must be associated with to be included

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :request_uuid (String)

    uniquely identifying this request; defaults to randomly generated

  • :time_to_live (Numeric)

    seconds before request expires and is to be ignored; non-positive value or nil means never expire

Returns:

  • (Result, NilClass)

    response from request

Raises:



161
162
163
# File 'lib/right_agent/clients/api_client.rb', line 161

def request(type, payload, target, options = {})
  map_request(type, payload, options)
end

#support?(type) ⇒ Array

Determine whether request supported by this client

Parameters:

  • type (String)

    of request as path specifying actor and action

Returns:

  • (Array)

    HTTP verb and path



170
171
172
# File 'lib/right_agent/clients/api_client.rb', line 170

def support?(type)
  API_MAP.has_key?(type)
end