Class: Elasticsearch::Transport::Transport::Sniffer
- Inherits:
-
Object
- Object
- Elasticsearch::Transport::Transport::Sniffer
- Defined in:
- lib/elasticsearch/transport/transport/sniffer.rb
Overview
Handles node discovery (“sniffing”)
Constant Summary collapse
- PROTOCOL =
'http'
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
-
#hosts ⇒ Array<Hash>
Retrieves the node list from the Elasticsearch’s [_Nodes Info API_](www.elastic.co/guide/reference/api/admin-cluster-nodes-info/) and returns a normalized Array of information suitable for passing to transport.
-
#initialize(transport) ⇒ Sniffer
constructor
A new instance of Sniffer.
Constructor Details
#initialize(transport) ⇒ Sniffer
Returns a new instance of Sniffer.
32 33 34 35 |
# File 'lib/elasticsearch/transport/transport/sniffer.rb', line 32 def initialize(transport) @transport = transport @timeout = transport.[:sniffer_timeout] || 1 end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
28 29 30 |
# File 'lib/elasticsearch/transport/transport/sniffer.rb', line 28 def timeout @timeout end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
27 28 29 |
# File 'lib/elasticsearch/transport/transport/sniffer.rb', line 27 def transport @transport end |
Instance Method Details
#hosts ⇒ Array<Hash>
Retrieves the node list from the Elasticsearch’s [_Nodes Info API_](www.elastic.co/guide/reference/api/admin-cluster-nodes-info/) and returns a normalized Array of information suitable for passing to transport.
Shuffles the collection before returning it when the ‘randomize_hosts` option is set for transport.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/elasticsearch/transport/transport/sniffer.rb', line 46 def hosts Timeout::timeout(timeout, SnifferTimeoutError) do nodes = perform_sniff_request.body hosts = nodes['nodes'].map do |id, info| next unless info[PROTOCOL] host, port = parse_publish_address(info[PROTOCOL]['publish_address']) { id: id, name: info['name'], version: info['version'], host: host, port: port, roles: info['roles'], attributes: info['attributes'] } end.compact hosts.shuffle! if transport.[:randomize_hosts] hosts end end |