Module: Elasticsearch::Manager::CMD

Includes:
Elasticsearch::Manager
Defined in:
lib/elasticsearch/manager/cmd.rb

Constant Summary

Constants included from Elasticsearch::Manager

VERSION

Class Method Summary collapse

Class Method Details

.disable_routing(opts) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/elasticsearch/manager/cmd.rb', line 57

def self.disable_routing(opts)
  manager = _manager(opts)
  print "Disabling shard routing allocation..."
  msg = if manager.disable_routing
          "disabled!".colorize(:green)
        else
          "error, unable to disable shard routing allocation!".colorize(:red)
        end
  print "\rDisabling shard routing allocation... #{msg}\n"
  return 0
end

.enable_routing(opts) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/elasticsearch/manager/cmd.rb', line 69

def self.enable_routing(opts)
  manager = _manager(opts)
  print "Enabling shard routing allocation..."
  msg = if manager.enable_routing
          "enabled!".colorize(:green)
        else
          "error, unable to enable shard routing allocation!".colorize(:red)
        end
  print "\rEnabling shard routing allocation... #{msg}\n"
  return 0
end

.list_nodes(opts) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/elasticsearch/manager/cmd.rb', line 48

def self.list_nodes(opts)
  manager = _manager(opts)
  print "Discovering cluster members..." if opts[:verbose]
  manager.cluster_members!
  print "\rDiscovering cluster members... Done!\n" if opts[:verbose]
  manager.list_node_ips
  return 0
end

.rolling_restart(opts) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elasticsearch/manager/cmd.rb', line 12

def self.rolling_restart(opts)
  manager = _manager(opts)
  # Check that the cluster is stable?
  begin
    unless manager.cluster_stable?
      print_cluster_status(manager, 'The cluster is currently unstable! Not proceeding with rolling-restart')
      return 2
    end

    print "Discovering cluster members..." if opts[:verbose]
    manager.cluster_members!
    print "\rDiscovering cluster members... Done!\n" if opts[:verbose]
  rescue Elasticsearch::Manager::ApiError => e
    puts e
    return 3
  rescue Exception => e
    puts e
    return 2
  end

  timeout = opts[:timeout] || 600
  sleep_interval = opts[:sleep_interval] || 30

  begin
    manager.rolling_restart(timeout, sleep_interval)
  rescue Elasticsearch::Manager::ApiError => e
    puts e
    return 3
  rescue Exception => e
    puts e
    return 2
  end
  puts 'Rolling restart complete.'
  return 0
end

.shard_states(opts) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/elasticsearch/manager/cmd.rb', line 81

def self.shard_states(opts)
  manager = _manager(opts)
  print "Discovering cluster members..." if opts[:verbose]
  manager.cluster_members!
  print "\rDiscovering cluster members... Done!\n" if opts[:verbose]
  puts "UNASSIGNED: #{manager.state.count_unassigned_shards}"
  manager.nodes.each do |node|
    puts "#{node.ip}:\tSTARTED: #{node.count_started_shards}\t|\tINITIALIZING: #{node.count_initializing_shards}\t|\tRELOCATING: #{node.count_relocating_shards}"
  end
  return 0
end

.status(opts) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/elasticsearch/manager/cmd.rb', line 93

def self.status(opts)
  manager = _manager(opts)
  status = manager.cluster_status
  puts "The Elasticsearch cluster is currently: #{status.colorize(status.to_sym)}"
  print_cluster_status(manager) if opts[:verbose]
  return 0
end