Class: Elasticsearch::Drain::Nodes

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticsearch/drain/nodes.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#client

Instance Method Summary collapse

Constructor Details

#initialize(client, asg) ⇒ Nodes

Returns a new instance of Nodes.



12
13
14
15
16
# File 'lib/elasticsearch/drain/nodes.rb', line 12

def initialize(client, asg)
  super(client)
  @asg = asg
  load
end

Instance Attribute Details

#infoObject (readonly)

The Elasticsearch node info json object



10
11
12
# File 'lib/elasticsearch/drain/nodes.rb', line 10

def info
  @info
end

#statsObject (readonly)

The Elasticsearch node stats json object



6
7
8
# File 'lib/elasticsearch/drain/nodes.rb', line 6

def stats
  @stats
end

Instance Method Details

#filter_nodes(instances, reload = false) ⇒ Object



41
42
43
# File 'lib/elasticsearch/drain/nodes.rb', line 41

def filter_nodes(instances, reload = false)
  nodes(reload).find_all { |n| instances.include? n.ipaddress }
end

#loadObject



18
19
20
21
22
23
24
# File 'lib/elasticsearch/drain/nodes.rb', line 18

def load
  tries ||= 3
  @info = client.nodes.info metric: '_all'
  @stats = client.nodes.stats metric: '_all'
rescue Faraday::TimeoutError
  retry unless (tries -= 1).zero?
end

#nodes(reload = false) ⇒ Array<OpenStruct>

Get list of nodes in the cluster

Returns:

  • (Array<OpenStruct>)

    Array of node objects



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/elasticsearch/drain/nodes.rb', line 29

def nodes(reload = false)
  load if reload
  @info['nodes'].map do |node|
    Drain::Node.new(
      stats['nodes'].find { |n| n[0] == node[0] },
      node,
      client,
      @asg
    )
  end
end