flare-tools 0.4.5.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.gitignore +24 -0
  2. data/.travis.yml +15 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +28 -0
  5. data/History.txt +5 -0
  6. data/Makefile +25 -0
  7. data/README.txt +2 -2
  8. data/Rakefile +36 -34
  9. data/flare-tools.gemspec +26 -0
  10. data/lib/flare/entity/server.rb +4 -0
  11. data/lib/flare/tools.rb +3 -3
  12. data/lib/flare/tools/cli.rb +1 -0
  13. data/lib/flare/tools/cli/activate.rb +19 -13
  14. data/lib/flare/tools/cli/balance.rb +15 -8
  15. data/lib/flare/tools/cli/deploy.rb +53 -49
  16. data/lib/flare/tools/cli/dispatch.rb +101 -0
  17. data/lib/flare/tools/cli/down.rb +19 -14
  18. data/lib/flare/tools/cli/dump.rb +19 -14
  19. data/lib/flare/tools/cli/dumpkey.rb +21 -16
  20. data/lib/flare/tools/cli/flare_admin.rb +16 -72
  21. data/lib/flare/tools/cli/flare_argv0.rb +7 -51
  22. data/lib/flare/tools/cli/index.rb +10 -7
  23. data/lib/flare/tools/cli/index_server_config.rb +94 -0
  24. data/lib/flare/tools/cli/list.rb +14 -12
  25. data/lib/flare/tools/cli/master.rb +18 -12
  26. data/lib/flare/tools/cli/option.rb +55 -0
  27. data/lib/flare/tools/cli/part.rb +13 -12
  28. data/lib/flare/tools/cli/ping.rb +11 -13
  29. data/lib/flare/tools/cli/reconstruct.rb +22 -15
  30. data/lib/flare/tools/cli/remove.rb +20 -17
  31. data/lib/flare/tools/cli/restore.rb +20 -20
  32. data/lib/flare/tools/cli/slave.rb +20 -14
  33. data/lib/flare/tools/cli/stats.rb +171 -118
  34. data/lib/flare/tools/cli/sub_command.rb +16 -5
  35. data/lib/flare/tools/cli/summary.rb +12 -10
  36. data/lib/flare/tools/cli/threads.rb +15 -9
  37. data/lib/flare/tools/cli/verify.rb +20 -18
  38. data/lib/flare/tools/cluster.rb +3 -2
  39. data/lib/flare/util/constant.rb +3 -0
  40. data/lib/flare/util/pretty_table.rb +8 -0
  41. data/lib/flare/util/pretty_table/column.rb +41 -0
  42. data/lib/flare/util/pretty_table/row.rb +29 -0
  43. data/lib/flare/util/pretty_table/table.rb +37 -0
  44. data/package/Rakefile +44 -0
  45. data/package/flare-tools/Makefile +23 -0
  46. data/package/flare-tools/debian/changelog +135 -0
  47. data/package/flare-tools/debian/compat +1 -0
  48. data/package/flare-tools/debian/control +20 -0
  49. data/package/flare-tools/debian/copyright +35 -0
  50. data/package/flare-tools/debian/dirs +2 -0
  51. data/{.gemtest → package/flare-tools/debian/docs} +0 -0
  52. data/package/flare-tools/debian/rules +125 -0
  53. data/test/{test/experimental → experimental}/cache_test.rb +0 -0
  54. data/test/{test/experimental → experimental}/key_distribution_test.rb +0 -0
  55. data/test/{test/experimental → experimental}/keychecker_test.rb +0 -0
  56. data/test/{test/experimental → experimental}/list_test.rb +0 -0
  57. data/test/{test/extra → extra}/replication_test.rb +0 -0
  58. data/test/{test/integration → integration}/cli_test.rb +9 -7
  59. data/test/{test/integration → integration}/dump_expired_test.rb +4 -3
  60. data/test/{test/integration → integration}/dump_test.rb +5 -5
  61. data/test/{test/integration → integration}/index_server_test.rb +1 -1
  62. data/test/{test/integration → integration}/node_test.rb +1 -1
  63. data/test/{test/integration → integration}/partition_test.rb +6 -5
  64. data/test/{test/integration → integration}/proxy_test.rb +4 -3
  65. data/test/{test/integration → integration}/stats_test.rb +1 -1
  66. data/test/integration/subcommands.rb +128 -0
  67. data/test/{test/system → system}/flare_admin_test.rb +7 -5
  68. data/test/{test/unit → unit}/bwlimit_test.rb +0 -0
  69. data/test/{test/unit → unit}/cluster_test.rb +1 -1
  70. data/test/{test/unit → unit}/daemon_test.rb +0 -0
  71. data/test/{test/unit → unit}/logger_test.rb +0 -0
  72. data/test/{test/unit → unit}/tools_test.rb +0 -0
  73. data/test/unit/util/pretty_table_test.rb +46 -0
  74. data/test/{test/unit → unit}/util_test.rb +7 -2
  75. metadata +88 -100
  76. data/PostInstall.txt +0 -7
  77. data/lib/flare/tools/cli/cli_util.rb +0 -77
  78. data/lib/flare/util/command_line.rb +0 -79
@@ -6,68 +6,70 @@
6
6
  require 'flare/util'
7
7
  require 'flare/tools/index_server'
8
8
  require 'flare/tools/cli/sub_command'
9
+ require 'flare/tools/cli/index_server_config'
9
10
 
10
- #
11
11
  module Flare
12
12
  module Tools
13
13
  module Cli
14
14
 
15
- # == Description
16
- #
17
15
  class Deploy < SubCommand
18
16
  include Flare::Util::Conversion
19
17
  include Flare::Util::FileSystem
18
+ include Flare::Tools::Cli::IndexServerConfig
20
19
 
21
20
  myname :deploy
22
21
  desc "deploy for Debian-based system."
23
22
  usage "deploy [hostname:port:balance:partition] ..."
24
-
25
- def setup(opt)
26
- opt.on('--deploy-index', "deploy the index server") {@deploy_index = true}
27
- opt.on('--delete', "delete existing contents before deploying") {@delete = true}
28
- opt.on('--flarei=PATH', "a path for flarei executable") {|v| @flarei = v}
29
- opt.on('--flared=PATH', "a path for flared executable") {|v| @flared = v}
30
- opt.separator('flarei/flared options:')
31
- opt.on('--back-log=BACKLOG', "back log parameter for listen()" ) {|v| @iconf["back-log"] = v}
32
- opt.on('--thread-pool-size=SIZE', "thread pool size" ) {|v| @iconf["thread_pool_size"] = @dconf["thread_pool_size"] = v}
33
- opt.on('--daemonize=BOOL', "daemonize" ) {|v| @iconf["daemonize"] = @dconf["daemonize"] = v}
34
- opt.on('--data-dir=PATH', "data directory" ) {|v| @iconf["data-dir"] = @dconf["data-dir"] = v}
35
- opt.on('--log-facility=NAME', "log facility" ) {|v| @iconf["log-facility"] = @dconf["log-facility"] = v}
36
- opt.on('--max-connection=SIZE', "max connection" ) {|v| @iconf["max-connection"] = @dconf["max-connection"] = v}
37
- opt.on('--net-read-timeout=MILLISECOND', "read timeout for server connections") {|v| @iconf["net-read-timeout"] = @dconf["net-read-timeout"] = v}
38
- opt.on('--stack-size=KB', "stack size" ) {|v| @iconf["stack-size"] = @dconf["stack-size"] = v}
39
- opt.separator('flarei options:')
40
- opt.on('--monitor-threshold=COUNT', "monitor threshold" ) {|v| @iconf["monitor-threshold"] = v}
41
- opt.on('--monitor-interval=SECOND', "monitor interval" ) {|v| @iconf["monitor-interval"] = v}
42
- opt.on('--monitor-read-timeout=MILLISECOND', "monitor read timeout in millisecond") {|v| @iconf["monitor-read-timeout"] = v}
43
- opt.on('--partition-type=NAME', "partition type(modular)" ) {|v| @iconf["partition-type"] = v}
44
- opt.on('--key-hash-algorithm=NAME' "hash algorithm for key distribution") {|v| @iconf["key-hash-algorithm"] = v}
45
- opt.separator('flared options:')
46
- opt.on('--proxy-concurrency=SIZE', "proxy concurrency" ) {|v| @dconf["proxy-concurrency"] = v}
47
- opt.on('--mutex-slot=SIZE', "mutex slot size" ) {|v| @dconf["mutex-slot"]= v}
48
- opt.on('--reconstruction-interval=MICROSEC', "reconstruction interval" ) {|v| @dconf["reconstruction-interval"] = v}
49
- opt.on('--reconstruction-bwlimit=BYTES', "reconstruction bandwitdh limit" ) {|v| @dconf["reconstruction-bwlimit"] = v}
50
- opt.on('--storage-ap=SIZE', "alignment power" ) {|v| @dconf["storage-ap"] = v}
51
- opt.on('--storage-bucket-size=SIZE', "storage bucket size" ) {|v| @dconf["storage-bucket-size"] = v}
52
- opt.on('--storage-cache-size=SIZE', "storage cache size" ) {|v| @dconf["storage-cache-size"] = v}
53
- opt.on('--storage-compress=NAME', "storage compress type(deflate|bz2|tcbs)") {|v| @dconf["storage-compress"] = v}
54
- opt.on('--storage-large', "strage large" ) {@dconf["storage-large"] = true}
55
- opt.on('--storage-type=NAME', "storage type" ) {|v| @dconf["storage-type"] = v}
56
- opt.on('--proxy-prior-netmask=SIZE', "proxy priority mask (ex. 24 for 255.255.255.0)") {|v| @dconf["proxy-prior-netmask"] = v}
57
- opt.on('--max-total-thread-queue=SIZE', "max total thread queue" ) {|v| @dconf["max-total-thread-queue"] = v}
58
- opt.on('--index-servers=NAME', "index servers" ) {|v| @dconf["index-servers"] = v}
59
- opt.on('--noreply-window-limit=SIZE', "noreply window limit (experimental)") {|v| @dconf["noreply-window-limit"] = v}
60
- opt.on('--mysql-replication', "MySQL replication (experimental)" ) {@dconf["mysql-replication"] = true}
61
- opt.on('--mysql-replication-port=PORT', "MySQL replication port (experimental)") {|v| @dconf["mysql-replication-port"] = v}
62
- opt.on('--mysql-replication-id=ID', "MySQL replication ID (experimental)") {|v| @dconf["mysql-replication-id"] = v}
63
- opt.on('--mysql-replication-db=NAME', "MySQL replication DB (experimental)") {|v| @dconf["mysql-replication-db"] = v}
64
- opt.on('--mysql-replication-table=NAME', "MySQL replication table (experimental)") {|v| @dconf["mysql-replication-table"] = v}
65
- opt.on('--proxy-cache-size=SIZE', "proxy cache entry size (experimental)") {|v| @dconf["proxy-cache-size"] = v}
66
- opt.on('--proxy-cache-expire=SECOND', "cache life-time in second (experimental)") {|v| @dconf["proxy-cache-expire"] = v}
23
+
24
+ def setup
25
+ super
26
+ set_option_index_server
27
+ @optp.on('--deploy-index', "deploy the index server") {@deploy_index = true}
28
+ @optp.on('--delete', "delete existing contents before deploying") {@delete = true}
29
+ @optp.on('--flarei=PATH', "a path for flarei executable") {|v| @flarei = v}
30
+ @optp.on('--flared=PATH', "a path for flared executable") {|v| @flared = v}
31
+ @optp.separator('flarei/flared options:')
32
+ @optp.on('--back-log=BACKLOG', "back log parameter for listen()" ) {|v| @iconf["back-log"] = v}
33
+ @optp.on('--thread-pool-size=SIZE', "thread pool size" ) {|v| @iconf["thread_pool_size"] = @dconf["thread_pool_size"] = v}
34
+ @optp.on('--daemonize=BOOL', "daemonize" ) {|v| @iconf["daemonize"] = @dconf["daemonize"] = v}
35
+ @optp.on('--data-dir=PATH', "data directory" ) {|v| @iconf["data-dir"] = @dconf["data-dir"] = v}
36
+ @optp.on('--log-facility=NAME', "log facility" ) {|v| @iconf["log-facility"] = @dconf["log-facility"] = v}
37
+ @optp.on('--max-connection=SIZE', "max connection" ) {|v| @iconf["max-connection"] = @dconf["max-connection"] = v}
38
+ @optp.on('--net-read-timeout=MILLISECOND', "read timeout for server connections") {|v| @iconf["net-read-timeout"] = @dconf["net-read-timeout"] = v}
39
+ @optp.on('--stack-size=KB', "stack size" ) {|v| @iconf["stack-size"] = @dconf["stack-size"] = v}
40
+ @optp.separator('flarei options:')
41
+ @optp.on('--monitor-threshold=COUNT', "monitor threshold" ) {|v| @iconf["monitor-threshold"] = v}
42
+ @optp.on('--monitor-interval=SECOND', "monitor interval" ) {|v| @iconf["monitor-interval"] = v}
43
+ @optp.on('--monitor-read-timeout=MILLISECOND', "monitor read timeout in millisecond") {|v| @iconf["monitor-read-timeout"] = v}
44
+ @optp.on('--partition-type=NAME', "partition type(modular)" ) {|v| @iconf["partition-type"] = v}
45
+ @optp.on('--key-hash-algorithm=NAME' "hash algorithm for key distribution") {|v| @iconf["key-hash-algorithm"] = v}
46
+ @optp.separator('flared options:')
47
+ @optp.on('--proxy-concurrency=SIZE', "proxy concurrency" ) {|v| @dconf["proxy-concurrency"] = v}
48
+ @optp.on('--mutex-slot=SIZE', "mutex slot size" ) {|v| @dconf["mutex-slot"]= v}
49
+ @optp.on('--reconstruction-interval=MICROSEC', "reconstruction interval" ) {|v| @dconf["reconstruction-interval"] = v}
50
+ @optp.on('--reconstruction-bwlimit=BYTES', "reconstruction bandwitdh limit" ) {|v| @dconf["reconstruction-bwlimit"] = v}
51
+ @optp.on('--storage-ap=SIZE', "alignment power" ) {|v| @dconf["storage-ap"] = v}
52
+ @optp.on('--storage-bucket-size=SIZE', "storage bucket size" ) {|v| @dconf["storage-bucket-size"] = v}
53
+ @optp.on('--storage-cache-size=SIZE', "storage cache size" ) {|v| @dconf["storage-cache-size"] = v}
54
+ @optp.on('--storage-compress=NAME', "storage compress type(deflate|bz2|tcbs)") {|v| @dconf["storage-compress"] = v}
55
+ @optp.on('--storage-large', "strage large" ) {@dconf["storage-large"] = true}
56
+ @optp.on('--storage-type=NAME', "storage type" ) {|v| @dconf["storage-type"] = v}
57
+ @optp.on('--proxy-prior-netmask=SIZE', "proxy priority mask (ex. 24 for 255.255.255.0)") {|v| @dconf["proxy-prior-netmask"] = v}
58
+ @optp.on('--max-total-thread-queue=SIZE', "max total thread queue" ) {|v| @dconf["max-total-thread-queue"] = v}
59
+ @optp.on('--index-servers=NAME', "index servers" ) {|v| @dconf["index-servers"] = v}
60
+ @optp.on('--noreply-window-limit=SIZE', "noreply window limit (experimental)") {|v| @dconf["noreply-window-limit"] = v}
61
+ @optp.on('--mysql-replication', "MySQL replication (experimental)" ) {@dconf["mysql-replication"] = true}
62
+ @optp.on('--mysql-replication-port=PORT', "MySQL replication port (experimental)") {|v| @dconf["mysql-replication-port"] = v}
63
+ @optp.on('--mysql-replication-id=ID', "MySQL replication ID (experimental)") {|v| @dconf["mysql-replication-id"] = v}
64
+ @optp.on('--mysql-replication-db=NAME', "MySQL replication DB (experimental)") {|v| @dconf["mysql-replication-db"] = v}
65
+ @optp.on('--mysql-replication-table=NAME', "MySQL replication table (experimental)") {|v| @dconf["mysql-replication-table"] = v}
66
+ @optp.on('--proxy-cache-size=SIZE', "proxy cache entry size (experimental)") {|v| @dconf["proxy-cache-size"] = v}
67
+ @optp.on('--proxy-cache-expire=SECOND', "cache life-time in second (experimental)") {|v| @dconf["proxy-cache-expire"] = v}
67
68
 
68
69
  end
69
70
 
70
71
  def initialize
72
+ super
71
73
  @deploy_index = false
72
74
  @delete = false
73
75
  @flarei = "/usr/local/bin/flarei"
@@ -87,14 +89,14 @@ module Flare
87
89
  f.puts starting
88
90
  end
89
91
  File.chmod(0744, start)
90
-
92
+
91
93
  stop = basedir+"/stop.sh"
92
94
  open(stop, "w") do |f|
93
95
  f.puts "#!/bin/sh"
94
96
  f.puts stopping
95
97
  end
96
98
  File.chmod(0744, stop)
97
-
99
+
98
100
  restart = basedir+"/restart.sh"
99
101
  open(restart, "w") do |f|
100
102
  f.puts "#!/bin/sh"
@@ -105,7 +107,9 @@ module Flare
105
107
  File.chmod(0744, restart)
106
108
  end
107
109
 
108
- def execute(config, *args)
110
+ def execute(config, args)
111
+ parse_index_server(config, args)
112
+
109
113
  if @deploy_index
110
114
  hostname = config[:index_server_hostname]
111
115
  port = config[:index_server_port]
@@ -0,0 +1,101 @@
1
+ require 'optparse'
2
+ require 'resolv'
3
+ require 'flare/tools'
4
+ require 'flare/util/logging'
5
+ require 'flare/util/conversion.rb'
6
+ require 'flare/tools/cli/option'
7
+ require 'flare/util/constant'
8
+
9
+ module Flare; end
10
+ module Flare::Tools; end
11
+ module Flare::Tools::Cli; end
12
+ class Flare::Tools::Cli::Dispatch
13
+ include Flare::Util::Logging
14
+ include Flare::Tools::Cli::Option
15
+ include Flare::Util::Constant
16
+ Cli = Flare::Tools::Cli
17
+
18
+ attr_accessor :subcommands
19
+
20
+ def initialize
21
+ @subcommands = {
22
+ 'list' => Cli::List,
23
+ 'balance' => Cli::Balance,
24
+ 'down' => Cli::Down,
25
+ 'slave' => Cli::Slave,
26
+ 'reconstruct' => Cli::Reconstruct,
27
+ 'master' => Cli::Master,
28
+ 'threads' => Cli::Threads,
29
+ 'ping' => Cli::Ping,
30
+ 'remove' => Cli::Remove,
31
+ 'index' => Cli::Index,
32
+ 'activate' => Cli::Activate,
33
+ 'dump' => Cli::Dump,
34
+ 'dumpkey' => Cli::Dumpkey,
35
+ 'verify' => Cli::Verify,
36
+ 'stats' => Cli::Stats,
37
+ 'restore' => Cli::Restore,
38
+ 'summary' => Cli::Summary,
39
+ 'part' => Cli::Part,
40
+ }
41
+ end
42
+
43
+ def main(subcommand_name, argv, as_subcommand)
44
+ _main(subcommand_name, argv, as_subcommand)
45
+ rescue => e
46
+ level = 1
47
+ error(e.to_s)
48
+ e.backtrace.each do |line|
49
+ error(" %3s: %s" % [level, line])
50
+ level += 1
51
+ end
52
+ raise e if $DEBUG
53
+ STATUS_NG
54
+ end
55
+
56
+ private
57
+
58
+ def _main(subcommand_name, argv, as_subcommand)
59
+ @subcommand_name = subcommand_name
60
+
61
+ subc = dispatch_subcommmand(@subcommand_name)
62
+ unless subc
63
+ show_undefined_command_error(as_subcommand)
64
+ exit STATUS_NG
65
+ end
66
+ set_banner subc.optp, as_subcommand
67
+ config = {
68
+ :command => File.basename($PROGRAM_NAME),
69
+ }
70
+ subc.execute_subcommand(config, argv)
71
+ end
72
+
73
+ def dispatch_subcommmand(name)
74
+ return nil unless @subcommands.include?(name)
75
+ @subcommands[name].new
76
+ end
77
+
78
+ def set_banner(optp, as_subcommand)
79
+ if as_subcommand
80
+ optp.banner = "#{Flare::Tools::TITLE}\nUsage: flare-#{@subcommand_name} [options]"
81
+ else
82
+ optp.banner = "#{Flare::Tools::TITLE}\nUsage: flare-admin #{@subcommand_name} [options]"
83
+ end
84
+ end
85
+
86
+ def show_undefined_command_error(as_subcommand)
87
+ if as_subcommand
88
+ error "unknown subcommand '#{@subcommand_name}'"
89
+ puts "subcommands:"
90
+ @subcommands.each do |name, klass|
91
+ sc = klass.new
92
+ sc.setup
93
+ sc.optp.banner = "[#{klass.to_s}] " + klass.desc
94
+ sc.optp.separator(" Usage: flare-admin " + klass.usage)
95
+ puts sc.optp.help
96
+ end
97
+ else
98
+ puts "unknown command"
99
+ end
100
+ end
101
+ end
@@ -11,30 +11,35 @@ require 'flare/tools/cluster'
11
11
  require 'flare/util/conversion'
12
12
  require 'flare/util/constant'
13
13
  require 'flare/tools/cli/sub_command'
14
+ require 'flare/tools/cli/index_server_config'
14
15
 
15
16
  module Flare
16
17
  module Tools
17
18
  module Cli
18
-
19
+
19
20
  class Down < SubCommand
20
21
  include Flare::Util::Conversion
21
22
  include Flare::Util::Constant
22
23
  include Flare::Tools::Common
23
-
24
+ include Flare::Tools::Cli::IndexServerConfig
25
+
24
26
  myname :down
25
27
  desc "turn down nodes and move them to proxy state."
26
28
  usage "down [hostname:port] ..."
27
-
28
- def setup(opt)
29
- opt.on('--force', "commit changes without confirmation") {@force = true}
29
+
30
+ def setup
31
+ super
32
+ set_option_index_server
33
+ set_option_dry_run
34
+ set_option_force
30
35
  end
31
36
 
32
37
  def initialize
33
38
  super
34
- @force = false
35
39
  end
36
40
 
37
- def execute(config, *args)
41
+ def execute(config, args)
42
+ parse_index_server(config, args)
38
43
  return S_NG if args.size < 1
39
44
 
40
45
  hosts = args.map {|x| x.split(':')}
@@ -44,15 +49,15 @@ module Flare
44
49
  return S_NG
45
50
  end
46
51
  end
47
-
48
- Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], config[:timeout]) do |s|
52
+
53
+ Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
49
54
  cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)
50
-
55
+
51
56
  hosts.each do |hostname,port|
52
57
  down = 'down'
53
58
  nodekey = nodekey_of hostname, port
54
59
  ipaddr = address_of_hostname(hostname)
55
-
60
+
56
61
  unless cluster.has_nodekey? nodekey
57
62
  error "invalid 'hostname:port' pair: #{nodekey}"
58
63
  return S_NG
@@ -69,16 +74,16 @@ module Flare
69
74
  exec = interruptible {(gets.chomp.upcase == "Y")}
70
75
  end
71
76
  if exec
72
- s.set_state(hostname, port, down) unless config[:dry_run]
77
+ s.set_state(hostname, port, down) unless @dry_run
73
78
  end
74
79
  end
75
80
 
76
81
  puts string_of_nodelist(s.stats_nodes, hosts.map {|x| "#{x[0]}:#{x[1]}"})
77
82
  end
78
-
83
+
79
84
  S_OK
80
85
  end # execute()
81
-
86
+
82
87
  end
83
88
  end
84
89
  end
@@ -10,6 +10,7 @@ require 'flare/util/conversion'
10
10
  require 'flare/util/constant'
11
11
  require 'flare/util/bwlimit'
12
12
  require 'flare/tools/cli/sub_command'
13
+ require 'flare/tools/cli/index_server_config'
13
14
  require 'csv'
14
15
 
15
16
  begin
@@ -20,7 +21,7 @@ end
20
21
  module Flare
21
22
  module Tools
22
23
  module Cli
23
-
24
+
24
25
  class Dump < SubCommand
25
26
 
26
27
  class Dumper
@@ -105,19 +106,22 @@ module Flare
105
106
  include Flare::Util::Conversion
106
107
  include Flare::Util::Constant
107
108
  include Flare::Tools::Common
108
-
109
+ include Flare::Tools::Cli::IndexServerConfig
110
+
109
111
  myname :dump
110
112
  desc "dump data from nodes. (experimental)"
111
113
  usage "dump [hostname:port] ..."
112
-
113
- def setup(opt)
114
- opt.on('-o', '--output=FILE', "output to file") {|v| @output = v}
115
- opt.on('-f', '--format=FORMAT', "specify output format [#{Formats.join(',')}]") {|v| @format = v}
116
- opt.on( '--bwlimit=BANDWIDTH', "specify bandwidth limit (bps)") {|v|
114
+
115
+ def setup
116
+ super
117
+ set_option_index_server
118
+ @optp.on('-o', '--output=FILE', "output to file") {|v| @output = v}
119
+ @optp.on('-f', '--format=FORMAT', "specify output format [#{Formats.join(',')}]") {|v| @format = v}
120
+ @optp.on( '--bwlimit=BANDWIDTH', "specify bandwidth limit (bps)") {|v|
117
121
  @bwlimit = Flare::Util::Bwlimit.bps(v)
118
122
  }
119
- opt.on('--all', "dump from all master nodes") {|v| @all = true}
120
- opt.on('--raw', "raw dump mode (for debugging)") {|v| @raw = true}
123
+ @optp.on('--all', "dump from all master nodes") {|v| @all = true}
124
+ @optp.on('--raw', "raw dump mode (for debugging)") {|v| @raw = true}
121
125
  end
122
126
 
123
127
  def initialize
@@ -130,11 +134,12 @@ module Flare
130
134
  @partition_size = 1
131
135
  end
132
136
 
133
- def execute(config, *args)
137
+ def execute(config, args)
138
+ parse_index_server(config, args)
134
139
  STDERR.puts "please install tokyocabinet via gem command." unless defined? TokyoCabinet
135
140
 
136
141
  cluster = nil
137
- Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], config[:timeout]) do |s|
142
+ Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
138
143
  cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)
139
144
  end
140
145
  return S_NG if cluster.nil?
@@ -177,7 +182,7 @@ module Flare
177
182
  return S_NG
178
183
  end
179
184
  end
180
-
185
+
181
186
  dumper = case @format
182
187
  when CsvDumper.myname
183
188
  CsvDumper.new(@output || STDOUT)
@@ -188,7 +193,7 @@ module Flare
188
193
  end
189
194
 
190
195
  hosts.each do |hostname,port,partition|
191
- Flare::Tools::Node.open(hostname, port.to_i, config[:timeout], 0, @bwlimit) do |n|
196
+ Flare::Tools::Node.open(hostname, port.to_i, @timeout, 0, @bwlimit) do |n|
192
197
  interval = 0
193
198
  part, partsize = if @raw
194
199
  [0, 1]
@@ -208,7 +213,7 @@ module Flare
208
213
  end
209
214
 
210
215
  dumper.close
211
-
216
+
212
217
  S_OK
213
218
  end # execute()
214
219
 
@@ -10,29 +10,33 @@ require 'flare/util/conversion'
10
10
  require 'flare/util/constant'
11
11
  require 'flare/util/bwlimit'
12
12
  require 'flare/tools/cli/sub_command'
13
+ require 'flare/tools/cli/index_server_config'
13
14
 
14
15
  require 'csv'
15
16
 
16
17
  module Flare
17
18
  module Tools
18
19
  module Cli
19
-
20
+
20
21
  class Dumpkey < SubCommand
21
22
  include Flare::Util::Conversion
22
23
  include Flare::Util::Constant
23
24
  include Flare::Tools::Common
24
-
25
+ include Flare::Tools::Cli::IndexServerConfig
26
+
25
27
  myname :dumpkey
26
28
  desc "dump key from nodes."
27
29
  usage "dumpkey [hostname:port] ..."
28
-
29
- def setup(opt)
30
- opt.on('-o', '--output=FILE', "output to file" ) {|v| @output = v}
31
- opt.on('-f', '--format=FORMAT', "output format [csv]" ) {|v| @format = v}
32
- opt.on('-p', '--partition=NUMBER', "partition number" ) {|v| @part = v.to_i if v.to_i >= 0}
33
- opt.on('-s', '--partition-size=SIZE', "partition size" ) {|v| @partsize = v.to_i if v.to_i > 0}
34
- opt.on( '--bwlimit=BANDWIDTH', "bandwidth limit (bps)" ) {|v| @bwlimit = v if v.to_i > 0}
35
- opt.on( '--all', "dump form all partitions") {@all = true}
30
+
31
+ def setup
32
+ super
33
+ set_option_index_server
34
+ @optp.on('-o', '--output=FILE', "output to file" ) {|v| @output = v}
35
+ @optp.on('-f', '--format=FORMAT', "output format [csv]" ) {|v| @format = v}
36
+ @optp.on('-p', '--partition=NUMBER', "partition number" ) {|v| @part = v.to_i if v.to_i >= 0}
37
+ @optp.on('-s', '--partition-size=SIZE', "partition size" ) {|v| @partsize = v.to_i if v.to_i > 0}
38
+ @optp.on( '--bwlimit=BANDWIDTH', "bandwidth limit (bps)" ) {|v| @bwlimit = v if v.to_i > 0}
39
+ @optp.on( '--all', "dump form all partitions") {@all = true}
36
40
  end
37
41
 
38
42
  def initialize
@@ -45,9 +49,10 @@ module Flare
45
49
  @all = false
46
50
  end
47
51
 
48
- def execute(config, *args)
52
+ def execute(config, args)
53
+ parse_index_server(config, args)
49
54
  cluster = nil
50
- Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], config[:timeout]) do |s|
55
+ Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
51
56
  cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)
52
57
  end
53
58
  return S_NG if cluster.nil?
@@ -80,9 +85,9 @@ module Flare
80
85
  return S_NG
81
86
  end
82
87
  end
83
-
88
+
84
89
  hosts.each do |hostname,port|
85
- Flare::Tools::Node.open(hostname, port.to_i, config[:timeout], @bwlimit, @bwlimit) do |n|
90
+ Flare::Tools::Node.open(hostname, port.to_i, @timeout, @bwlimit, @bwlimit) do |n|
86
91
  output = STDOUT
87
92
  unless @output.nil?
88
93
  output = File.open(@output, "w")
@@ -106,10 +111,10 @@ module Flare
106
111
  output.close if output != STDOUT
107
112
  end
108
113
  end
109
-
114
+
110
115
  S_OK
111
116
  end # execute()
112
-
117
+
113
118
  end
114
119
  end
115
120
  end