Class: Flare::Tools::Cli::List
- Inherits:
-
SubCommand
- Object
- SubCommand
- Flare::Tools::Cli::List
- Includes:
- IndexServerConfig, Flare::Tools::Common, Util::Conversion
- Defined in:
- lib/flare/tools/cli/list.rb
Constant Summary collapse
- HeaderConfig =
[ ['%-32s', 'node'], ['%9s', 'partition'], ['%6s', 'role'], ['%6s', 'state'], ['%7s', 'balance'] ]
Constants included from IndexServerConfig
IndexServerConfig::Entity, IndexServerConfig::FLARE_INDEX_SERVER, IndexServerConfig::FLARE_INDEX_SERVERS
Constants included from Util::Constant
Util::Constant::DefalutBwlimit, Util::Constant::DefaultIndexServerName, Util::Constant::DefaultIndexServerPort, Util::Constant::DefaultNodePort, Util::Constant::DefaultTimeout, Util::Constant::STATUS_NG, Util::Constant::STATUS_OK
Constants included from Flare::Tools::Common
Flare::Tools::Common::NodeListFormat, Flare::Tools::Common::NodeListHeader
Constants inherited from SubCommand
SubCommand::S_NG, SubCommand::S_OK
Constants included from Util::Interruption
Util::Interruption::InterruptionTargets
Instance Attribute Summary
Attributes included from Option
Instance Method Summary collapse
- #execute(config, args) ⇒ Object
- #get_address_or_remain(hostname) ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #print_header ⇒ Object
- #print_node(*args) ⇒ Object
- #setup ⇒ Object
Methods included from Util::Logging
#debug, #error, #fatal, #info, logger, #puts, set_logger, #trace, #warn
Methods included from Flare::Tools::Common
#address_of_hostname, #fetch_cluster, #hostname_of_address, #nodekey_of, #string_of_nodelist, #user_confirmed, #wait_for_master_construction, #wait_for_servers, #wait_for_slave_construction
Methods included from Util::Conversion
Methods inherited from SubCommand
desc, #execute_subcommand, myname, #myname, to_s, to_sym, usage
Methods included from Util::Interruption
included, #initialize_interruption, #interrupt, #interrupt_, interrupt_all, #interrupted?, #interruptible, #interruptible?
Methods included from Option
#option_init, #parse_options, #set_option_dry_run, #set_option_force, #set_option_global, #set_option_index_server
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
38 39 40 41 42 43 |
# File 'lib/flare/tools/cli/list.rb', line 38 def initialize super @numeric_hosts = false @format = HeaderConfig.map {|x| x[0]}.join(' ') @cout = STDOUT end |
Instance Method Details
#execute(config, args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/flare/tools/cli/list.rb', line 63 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) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/flare/tools/cli/list.rb', line 55 def get_address_or_remain hostname begin Resolv.getaddress(hostname) rescue Resolv::ResolvError hostname end end |
#print_header ⇒ Object
45 46 47 48 |
# File 'lib/flare/tools/cli/list.rb', line 45 def print_header @cout.puts @format % HeaderConfig.map{|x| x[1]}.flatten nil end |
#print_node(*args) ⇒ Object
50 51 52 53 |
# File 'lib/flare/tools/cli/list.rb', line 50 def print_node *args @cout.puts @format % args nil end |
#setup ⇒ Object
32 33 34 35 36 |
# File 'lib/flare/tools/cli/list.rb', line 32 def setup super set_option_index_server @optp.on('--numeric-hosts', "show numerical host addresses") {@numeric_hosts = true} end |