flare-tools 0.1.4 → 0.4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.gemtest +0 -0
  2. data/Flare-tools.txt +0 -0
  3. data/History.txt +114 -2
  4. data/LICENSE +21 -0
  5. data/Manifest.txt +65 -8
  6. data/README.txt +356 -0
  7. data/Rakefile +90 -25
  8. data/Tutorial.txt +370 -0
  9. data/bin/flare-admin +6 -0
  10. data/bin/flare-argv0 +6 -0
  11. data/bin/flare-deploy +6 -0
  12. data/bin/flare-keychecker +6 -0
  13. data/bin/flare-part +6 -0
  14. data/bin/flare-ping +6 -0
  15. data/bin/flare-stats +4 -10
  16. data/bin/flare-zkadmin +6 -0
  17. data/lib/flare/net/connection.rb +98 -0
  18. data/lib/flare/test/cluster.rb +140 -0
  19. data/lib/flare/test/daemon.rb +144 -0
  20. data/lib/flare/test/node.rb +62 -0
  21. data/lib/flare/tools.rb +18 -16
  22. data/lib/flare/tools/cli.rb +32 -0
  23. data/lib/flare/tools/cli/activate.rb +106 -0
  24. data/lib/flare/tools/cli/balance.rb +83 -0
  25. data/lib/flare/tools/cli/cli_util.rb +77 -0
  26. data/lib/flare/tools/cli/deploy.rb +170 -0
  27. data/lib/flare/tools/cli/down.rb +85 -0
  28. data/lib/flare/tools/cli/dump.rb +219 -0
  29. data/lib/flare/tools/cli/dumpkey.rb +117 -0
  30. data/lib/flare/tools/cli/flare_admin.rb +81 -0
  31. data/lib/flare/tools/cli/flare_argv0.rb +60 -0
  32. data/lib/flare/tools/cli/flare_keychecker.rb +106 -0
  33. data/lib/flare/tools/cli/flare_zkadmin.rb +226 -0
  34. data/lib/flare/tools/cli/index.rb +54 -0
  35. data/lib/flare/tools/cli/list.rb +93 -0
  36. data/lib/flare/tools/cli/master.rb +143 -0
  37. data/lib/flare/tools/cli/part.rb +100 -0
  38. data/lib/flare/tools/cli/ping.rb +81 -0
  39. data/lib/flare/tools/cli/reconstruct.rb +164 -0
  40. data/lib/flare/tools/cli/remove.rb +119 -0
  41. data/lib/flare/tools/cli/restore.rb +180 -0
  42. data/lib/flare/tools/cli/slave.rb +125 -0
  43. data/lib/flare/tools/cli/stats.rb +229 -122
  44. data/lib/flare/tools/cli/sub_command.rb +73 -0
  45. data/lib/flare/tools/cli/summary.rb +97 -0
  46. data/lib/flare/tools/cli/threads.rb +78 -0
  47. data/lib/flare/tools/cli/verify.rb +202 -0
  48. data/lib/flare/tools/client.rb +267 -0
  49. data/lib/flare/tools/cluster.rb +319 -0
  50. data/lib/flare/tools/common.rb +196 -0
  51. data/lib/flare/tools/index_server.rb +51 -0
  52. data/lib/flare/tools/node.rb +162 -0
  53. data/lib/flare/tools/stats.rb +75 -0
  54. data/lib/flare/tools/zk_util.rb +28 -0
  55. data/lib/flare/util.rb +34 -0
  56. data/lib/flare/util/bwlimit.rb +132 -0
  57. data/lib/flare/util/command_line.rb +79 -0
  58. data/lib/flare/util/conf.rb +71 -0
  59. data/lib/flare/util/constant.rb +25 -0
  60. data/lib/flare/util/conversion.rb +26 -0
  61. data/lib/flare/util/default_logger.rb +52 -0
  62. data/lib/flare/util/exception.rb +19 -0
  63. data/lib/flare/util/filesystem.rb +30 -0
  64. data/lib/flare/util/flared_conf.rb +33 -0
  65. data/lib/flare/util/flarei_conf.rb +32 -0
  66. data/lib/flare/util/hash_function.rb +32 -0
  67. data/lib/flare/util/interruption.rb +70 -0
  68. data/lib/flare/util/key_resolver.rb +67 -0
  69. data/lib/flare/util/log4r_logger.rb +79 -0
  70. data/lib/flare/util/logger.rb +40 -0
  71. data/lib/flare/util/logging.rb +84 -0
  72. data/lib/flare/util/result.rb +53 -0
  73. data/test/test/experimental/cache_test.rb +113 -0
  74. data/test/test/experimental/key_distribution_test.rb +38 -0
  75. data/test/test/experimental/keychecker_test.rb +60 -0
  76. data/test/test/experimental/list_test.rb +108 -0
  77. data/test/test/extra/replication_test.rb +184 -0
  78. data/test/test/integration/cli_test.rb +348 -0
  79. data/test/test/integration/dump_expired_test.rb +103 -0
  80. data/test/test/integration/dump_test.rb +128 -0
  81. data/test/test/integration/index_server_test.rb +35 -0
  82. data/test/test/integration/node_test.rb +78 -0
  83. data/test/test/integration/partition_test.rb +235 -0
  84. data/test/test/integration/proxy_test.rb +54 -0
  85. data/test/test/integration/stats_test.rb +79 -0
  86. data/test/test/system/flare_admin_test.rb +191 -0
  87. data/test/test/unit/bwlimit_test.rb +52 -0
  88. data/test/test/unit/cluster_test.rb +96 -0
  89. data/test/test/unit/daemon_test.rb +30 -0
  90. data/test/test/unit/logger_test.rb +46 -0
  91. data/test/test/unit/tools_test.rb +25 -0
  92. data/test/test/unit/util_test.rb +70 -0
  93. metadata +239 -84
  94. data/README.rdoc +0 -83
  95. data/bin/flare-partition-setting +0 -12
  96. data/lib/flare/tools/cli/partition_setting.rb +0 -86
  97. data/lib/flare/tools/core.rb +0 -189
  98. data/lib/flare/tools/logger.rb +0 -31
  99. data/test/test_flare-tools.rb +0 -11
  100. data/test/test_helper.rb +0 -3
data/README.rdoc DELETED
@@ -1,83 +0,0 @@
1
- = flare-tools
2
-
3
- * http://github.com/kgws/flare-tools
4
-
5
- == DESCRIPTION:
6
-
7
- Management Tools for Flare
8
-
9
- == SYNOPSIS:
10
-
11
- * flare-stats
12
- $ flare-stats --index-server=flare1.example.com
13
- hostname: port state role partition balance items conn behind hit size uptime version
14
- flare1.example.com:12121 active master 0 1 10000 111 0 100 10 12d 1.0.10
15
- flare2.example.com:12121 active slave 0 1 10000 111 0 100 10 12d 1.0.10
16
- flare3.example.com:12121 active master 1 1 10001 111 0 100 10 12d 1.0.10
17
- flare4.example.com:12121 active slave 1 1 10001 111 0 100 10 12d 1.0.10
18
-
19
- * flare-partition-setting
20
- $ flare-partition-setting --partition=2
21
-
22
- == REQUIREMENTS:
23
-
24
- * Flare >= 1.0.0
25
-
26
- == INSTALL:
27
-
28
- * Install Flare
29
- {Flare}[http://labs.gree.jp/Top/OpenSource/Flare.html]
30
-
31
- * Install flare-tools
32
- # gem install flare-tools
33
-
34
- == AUTHORS:
35
-
36
- * kgws[http://d.hatena.ne.jp/kgws]
37
-
38
- == USAGE:
39
- * flare-stats-nodes
40
- Usage: flare-stats [options]
41
- -h, --help this message show
42
- -d, --debug debug mode on
43
- -w, --warn turn warnings on for this script
44
- --index-server=[HOSTNAME] index server hostname(default:127.0.0.1)
45
- --index-server-port=[PORT] index server port(default:12120)
46
-
47
- * flare-partition-setting
48
- Usage: flare-partition-setting [options]
49
- -h, --help this message show
50
- -d, --debug debug mode on
51
- -w, --warn turn warnings on for this script
52
- -n, --dry-run dry run
53
- --index-server=[HOSTNAME] index server hostname(default:127.0.0.1)
54
- --index-server-port=[PORT] index server port(default:11210)
55
- --partition=partition partition
56
-
57
- == LICENSE:
58
-
59
- (The MIT License)
60
-
61
- Copyright (c) 2010- kgws
62
-
63
- Permission is hereby granted, free of charge, to any person obtaining
64
- a copy of this software and associated documentation files (the
65
- 'Software'), to deal in the Software without restriction, including
66
- without limitation the rights to use, copy, modify, merge, publish,
67
- distribute, sublicense, and/or sell copies of the Software, and to
68
- permit persons to whom the Software is furnished to do so, subject to
69
- the following conditions:
70
-
71
- The above copyright notice and this permission notice shall be
72
- included in all copies or substantial portions of the Software.
73
-
74
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
75
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
77
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
78
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
79
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
80
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81
-
82
- == THANKS:
83
- * Masaki FUJIMOTO (Flare author)
@@ -1,12 +0,0 @@
1
- #! /usr/bin/env ruby
2
- # -*- coding: utf-8; -*-
3
- # Author:: kgws (http://d.hatena.ne.jp/kgws/)
4
- # Copyright:: Copyright (c) 2010- kgws.
5
- # License:: This program is licenced under the same licence as kgws.
6
- #
7
- # $--- flare-partition-setting - [ by Ruby ] $
8
- # vim: foldmethod=marker tabstop=2 shiftwidth=2
9
- $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
10
- require 'flare/tools/cli/partition_setting'
11
-
12
- FlareTools::PartitionSetting.new.execute
@@ -1,86 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- # Author:: kgws (http://d.hatena.ne.jp/kgws/)
3
- # Copyright:: Copyright (c) 2010- kgws.
4
- # License:: This program is licenced under the same licence as kgws.
5
- #
6
- # $--- flare-partition-setting - [ by Ruby ] $
7
- # vim: foldmethod=marker tabstop=2 shiftwidth=2
8
- require 'flare/tools'
9
-
10
- module FlareTools
11
- class PartitionSetting < Core
12
- # {{{ constractor
13
- def initialize()
14
- @partition = 0
15
- @run_flag = true
16
- super
17
- end
18
- # }}}
19
- # {{{ option_on
20
- def option_on
21
- super
22
- @option.on("-n", '--dry-run', "dry run") {@run_flag = false}
23
- @option.on( '--partition=partition', "partition") {|v| @partition = v.to_i}
24
- @option.on( '--index-server=[HOSTNAME]', "index server hostname(default:#{@index_server_hostname})") {|v| @index_server_hostname = v}
25
- @option.on( '--index-server-port=[PORT]', "index server port(default:#{@index_server_port})") {|v| @index_server_port = v.to_i}
26
- end
27
- # }}}
28
- # {{{ option_param_check
29
- def option_param_check
30
- flag = false
31
- if @partition == 0
32
- self.error "specifies the number of partitions"
33
- flag = true
34
- end
35
- if flag
36
- exit 1
37
- end
38
- end
39
- # }}}
40
- # {{{ execute
41
- def execute
42
- servers = self.get_stats_nodes.sort
43
-
44
- # partition size check
45
- unless servers.size % @partition == 0
46
- self.error "Invalid partition setting. nodes_server=[#{servers.size}] partition=[#{@partition}]"
47
- exit 1
48
- end
49
-
50
- server_group_num = servers.size / @partition
51
- partition_num = 0
52
- count = 0
53
- balance = 1
54
- servers.each do |server, stats|
55
- count +=1
56
- if count == 1
57
- state = 'master'
58
- else
59
- state = 'slave'
60
- end
61
- self.debug "index_server=[#{@index_server_hostname}:#{@index_server_port}] server=[#{server}:#{stats['port']}] count=[#{count}] partition_num=[#{partition_num}] server_group
62
- _num=[#{server_group_num}]"
63
-
64
- # nodes group setting
65
- unless self.set_node_role(server, stats['port'], state, balance, partition_num)
66
- self.error "Can't set. server=[#{server}:#{stats['port']} state=[#{state}]] balance=[#{balance}] partition=[#{partition_num}]"
67
- exit 1
68
- end
69
-
70
- # node state active
71
- if state == 'master'
72
- unless self.set_nodes_state(server, stats['port'], "active")
73
- self.error "Unable to activate. server=[#{server}:#{stats['port']}]"
74
- exit 1
75
- end
76
- end
77
-
78
- if server_group_num == count
79
- count = 0
80
- partition_num += 1
81
- end
82
- end
83
- end
84
- # }}}
85
- end
86
- end
@@ -1,189 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- # Author:: kgws (http://d.hatena.ne.jp/kgws/)
3
- # Copyright:: Copyright (c) 2010- kgws.
4
- # License:: This program is licenced under the same licence as kgws.
5
- #
6
- # $--- flare-tools - [ by Ruby ] $
7
- # vim: foldmethod=marker tabstop=2 shiftwidth=2
8
-
9
- module FlareTools
10
- class Core
11
- #{{{ Constructor
12
- def initialize()
13
- @index_server_hostname = '127.0.0.1'
14
- @index_server_port = 12120
15
- @run_flag = true
16
- @timeout = 10
17
- @logger = Logger.new
18
- @option = OptionParser.new
19
- self.option_on
20
- self.option_parse
21
- self.option_param_check
22
- end
23
- # }}}
24
- # {{{ option_on
25
- def option_on
26
- @option.on('-h', '--help', "this message show") {puts @option.help; exit 1}
27
- @option.on('-d', '--debug', "debug mode on") {$DEBUG = true}
28
- @option.on("-w", '--warn', "turn warnings on for this script") {$-w = true}
29
- end
30
- # }}}
31
- # {{{ option_parse
32
- def option_parse
33
- begin
34
- @option.parse!(ARGV)
35
- rescue OptionParser::ParseError => err
36
- puts err.message
37
- puts @option.to_s
38
- exit 1
39
- end
40
- end
41
- # }}}
42
- # {{{ option_param_check
43
- def option_param_check ; end
44
- # }}}
45
- # {{{ str_date
46
- def str_date(date)
47
- date = date.to_i
48
- res = ""
49
- # sec
50
- if date >= 60
51
- date = date / 60
52
- else
53
- return "#{date}s"
54
- end
55
-
56
- # min
57
- if date >= 60
58
- date = date / 60
59
- else
60
- return date + "m"
61
- end
62
-
63
- # hour
64
- if date >= 24
65
- date = date / 24
66
- else
67
- return date + "h"
68
- end
69
-
70
- # day
71
- "#{date}d"
72
- end
73
- # }}}
74
- # {{{ command
75
- def command(host, port, cmd, flag=false, t=10)
76
- @logger.debug "Enter the command server. server=[#{host}:#{port}] command=[#{cmd.strip}]"
77
- return true if @run_flag === false && flag === false
78
- cmd += "\n" unless /\n$/ =~ cmd
79
- str = ""
80
- timeout(t) do
81
- s = TCPSocket.open(host, port)
82
- s.write cmd
83
- while x = s.gets
84
- if x == "OK\r\n" || x == "END\r\n"
85
- break
86
- elsif x == "ERROR\r\n"
87
- self.error "Failed command. server=[#{host}:#{port}] command=[#{cmd.strip}]"
88
- str = false
89
- break
90
- end
91
- str += x
92
- end
93
- s.close
94
- end
95
- str
96
- rescue Errno::ECONNREFUSED
97
- @logger.error "Connection refused. server=[#{host}:#{port}] command=[#{cmd.strip}]"
98
- exit 1
99
- rescue TimeoutError
100
- @logger.error "Connection timeout. server=[#{host}:#{port}] command=[#{cmd.strip}]"
101
- exit 1
102
- end
103
- # }}}
104
- # {{{ get_stats
105
- def get_stats(hostname, port, t=10)
106
- str = self.command(hostname, port, "stats", true, t)
107
- self.stats_parse(str)
108
- end
109
- # }}}
110
- # {{{ get_stats_nodes
111
- def get_stats_nodes(t=10)
112
- str = self.command(@index_server_hostname, @index_server_port, "stats nodes", true, t)
113
- self.stats_nodes_parse(str)
114
- end
115
- # }}}
116
- # {{{ get_stats_threads
117
- def get_stats_threads(t=10)
118
- str = self.command(@index_server_hostname, @index_server_port, "stats threads", true, t)
119
- self.stats_threads_parse(str)
120
- end
121
- # }}}
122
- # {{{ set_node_role
123
- def set_node_role(host, port, state, balance, partition, t=10)
124
- cmd = "node role %s %s %s %s %s\n" % [host, port, state, balance, partition]
125
- self.command(@index_server_hostname, @index_server_port, cmd, false, t)
126
- end
127
- # }}}
128
- # {{{ set_nodes_state
129
- def set_nodes_state(host, port, state="active", t=10)
130
- cmd = "node state %s %s %s\n" % [host, port, state]
131
- self.command(@index_server_hostname, @index_server_port, cmd, false, t)
132
- end
133
- # }}}
134
- # {{{ flush_all
135
- def flush_all(hostname, port, t=10)
136
- self.command(hostname, port, "flush_all", true, t)
137
- end
138
- # }}}
139
- # {{{ dump
140
- def dump(partition, partition_size, wait=0, t=10)
141
- self.command(@index_server_hostname, @index_server_port, cmd, false, t)
142
- end
143
- # }}}
144
- # {{{ stats_parse
145
- def stats_parse(str)
146
- res = {}
147
- str.gsub(/STAT /, '').split("\r\n").each do |x|
148
- key, val = x.split(" ", 2)
149
- res[key] = val
150
- end
151
- res
152
- end
153
- # }}}
154
- # {{{ stats_nodes_parse
155
- def stats_nodes_parse(str)
156
- res = {}
157
- str.gsub(/STAT /, '').split("\r\n").each do |x|
158
- ip, port, stat = x.split(":", 3)
159
- key, val = stat.split(" ")
160
- res["#{ip}:#{port}"] = {} if res["#{ip}:#{port}"].nil?
161
- res["#{ip}:#{port}"]['port'] = port
162
- res["#{ip}:#{port}"][key] = val
163
- end
164
- res
165
- end
166
- # }}}
167
- # {{{ stats_threads_parse
168
- def stats_threads_parse(str)
169
- threads = {}
170
- res = {}
171
- str.gsub(/STAT /, '').split("\r\n").each do |x|
172
- thread_id, stat = x.split(":", 2)
173
- key, val = stat.split(" ")
174
- threads[thread_id] = {} if threads[thread_id].nil?
175
- threads[thread_id][key] = val
176
- end
177
- threads.each do |thread_id, stat|
178
- res[stat['peer']] = {} if res[stat['peer']].nil?
179
- res[stat['peer']]['thread_id'] = thread_id
180
- res[stat['peer']].merge!(stat)
181
- end
182
- res
183
- end
184
- # }}}
185
- # {{{ execute
186
- def execute ; end
187
- # }}}
188
- end
189
- end
@@ -1,31 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- # Author:: kgws (http://d.hatena.ne.jp/kgws/)
3
- # Copyright:: Copyright (c) 2010- kgws.
4
- # License:: This program is licenced under the same licence as kgws.
5
- #
6
- # $--- flare-tools - [ by Ruby ] $
7
- # vim: foldmethod=marker tabstop=2 shiftwidth=2
8
-
9
- module FlareTools
10
- class Logger
11
- #{{{ Constructor
12
- def initialize()
13
- end
14
- # }}}
15
- # {{{ info
16
- def info(msg)
17
- puts "[INFO] #{msg}"
18
- end
19
- # }}}
20
- # {{{ error
21
- def error(msg)
22
- puts "\033[31m[ERROR]\033[m #{msg}"
23
- end
24
- # }}}
25
- # {{{ debug
26
- def debug(msg)
27
- puts "[DEBUG] #{msg}" if $DEBUG
28
- end
29
- # }}}
30
- end
31
- end
@@ -1,11 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestFlareTools < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end
data/test/test_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'stringio'
2
- require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/flare/tools'