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
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ doc
2
+ pkg
3
+ work/*.log
4
+ work/*
5
+ *.gem
6
+ *.rbc
7
+ .bundle
8
+ .config
9
+ .yardoc
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ *.bundle
21
+ *.so
22
+ *.o
23
+ *.a
24
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.8.7
5
+ - 2.0.0
6
+ - 2.1.3
7
+ before_install:
8
+ - travis_retry sudo apt-get update
9
+ - travis_retry sudo apt-get install libtokyocabinet-dev
10
+ - travis_retry sudo apt-get install libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-thread-dev
11
+ - travis_retry sudo apt-get install uuid-dev
12
+ - git clone https://github.com/gree/flare.git flare
13
+ - (cd flare && ./autogen.sh)
14
+ - (cd flare && ./configure)
15
+ - (cd flare && sudo make install)
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'log4r'
4
+ gem 'zookeeper', '>=1.2.6'
5
+ gem 'tokyocabinet', '>=1.29'
6
+ gem 'rdoc'
7
+ gem 'test-unit'
8
+ gem 'ci_reporter', '=1.9.3'
9
+ gem 'rake'
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ builder (3.2.2)
5
+ ci_reporter (1.9.3)
6
+ builder (>= 2.1.2)
7
+ json (1.8.1)
8
+ log4r (1.1.10)
9
+ power_assert (0.1.4)
10
+ rake (10.3.2)
11
+ rdoc (4.1.2)
12
+ json (~> 1.4)
13
+ test-unit (3.0.1)
14
+ power_assert
15
+ tokyocabinet (1.29.1)
16
+ zookeeper (1.4.9)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ ci_reporter (= 1.9.3)
23
+ log4r
24
+ rake
25
+ rdoc
26
+ test-unit
27
+ tokyocabinet (>= 1.29)
28
+ zookeeper (>= 1.2.6)
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.5.0 / 2014-10-15
2
+ * Refactoring structures
3
+ * Refactoring.
4
+ * Replaced gem packaging tool. Use bundler instead of hoe & newgem.
5
+
1
6
  === 0.4.5 / 2012-10-17
2
7
  * Minor Enhancements
3
8
  * Fixed install target of Makefile.
data/Makefile ADDED
@@ -0,0 +1,25 @@
1
+
2
+ BINDIR=/usr/bin
3
+ RUBYLIBDIR=/usr/lib/ruby/${RUBYVER}
4
+ SRCDIR=.
5
+ BINS=flare-admin flare-argv0 flare-deploy flare-keychecker flare-part flare-ping flare-stats flare-zkadmin
6
+
7
+ install:
8
+ install -d ${DESTDIR}${BINDIR}
9
+ install -m 755 ${SRCDIR}/bin/* ${DESTDIR}${BINDIR}
10
+ echo ${addprefix ${DESTDIR}${BINDIR}/,${BINS}} | xargs -n 1 sed -i 1c\#!/usr/bin/ruby${RUBYVER}
11
+ install -d ${DESTDIR}${RUBYLIBDIR}/flare
12
+ install -m 644 ${SRCDIR}/lib/flare/*.rb ${DESTDIR}${RUBYLIBDIR}/flare
13
+ install -d ${DESTDIR}${RUBYLIBDIR}/flare/tools
14
+ install -m 644 ${SRCDIR}/lib/flare/tools/*.rb ${DESTDIR}${RUBYLIBDIR}/flare/tools
15
+ install -d ${DESTDIR}${RUBYLIBDIR}/flare/tools/cli
16
+ install -m 644 ${SRCDIR}/lib/flare/tools/cli/*.rb ${DESTDIR}${RUBYLIBDIR}/flare/tools/cli
17
+ install -d ${DESTDIR}${RUBYLIBDIR}/flare/util
18
+ install -m 644 ${SRCDIR}/lib/flare/util/*.rb ${DESTDIR}${RUBYLIBDIR}/flare/util
19
+ install -d ${DESTDIR}${RUBYLIBDIR}/flare/net
20
+ install -m 644 ${SRCDIR}/lib/flare/net/*.rb ${DESTDIR}${RUBYLIBDIR}/flare/net
21
+ install -d ${DESTDIR}${RUBYLIBDIR}/flare/test
22
+ install -m 644 ${SRCDIR}/lib/flare/test/*.rb ${DESTDIR}${RUBYLIBDIR}/flare/test
23
+
24
+ clean:
25
+
data/README.txt CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  = flare-tools
4
4
 
5
- http://labs.gree.jp/Top/OpenSource/Flare-en.html
5
+ https://github.com/gree/flare/wiki
6
6
 
7
7
  Flare-tools is a collection of command line tools to maintain a flare cluster.
8
8
 
@@ -38,7 +38,7 @@ License:: MIT-style
38
38
 
39
39
  * Install Flare
40
40
 
41
- Please see the web pages about {Flare}[http://labs.gree.jp/Top/OpenSource/Flare-en.html] in GREE Labs.
41
+ Please see the web pages about {Flare}[https://github.com/gree/flare/wiki].
42
42
 
43
43
  * Install flare-tools
44
44
  # gem install flare-tools
data/Rakefile CHANGED
@@ -1,37 +1,36 @@
1
1
 
2
- $LOAD_PATH.unshift File.dirname(__FILE__)+"/lib"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
3
3
 
4
4
  require 'rubygems'
5
- gem 'hoe', '>= 2.1.0'
6
- require 'hoe'
7
- gem 'rdoc'
5
+ require 'bundler/setup'
6
+ require "bundler/gem_tasks"
8
7
  require 'rdoc'
9
8
  require 'rdoc/markup'
10
9
  require 'rdoc/markup/formatter'
11
10
  require 'rdoc/markup/to_ansi'
11
+ require 'rake/testtask'
12
+ require 'ci/reporter/rake/test_unit_loader'
12
13
 
13
14
  require 'fileutils'
14
15
  require 'flare/tools'
15
16
 
16
- Hoe.plugin :newgem
17
-
18
- $hoe = Hoe.spec 'flare-tools' do
19
- self.version = Flare::Tools::VERSION
20
- self.developer 'kikehara', 'kiyoshi.ikehara@gree.net'
21
- self.urls = ['http://github.com/gree/flare-tools']
22
- self.summary = "Management Tools for Flare"
23
- self.post_install_message = 'PostInstall.txt'
24
- self.description = "Flare-tools is a collection of tools for Flare distributed key-value store."
25
- self.readme_file = "README.txt"
26
- self.extra_deps = [['log4r', '>= 1.1.4'], ['zookeeper', '>= 1.2.6'], ['tokyocabinet', '>= 1.29']]
27
- self.rubyforge_name = 'flare-tools'
28
- self.extra_rdoc_files = []
29
- end
30
-
31
- require 'newgem/tasks'
32
17
  Dir['tasks/**/*.rake'].each { |t| load t }
33
18
 
34
- task :default => [:spec, :features]
19
+ task :default => [:test]
20
+
21
+ task :help do
22
+ print <<EOS
23
+ Examples:
24
+ run a specific test script
25
+ > rake test TEST=testname_test.rb
26
+ run a specific test
27
+ > rake test TESTOPTS=--name=test_mytest1
28
+ run tests with --verbose
29
+ > rake test TESTOPTS=--verbose
30
+ run stress tests
31
+ > rake test FLARE_TOOLS_STRESS_TEST=yes
32
+ EOS
33
+ end
35
34
 
36
35
  task :manual do
37
36
  h = RDoc::Markup::ToAnsi.new
@@ -39,25 +38,23 @@ task :manual do
39
38
  puts h.convert(rdoc)
40
39
  end
41
40
 
42
- task :test do
43
- sh "(cd test && rake)"
41
+ Rake::TestTask.new do |test|
42
+ test.libs << './lib'
43
+ test.test_files = Dir['test/unit/**/*_test.rb', 'test/integration/**/*_test.rb', 'test/system/**/*_test.rb']
44
+ test.verbose = true
45
+ test.ruby_opts = ['-r', 'rubygems']
44
46
  end
45
47
 
46
- task :stress_test do
47
- sh "(cd test && rake stress)"
48
- end
48
+ task :test => :work
49
49
 
50
- task :clean do
51
- sh "(cd test && rake clean)"
52
- end
50
+ directory "work"
53
51
 
54
- task :manifest_post do
55
- sh "grep -ve '^debian' Manifest.txt| grep -ve '^test' | grep -ve '^package' | grep -ve '^Makefile' | grep -v '#\$' > Manifest.tmp"
56
- sh "mv Manifest.tmp Manifest.txt"
52
+ task :clean do
53
+ sh "rm -rf test/work/test*"
54
+ sh "rm -f test/*~"
55
+ sh "rm -f /tmp/flare[id].*.conf"
57
56
  end
58
57
 
59
- task :install => [:manifest, :manifest_post, :install_gem]
60
-
61
58
  task :debuild do |t|
62
59
  sh "debuild -us -uc"
63
60
  end
@@ -84,6 +81,11 @@ task :change do
84
81
  sh "git-dch --debian-branch='#{debian_branch}' --new-version #{version} --since=#{since}"
85
82
  end
86
83
 
84
+ task :killall do
85
+ sh "pkill /usr/local/bin/flarei"
86
+ sh "pkill /usr/local/bin/flared"
87
+ end
88
+
87
89
  task :cleanall => [:clean] do
88
90
  end
89
91
 
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.dirname(__FILE__) + '/lib'
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flare/tools'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flare-tools"
8
+ spec.version = Flare::Tools::VERSION
9
+ spec.authors = ["kikehara", "Yuya YAGUCHI"]
10
+ spec.email = ["kiyoshi.ikehara@gree.net", "yuya.yaguchi@gree.net"]
11
+ spec.summary = "Management Tools for Flare"
12
+ spec.description = "Flare-tools is a collection of tools for Flare distributed key-value store."
13
+ spec.homepage = "http://github.com/gree/flare-tools"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'log4r', '>= 1.1.10'
22
+ spec.add_dependency 'tokyocabinet', '>= 1.29'
23
+
24
+ spec.add_development_dependency "bundler", ">= 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,4 @@
1
+ module Flare; end
2
+ module Flare::Entity; end
3
+ class Flare::Entity::Server < Struct.new(:host, :port)
4
+ end
data/lib/flare/tools.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8; -*-
2
2
  # Authors:: Kiyoshi Ikehara <kiyoshi.ikehara@gree.net>
3
- # Copyright:: Copyright (C) GREE, Inc. 2011.
3
+ # Copyright:: Copyright (C) GREE, Inc. 2011-2014.
4
4
  # License:: MIT-style
5
5
 
6
6
  #
@@ -9,8 +9,8 @@ module Flare
9
9
  # flare-tools module.
10
10
  module Tools
11
11
  # the version number of flare-tools
12
- VERSION = '0.4.5.1'
13
- TITLE = "Flare-tools version #{VERSION} Copyright (C) GREE, Inc. 2011"
12
+ VERSION = '0.5.0'
13
+ TITLE = "Flare-tools version #{VERSION} Copyright (C) GREE, Inc. 2011-2014"
14
14
  autoload :Common, 'flare/tools/common'
15
15
  autoload :Cluster, 'flare/tools/cluster'
16
16
  autoload :Stats, 'flare/tools/stats'
@@ -25,6 +25,7 @@ module Flare
25
25
  autoload :Verify, 'flare/tools/cli/verify'
26
26
  autoload :Restore, 'flare/tools/cli/restore'
27
27
  autoload :Summary, 'flare/tools/cli/summary'
28
+ autoload :Part, 'flare/tools/cli/part'
28
29
  end
29
30
  end
30
31
  end
@@ -11,23 +11,28 @@ 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 Activate < SubCommand
20
21
  include Flare::Util::Conversion
21
22
  include Flare::Util::Constant
22
23
  include Flare::Util::Logging
23
24
  include Flare::Tools::Common
24
-
25
+ include Flare::Tools::Cli::IndexServerConfig
26
+
25
27
  myname :activate
26
28
  desc "activate "
27
29
  usage "activate [hostname:port] ..."
28
-
29
- def setup(opt)
30
- opt.on('--force', "commit changes without confirmation") {@force = true}
30
+
31
+ def setup
32
+ super
33
+ set_option_index_server
34
+ set_option_dry_run
35
+ set_option_force
31
36
  end
32
37
 
33
38
  def initialize
@@ -35,7 +40,8 @@ module Flare
35
40
  @force = false
36
41
  end
37
42
 
38
- def execute(config, *args)
43
+ def execute(config, args)
44
+ parse_index_server(config, args)
39
45
  return S_NG if args.size < 1
40
46
 
41
47
  hosts = args.map {|x| x.split(':')}
@@ -45,15 +51,15 @@ module Flare
45
51
  return S_NG
46
52
  end
47
53
  end
48
-
49
- Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], config[:timeout]) do |s|
54
+
55
+ Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
50
56
  cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)
51
57
  nodes = s.stats_nodes.sort_by{|key, val| [val['partition'], val['role'], key]}
52
-
58
+
53
59
  hosts.each do |hostname,port|
54
60
  nodekey = nodekey_of hostname, port
55
61
  ipaddr = address_of_hostname(hostname)
56
-
62
+
57
63
  unless cluster.has_nodekey? nodekey
58
64
  error "invalid 'hostname:port' pair: #{nodekey}"
59
65
  return S_NG
@@ -71,7 +77,7 @@ module Flare
71
77
  (gets.chomp.upcase == "Y")
72
78
  }
73
79
  end
74
- if exec && !config[:dry_run]
80
+ if exec && !@dry_run
75
81
  if @force
76
82
  begin
77
83
  s.set_state(hostname, port, 'active')
@@ -96,10 +102,10 @@ module Flare
96
102
 
97
103
  STDOUT.puts string_of_nodelist(s.stats_nodes, hosts.map {|x| "#{x[0]}:#{x[1]}"})
98
104
  end
99
-
105
+
100
106
  S_OK
101
107
  end # execute()
102
-
108
+
103
109
  end
104
110
  end
105
111
  end
@@ -9,6 +9,7 @@ require 'flare/tools/common'
9
9
  require 'flare/util/conversion'
10
10
  require 'flare/util/constant'
11
11
  require 'flare/tools/cli/sub_command'
12
+ require 'flare/tools/cli/index_server_config'
12
13
 
13
14
  module Flare
14
15
  module Tools
@@ -17,20 +18,26 @@ module Flare
17
18
  include Flare::Util::Conversion
18
19
  include Flare::Util::Constant
19
20
  include Flare::Tools::Common
21
+ include Flare::Tools::Cli::IndexServerConfig
20
22
 
21
23
  myname :balance
22
24
  desc "set the balance values of nodes."
23
25
  usage "balance [hostname:port:balance] ..."
24
26
 
25
- def setup(opt)
26
- opt.on('--force', "commit changes without confirmation") {@force = true}
27
+ def setup
28
+ super
29
+ set_option_index_server
30
+ set_option_dry_run
31
+ set_option_force
27
32
  end
28
33
 
29
34
  def initialize
35
+ super
30
36
  @force = false
31
37
  end
32
-
33
- def execute(config, *args)
38
+
39
+ def execute(config, args)
40
+ parse_index_server(config, args)
34
41
  return S_NG if args.empty?
35
42
 
36
43
  hosts = args.map {|x| x.to_s.split(':')}
@@ -40,15 +47,15 @@ module Flare
40
47
  return S_NG
41
48
  end
42
49
  end
43
-
44
- Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], config[:timeout]) do |s|
50
+
51
+ Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
45
52
  cluster = Flare::Tools::Cluster.new(s.host, s.port, s.stats_nodes)
46
53
 
47
54
  hosts.each do |hostname,port,balance|
48
55
  balance = balance.to_i
49
56
  nodekey = nodekey_of hostname, port
50
57
  ipaddr = address_of_hostname(hostname)
51
-
58
+
52
59
  unless cluster.has_nodekey? nodekey
53
60
  error "unknown host: #{nodekey}"
54
61
  return S_NG
@@ -68,7 +75,7 @@ module Flare
68
75
  end
69
76
  end
70
77
  if exec
71
- s.set_role(hostname, port.to_i, node['role'], balance, node['partition']) unless config[:dry_run]
78
+ s.set_role(hostname, port.to_i, node['role'], balance, node['partition']) unless @dry_run
72
79
  end
73
80
  end
74
81
  STDOUT.puts string_of_nodelist(s.stats_nodes, hosts.map {|x| "#{x[0]}:#{x[1]}"})