drbqs 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'drbqs'
4
+ require 'optparse'
5
+
6
+ Version = '0.0.1'
7
+
8
+ help_message =<<HELP
9
+ #{File.basename(__FILE__)} [uri] [process_number]
10
+ HELP
11
+
12
+ LOG_PREFIX_DEFAULT = 'drbqs_node'
13
+ LOG_LEVEL_DEFAULT = Logger::ERROR
14
+
15
+ options = {
16
+ :log_prefix => LOG_PREFIX_DEFAULT,
17
+ :log_level => LOG_LEVEL_DEFAULT,
18
+ :load => []
19
+ }
20
+
21
+ begin
22
+ OptionParser.new(help_message) do |opt|
23
+ opt.on('-l', '--load FILE', String, 'Add a file to load.') do |v|
24
+ options[:load] << File.expand_path(v)
25
+ end
26
+ opt.on('--log-prefix STR', String, "Set the prefix of log files. The default is '#{LOG_PREFIX_DEFAULT}'.") do |v|
27
+ options[:log_prefix] = v
28
+ end
29
+ opt.on('--log-level LEVEL', String,
30
+ "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") do |v|
31
+ if /^(fatal)|(error)|(warn)|(info)|(debug)$/i =~ v
32
+ options[:log_level] = eval("Logger::#{v.upcase}")
33
+ else
34
+ raise "Invalid log level."
35
+ end
36
+ end
37
+ opt.on('--log-stdout', 'Use stdout for outputting logs. This option cancels --log-prefix.') do |v|
38
+ options[:log_prefix] = nil
39
+ end
40
+ opt.parse!(ARGV)
41
+ end
42
+ rescue OptionParser::InvalidOption
43
+ $stderr.print <<MES
44
+ error: Invalid Option
45
+ #{help_message}
46
+ MES
47
+ exit(2)
48
+ rescue OptionParser::InvalidArgument
49
+ $stderr.print <<MES
50
+ error: Invalid Argument
51
+ #{help_message}
52
+ MES
53
+ exit(2)
54
+ end
55
+
56
+ if ARGV.size > 2
57
+ raise "Too many arguments. Please refer '#{File.basename(__FILE__)} -h'."
58
+ end
59
+
60
+ process_num = 1
61
+ uri = "druby://localhost:#{DRbQS::ROOT_DEFAULT_PORT}"
62
+
63
+ ARGV.each do |arg|
64
+ if /^\d+$/ =~ arg
65
+ process_num = arg.to_i
66
+ else
67
+ uri = arg
68
+ end
69
+ end
70
+
71
+ options[:load].each do |v|
72
+ puts "load #{v}"
73
+ load v
74
+ end
75
+
76
+ puts "Connect to #{uri}"
77
+ puts "Execute #{process_num} processes"
78
+
79
+ if options[:log_prefix]
80
+ if /\/$/ =~ options[:log_prefix]
81
+ options[:log_prefix] += 'out'
82
+ end
83
+ options[:log_prefix] = File.expand_path(options[:log_prefix])
84
+ FileUtils.mkdir_p(File.dirname(options[:log_prefix]))
85
+ end
86
+
87
+ process_num.times do |i|
88
+ fork do
89
+ if options[:log_prefix]
90
+ logfile = "#{options[:log_prefix]}_#{Time.now.strftime("%Y%m%d%H%M")}_#{Process.pid}.log"
91
+ else
92
+ logfile = STDOUT
93
+ end
94
+ client = DRbQS::Client.new(uri, :log_level => options[:log_level], :log_file => logfile)
95
+ client.connect
96
+ client.calculate
97
+ end
98
+ end
99
+
100
+ Process.waitall
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{drbqs}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takayuki YAMAGUCHI"]
12
- s.date = %q{2011-02-27}
12
+ s.date = %q{2011-02-28}
13
+ s.default_executable = %q{drbqs-node}
13
14
  s.description = %q{Queuing system over network that is implemented by dRuby.}
14
15
  s.email = %q{d@ytak.info}
16
+ s.executables = ["drbqs-node"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
19
  "README.rdoc"
@@ -24,15 +26,20 @@ Gem::Specification.new do |s|
24
26
  "README.rdoc",
25
27
  "Rakefile",
26
28
  "VERSION",
29
+ "bin/drbqs-node",
27
30
  "drbqs.gemspec",
28
31
  "lib/drbqs.rb",
32
+ "lib/drbqs/acl_file.rb",
29
33
  "lib/drbqs/client.rb",
30
34
  "lib/drbqs/connection.rb",
31
35
  "lib/drbqs/message.rb",
32
36
  "lib/drbqs/queue.rb",
33
37
  "lib/drbqs/server.rb",
34
38
  "lib/drbqs/task_client.rb",
39
+ "spec/acl_file_spec.rb",
40
+ "spec/data/acl.txt",
35
41
  "spec/drbqs_spec.rb",
42
+ "spec/server_spec.rb",
36
43
  "spec/spec_helper.rb"
37
44
  ]
38
45
  s.homepage = %q{http://github.com/ytaka/drbqs}
@@ -41,7 +48,9 @@ Gem::Specification.new do |s|
41
48
  s.rubygems_version = %q{1.5.2}
42
49
  s.summary = %q{dRuby Queueing System}
43
50
  s.test_files = [
51
+ "spec/acl_file_spec.rb",
44
52
  "spec/drbqs_spec.rb",
53
+ "spec/server_spec.rb",
45
54
  "spec/spec_helper.rb"
46
55
  ]
47
56
 
@@ -9,4 +9,6 @@ require 'rinda/rinda'
9
9
  module DRbQS
10
10
  autoload :Server, 'drbqs/server'
11
11
  autoload :Client, 'drbqs/client'
12
+
13
+ ROOT_DEFAULT_PORT = 13500
12
14
  end
@@ -0,0 +1,13 @@
1
+ module DRbQS
2
+ module ACLFile
3
+
4
+ # Create ACL object from file.
5
+ # The example of file is the following:
6
+ # deny all
7
+ # allow localhost
8
+ # allow 127.0.0.1
9
+ def self.load(path)
10
+ ACL.new(File.read(path).split)
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,6 @@
1
1
  require 'drbqs/message'
2
2
  require 'drbqs/queue'
3
+ require 'drbqs/acl_file'
3
4
 
4
5
  module DRbQS
5
6
  class CheckAlive
@@ -17,27 +18,41 @@ module DRbQS
17
18
  end
18
19
  end
19
20
 
20
- ROOT_DEFAULT_PORT = 13500
21
-
22
21
  class Server
23
22
  attr_reader :queue
24
23
 
25
24
  def initialize(opts = {})
26
25
  @port = opts[:port] || ROOT_DEFAULT_PORT
27
- @acl = opts[:acl]
26
+ @acl = acl_init(opts[:acl])
28
27
  @ts = {
29
28
  :message => Rinda::TupleSpace.new,
30
29
  :queue => Rinda::TupleSpace.new,
31
30
  :result => Rinda::TupleSpace.new
32
31
  }
33
- @logger = Logger.new(opts[:log_file] || 'drbqs_server.log')
34
- @logger.level = opts[:log_level] || Logger::ERROR
32
+ if opts[:log_file]
33
+ @logger = Logger.new(opts[:log_file])
34
+ @logger.level = opts[:log_level] || Logger::ERROR
35
+ else
36
+ @logger = nil
37
+ end
35
38
  @message = MessageServer.new(@ts[:message], @logger)
36
39
  @queue= QueueServer.new(@ts[:queue], @ts[:result], @logger)
37
40
  @check_alive = CheckAlive.new(opts[:check_alive])
38
41
  @empty_queue_hook = nil
39
42
  end
40
43
 
44
+ def acl_init(acl_arg)
45
+ case acl_arg
46
+ when Array
47
+ ACL.new(acl_arg)
48
+ when String
49
+ ACLFile.load(acl_arg)
50
+ else
51
+ nil
52
+ end
53
+ end
54
+ private :acl_init
55
+
41
56
  def start
42
57
  DRb.install_acl(@acl) if @acl
43
58
  uri = "druby://:#{@port}"
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'drbqs/acl_file'
3
+
4
+ describe DRbQS::ACLFile do
5
+ it "should return an ACL object" do
6
+ acl = DRbQS::ACLFile.load(File.dirname(__FILE__) + '/data/acl.txt')
7
+ acl.should be_an_instance_of ACL
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ deny all
2
+ allow localhost
3
+ allow 127.0.0.1
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe DRbQS::Server do
4
+ context "when we setup ACL objects" do
5
+ it "should initialize an ACL object by ACLFile.load" do
6
+ path = File.dirname(__FILE__) + '/data/acl.txt'
7
+ DRbQS::ACLFile.should_receive(:load).with(path)
8
+ DRbQS::Server.new(:acl => path, :log_file => nil)
9
+ end
10
+
11
+ it "should initialize an ACL object by ACL.new" do
12
+ ary = ['deny', 'all', 'allow', 'localhost']
13
+ ACL.should_receive(:new).with(ary)
14
+ DRbQS::Server.new(:acl => ary, :log_file => nil)
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: drbqs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Takayuki YAMAGUCHI
@@ -10,8 +10,8 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-27 00:00:00 +09:00
14
- default_executable:
13
+ date: 2011-02-28 00:00:00 +09:00
14
+ default_executable: drbqs-node
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -70,8 +70,8 @@ dependencies:
70
70
  version_requirements: *id005
71
71
  description: Queuing system over network that is implemented by dRuby.
72
72
  email: d@ytak.info
73
- executables: []
74
-
73
+ executables:
74
+ - drbqs-node
75
75
  extensions: []
76
76
 
77
77
  extra_rdoc_files:
@@ -85,15 +85,20 @@ files:
85
85
  - README.rdoc
86
86
  - Rakefile
87
87
  - VERSION
88
+ - bin/drbqs-node
88
89
  - drbqs.gemspec
89
90
  - lib/drbqs.rb
91
+ - lib/drbqs/acl_file.rb
90
92
  - lib/drbqs/client.rb
91
93
  - lib/drbqs/connection.rb
92
94
  - lib/drbqs/message.rb
93
95
  - lib/drbqs/queue.rb
94
96
  - lib/drbqs/server.rb
95
97
  - lib/drbqs/task_client.rb
98
+ - spec/acl_file_spec.rb
99
+ - spec/data/acl.txt
96
100
  - spec/drbqs_spec.rb
101
+ - spec/server_spec.rb
97
102
  - spec/spec_helper.rb
98
103
  has_rdoc: true
99
104
  homepage: http://github.com/ytaka/drbqs
@@ -109,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
114
  requirements:
110
115
  - - ">="
111
116
  - !ruby/object:Gem::Version
112
- hash: 1630307079048384788
117
+ hash: 4288822500604112980
113
118
  segments:
114
119
  - 0
115
120
  version: "0"
@@ -127,5 +132,7 @@ signing_key:
127
132
  specification_version: 3
128
133
  summary: dRuby Queueing System
129
134
  test_files:
135
+ - spec/acl_file_spec.rb
130
136
  - spec/drbqs_spec.rb
137
+ - spec/server_spec.rb
131
138
  - spec/spec_helper.rb