Class: Elastomer::CLI::Cluster

Inherits:
Base
  • Object
show all
Defined in:
lib/elastomer/cli/cluster.rb

Instance Method Summary collapse

Instance Method Details

#allocation(command) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/elastomer/cli/cluster.rb', line 75

def allocation(command)
  if client.version =~ /^0.90/
    setting = "cluster.routing.allocation.disable_allocation"
    value = case command
    when 'enable'
      false
    when 'disable'
      true
    else
      raise Thor::Error, "ERROR: Unknown allocation command: #{command}"
    end
  elsif client.version =~ /^1./
    setting = "cluster.routing.allocation.enable"
    value = case command
    when 'enable'
      'all'
    when 'disable'
      'none'
    when 'all', 'primaries', 'new_primaries', 'none'
      command
    else
      raise Thor::Error, "ERROR: Unknown allocation command: #{command}"
    end
  else
    raise Thor::Error, "ERROR: Unknown Elasticsearch version: #{client.version}"
    return
  end

  scope = options[:persistent] ? "persistent" : "transient"
  puts "Setting #{setting}=#{value}"
  response = cluster.update_settings({scope => { setting => value }}, {:flat_settings => true})
  print_settings(response)
end

#healthObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/elastomer/cli/cluster.rb', line 5

def health
  name = client.info["name"]
  response = cluster.health
  puts Terminal::Table.new(
    :headings => ['CLUSTER HEALTH', name],
    :rows => [
      ['Name',                  response["cluster_name"]],
      ['Status',                response["status"]],
      ['Timed Out',             response["timed_out"]],
      ['Number of Nodes',       response["number_of_nodes"]],
      ['Number of Data Nodes',  response["number_of_data_nodes"]],
      ['Active Primary Shards', response["active_primary_shards"]],
      ['Active Shards',         response["active_shards"]],
      ['Relocating Shards',     response["relocating_shards"]],
      ['Initializing Shards',   response["initializing_shards"]],
      ['Unassigned Shards',     response["unassigned_shards"]]
  ])
end

#settingsObject



25
26
27
28
29
# File 'lib/elastomer/cli/cluster.rb', line 25

def settings
  response = cluster.get_settings(:flat_settings => true)

  print_settings(response)
end

#update(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/elastomer/cli/cluster.rb', line 41

def update(*args)
  updated_settings = {}
  args.each do |arg|
    if match = arg.match(/\A([^=]+)=([^=]*)\Z/)
      updated_settings[match.captures[0]] = match.captures[1]
    end
  end

  scope = options[:persistent] ? "persistent" : "transient"
  updated_settings.each do |key, value|
    puts "Setting #{scope} #{key}=#{value}"
  end
  response = cluster.update_settings({scope => updated_settings}, {:flat_settings => true})
  print_settings(response)
end