royw-drbman 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,47 @@
3
3
  Support for running ruby tasks via drb (druby) on multiple cores and/or systems.
4
4
 
5
5
  Drbman provides:
6
- * the infrastructure for pushing ruby code to remote systems,
7
- * installing remote gems
6
+ * the infrastructure for pushing drb servers to remote systems,
7
+ * checking that gems are installed on remote systems,
8
8
  * starting and stopping the remote drb server(s)
9
- * cleaning up the remote system by removing any artifacts used
9
+ * cleaning up the remote system by stopping and removing drb servers
10
10
 
11
+ == Usage
12
+
13
+ An article on using drbman is available at: http://royw.wordpress.com/2009/07/15/a-manager-for-drb/
14
+
15
+ In a nut shell, write your drb server object then add:
16
+
17
+ require 'drbman_server'
18
+
19
+ class YourServer
20
+ include DrbmanServer
21
+ ...
22
+ end
23
+ DrbmanServer.start_service(YourServer)
24
+
25
+
26
+ Next in your client app set up: choices[:hosts], choices[:dirs], choices[:run], choices[:gems]
27
+
28
+ Then create a Drbman instance and use it:
29
+
30
+ Drbman.new(@logger, choices) do |drbman|
31
+ loop do
32
+ drbman.get_object do |your_drb_server|
33
+ your_drb_server.your_method
34
+ end
35
+ end
36
+ end
37
+
38
+ == Installation
39
+
40
+ sudo gem install royw-drbman --source http://gems.github.com
41
+
42
+ == Notes
43
+
44
+ drbman uses yard comments so you can generate yard documents using:
45
+
46
+ rake yardoc
11
47
 
12
48
  == Copyright
13
49
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{drbman}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Roy Wright"]
9
- s.date = %q{2009-07-16}
9
+ s.date = %q{2009-07-17}
10
10
  s.default_executable = %q{drbman}
11
11
  s.email = %q{roy@wright.org}
12
12
  s.executables = ["drbman"]
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
23
23
  "VERSION",
24
24
  "bin/drbman",
25
25
  "drbman.gemspec",
26
+ "examples/primes/LICENSE",
27
+ "examples/primes/README.rdoc",
26
28
  "examples/primes/VERSION",
27
29
  "examples/primes/bin/primes",
28
30
  "examples/primes/lib/drb_server/prime_helper.rb",
@@ -34,6 +36,7 @@ Gem::Specification.new do |s|
34
36
  "examples/primes/spec/primes_spec.rb",
35
37
  "examples/primes/spec/spec_helper.rb",
36
38
  "examples/primes/stress_test.rb",
39
+ "lib/drb_server/drbman_server.rb",
37
40
  "lib/drbman.rb",
38
41
  "lib/drbman/cli.rb",
39
42
  "lib/drbman/drb_pool.rb",
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Roy Wright
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ = primes
2
+
3
+ Primes is an example of using drbman to parallelize part of an application across one or more systems.
4
+
5
+ == Usage
6
+
7
+ N is the upper bound on the primes you want to find. For example to
8
+ find all primes below 200, N would be 200.
9
+
10
+ single drb instance on localhost using ssh public key authentication:
11
+ bin/primes N
12
+ or
13
+ bin/primes N -H localhost
14
+
15
+ two drb instances on localhost using ssh public key authentication:
16
+ bin/primes N -H localhost,localhost
17
+
18
+ three drb instances on remote hosts using ssh public key authentication:
19
+ bin/primes N -H one.example.com,two.example.com,three.example.com
20
+
21
+ single drb instance on remote host using different account and ssh public key authentication:
22
+ bin/primes H -H username@example.com
23
+
24
+ single drb instance on remote host using ssh passward authentication:
25
+ bin/primes H -H username:sekret@example.com
26
+
27
+ help
28
+ bin/primes --help
29
+
30
+ == Installation
31
+
32
+ primes is installed as an example in drbman
33
+
34
+ == Notes
35
+
36
+ primes uses yard comments so you can generate yard documents using:
37
+
38
+ rake yardoc
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2009 Roy Wright. See LICENSE for details.
@@ -1,4 +1,4 @@
1
- require 'drb'
1
+ require 'drbman_server'
2
2
 
3
3
  # A helper object for calculating primes using the Sieve of Eratosthenes
4
4
  #
@@ -13,7 +13,7 @@ require 'drb'
13
13
  # will run the service as: druby://localhost:9000
14
14
  #
15
15
  class PrimeHelper
16
- attr_accessor :name
16
+ include DrbmanServer
17
17
 
18
18
  # Find the multiples of the give prime number that are less than the
19
19
  # given maximum.
@@ -27,18 +27,6 @@ class PrimeHelper
27
27
  2.upto((maximum - 1) / prime) { |i| a << (i * prime) }
28
28
  a
29
29
  end
30
-
31
- # Stop the DRb service
32
- def stop_service
33
- DRb.stop_service
34
- end
35
30
  end
36
31
 
37
- machine = 'localhost'
38
- machine = ARGV[0] unless ARGV.length < 1
39
- port = 9000
40
- port = ARGV[1] unless ARGV.length < 2
41
- server = PrimeHelper.new
42
- server.name = "druby://#{machine}:#{port}"
43
- DRb.start_service(server.name, server)
44
- DRb.thread.join
32
+ DrbmanServer.start_service(PrimeHelper)
@@ -1,3 +1,4 @@
1
+ # The command line interface for running Primes
1
2
  class CLI < UserChoices::Command
2
3
  include UserChoices
3
4
  include Singleton
@@ -1,4 +1,7 @@
1
1
  module Kernel
2
+ # adds a elapse time method
3
+ # @yield the block to find the execution elapsed time of
4
+ # @return [Float] the number of seconds the block took to execute
2
5
  def elapse(&block)
3
6
  seconds = 0
4
7
  unless block.nil?
@@ -1,7 +1,19 @@
1
-
1
+ # == Synopsis
2
+ # Calculate the prime numbers less than a given maximum integer.
3
+ #
4
+ # @example
5
+ # choices = {}
6
+ # choices[:max_integer] = 20
7
+ # sieve = Primes.new(@logger, choices)
8
+ # primes = sieve.execute
9
+ # # primes => [2,3,5,7,11,13,17,19]
10
+ #
11
+ # Note, uses the Command design pattern
2
12
  class Primes
3
13
  attr_reader :primes_elapse_time
4
-
14
+
15
+ # @param [Logger] logger the logger to use
16
+ # @param choices {see SieveOfEratosthenes#Initialize}
5
17
  def initialize(logger, choices)
6
18
  @logger = logger
7
19
  @user_choices = choices
@@ -14,6 +26,4 @@ class Primes
14
26
  @primes_elapse_time = sieve.primes_elapse_time
15
27
  result
16
28
  end
17
-
18
-
19
29
  end
@@ -52,6 +52,10 @@ class SieveOfEratosthenes
52
52
 
53
53
  private
54
54
 
55
+ # recursive prime calculation
56
+ # @param maximum (see #initialize)
57
+ # @param [Drbman] drbman the drb manager instance
58
+ # @return [Array<Integer>] the array of primes
55
59
  def primes(maximum, drbman)
56
60
  indices = []
57
61
  if maximum > 2
@@ -62,11 +66,14 @@ class SieveOfEratosthenes
62
66
  indices
63
67
  end
64
68
 
65
- # when n = 20
66
- # sqr_primes = [2,3]
67
- # composites = [[2*2, 2*3, 2*4,...,2*9], [3*2, 3*3, 3*4,...,3*6]]
68
- # returns Array
69
+ # find the composites array
70
+ # @param maximum (see #initialize)
71
+ # @param drbman (see #primes)
72
+ # @return [Array<Integer>] the composites array
69
73
  def calc_composites(maximum, drbman)
74
+ # when n = 20
75
+ # sqr_primes = [2,3]
76
+ # composites = [[2*2, 2*3, 2*4,...,2*9], [3*2, 3*3, 3*4,...,3*6]]
70
77
  sqr_primes = primes(Math.sqrt(maximum).to_i, drbman)
71
78
  composites = []
72
79
  threads = []
@@ -87,6 +94,9 @@ class SieveOfEratosthenes
87
94
  composites
88
95
  end
89
96
 
97
+ # sift the indices to find the primes
98
+ # @param [Array<Integer>] flat_comps the flattened composites array
99
+ # @param maximum (see #initialize)
90
100
  def calc_indices(flat_comps, maximum)
91
101
  indices = []
92
102
  flags = Array.new(maximum, true)
@@ -0,0 +1,22 @@
1
+ require 'drb'
2
+
3
+ module DrbmanServer
4
+ attr_accessor :name
5
+ # Stop the DRb service
6
+ def stop_service
7
+ DRb.stop_service
8
+ end
9
+
10
+ def start_service(klass)
11
+ machine = 'localhost'
12
+ machine = ARGV[0] unless ARGV.length < 1
13
+ port = 9000
14
+ port = ARGV[1] unless ARGV.length < 2
15
+ server = klass.new
16
+ server.name = "druby://#{machine}:#{port}"
17
+ # puts server.inspect
18
+ DRb.start_service(server.name, server)
19
+ DRb.thread.join
20
+ end
21
+ module_function :start_service
22
+ end
@@ -20,6 +20,7 @@ require 'net/ssh'
20
20
  require 'net/scp'
21
21
  require 'daemons'
22
22
  require 'uuidtools'
23
+ require 'tempfile'
23
24
 
24
25
  # require all of the .rb files in the drbman/ subdirectory
25
26
  Dir.glob(File.join(File.dirname(__FILE__), 'drbman/**/*.rb')).each do |name|
@@ -1,7 +1,7 @@
1
1
  # require 'commandline/optionparser'
2
2
 
3
3
  # == Synopsis
4
- # The Command Line Interface
4
+ # The Command Line Interface for Drbman
5
5
  class CLI < UserChoices::Command
6
6
  include UserChoices
7
7
  include Singleton
@@ -164,14 +164,20 @@ class Drbman
164
164
  end
165
165
  end
166
166
  end
167
-
167
+
168
168
  # Create the daemon controller on the host machine
169
169
  # @param [HostMachine] host the host machine
170
170
  def create_controller(host)
171
171
  unless @user_choices[:run].blank?
172
172
  host.controller = File.basename(@user_choices[:run], '.*') + '_controller.rb'
173
- controller = "require 'rubygems' ; require 'daemons' ; Daemons.run('#{@user_choices[:run]}')"
174
- host.sh("cd #{host.dir};echo \"#{controller}\" > #{host.controller}")
173
+ tempfile = Tempfile.new('controller')
174
+ tempfile.puts "require 'rubygems'"
175
+ tempfile.puts "require 'daemons'"
176
+ tempfile.puts "$LOAD_PATH.unshift(File.expand_path(File.dirname('#{@user_choices[:run]}')))"
177
+ tempfile.puts "Daemons.run('#{@user_choices[:run]}')"
178
+ tempfile.close
179
+ host.upload(tempfile.path, host.dir)
180
+ host.sh("cd #{host.dir};mv #{File.basename(tempfile.path)} #{host.controller}")
175
181
  end
176
182
  end
177
183
 
@@ -180,9 +186,11 @@ class Drbman
180
186
  # @param [HostMachine] host the host machine
181
187
  def upload_dirs(host)
182
188
  unless @user_choices[:dirs].blank?
189
+ drb_server_file = File.join(File.dirname(__FILE__), "../drb_server/drbman_server.rb")
183
190
  @user_choices[:dirs].each do |name|
184
191
  if File.directory?(name)
185
192
  host.upload(name, "#{host.dir}/#{File.basename(name)}")
193
+ host.upload(drb_server_file, "#{host.dir}/#{File.basename(name)}")
186
194
  else
187
195
  @logger.error { "\"#{name}\" is not a directory" }
188
196
  end
@@ -73,6 +73,8 @@ class HostMachine
73
73
  connect
74
74
  end
75
75
  yield self
76
+ rescue Net::SSH::AuthenticationFailed => e
77
+ @logger.error { "Authentication Failed" }
76
78
  rescue Exception => e
77
79
  @logger.error { e }
78
80
  @logger.error { e.backtrace.join("\n") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: royw-drbman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Wright
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-16 00:00:00 -07:00
12
+ date: 2009-07-17 00:00:00 -07:00
13
13
  default_executable: drbman
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,8 @@ files:
90
90
  - VERSION
91
91
  - bin/drbman
92
92
  - drbman.gemspec
93
+ - examples/primes/LICENSE
94
+ - examples/primes/README.rdoc
93
95
  - examples/primes/VERSION
94
96
  - examples/primes/bin/primes
95
97
  - examples/primes/lib/drb_server/prime_helper.rb
@@ -101,6 +103,7 @@ files:
101
103
  - examples/primes/spec/primes_spec.rb
102
104
  - examples/primes/spec/spec_helper.rb
103
105
  - examples/primes/stress_test.rb
106
+ - lib/drb_server/drbman_server.rb
104
107
  - lib/drbman.rb
105
108
  - lib/drbman/cli.rb
106
109
  - lib/drbman/drb_pool.rb