Class: Elasticsearch::Drain::Node
- Defined in:
- lib/elasticsearch/drain/node.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
The Elasticsearch node info json object.
-
#instance_id ⇒ Object
The Elasticsearch node Instance ID.
-
#stats ⇒ Object
readonly
The Elasticsearch node stats json object.
Attributes inherited from Base
Instance Method Summary collapse
-
#address(str) ⇒ String
Extract ip:port from string passed in.
-
#bytes_stored ⇒ Integer
Get size in bytes used for indices for a node.
-
#hostname ⇒ String
The Elasticsearch node hostname.
-
#http_address ⇒ String
The Elasticsearch node HTTP Address.
-
#id ⇒ String
The Elasticsearch node id.
- #in_recovery? ⇒ Boolean
-
#initialize(stats, info, client, asg) ⇒ Node
constructor
A new instance of Node.
-
#ipaddress ⇒ String
The Elasticsearch node ipaddress.
-
#name ⇒ String
The Elasticsearch node name.
- #terminate ⇒ Object
-
#transport_address ⇒ String
The Elasticsearch node Transport Address.
-
#version ⇒ String
The Elasticsearch node version.
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
#info ⇒ Object (readonly)
The Elasticsearch node info json object
10 11 12 |
# File 'lib/elasticsearch/drain/node.rb', line 10 def info @info end |
#instance_id ⇒ Object
The Elasticsearch node Instance ID
14 15 16 |
# File 'lib/elasticsearch/drain/node.rb', line 14 def instance_id @instance_id end |
#stats ⇒ Object (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
95 96 97 |
# File 'lib/elasticsearch/drain/node.rb', line 95 def address(str) str.match(/.+\[\/(.+)\]/)[1] end |
#bytes_stored ⇒ Integer
Get size in bytes used for indices for a node
87 88 89 |
# File 'lib/elasticsearch/drain/node.rb', line 87 def bytes_stored stats[1]['indices']['store']['size_in_bytes'] end |
#hostname ⇒ String
The Elasticsearch node hostname
41 42 43 |
# File 'lib/elasticsearch/drain/node.rb', line 41 def hostname info[1]['host'] end |
#http_address ⇒ String
The Elasticsearch node HTTP Address
80 81 82 |
# File 'lib/elasticsearch/drain/node.rb', line 80 def http_address address(info[1]['http_address']) end |
#id ⇒ String
The Elasticsearch node id
27 28 29 |
# File 'lib/elasticsearch/drain/node.rb', line 27 def id info[0] end |
#in_recovery? ⇒ Boolean
99 100 101 102 |
# File 'lib/elasticsearch/drain/node.rb', line 99 def in_recovery? recovery = client.cat.recovery(format: 'json', v: true).first.values [hostname, name].any? { |a| recovery.include?(a) } end |
#ipaddress ⇒ String
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.
60 61 62 63 64 65 66 67 68 |
# 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 ⇒ String
The Elasticsearch node name
48 49 50 |
# File 'lib/elasticsearch/drain/node.rb', line 48 def name info[1]['name'] end |
#terminate ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/elasticsearch/drain/node.rb', line 104 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 ⇒ String
The Elasticsearch node Transport Address
73 74 75 |
# File 'lib/elasticsearch/drain/node.rb', line 73 def transport_address address(info[1]['transport_address']) end |
#version ⇒ String
The Elasticsearch node version
34 35 36 |
# File 'lib/elasticsearch/drain/node.rb', line 34 def version info[1]['version'] end |