elasticsearch-drain 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57f2263aa275c59fbda6c32bb057717d8a096bf0
4
- data.tar.gz: 88cb776d2905e4fd9d6c104c4425cc5b775a6d5b
3
+ metadata.gz: 5636da7177de03b2cc46e1f5f9c3382c542c25b1
4
+ data.tar.gz: ae9b51d1c2ace5e83497a6a92ba956523d713e01
5
5
  SHA512:
6
- metadata.gz: 65ede075fec1ff5d976692bbf8ad3ae617976d47f9b9e73df9e4eb535f91c5da78a9fcb194556c5aafcc40192b2bf20ea5f7039990d1baa7cb9eb1031b01d987
7
- data.tar.gz: 43b1ed542429a2b52e54e06e5e8cd88b9ee7a2f6f2d5deccc7118ead87a20d6a11f84a3b76ee560ebbdd08ffb4ffc2743a91f1b3dba542b41460baa9cd768183
6
+ metadata.gz: 7bbe3a3434ff69a13826251cb29561a6d95431294a7bc8590883480edbba598ff206c4d17d048a17a053e95fae4fb53f19ddf624599bf334215fa0b79ab34c1b
7
+ data.tar.gz: dfec04ba5e72334f4d75a597b512230f93670374d22afcbfc92f4b6e3a0683a2cf191394dba4072b84c68fefdf25f1def1417984d5a44f1f4d6a2616142ec346
data/Gemfile.lock CHANGED
@@ -14,12 +14,12 @@ GEM
14
14
  ast (2.1.0)
15
15
  astrolabe (1.3.1)
16
16
  parser (~> 2.2)
17
- aws-sdk (2.2.1)
18
- aws-sdk-resources (= 2.2.1)
19
- aws-sdk-core (2.2.1)
17
+ aws-sdk (2.4.4)
18
+ aws-sdk-resources (= 2.4.4)
19
+ aws-sdk-core (2.4.4)
20
20
  jmespath (~> 1.0)
21
- aws-sdk-resources (2.2.1)
22
- aws-sdk-core (= 2.2.1)
21
+ aws-sdk-resources (2.4.4)
22
+ aws-sdk-core (= 2.4.4)
23
23
  coderay (1.1.0)
24
24
  crack (0.4.2)
25
25
  safe_yaml (~> 1.0.0)
@@ -53,7 +53,7 @@ GEM
53
53
  guard-compat (~> 1.2)
54
54
  minitest (>= 3.0)
55
55
  hashdiff (0.2.2)
56
- jmespath (1.1.3)
56
+ jmespath (1.3.1)
57
57
  json (1.8.3)
58
58
  listen (3.0.3)
59
59
  rb-fsevent (>= 0.9.3)
@@ -62,7 +62,7 @@ GEM
62
62
  method_source (0.8.2)
63
63
  minitest (5.8.1)
64
64
  mixlib-shellout (2.2.3)
65
- multi_json (1.11.2)
65
+ multi_json (1.12.1)
66
66
  multipart-post (2.0.0)
67
67
  nenv (0.2.0)
68
68
  notiffany (0.0.8)
@@ -40,7 +40,7 @@ module Elasticsearch
40
40
 
41
41
  # Convience method to access {Elasticsearch::Drain::Nodes}
42
42
  def nodes
43
- Nodes.new(client, asg)
43
+ @nodes ||= Nodes.new(client, asg)
44
44
  end
45
45
 
46
46
  # Convience method to access {Elasticsearch::Drain::Cluster#cluster}
@@ -52,7 +52,7 @@ module Elasticsearch
52
52
 
53
53
  def active_nodes_in_asg
54
54
  instances = asg.instances
55
- nodes.nodes_in_asg(reload: true, instances: instances)
55
+ nodes.filter_nodes(instances, true)
56
56
  end
57
57
 
58
58
  module Errors
@@ -12,12 +12,20 @@ module Elasticsearch
12
12
  option :host, default: 'localhost:9200'
13
13
  option :asg, required: true
14
14
  option :region, required: true
15
+ option :nodes
15
16
  def asg # rubocop:disable Metrics/MethodLength
16
17
  @drainer = Elasticsearch::Drain.new(options[:host],
17
18
  options[:asg],
18
19
  options[:region])
19
20
  ensure_cluster_healthy
20
21
  @active_nodes = drainer.active_nodes_in_asg
22
+
23
+ # If a node or nodes are specified, only drain the requested node(s)
24
+ @active_nodes = active_nodes.find_all do |n|
25
+ instance_id = drainer.asg.instance(n.ipaddress).instance_id
26
+ options[:nodes].split(',').include?(instance_id)
27
+ end if options[:nodes]
28
+
21
29
  do_exit { say_status 'Complete', 'Nothing to do', :green } if active_nodes.empty?
22
30
  say_status 'Found Nodes', "AutoScalingGroup: #{instances}", :magenta
23
31
  ensure_cluster_healthy
@@ -45,8 +53,21 @@ module Elasticsearch
45
53
  instances.join(' ')
46
54
  end
47
55
 
56
+ def adjusted_min_size
57
+ min_size = drainer.asg.min_size
58
+ desired_capacity = drainer.asg.desired_capacity
59
+ if (desired_capacity - active_nodes.length) >= min_size # Removing the active_nodes won't violate the min_size
60
+ # Reduce the asg min_size proportionally
61
+ desired_min_size = (min_size - active_nodes.length) <= 0 ? 0 : (min_size - active_nodes.length)
62
+ else
63
+ # Removing the active_nodes will result in the min_size being violated
64
+ desired_min_size = desired_capacity - active_nodes.length
65
+ end
66
+ desired_min_size
67
+ end
68
+
48
69
  def drain_nodes
49
- drainer.asg.min_size = 0
70
+ drainer.asg.min_size = adjusted_min_size
50
71
  nodes_to_drain = active_nodes.map(&:id).join(',')
51
72
  say_status 'Drain Nodes', "Draining nodes: #{nodes_to_drain}", :magenta
52
73
  drainer.cluster.drain_nodes(nodes_to_drain, '_id')
@@ -55,13 +76,13 @@ module Elasticsearch
55
76
  def remove_nodes # rubocop:disable Metrics/MethodLength
56
77
  while active_nodes.length > 0
57
78
  active_nodes.each do |instance|
58
- self.active_nodes = drainer.active_nodes_in_asg
79
+ instance = drainer.nodes.filter_nodes([instance], true).first
59
80
  if instance.bytes_stored > 0
60
81
  say_status 'Drain Status', "Node #{instance.ipaddress} has #{instance.bytes_stored} bytes to move", :blue
61
82
  sleep 2
62
83
  else
63
84
  next unless remove_node(instance)
64
- self.active_nodes = drainer.active_nodes_in_asg
85
+ active_nodes.delete_if { |n| n.ipaddress == instance.ipaddress }
65
86
  break if active_nodes.length < 1
66
87
  say_status 'Waiting', 'Sleeping for 1 minute before removing the next node', :green
67
88
  sleep 60
@@ -26,7 +26,7 @@ module Elasticsearch
26
26
  # Get list of nodes in the cluster
27
27
  #
28
28
  # @return [Array<OpenStruct>] Array of node objects
29
- def nodes(reload: false)
29
+ def nodes(reload = false)
30
30
  load if reload
31
31
  @info['nodes'].map do |node|
32
32
  Drain::Node.new(
@@ -38,8 +38,8 @@ module Elasticsearch
38
38
  end
39
39
  end
40
40
 
41
- def nodes_in_asg(reload: false, instances:)
42
- nodes(reload: false).find_all { |n| instances.include? n.ipaddress }
41
+ def filter_nodes(instances, reload = false)
42
+ nodes(reload).find_all { |n| instances.include? n.ipaddress }
43
43
  end
44
44
  end
45
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-drain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler