Class: ReceptorController::Client
- Inherits:
-
Object
- Object
- ReceptorController::Client
- Defined in:
- lib/receptor_controller/client.rb,
lib/receptor_controller/client/version.rb,
lib/receptor_controller/client/exception.rb
Defined Under Namespace
Classes: Configuration, ControllerResponseError, Directive, DirectiveBlocking, DirectiveNonBlocking, Error, ResponseError, ResponseTimeoutError, ResponseWorker, UnknownResponseTypeError
Constant Summary collapse
- STATUS_DISCONNECTED =
{'status' => 'disconnected'}.freeze
- VERSION =
"0.0.7".freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#default_headers ⇒ Object
Returns the value of attribute default_headers.
-
#identity_header ⇒ Object
Returns the value of attribute identity_header.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#response_worker ⇒ Object
Returns the value of attribute response_worker.
Class Method Summary collapse
Instance Method Summary collapse
- #connection_status(account_number, node_id) ⇒ Object
- #directive(account_number, node_id, payload:, directive:, log_message_common: nil, type: :non_blocking) ⇒ Object
- #headers(account = nil) ⇒ Object
-
#initialize(config: Configuration.default, logger: ManageIQ::Messaging::NullLogger.new) ⇒ Client
constructor
A new instance of Client.
- #receptor_log_msg(msg, account, node_id, exception = nil) ⇒ Object
Constructor Details
#initialize(config: Configuration.default, logger: ManageIQ::Messaging::NullLogger.new) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 |
# File 'lib/receptor_controller/client.rb', line 28 def initialize(config: Configuration.default, logger: ManageIQ::Messaging::NullLogger.new) self.config = config self.default_headers = {"Content-Type" => "application/json"} self.logger = logger self.response_worker = ResponseWorker.new(config, logger) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/receptor_controller/client.rb', line 13 def config @config end |
#default_headers ⇒ Object
Returns the value of attribute default_headers.
12 13 14 |
# File 'lib/receptor_controller/client.rb', line 12 def default_headers @default_headers end |
#identity_header ⇒ Object
Returns the value of attribute identity_header.
12 13 14 |
# File 'lib/receptor_controller/client.rb', line 12 def identity_header @identity_header end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/receptor_controller/client.rb', line 12 def logger @logger end |
#response_worker ⇒ Object
Returns the value of attribute response_worker.
12 13 14 |
# File 'lib/receptor_controller/client.rb', line 12 def response_worker @response_worker end |
Class Method Details
.configure ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/receptor_controller/client.rb', line 18 def configure if block_given? yield(Configuration.default) else Configuration.default end end |
Instance Method Details
#connection_status(account_number, node_id) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/receptor_controller/client.rb', line 35 def connection_status(account_number, node_id) body = { :account => account_number, :node_id => node_id }.to_json response = Faraday.post(config.connection_status_url, body, headers(account_number)) if response.success? JSON.parse(response.body) else logger.error(receptor_log_msg("Connection_status failed: HTTP #{response.status}", account_number, node_id)) STATUS_DISCONNECTED end rescue Faraday::Error => e logger.error(receptor_log_msg("Connection_status failed", account_number, node_id, e)) STATUS_DISCONNECTED end |
#directive(account_number, node_id, payload:, directive:, log_message_common: nil, type: :non_blocking) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/receptor_controller/client.rb', line 53 def directive(account_number, node_id, payload:, directive:, log_message_common: nil, type: :non_blocking) klass = type == :non_blocking ? DirectiveNonBlocking : DirectiveBlocking klass.new(:name => directive, :account => account_number, :node_id => node_id, :payload => payload, :log_message_common => , :client => self) end |
#headers(account = nil) ⇒ Object
67 68 69 |
# File 'lib/receptor_controller/client.rb', line 67 def headers(account = nil) default_headers.merge(auth_headers(account) || {}) end |
#receptor_log_msg(msg, account, node_id, exception = nil) ⇒ Object
71 72 73 74 75 |
# File 'lib/receptor_controller/client.rb', line 71 def receptor_log_msg(msg, account, node_id, exception = nil) = "Receptor: #{msg}" += "; #{exception.class.name}: #{exception.}" if exception.present? + " [Account number: #{account}; Receptor node: #{node_id}]" end |