Class: Flare::Tools::Cli::Summary

Inherits:
SubCommand show all
Includes:
IndexServerConfig, Flare::Tools::Common, Util::Conversion, Util::Logging
Defined in:
lib/flare/tools/cli/summary.rb

Constant Summary collapse

HeaderConfig =
[ ['%-30.30s', '#cluster'],
['%6s',      'part'],
['%6s',      'node'],
['%7s',      'master'],
['%6s',      'slave'],
['%16s',     'size'],
['%13s',    'items'] ]

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

Flare::Tools::Cli::SubCommand::S_NG, Flare::Tools::Cli::SubCommand::S_OK

Constants included from Util::Interruption

Util::Interruption::InterruptionTargets

Instance Attribute Summary

Attributes included from Option

#optp

Instance Method Summary collapse

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

#short_desc_of_second

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

#initializeSummary

Returns a new instance of Summary.



40
41
42
# File 'lib/flare/tools/cli/summary.rb', line 40

def initialize
  super
end

Instance Method Details

#execute(config, args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
91
92
# File 'lib/flare/tools/cli/summary.rb', line 44

def execute(config, args)
  parse_index_server(config, args)
  nodes = {}
  threads = {}
  header = HeaderConfig

  Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
    nodes = s.stats_nodes
    unless nodes
      error "Invalid index server."
      return S_NG
    end
    nodes = nodes.sort_by{|key,val| [val['partition'].to_i, val['role'], key]}
  end

  name = if config[:cluster].nil? then
           "#{config[:index_server_hostname]}:#{config[:index_server_port]}"
         else
           config[:cluster]
         end

  total_bytes = 0
  total_parts = 0
  total_nodes = 0
  total_items = 0
  total_masters = 0
  total_slaves = 0

  nodes.each do |hostname_port,data|
    hostname, port = hostname_port.split(":", 2)
    Flare::Tools::Stats.open(hostname, data['port'], @timeout) do |s|
      stats = s.stats
      p = data['partition'].to_i
      total_parts = p+1 if p+1 > total_parts if data['role'] == 'master'
      total_nodes += 1
      total_masters += 1 if data['role'] == 'master'
      total_slaves += 1 if data['role'] == 'slave'
      total_bytes += stats['bytes'].to_i if data['role'] == 'master'
      total_items += stats['curr_items'].to_i if data['role'] == 'master'
    end
  end

  format = header.map {|x| x[0]}.join(@delimiter)
  label = format % header.map{|x| x[1]}.flatten
  puts label
  puts(format % [name, total_parts, total_nodes, total_masters, total_slaves, total_bytes, total_items])

  S_OK
end

#setupObject



35
36
37
38
# File 'lib/flare/tools/cli/summary.rb', line 35

def setup
  super
  set_option_index_server
end