class Elastomer::CLI::Cluster
Public Instance Methods
allocation(command)
click to toggle source
# 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./ || client.version =~ /^2./ 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
health()
click to toggle source
# 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
settings()
click to toggle source
# File lib/elastomer/cli/cluster.rb, line 25 def settings response = cluster.get_settings(:flat_settings => true) print_settings(response) end
update(*args)
click to toggle source
# 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
Private Instance Methods
cluster()
click to toggle source
# File lib/elastomer/cli/cluster.rb, line 110 def cluster client.cluster end
print_settings(scoped_settings)
click to toggle source
# File lib/elastomer/cli/cluster.rb, line 114 def print_settings(scoped_settings) out = Terminal::Table.new do |table| unless scoped_settings["persistent"].empty? table << ['PERSISTENT', ""] table << :separator scoped_settings["persistent"].each { |row| table << row } table << :separator table << :separator end unless scoped_settings["transient"].empty? table << ['TRANSIENT', ""] table << :separator scoped_settings["transient"].each { |row| table << row } end end puts out end