drbqs 0.0.8 → 0.0.9
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.
- data/README.md +151 -0
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/bin/drbqs-manage +27 -7
- data/bin/drbqs-node +1 -0
- data/drbqs.gemspec +25 -7
- data/example/transfer/file.rb +46 -0
- data/example/transfer/server_def.rb +19 -0
- data/lib/drbqs.rb +5 -2
- data/lib/drbqs/client.rb +14 -1
- data/lib/drbqs/config.rb +15 -3
- data/lib/drbqs/manage.rb +50 -3
- data/lib/drbqs/message.rb +26 -1
- data/lib/drbqs/node_list.rb +25 -0
- data/lib/drbqs/queue.rb +1 -0
- data/lib/drbqs/server.rb +10 -2
- data/lib/drbqs/ssh/host.rb +26 -0
- data/lib/drbqs/{ssh_shell.rb → ssh/shell.rb} +64 -17
- data/lib/drbqs/ssh/transfer.rb +70 -0
- data/lib/drbqs/task.rb +17 -4
- data/lib/drbqs/utils/filename.rb +118 -0
- data/spec/filename_spec.rb +44 -0
- data/spec/message_spec.rb +10 -0
- data/spec/node_list_spec.rb +40 -0
- data/spec/server_define_spec.rb +23 -12
- data/spec/ssh_shell_spec.rb +1 -1
- data/spec/task_spec.rb +13 -0
- data/spec/transfer_spec.rb +13 -0
- metadata +48 -6
- data/README.rdoc +0 -128
data/lib/drbqs/task.rb
CHANGED
@@ -36,11 +36,16 @@ module DRbQS
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class CommandExecute
|
39
|
-
|
39
|
+
|
40
|
+
# :transfer String or Array
|
41
|
+
# :compress true or false
|
42
|
+
def initialize(cmd, opts = {})
|
40
43
|
@cmd = cmd
|
41
44
|
unless (Array === @cmd || String === @cmd)
|
42
45
|
raise ArgumentError, "Invalid command: #{@cmd.inspect}"
|
43
46
|
end
|
47
|
+
@transfer = opts[:transfer]
|
48
|
+
@compress = opts[:compress]
|
44
49
|
end
|
45
50
|
|
46
51
|
def exec
|
@@ -50,14 +55,22 @@ module DRbQS
|
|
50
55
|
when String
|
51
56
|
system(@cmd)
|
52
57
|
end
|
53
|
-
$?.exitstatus
|
58
|
+
exit_status = $?.exitstatus
|
59
|
+
if @transfer
|
60
|
+
if Array === @transfer
|
61
|
+
@transfer.each { |path| DRbQS::FileTransfer.enqueue(path, @compress) }
|
62
|
+
else
|
63
|
+
DRbQS::FileTransfer.enqueue(@transfer, @compress)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
exit_status
|
54
67
|
end
|
55
68
|
end
|
56
69
|
|
57
70
|
class CommandTask < Task
|
58
71
|
# &hook takes a server instance and exit number of command.
|
59
|
-
def initialize(cmd, &hook)
|
60
|
-
super(CommandExecute.new(cmd), :exec, &hook)
|
72
|
+
def initialize(cmd, opts = {}, &hook)
|
73
|
+
super(CommandExecute.new(cmd, {}), :exec, &hook)
|
61
74
|
end
|
62
75
|
end
|
63
76
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module DRbQS
|
4
|
+
class FileName
|
5
|
+
|
6
|
+
# The options are following:
|
7
|
+
# * :start
|
8
|
+
# Fixnum
|
9
|
+
# If ID string type is number, the ID starts from the specified number.
|
10
|
+
#
|
11
|
+
# * :digit
|
12
|
+
# Fixnum
|
13
|
+
# ID number converted to a string with specified digit.
|
14
|
+
#
|
15
|
+
# * :delimiter
|
16
|
+
# String
|
17
|
+
#
|
18
|
+
# * :type
|
19
|
+
# :number or :time
|
20
|
+
# If the value is :number, use a number for ID string.
|
21
|
+
# If the value is :time, use current time.
|
22
|
+
#
|
23
|
+
# * :position
|
24
|
+
# :prefix, :suffix, or :middle
|
25
|
+
# Set the position of an ID string.
|
26
|
+
def initialize(basepath, opts = {})
|
27
|
+
@basepath = File.expand_path(basepath)
|
28
|
+
@number = opts[:start] || 0
|
29
|
+
@digit = opts[:digit] || 2
|
30
|
+
@type = opts[:type] || :number
|
31
|
+
@position = opts[:position] || :suffix
|
32
|
+
@delimiter = opts[:delimiter] || (@position == :suffix ? '.' : '_')
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_basepath(extension = nil)
|
36
|
+
if extension
|
37
|
+
extension = '.' + extension unless extension[0] == '.'
|
38
|
+
oldext = File.extname(@basepath)
|
39
|
+
if oldext.size > 0
|
40
|
+
@basepath.sub(Regexp.new("\\#{oldext}$"), extension)
|
41
|
+
else
|
42
|
+
@basepath + extension
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@basepath
|
46
|
+
end
|
47
|
+
end
|
48
|
+
private :get_basepath
|
49
|
+
|
50
|
+
def get_addition(add, filename)
|
51
|
+
if add != :prohibit && (add == :always || File.exist?(filename))
|
52
|
+
case @type
|
53
|
+
when :time
|
54
|
+
t = Time.now
|
55
|
+
return t.strftime("%Y%m%d_%H%M%S_") + sprintf("%06d", t.usec)
|
56
|
+
when :number
|
57
|
+
s = sprintf("%0#{@digit}d", @number)
|
58
|
+
@number += 1
|
59
|
+
return s
|
60
|
+
else
|
61
|
+
raise "Invalid type of addition."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
private :get_addition
|
67
|
+
|
68
|
+
def add_addition(filename, addition)
|
69
|
+
case @position
|
70
|
+
when :prefix
|
71
|
+
dir, base = File.split(filename)
|
72
|
+
dir + '/' + addition + @delimiter + base
|
73
|
+
when :middle
|
74
|
+
dir, base = File.split(filename)
|
75
|
+
ext = File.extname(base)
|
76
|
+
if ext.size > 0
|
77
|
+
filename.sub(Regexp.new("\\#{ext}$"), @delimiter + addition + ext)
|
78
|
+
else
|
79
|
+
filename + @delimiter + addition
|
80
|
+
end
|
81
|
+
else # :suffix
|
82
|
+
filename + @delimiter + addition
|
83
|
+
end
|
84
|
+
end
|
85
|
+
private :add_addition
|
86
|
+
|
87
|
+
# The options are following:
|
88
|
+
# * :extension
|
89
|
+
# String of extension
|
90
|
+
# Use the extension if the value is specified.
|
91
|
+
#
|
92
|
+
# * :add
|
93
|
+
# :always Always add an ID string.
|
94
|
+
# :auto If some file exists, add an ID string.
|
95
|
+
# :prohibit Even if some file exists, add no ID string.
|
96
|
+
#
|
97
|
+
# * :directory
|
98
|
+
# If the value is true and the parent directory does not exist,
|
99
|
+
# create the directory.
|
100
|
+
def create(opts = {})
|
101
|
+
base = get_basepath(opts[:extension])
|
102
|
+
FileUtils.mkdir_p(File.dirname(base)) if opts[:directory]
|
103
|
+
if addition = get_addition(opts[:add], base)
|
104
|
+
path = add_addition(base, addition)
|
105
|
+
while File.exist?(path)
|
106
|
+
if addition = get_addition(opts[:add], base)
|
107
|
+
path = add_addition(base, addition)
|
108
|
+
else
|
109
|
+
raise "Can not create new filename."
|
110
|
+
end
|
111
|
+
end
|
112
|
+
path
|
113
|
+
else
|
114
|
+
base
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe DRbQS::FileName do
|
4
|
+
it "should return unchanged filename" do
|
5
|
+
filename = DRbQS::FileName.new("abc.txt")
|
6
|
+
filename.create.should == File.expand_path(File.dirname('.') + '/abc.txt')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return new filename with number" do
|
10
|
+
filename = DRbQS::FileName.new(__FILE__)
|
11
|
+
path = filename.create
|
12
|
+
File.exist?(path).should_not be_true
|
13
|
+
path.should match(/\.\d+$/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return new filename with time" do
|
17
|
+
filename = DRbQS::FileName.new(__FILE__, :type => :time)
|
18
|
+
path = filename.create
|
19
|
+
File.exist?(path).should_not be_true
|
20
|
+
path.should match(/\.[\d_]+$/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return same filename" do
|
24
|
+
filename = DRbQS::FileName.new(__FILE__)
|
25
|
+
path = filename.create(:add => :prohibit)
|
26
|
+
path.should == File.expand_path(__FILE__)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return filename with prefix" do
|
30
|
+
filename = DRbQS::FileName.new(__FILE__, :position => :prefix)
|
31
|
+
path = filename.create
|
32
|
+
dir, name = File.split(path)
|
33
|
+
name.should match(/^\d+_/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return filename with addition before extension" do
|
37
|
+
filename = DRbQS::FileName.new(__FILE__, :position => :middle)
|
38
|
+
path = filename.create
|
39
|
+
dir, name = File.split(path)
|
40
|
+
ext = File.extname(name)
|
41
|
+
name.should match(Regexp.new("_\\d+\\#{ext}"))
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/message_spec.rb
CHANGED
@@ -68,4 +68,14 @@ describe DRbQS::MessageServer do
|
|
68
68
|
end.should raise_error Rinda::RequestExpiredError
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
it "should get :request_status message" do
|
73
|
+
@message.write([:request_status, 'message_test'])
|
74
|
+
@message_server.get_message.should == :request_status
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should send status" do
|
78
|
+
@message_server.send_status({})
|
79
|
+
@message.take([:status, nil]).should be_true
|
80
|
+
end
|
71
81
|
end
|
data/spec/node_list_spec.rb
CHANGED
@@ -2,6 +2,32 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
require 'drbqs/node_list'
|
4
4
|
|
5
|
+
describe DRbQS::NodeHistory do
|
6
|
+
subject { DRbQS::NodeHistory.new }
|
7
|
+
|
8
|
+
it "should add new id" do
|
9
|
+
subject.add(1, 'hello')
|
10
|
+
ary = subject.each.to_a
|
11
|
+
ary.should have(1).items
|
12
|
+
ary[0][0].should == 1
|
13
|
+
ary[0][1].should have(2).items
|
14
|
+
ary[0][1][0].should == 'hello'
|
15
|
+
ary[0][1][1].should be_an_instance_of Time
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set disconnected" do
|
19
|
+
subject.add(1, 'hello')
|
20
|
+
subject.disconnect(1)
|
21
|
+
ary = subject.each.to_a
|
22
|
+
ary.should have(1).items
|
23
|
+
ary[0][0].should == 1
|
24
|
+
ary[0][1].should have(3).items
|
25
|
+
ary[0][1][0].should == 'hello'
|
26
|
+
ary[0][1][1].should be_an_instance_of Time
|
27
|
+
ary[0][1][2].should be_an_instance_of Time
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
5
31
|
describe DRbQS::NodeList do
|
6
32
|
before(:all) do
|
7
33
|
@node_list = DRbQS::NodeList.new
|
@@ -51,4 +77,18 @@ describe DRbQS::NodeList do
|
|
51
77
|
end
|
52
78
|
end
|
53
79
|
|
80
|
+
it "should add to history" do
|
81
|
+
node_list = DRbQS::NodeList.new
|
82
|
+
node_list.history.should_receive(:add)
|
83
|
+
node_list.get_new_id('hello')
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should set disconnection to history" do
|
87
|
+
node_list = DRbQS::NodeList.new
|
88
|
+
node_list.history.should_receive(:disconnect)
|
89
|
+
node_list.get_new_id('hello')
|
90
|
+
node_list.set_check_connection
|
91
|
+
node_list.delete_not_alive
|
92
|
+
end
|
93
|
+
|
54
94
|
end
|
data/spec/server_define_spec.rb
CHANGED
@@ -7,28 +7,39 @@ describe DRbQS::ServerDefinition do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should define server" do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
lambda do
|
11
|
+
DRbQS.define_server do |server, argv, opts|
|
12
|
+
server.add_hook(:finish) do |serv|
|
13
|
+
serv.exit
|
14
|
+
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end.should change { @server_definition.instance_variable_get(:@default_server_opts) }.from(nil).to({})
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should set parser of options" do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
lambda do
|
21
|
+
DRbQS.option_parser do |opt, hash|
|
22
|
+
opt.on('--test') do |v|
|
23
|
+
hash[:test] = true
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
26
|
+
end.should change { @server_definition.instance_variable_get(:@option_parse) }.from(nil)
|
25
27
|
end
|
26
28
|
|
27
29
|
it "should parse options" do
|
28
|
-
|
29
|
-
|
30
|
+
lambda do
|
31
|
+
DRbQS.parse_option(['--test'])
|
32
|
+
end.should change { @server_definition.instance_variable_get(:@argv) }.from(nil)
|
30
33
|
end
|
31
34
|
|
35
|
+
it "should start server" do
|
36
|
+
DRbQS::Server.should_receive(:new)
|
37
|
+
begin
|
38
|
+
# After DRbQS::Server.new returns nil, raise error
|
39
|
+
DRbQS.start_server(:uri => 'druby://localhost:13500')
|
40
|
+
rescue
|
41
|
+
end
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
end
|
data/spec/ssh_shell_spec.rb
CHANGED
data/spec/task_spec.rb
CHANGED
@@ -19,3 +19,16 @@ describe DRbQS::Task do
|
|
19
19
|
task1.same_target?(task2).should be_true
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
describe DRbQS::CommandExecute do
|
24
|
+
it "should execute command" do
|
25
|
+
cmd_exec = DRbQS::CommandExecute.new('ls > /dev/null')
|
26
|
+
cmd_exec.exec.should == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should enqueue files" do
|
30
|
+
DRbQS::FileTransfer.should_receive(:enqueue).exactly(2)
|
31
|
+
cmd_exec = DRbQS::CommandExecute.new('ls > /dev/null', :transfer => ['hello', 'world'])
|
32
|
+
cmd_exec.exec
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe DRbQS::FileTransfer do
|
4
|
+
it "should enqueue path" do
|
5
|
+
DRbQS::FileTransfer.enqueue('hello/world')
|
6
|
+
DRbQS::FileTransfer.empty?.should_not be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should dequeue path" do
|
10
|
+
DRbQS::FileTransfer.dequeue.should == 'hello/world'
|
11
|
+
DRbQS::FileTransfer.empty?.should be_true
|
12
|
+
end
|
13
|
+
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.
|
5
|
+
version: 0.0.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Takayuki YAMAGUCHI
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-22 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -68,6 +68,39 @@ dependencies:
|
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: net-ssh
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.1.3
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: net-ssh-shell
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.1.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: rspec
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 2.5.0
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
71
104
|
description: Task queuing system over network that is implemented by dRuby.
|
72
105
|
email: d@ytak.info
|
73
106
|
executables:
|
@@ -78,13 +111,13 @@ extensions: []
|
|
78
111
|
|
79
112
|
extra_rdoc_files:
|
80
113
|
- LICENSE.txt
|
81
|
-
- README.
|
114
|
+
- README.md
|
82
115
|
files:
|
83
116
|
- .document
|
84
117
|
- .rspec
|
85
118
|
- Gemfile
|
86
119
|
- LICENSE.txt
|
87
|
-
- README.
|
120
|
+
- README.md
|
88
121
|
- Rakefile
|
89
122
|
- VERSION
|
90
123
|
- bin/drbqs-manage
|
@@ -101,6 +134,8 @@ files:
|
|
101
134
|
- example/sum/sum.rb
|
102
135
|
- example/sum2/server_def.rb
|
103
136
|
- example/sum2/sum.rb
|
137
|
+
- example/transfer/file.rb
|
138
|
+
- example/transfer/server_def.rb
|
104
139
|
- lib/drbqs.rb
|
105
140
|
- lib/drbqs/acl_file.rb
|
106
141
|
- lib/drbqs/client.rb
|
@@ -113,14 +148,18 @@ files:
|
|
113
148
|
- lib/drbqs/server.rb
|
114
149
|
- lib/drbqs/server_define.rb
|
115
150
|
- lib/drbqs/server_hook.rb
|
116
|
-
- lib/drbqs/
|
151
|
+
- lib/drbqs/ssh/host.rb
|
152
|
+
- lib/drbqs/ssh/shell.rb
|
153
|
+
- lib/drbqs/ssh/transfer.rb
|
117
154
|
- lib/drbqs/task.rb
|
118
155
|
- lib/drbqs/task_client.rb
|
119
156
|
- lib/drbqs/task_generator.rb
|
157
|
+
- lib/drbqs/utils/filename.rb
|
120
158
|
- spec/acl_file_spec.rb
|
121
159
|
- spec/config_spec.rb
|
122
160
|
- spec/connection_spec.rb
|
123
161
|
- spec/data/acl.txt
|
162
|
+
- spec/filename_spec.rb
|
124
163
|
- spec/manage_spec.rb
|
125
164
|
- spec/message_spec.rb
|
126
165
|
- spec/node_list_spec.rb
|
@@ -136,6 +175,7 @@ files:
|
|
136
175
|
- spec/test/test1.rb
|
137
176
|
- spec/test1_spec.rb
|
138
177
|
- spec/test2_spec.rb
|
178
|
+
- spec/transfer_spec.rb
|
139
179
|
has_rdoc: true
|
140
180
|
homepage: http://github.com/ytaka/drbqs
|
141
181
|
licenses:
|
@@ -150,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
190
|
requirements:
|
151
191
|
- - ">="
|
152
192
|
- !ruby/object:Gem::Version
|
153
|
-
hash:
|
193
|
+
hash: -3321628204237987958
|
154
194
|
segments:
|
155
195
|
- 0
|
156
196
|
version: "0"
|
@@ -171,6 +211,7 @@ test_files:
|
|
171
211
|
- spec/acl_file_spec.rb
|
172
212
|
- spec/config_spec.rb
|
173
213
|
- spec/connection_spec.rb
|
214
|
+
- spec/filename_spec.rb
|
174
215
|
- spec/manage_spec.rb
|
175
216
|
- spec/message_spec.rb
|
176
217
|
- spec/node_list_spec.rb
|
@@ -186,3 +227,4 @@ test_files:
|
|
186
227
|
- spec/test/test1.rb
|
187
228
|
- spec/test1_spec.rb
|
188
229
|
- spec/test2_spec.rb
|
230
|
+
- spec/transfer_spec.rb
|