Class: Flare::Tools::Cli::Dumpkey
- Inherits:
-
SubCommand
- Object
- SubCommand
- Flare::Tools::Cli::Dumpkey
- Defined in:
- lib/flare/tools/cli/dumpkey.rb
Constant Summary
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
-
#initialize ⇒ Dumpkey
constructor
A new instance of Dumpkey.
- #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 ⇒ Dumpkey
Returns a new instance of Dumpkey.
42 43 44 45 46 47 48 49 50 |
# File 'lib/flare/tools/cli/dumpkey.rb', line 42 def initialize super @output = nil @format = nil @part = nil @partsize = nil @bwlimit = nil @all = false end |
Instance Method Details
#execute(config, args) ⇒ Object
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/flare/tools/cli/dumpkey.rb', line 52 def execute(config, args) parse_index_server(config, args) cluster = nil Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s| cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes) end return S_NG if cluster.nil? if @all unless args.empty? STDERR.puts "don't specify any nodes with --all option." return S_NG else args = cluster.master_nodekeys end else if args.empty? STDERR.puts "please specify --all option to get complete dump." return S_NG end end unless @format.nil? unless ["csv"].include? @format puts "unknown format: #{@format}" return S_NG end end hosts = args.map {|x| x.split(':')} hosts.each do |x| if x.size != 2 puts "invalid argument '#{x.join(':')}'." return S_NG end end hosts.each do |hostname,port| Flare::Tools::Node.open(hostname, port.to_i, @timeout, @bwlimit, @bwlimit) do |n| output = STDOUT unless @output.nil? output = File.open(@output, "w") end case @format when "csv" writer = CSV::Writer.generate(output) output.puts "# key" end interruptible { n.dumpkey(@part, @partsize) do |key| case @format when "csv" writer << [key] else output.puts "#{key}" end false end } output.close if output != STDOUT end end S_OK end |
#setup ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/flare/tools/cli/dumpkey.rb', line 31 def setup super set_option_index_server @optp.on('-o', '--output=FILE', "output to file" ) {|v| @output = v} @optp.on('-f', '--format=FORMAT', "output format [csv]" ) {|v| @format = v} @optp.on('-p', '--partition=NUMBER', "partition number" ) {|v| @part = v.to_i if v.to_i >= 0} @optp.on('-s', '--partition-size=SIZE', "partition size" ) {|v| @partsize = v.to_i if v.to_i > 0} @optp.on( '--bwlimit=BANDWIDTH', "bandwidth limit (bps)" ) {|v| @bwlimit = v if v.to_i > 0} @optp.on( '--all', "dump form all partitions") {@all = true} end |