class Flare::Tools::Cli::List

Constants

HeaderConfig

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/flare/tools/cli/list.rb, line 37
def initialize
  super
  @numeric_hosts = false
  @format = HeaderConfig.map {|x| x[0]}.join(' ')
  @cout = STDOUT
end

Public Instance Methods

execute(config, args) click to toggle source
# File lib/flare/tools/cli/list.rb, line 62
def execute(config, args)
  parse_index_server(config, args)
  if args.size > 0
    error "invalid arguments: "+args.join(' ')
    return S_NG
  end

  cluster = Flare::Tools::IndexServer.open(config[:index_server_hostname],
                                           config[:index_server_port], @timeout) do |s|
    Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)
  end

  if cluster.nil?
    error "Invalid index server."
    return S_NG
  end

  print_header
  cluster.nodekeys.each do |nodekey|
    data = cluster.node_stat(nodekey)
    hostname, port = nodekey.split(":", 2)
    hostname = get_address_or_remain(hostname) if @numeric_hosts
    partition = (data.partition == -1) ? "-" : data.partition
    print_node nodekey_of(hostname, port), partition, data.role, data.state, data.balance
  end

  S_OK
end
get_address_or_remain(hostname) click to toggle source
# File lib/flare/tools/cli/list.rb, line 54
def get_address_or_remain hostname
  begin
    Resolv.getaddress(hostname)
  rescue Resolv::ResolvError
    hostname
  end
end
print_header() click to toggle source
print_node(*args) click to toggle source
setup() click to toggle source
Calls superclass method
# File lib/flare/tools/cli/list.rb, line 31
def setup
  super
  set_option_index_server
  @optp.on('--numeric-hosts',            "show numerical host addresses") {@numeric_hosts = true}
end