class Elasticsearch::Drain::Node

Attributes

info[R]

@!attribute [r] The Elasticsearch node info json object

instance_id[RW]

@!attribute [rw] The Elasticsearch node Instance ID

stats[R]

@!attribute [r] The Elasticsearch node stats json object

Public Class Methods

new(stats, info, client, asg) click to toggle source
Calls superclass method Elasticsearch::Drain::Base::new
# 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

Public Instance Methods

address(str) click to toggle source

Extract ip:port from string passed in

@param [String] str The address object to parse for the ip:port @return [String] ip:port pair from the data passed in

# File lib/elasticsearch/drain/node.rb, line 95
def address(str)
  str.match(/.+\[\/(.+)\]/)[1]
end
bytes_stored() click to toggle source

Get size in bytes used for indices for a node

@return [Integer] size in bytes used to store indicies on node

# File lib/elasticsearch/drain/node.rb, line 87
def bytes_stored
  stats[1]['indices']['store']['size_in_bytes']
end
hostname() click to toggle source

The Elasticsearch node hostname

@return [String] Elasticsearch node hostname

# File lib/elasticsearch/drain/node.rb, line 41
def hostname
  info[1]['host']
end
http_address() click to toggle source

The Elasticsearch node HTTP Address

@return [String] Elasticsearch nodes HTTP Address

# File lib/elasticsearch/drain/node.rb, line 80
def http_address
  address(info[1]['http_address'])
end
id() click to toggle source

The Elasticsearch node id

@return [String] Elasticsearch node id

# File lib/elasticsearch/drain/node.rb, line 27
def id
  info[0]
end
in_recovery?() click to toggle source
# File lib/elasticsearch/drain/node.rb, line 99
def in_recovery?
  recovery = client.cat.recovery(format: 'json', v: true)
  if recovery.first != nil
    recovery = recovery.first.values
  end
  [hostname, name].any? { |a| recovery.include?(a) }
end
ipaddress() click to toggle source

The Elasticsearch node ipaddress

For ES v1.x, we must extract and modify the IP address from the http_address key. For all later versions, we can use the host key directly. That's why we check with the if/else statement.

@return [String] Elasticsearch node ipaddress

# File lib/elasticsearch/drain/node.rb, line 60
def ipaddress
  block = /\d{,2}|1\d{2}|2[0-4]\d|25[0-5]/
  re = /\A#{block}\.#{block}\.#{block}\.#{block}\z/
  if info[1]['host'] && re =~ info[1]['host']
    info[1]['host']
  else
    address(info[1]['http_address']).split(':')[0]  
  end
end
name() click to toggle source

The Elasticsearch node name

@return [String] Elasticsearch node name

# File lib/elasticsearch/drain/node.rb, line 48
def name
  info[1]['name']
end
terminate() click to toggle source
# File lib/elasticsearch/drain/node.rb, line 107
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_address() click to toggle source

The Elasticsearch node Transport Address

@return [String] Elasticsearch node Transport Address

# File lib/elasticsearch/drain/node.rb, line 73
def transport_address
  address(info[1]['transport_address'])
end
version() click to toggle source

The Elasticsearch node version

@return [String] Elasticsearch node version

# File lib/elasticsearch/drain/node.rb, line 34
def version
  info[1]['version']
end