drbqs 0.0.13 → 0.0.14
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/Gemfile +10 -7
- data/README.md +52 -11
- data/Rakefile +32 -10
- data/VERSION +1 -1
- data/bin/drbqs-manage +3 -93
- data/bin/drbqs-node +3 -89
- data/bin/drbqs-server +3 -117
- data/bin/drbqs-ssh +6 -0
- data/drbqs.gemspec +118 -97
- data/example/README.md +2 -2
- data/lib/drbqs/config/config.rb +88 -0
- data/lib/drbqs/config/process_list.rb +194 -0
- data/lib/drbqs/config/ssh_host.rb +41 -0
- data/lib/drbqs/{execute_node.rb → manage/execute_node.rb} +6 -4
- data/lib/drbqs/manage/manage.rb +100 -0
- data/lib/drbqs/manage/send_signal.rb +45 -0
- data/lib/drbqs/manage/ssh_execute.rb +23 -0
- data/lib/drbqs/manage/ssh_shell.rb +143 -0
- data/lib/drbqs/node/connection.rb +69 -0
- data/lib/drbqs/{client.rb → node/node.rb} +48 -18
- data/lib/drbqs/node/task_client.rb +94 -0
- data/lib/drbqs/server/acl_file.rb +15 -0
- data/lib/drbqs/server/check_alive.rb +23 -0
- data/lib/drbqs/server/history.rb +49 -0
- data/lib/drbqs/server/message.rb +142 -0
- data/lib/drbqs/server/node_list.rb +59 -0
- data/lib/drbqs/server/queue.rb +128 -0
- data/lib/drbqs/{server.rb → server/server.rb} +66 -74
- data/lib/drbqs/server/server_hook.rb +72 -0
- data/lib/drbqs/server/transfer_setting.rb +30 -0
- data/lib/drbqs/task/command_task.rb +43 -0
- data/lib/drbqs/{task.rb → task/task.rb} +18 -39
- data/lib/drbqs/{task_generator.rb → task/task_generator.rb} +2 -0
- data/lib/drbqs/utility/argument.rb +27 -0
- data/lib/drbqs/utility/command_line/command_base.rb +27 -0
- data/lib/drbqs/utility/command_line/command_manage.rb +121 -0
- data/lib/drbqs/utility/command_line/command_node.rb +103 -0
- data/lib/drbqs/utility/command_line/command_server.rb +165 -0
- data/lib/drbqs/utility/command_line/command_ssh.rb +126 -0
- data/lib/drbqs/utility/command_line.rb +15 -0
- data/lib/drbqs/utility/misc.rb +72 -0
- data/lib/drbqs/{server_define.rb → utility/server_define.rb} +23 -8
- data/lib/drbqs/utility/temporary.rb +49 -0
- data/lib/drbqs/{ssh/transfer.rb → utility/transfer/file_transfer.rb} +18 -58
- data/lib/drbqs/utility/transfer/transfer_client.rb +90 -0
- data/lib/drbqs.rb +10 -22
- data/spec/config/config_spec.rb +84 -0
- data/spec/config/process_list_spec.rb +149 -0
- data/spec/config/ssh_host_spec.rb +81 -0
- data/spec/integration_test/01_basic_usage_spec.rb +54 -0
- data/spec/integration_test/02_use_generator_spec.rb +53 -0
- data/spec/integration_test/03_use_temporary_file_spec.rb +26 -0
- data/spec/integration_test/04_use_unix_domain_spec.rb +34 -0
- data/spec/integration_test/05_server_exit_signal_spec.rb +23 -0
- data/spec/integration_test/06_node_exit_after_task_spec.rb +42 -0
- data/spec/integration_test/07_command_server_with_node_spec.rb +44 -0
- data/spec/integration_test/definition/server01.rb +20 -0
- data/spec/integration_test/definition/server02.rb +16 -0
- data/spec/integration_test/definition/task_obj_definition.rb +49 -0
- data/spec/manage/manage_spec.rb +33 -0
- data/spec/manage/send_signal_spec.rb +39 -0
- data/spec/{ssh_shell_spec.rb → manage/ssh_shell_spec.rb} +8 -8
- data/spec/node/connection_spec.rb +66 -0
- data/spec/node/task_client_spec.rb +212 -0
- data/spec/server/acl_file_spec.rb +9 -0
- data/spec/{server_check_alive_spec.rb → server/check_alive_spec.rb} +15 -11
- data/spec/{data → server/data}/acl.txt +0 -0
- data/spec/{history_spec.rb → server/history_spec.rb} +9 -5
- data/spec/server/message_spec.rb +195 -0
- data/spec/server/node_list_spec.rb +111 -0
- data/spec/server/queue_spec.rb +239 -0
- data/spec/{server_hook_spec.rb → server/server_hook_spec.rb} +23 -17
- data/spec/server/server_spec.rb +89 -0
- data/spec/server/transfer_setting_spec.rb +37 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/task/file_transfer_spec.rb +107 -0
- data/spec/{task_generator_spec.rb → task/task_generator_spec.rb} +2 -2
- data/spec/{task_spec.rb → task/task_spec.rb} +3 -1
- data/spec/utility/argument_spec.rb +39 -0
- data/spec/utility/command_line/command_base_spec.rb +33 -0
- data/spec/utility/command_line/commands_spec.rb +15 -0
- data/spec/utility/misc_spec.rb +77 -0
- data/spec/utility/server_define_spec.rb +59 -0
- data/spec/utility/temporary_spec.rb +39 -0
- metadata +158 -93
- data/example/drbqs-manage-test.rb +0 -3
- data/example/drbqs-node-test.rb +0 -3
- data/example/drbqs-server-test.rb +0 -3
- data/lib/drbqs/acl_file.rb +0 -13
- data/lib/drbqs/config.rb +0 -98
- data/lib/drbqs/connection.rb +0 -67
- data/lib/drbqs/history.rb +0 -34
- data/lib/drbqs/manage.rb +0 -84
- data/lib/drbqs/message.rb +0 -119
- data/lib/drbqs/node_list.rb +0 -52
- data/lib/drbqs/queue.rb +0 -138
- data/lib/drbqs/server_hook.rb +0 -67
- data/lib/drbqs/ssh/host.rb +0 -26
- data/lib/drbqs/ssh/shell.rb +0 -139
- data/lib/drbqs/task_client.rb +0 -86
- data/lib/drbqs/utils.rb +0 -19
- data/spec/acl_file_spec.rb +0 -9
- data/spec/config_spec.rb +0 -14
- data/spec/connection_spec.rb +0 -49
- data/spec/manage_spec.rb +0 -57
- data/spec/message_spec.rb +0 -81
- data/spec/node_list_spec.rb +0 -68
- data/spec/queue_spec.rb +0 -59
- data/spec/server_define_spec.rb +0 -45
- data/spec/server_spec.rb +0 -56
- data/spec/task_client_spec.rb +0 -53
- data/spec/test/test1.rb +0 -13
- data/spec/test1_spec.rb +0 -80
- data/spec/test2_spec.rb +0 -69
- data/spec/transfer_spec.rb +0 -13
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
module DRbQS
|
|
2
|
+
class CommandSSH < CommandBase
|
|
3
|
+
HELP_MESSAGE =<<HELP
|
|
4
|
+
Usage: #{@@command_name} <command> [arguments ...]
|
|
5
|
+
Execute command over SSH.
|
|
6
|
+
<command> is 'list', 'show', 'execute', or 'environment'
|
|
7
|
+
|
|
8
|
+
#{@@command_name} list
|
|
9
|
+
#{@@command_name} show <configuration>
|
|
10
|
+
#{@@command_name} environment <destination>
|
|
11
|
+
#{@@command_name} execute <destination>
|
|
12
|
+
|
|
13
|
+
HELP
|
|
14
|
+
|
|
15
|
+
def parse_option(argv)
|
|
16
|
+
options = {}
|
|
17
|
+
argv, command_args = split_arguments(argv)
|
|
18
|
+
|
|
19
|
+
begin
|
|
20
|
+
OptionParser.new(HELP_MESSAGE) do |opt|
|
|
21
|
+
opt.on('--debug', 'Set $DEBUG true.') do |v|
|
|
22
|
+
$DEBUG = true
|
|
23
|
+
end
|
|
24
|
+
opt.on('--dir DIR', String, 'Set the base directory over ssh.') do |v|
|
|
25
|
+
options[:dir] = v
|
|
26
|
+
end
|
|
27
|
+
opt.on('--shell STR', String, 'Set the shell over ssh') do |v|
|
|
28
|
+
options[:shell] = v
|
|
29
|
+
end
|
|
30
|
+
opt.on('--rvm STR', String, 'Ruby version to use on RVM over ssh.') do |v|
|
|
31
|
+
options[:rvm] = v
|
|
32
|
+
end
|
|
33
|
+
opt.on('--rvm-init PATH', String, 'Path of script to initialize RVM over ssh.') do |v|
|
|
34
|
+
options[:rvm_init] = v
|
|
35
|
+
end
|
|
36
|
+
opt.on('--output PATH', String, 'File path that stdout and stderr are output to over ssh.') do |v|
|
|
37
|
+
options[:output] = v
|
|
38
|
+
end
|
|
39
|
+
opt.on('--nice NUM', Integer, 'Set the value for nice command.') do |v|
|
|
40
|
+
options[:nice] = v
|
|
41
|
+
end
|
|
42
|
+
opt.on('--nohup', 'Use nohup command.') do |v|
|
|
43
|
+
options[:nohup] = true
|
|
44
|
+
end
|
|
45
|
+
opt.parse!(argv)
|
|
46
|
+
end
|
|
47
|
+
rescue OptionParser::InvalidOption
|
|
48
|
+
$stderr.print "error: Invalid Option\n\n" << HELP_MESSAGE
|
|
49
|
+
exit_invalid_option
|
|
50
|
+
rescue OptionParser::InvalidArgument
|
|
51
|
+
$stderr.print "error: Invalid Argument\n\n" << HELP_MESSAGE
|
|
52
|
+
exit_invalid_option
|
|
53
|
+
end
|
|
54
|
+
@options = options
|
|
55
|
+
@command = argv.shift
|
|
56
|
+
@argv = argv
|
|
57
|
+
@command_args = command_args
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def command_list
|
|
61
|
+
ssh_host = DRbQS::Config.new.ssh_host
|
|
62
|
+
$stdout.puts ssh_host.config_names.join("\n")
|
|
63
|
+
exit_normally
|
|
64
|
+
end
|
|
65
|
+
private :command_list
|
|
66
|
+
|
|
67
|
+
def command_show
|
|
68
|
+
check_argument_size(@argv, :==, 1)
|
|
69
|
+
name = @argv[0]
|
|
70
|
+
ssh_host = DRbQS::Config.new.ssh_host
|
|
71
|
+
if path = ssh_host.get_path(name)
|
|
72
|
+
$stdout.puts File.read(path)
|
|
73
|
+
exit_normally
|
|
74
|
+
else
|
|
75
|
+
$stderr.print "Can not find configuration file '#{name}'."
|
|
76
|
+
exit_unusually
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
private :command_show
|
|
80
|
+
|
|
81
|
+
def manage_ssh(dest)
|
|
82
|
+
DRbQS::Manage::SSHExecute.new(dest, @options)
|
|
83
|
+
end
|
|
84
|
+
private :manage_ssh
|
|
85
|
+
|
|
86
|
+
def command_environment
|
|
87
|
+
check_argument_size(@argv, :==, 1)
|
|
88
|
+
dest = @argv[0]
|
|
89
|
+
manage_ssh(dest).get_environment
|
|
90
|
+
exit_normally
|
|
91
|
+
end
|
|
92
|
+
private :command_environment
|
|
93
|
+
|
|
94
|
+
def command_execute
|
|
95
|
+
check_argument_size(@argv, :==, 1)
|
|
96
|
+
dest = @argv[0]
|
|
97
|
+
mng_ssh = manage_ssh(dest)
|
|
98
|
+
if @command_args.size > 0
|
|
99
|
+
mng_ssh.execute(@command_args)
|
|
100
|
+
exit_normally
|
|
101
|
+
else
|
|
102
|
+
$stderr.print "error: There is no command for ssh.\n\n" << HELP_MESSAGE
|
|
103
|
+
exit_unusually
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
private :command_execute
|
|
107
|
+
|
|
108
|
+
def exec
|
|
109
|
+
case @command
|
|
110
|
+
when 'list'
|
|
111
|
+
command_list
|
|
112
|
+
when 'show'
|
|
113
|
+
command_show
|
|
114
|
+
when 'environment'
|
|
115
|
+
command_environment
|
|
116
|
+
when 'execute'
|
|
117
|
+
command_execute
|
|
118
|
+
end
|
|
119
|
+
$stderr.print "error: Invalid command '#{@command}'.\n\n" << HELP_MESSAGE
|
|
120
|
+
exit_invalid_option
|
|
121
|
+
rescue => err
|
|
122
|
+
$stderr.print "error: #{err.to_s}\n" << err.backtrace.join("\n")
|
|
123
|
+
exit_unusually
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'drbqs'
|
|
2
|
+
require 'drbqs/utility/argument'
|
|
3
|
+
require 'drbqs/manage/manage'
|
|
4
|
+
require 'drbqs/manage/execute_node'
|
|
5
|
+
require 'drbqs/utility/command_line/command_base'
|
|
6
|
+
require 'optparse'
|
|
7
|
+
|
|
8
|
+
Version = DRbQS::VERSION
|
|
9
|
+
|
|
10
|
+
module DRbQS
|
|
11
|
+
autoload :CommandManage, 'drbqs/utility/command_line/command_manage'
|
|
12
|
+
autoload :CommandServer, 'drbqs/utility/command_line/command_server'
|
|
13
|
+
autoload :CommandNode, 'drbqs/utility/command_line/command_node'
|
|
14
|
+
autoload :CommandSSH, 'drbqs/utility/command_line/command_ssh'
|
|
15
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'sys/proctable'
|
|
2
|
+
|
|
3
|
+
module DRbQS
|
|
4
|
+
class LoggerDummy
|
|
5
|
+
def info(*args)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def warn(*args)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def error(*args)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def debug(*args)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module Misc
|
|
19
|
+
def create_uri(opts = {})
|
|
20
|
+
if opts[:port] || !opts[:unix]
|
|
21
|
+
port = opts[:port] || ROOT_DEFAULT_PORT
|
|
22
|
+
"druby://:#{port}"
|
|
23
|
+
else
|
|
24
|
+
path = File.expand_path(opts[:unix])
|
|
25
|
+
if !File.directory?(File.dirname(path))
|
|
26
|
+
raise ArgumentError, "Directory #{File.dirname(path)} does not exist."
|
|
27
|
+
elsif File.exist?(path)
|
|
28
|
+
raise ArgumentError, "File #{path} already exists."
|
|
29
|
+
end
|
|
30
|
+
"drbunix:#{path}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
module_function :create_uri
|
|
34
|
+
|
|
35
|
+
def create_logger(log_file, log_level)
|
|
36
|
+
if IO === log_file
|
|
37
|
+
log_output = log_file
|
|
38
|
+
elsif log_file
|
|
39
|
+
log_output = FileName.create(log_file, :position => :middle, :directory => :parent, :type => :number)
|
|
40
|
+
else
|
|
41
|
+
log_output = STDOUT
|
|
42
|
+
end
|
|
43
|
+
logger = Logger.new(log_output)
|
|
44
|
+
logger.level = log_level || Logger::ERROR
|
|
45
|
+
logger
|
|
46
|
+
end
|
|
47
|
+
module_function :create_logger
|
|
48
|
+
|
|
49
|
+
def time_to_history_string(t)
|
|
50
|
+
t.strftime("%Y-%m-%d %H:%M:%S")
|
|
51
|
+
end
|
|
52
|
+
module_function :time_to_history_string
|
|
53
|
+
|
|
54
|
+
STRINGS_FOR_KEY = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
|
55
|
+
|
|
56
|
+
def random_key(size = 20)
|
|
57
|
+
n = STRINGS_FOR_KEY.size
|
|
58
|
+
Array.new(size) do
|
|
59
|
+
STRINGS_FOR_KEY[rand(n)]
|
|
60
|
+
end.join
|
|
61
|
+
end
|
|
62
|
+
module_function :random_key
|
|
63
|
+
|
|
64
|
+
# If process of +pid+ does not exist or its state is zombie then the method return false.
|
|
65
|
+
# If +pid+ is invalid then the method also returns false.
|
|
66
|
+
def process_running_normally?(pid)
|
|
67
|
+
Integer === pid && (ps_table = Sys::ProcTable.ps(pid)) && (ps_table.state != 'Z')
|
|
68
|
+
end
|
|
69
|
+
module_function :process_running_normally?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -2,17 +2,13 @@ module DRbQS
|
|
|
2
2
|
|
|
3
3
|
class ServerDefinition
|
|
4
4
|
HELP_MESSAGE =<<HELP
|
|
5
|
-
|
|
5
|
+
* Server specific options
|
|
6
6
|
These options are separated by '--' from command options.
|
|
7
7
|
|
|
8
8
|
HELP
|
|
9
9
|
|
|
10
10
|
def initialize
|
|
11
|
-
|
|
12
|
-
@option_parse = nil
|
|
13
|
-
@opts = {}
|
|
14
|
-
@argv = nil
|
|
15
|
-
@default_server_opts = nil
|
|
11
|
+
clear_definition
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
def define_server(default_opts = {}, &block)
|
|
@@ -40,6 +36,25 @@ HELP
|
|
|
40
36
|
@argv = opt_argv
|
|
41
37
|
end
|
|
42
38
|
|
|
39
|
+
def option_help_message
|
|
40
|
+
if @option_parse
|
|
41
|
+
OptionParser.new(HELP_MESSAGE) do |opt|
|
|
42
|
+
@option_parse.call(opt, @opts)
|
|
43
|
+
return opt.to_s
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def clear_definition
|
|
51
|
+
@server_create = nil
|
|
52
|
+
@option_parse = nil
|
|
53
|
+
@opts = {}
|
|
54
|
+
@argv = nil
|
|
55
|
+
@default_server_opts = nil
|
|
56
|
+
end
|
|
57
|
+
|
|
43
58
|
def create_server(options)
|
|
44
59
|
server = DRbQS::Server.new(@default_server_opts.merge(options))
|
|
45
60
|
@server_create.call(server, @argv, @opts)
|
|
@@ -71,10 +86,10 @@ HELP
|
|
|
71
86
|
end
|
|
72
87
|
end
|
|
73
88
|
|
|
74
|
-
@@server_def = ServerDefinition.new
|
|
89
|
+
@@server_def = DRbQS::ServerDefinition.new
|
|
75
90
|
|
|
76
91
|
class << self
|
|
77
|
-
[:define_server, :option_parser, :parse_option,
|
|
92
|
+
[:define_server, :option_parser, :parse_option, :option_help_message, :clear_definition,
|
|
78
93
|
:start_server, :test_server].each do |m|
|
|
79
94
|
define_method(m, &@@server_def.method(m))
|
|
80
95
|
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module DRbQS
|
|
2
|
+
module Temporary
|
|
3
|
+
@@root = nil
|
|
4
|
+
@@filename = nil
|
|
5
|
+
|
|
6
|
+
# Return FileName object to generate names of temporary files on DRbQS nodes.
|
|
7
|
+
def self.filename
|
|
8
|
+
unless @@filename
|
|
9
|
+
pid = Process.pid
|
|
10
|
+
@@root = sprintf("/tmp/drbqs_%d_%d", pid, rand(10000))
|
|
11
|
+
FileUtils.mkdir_p(@@root)
|
|
12
|
+
@@filename = FileName.new(File.join(@@root, sprintf("temp_%d_%d", pid, rand(10000))))
|
|
13
|
+
end
|
|
14
|
+
@@filename
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Create new temporary directory and return the path of directory.
|
|
18
|
+
def self.directory
|
|
19
|
+
filename.create(:add => :always, :directory => :self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Return new path of temporary file.
|
|
23
|
+
def self.file
|
|
24
|
+
filename.create(:add => :always)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Make root of temporary directory empty.
|
|
28
|
+
def self.delete
|
|
29
|
+
if @@root
|
|
30
|
+
FileUtils.rm_r(@@root)
|
|
31
|
+
FileUtils.mkdir_p(@@root)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Delete all temporary directory.
|
|
36
|
+
def self.delete_all
|
|
37
|
+
if @@root
|
|
38
|
+
FileUtils.rm_r(@@root)
|
|
39
|
+
@@root = nil
|
|
40
|
+
@@filename = nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Return root of temporary directory.
|
|
45
|
+
def self.root
|
|
46
|
+
@@root
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -1,66 +1,17 @@
|
|
|
1
1
|
module DRbQS
|
|
2
|
-
|
|
3
|
-
# Transfer files to directory on DRbQS server.
|
|
4
|
-
# In this class we use scp command.
|
|
5
|
-
# Note that after we transfer files we delete the files.
|
|
6
|
-
class Transfer
|
|
7
|
-
attr_reader :user, :host, :directory
|
|
8
|
-
|
|
9
|
-
# options
|
|
10
|
-
# :mkdir true or nil
|
|
11
|
-
def initialize(user, host, directory)
|
|
12
|
-
@user = user
|
|
13
|
-
@host = host
|
|
14
|
-
@directory = File.expand_path(directory)
|
|
15
|
-
FileUtils.mkdir_p(@directory)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def transfer_file(path, name)
|
|
19
|
-
system("scp -r #{path} #{@user}@#{@host}:#{File.join(@directory, name)} > /dev/null 2>&1")
|
|
20
|
-
end
|
|
21
|
-
private :transfer_file
|
|
22
|
-
|
|
23
|
-
def scp(path)
|
|
24
|
-
name = File.basename(path)
|
|
25
|
-
unless File.exist?(path)
|
|
26
|
-
raise ArgumentError, "File #{path} does not exist."
|
|
27
|
-
end
|
|
28
|
-
if transfer_file(path, name)
|
|
29
|
-
FileUtils.rm_r(path)
|
|
30
|
-
return true
|
|
31
|
-
end
|
|
32
|
-
return false
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def information
|
|
36
|
-
"#{@user}@#{@host} #{@directory}"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
class TransferTest < Transfer
|
|
41
|
-
def initialize(directory)
|
|
42
|
-
@directory = File.expand_path(directory)
|
|
43
|
-
FileUtils.mkdir_p(@directory)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def transfer_file(path, name)
|
|
47
|
-
FileUtils.cp(path, File.join(@directory, name))
|
|
48
|
-
true
|
|
49
|
-
end
|
|
50
|
-
private :transfer_file
|
|
51
|
-
|
|
52
|
-
def information
|
|
53
|
-
@directory
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
2
|
# To compress files, we use gzip and tar command.
|
|
58
3
|
# Note that if we compress files then we delete the source files.
|
|
59
4
|
module FileTransfer
|
|
60
5
|
@@files = Queue.new
|
|
61
6
|
|
|
62
|
-
|
|
63
|
-
|
|
7
|
+
# If opts[:compress] is true then the file of +path+ is compressed before tranfering.
|
|
8
|
+
def self.enqueue(path, opts = {})
|
|
9
|
+
if opts[:rename]
|
|
10
|
+
new_path = FileName.create(File.join(File.dirname(path), opts[:rename]), :directory => :parent)
|
|
11
|
+
FileUtils.mv(path, new_path)
|
|
12
|
+
path = new_path
|
|
13
|
+
end
|
|
14
|
+
if opts[:compress]
|
|
64
15
|
if File.directory?(path)
|
|
65
16
|
gz_path = "#{path.sub(/\/$/, '')}.tar.gz"
|
|
66
17
|
cmd = "tar czf #{gz_path} -C #{File.dirname(path)} #{File.basename(path)} > /dev/null 2>&1"
|
|
@@ -83,7 +34,7 @@ module DRbQS
|
|
|
83
34
|
end
|
|
84
35
|
|
|
85
36
|
def self.compress_enqueue(path)
|
|
86
|
-
self.enqueue(path, true)
|
|
37
|
+
self.enqueue(path, :compress => true)
|
|
87
38
|
end
|
|
88
39
|
|
|
89
40
|
def self.dequeue
|
|
@@ -94,6 +45,14 @@ module DRbQS
|
|
|
94
45
|
@@files.empty?
|
|
95
46
|
end
|
|
96
47
|
|
|
48
|
+
def self.dequeue_all
|
|
49
|
+
files = []
|
|
50
|
+
until self.empty?
|
|
51
|
+
files << self.dequeue
|
|
52
|
+
end
|
|
53
|
+
files.empty? ? nil : files
|
|
54
|
+
end
|
|
55
|
+
|
|
97
56
|
def self.decompress(server, filename)
|
|
98
57
|
dir = server.transfer_directory
|
|
99
58
|
path = File.join(dir, filename)
|
|
@@ -110,4 +69,5 @@ module DRbQS
|
|
|
110
69
|
end
|
|
111
70
|
end
|
|
112
71
|
end
|
|
72
|
+
|
|
113
73
|
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'net/sftp'
|
|
2
|
+
|
|
3
|
+
module DRbQS
|
|
4
|
+
|
|
5
|
+
class TransferClient
|
|
6
|
+
|
|
7
|
+
class ClientBase
|
|
8
|
+
def initialize(directory)
|
|
9
|
+
@directory = File.expand_path(directory)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def upload_name(path)
|
|
13
|
+
File.join(@directory, File.basename(path))
|
|
14
|
+
end
|
|
15
|
+
private :upload_name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Transfer files to directory on DRbQS server over sftp.
|
|
19
|
+
# Note that after we transfer files we delete the original files.
|
|
20
|
+
class SFTP < DRbQS::TransferClient::ClientBase
|
|
21
|
+
attr_reader :user, :host, :directory
|
|
22
|
+
|
|
23
|
+
def initialize(user, host, directory)
|
|
24
|
+
super(directory)
|
|
25
|
+
@user = user
|
|
26
|
+
@host = host
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Transfer and delete +files+.
|
|
30
|
+
def transfer(files)
|
|
31
|
+
Net::SFTP.start(@host, @user) do |sftp|
|
|
32
|
+
files.each do |path|
|
|
33
|
+
sftp.upload(path, upload_name(path))
|
|
34
|
+
FileUtils.rm_r(path)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
rescue => err
|
|
38
|
+
raise err.class, "user=#{@user}, host=#{@host}, directory=#{@directory}; #{err.to_s}", err.backtrace
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Local < DRbQS::TransferClient::ClientBase
|
|
43
|
+
def transfer(files)
|
|
44
|
+
files.each do |path|
|
|
45
|
+
FileUtils.mv(path, upload_name(path))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
attr_reader :directory, :local, :sftp
|
|
51
|
+
|
|
52
|
+
def initialize(dir)
|
|
53
|
+
@directory = File.expand_path(dir)
|
|
54
|
+
@local = DRbQS::TransferClient::Local.new(@directory)
|
|
55
|
+
@sftp = nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def make_directory
|
|
59
|
+
FileUtils.mkdir_p(@directory)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def set_sftp(user, host)
|
|
63
|
+
@sftp = DRbQS::TransferClient::SFTP.new(user, host, @directory)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def information
|
|
67
|
+
info = "directory: #{@directory}"
|
|
68
|
+
info << ", sftp: #{@sftp.user}@#{@sftp.host}" if @sftp
|
|
69
|
+
info
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def transfer(files, on_same_host = nil)
|
|
73
|
+
transfered = false
|
|
74
|
+
if on_same_host
|
|
75
|
+
begin
|
|
76
|
+
@local.transfer(files)
|
|
77
|
+
transfered = true
|
|
78
|
+
rescue
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
if !transfered
|
|
82
|
+
unless @sftp
|
|
83
|
+
raise "Can not transfer files."
|
|
84
|
+
end
|
|
85
|
+
@sftp.transfer(files)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
data/lib/drbqs.rb
CHANGED
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
require 'thread'
|
|
2
2
|
require 'drb'
|
|
3
3
|
require 'drb/acl'
|
|
4
|
+
require 'socket'
|
|
4
5
|
require 'rinda/tuplespace'
|
|
5
6
|
require 'rinda/rinda'
|
|
7
|
+
require 'logger'
|
|
8
|
+
require 'fileutils'
|
|
6
9
|
|
|
7
|
-
require '
|
|
10
|
+
require 'filename'
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
gem 'filename'
|
|
13
|
-
autoload :FileName, 'filename'
|
|
12
|
+
require 'drbqs/utility/server_define'
|
|
13
|
+
require 'drbqs/utility/misc'
|
|
14
14
|
|
|
15
15
|
module DRbQS
|
|
16
|
-
autoload :Server, 'drbqs/server'
|
|
17
|
-
autoload :
|
|
18
|
-
autoload :
|
|
19
|
-
autoload :TaskGenerator, 'drbqs/task_generator'
|
|
20
|
-
autoload :Manage, 'drbqs/manage'
|
|
21
|
-
autoload :Config, 'drbqs/config'
|
|
22
|
-
autoload :SSHShell, 'drbqs/ssh/shell'
|
|
23
|
-
autoload :SSHHost, 'drbqs/ssh/host'
|
|
24
|
-
autoload :CommandTask, 'drbqs/task'
|
|
25
|
-
autoload :CommandExecute, 'drbqs/task'
|
|
26
|
-
autoload :TaskSet, 'drbqs/task'
|
|
27
|
-
autoload :Transfer, 'drbqs/ssh/transfer'
|
|
28
|
-
autoload :FileTransfer, 'drbqs/ssh/transfer'
|
|
29
|
-
autoload :Utils, 'drbqs/utils'
|
|
30
|
-
autoload :ExecuteNode, 'drbqs/execute_node'
|
|
16
|
+
autoload :Server, 'drbqs/server/server'
|
|
17
|
+
autoload :Node, 'drbqs/node/node'
|
|
18
|
+
autoload :Config, 'drbqs/config/config'
|
|
31
19
|
|
|
32
20
|
ROOT_DEFAULT_PORT = 13500
|
|
33
21
|
|
|
34
|
-
VERSION = '0.0.
|
|
22
|
+
VERSION = '0.0.14'
|
|
35
23
|
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe DRbQS::Config do
|
|
4
|
+
before(:all) do
|
|
5
|
+
FileUtils.mkdir_p(HOME_FOR_SPEC)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
subject do
|
|
9
|
+
DRbQS::Config.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "when setting new homedirectory" do
|
|
13
|
+
before(:all) do
|
|
14
|
+
@old_home_directory = DRbQS::Config.get_home_directory
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should change home directory." do
|
|
18
|
+
new_home_directory = '/tmp/drbqs_new_home'
|
|
19
|
+
DRbQS::Config.set_home_directory(new_home_directory)
|
|
20
|
+
DRbQS::Config.get_home_directory.should == new_home_directory
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
after(:all) do
|
|
24
|
+
DRbQS::Config.set_home_directory(@old_home_directory)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when creating configuration directory" do
|
|
29
|
+
before(:all) do
|
|
30
|
+
@dir = File.join(HOME_FOR_SPEC, '.drbqs')
|
|
31
|
+
FileUtils.rm_r(@dir) if File.exist?(@dir)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should get directory existing." do
|
|
35
|
+
lambda do
|
|
36
|
+
subject
|
|
37
|
+
end.should change { File.exist?(@dir) }.from(false).to(true)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when saving samples" do
|
|
42
|
+
before(:all) do
|
|
43
|
+
subject.save_sample
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should get sample of ACL file." do
|
|
47
|
+
subject.directory.list_in_directory('.').should include('acl.txt.sample')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should get sample of host file." do
|
|
51
|
+
subject.directory.list_in_directory('host').should include('host.yaml.sample')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should get bashrc for SSH of drbqs." do
|
|
55
|
+
subject.directory.list_in_directory('shell').should include('bashrc')
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "when managing ACL file" do
|
|
60
|
+
before(:all) do
|
|
61
|
+
@path = subject.directory.file_path('acl.txt')
|
|
62
|
+
FileUtils.rm(@path) if File.exist?(@path)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should not have ACL file by default." do
|
|
66
|
+
subject.get_acl_file.should_not be_true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should return path of ACL file" do
|
|
70
|
+
open(@path, 'w') do |f|
|
|
71
|
+
end
|
|
72
|
+
subject.get_acl_file.should == File.join(@path)
|
|
73
|
+
FileUtils.rm(@path) if File.exist?(@path)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should return DRbQS::Config::SSHHost object." do
|
|
78
|
+
subject.ssh_host.should be_an_instance_of DRbQS::Config::SSHHost
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
after(:all) do
|
|
82
|
+
FileUtils.rm_r(HOME_FOR_SPEC)
|
|
83
|
+
end
|
|
84
|
+
end
|