Class: Elasticsearch::Drain::Node

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

Instance Attribute Summary collapse

Attributes inherited from Base

#client

Instance Method Summary collapse

Constructor Details

#initialize(stats, info, client, asg) ⇒ Node

Returns a new instance of Node.



16
17
18
19
20
21
22
# File 'lib/elasticsearch/drain/node.rb', line 16

def initialize(stats, info, client, asg)
  super(client)
  @stats = stats
  @info = info
  @asg = asg
  @instance_id = nil
end

Instance Attribute Details

#infoObject (readonly)

The Elasticsearch node info json object



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

def info
  @info
end

#instance_idObject

The Elasticsearch node Instance ID



14
15
16
# File 'lib/elasticsearch/drain/node.rb', line 14

def instance_id
  @instance_id
end

#statsObject (readonly)

The Elasticsearch node stats json object



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

def stats
  @stats
end

Instance Method Details

#address(str) ⇒ String

Extract ip:port from string passed in

Parameters:

  • str (String)

    The address object to parse for the ip:port

Returns:

  • (String)

    ip:port pair from the data passed in



84
85
86
# File 'lib/elasticsearch/drain/node.rb', line 84

def address(str)
  str.match(/.+\[\/(.+)\]/)[1]
end

#bytes_storedInteger

Get size in bytes used for indices for a node

Returns:

  • (Integer)

    size in bytes used to store indicies on node



76
77
78
# File 'lib/elasticsearch/drain/node.rb', line 76

def bytes_stored
  stats[1]['indices']['store']['size_in_bytes']
end

#hostnameString

The Elasticsearch node hostname

Returns:

  • (String)

    Elasticsearch node hostname



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

def hostname
  info[1]['host']
end

#http_addressString

The Elasticsearch node HTTP Address

Returns:

  • (String)

    Elasticsearch nodes HTTP Address



69
70
71
# File 'lib/elasticsearch/drain/node.rb', line 69

def http_address
  address(info[1]['http_address'])
end

#idString

The Elasticsearch node id

Returns:

  • (String)

    Elasticsearch node id



27
28
29
# File 'lib/elasticsearch/drain/node.rb', line 27

def id
  info[0]
end

#in_recovery?Boolean

Returns:

  • (Boolean)


88
89
90
91
# File 'lib/elasticsearch/drain/node.rb', line 88

def in_recovery?
  recovery = client.cat.recovery(format: 'json', v: true).first.values
  [hostname, name].any? { |a| recovery.include?(a) }
end

#ipaddressString

The Elasticsearch node ipaddress

Returns:

  • (String)

    Elasticsearch node ipaddress



55
56
57
# File 'lib/elasticsearch/drain/node.rb', line 55

def ipaddress
  address(info[1]['http_address']).split(':')[0]
end

#nameString

The Elasticsearch node name

Returns:

  • (String)

    Elasticsearch node name



48
49
50
# File 'lib/elasticsearch/drain/node.rb', line 48

def name
  info[1]['name']
end

#terminateObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/elasticsearch/drain/node.rb', line 93

def terminate
  @asg.ec2_client.terminate_instances(
    dry_run: false,
    instance_ids: [instance_id], # required
  )
  # poll for ~5mins seconds
  @asg.ec2_client.wait_until(:instance_terminated,
                             instance_ids: [instance_id]) do |w|
    w.max_attempts = 10
    w.delay = 60
  end
end

#transport_addressString

The Elasticsearch node Transport Address

Returns:

  • (String)

    Elasticsearch node Transport Address



62
63
64
# File 'lib/elasticsearch/drain/node.rb', line 62

def transport_address
  address(info[1]['transport_address'])
end

#versionString

The Elasticsearch node version

Returns:

  • (String)

    Elasticsearch node version



34
35
36
# File 'lib/elasticsearch/drain/node.rb', line 34

def version
  info[1]['version']
end