drbqs 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/drbqs-execute +6 -0
- data/bin/drbqs-manage +2 -2
- data/bin/drbqs-node +2 -2
- data/bin/drbqs-server +2 -2
- data/bin/drbqs-ssh +2 -2
- data/drbqs.gemspec +53 -16
- data/example/error_server/error.rb +6 -0
- data/example/error_server/server_def.rb +7 -0
- data/example/{error → error_task}/error.rb +0 -0
- data/example/{error → error_task}/server_def.rb +0 -0
- data/example/sum2/execute_def.rb +27 -0
- data/lib/drbqs/command_line/argument.rb +29 -0
- data/lib/drbqs/command_line/command_base.rb +81 -0
- data/lib/drbqs/command_line/command_execute.rb +33 -0
- data/lib/drbqs/command_line/command_line.rb +19 -0
- data/lib/drbqs/command_line/command_manage.rb +34 -0
- data/lib/drbqs/command_line/command_node.rb +26 -0
- data/lib/drbqs/command_line/command_server.rb +41 -0
- data/lib/drbqs/command_line/command_ssh.rb +51 -0
- data/lib/drbqs/command_line/option_setting.rb +42 -0
- data/lib/drbqs/execute/process_define.rb +213 -0
- data/lib/drbqs/execute/register.rb +147 -0
- data/lib/drbqs/{utility → execute}/server_define.rb +7 -14
- data/lib/drbqs/manage/execute_node.rb +4 -2
- data/lib/drbqs/manage/manage.rb +23 -16
- data/lib/drbqs/manage/send_signal.rb +31 -4
- data/lib/drbqs/manage/ssh_execute.rb +50 -6
- data/lib/drbqs/manage/ssh_shell.rb +95 -50
- data/lib/drbqs/node/connection.rb +1 -1
- data/lib/drbqs/node/node.rb +67 -17
- data/lib/drbqs/node/state.rb +109 -0
- data/lib/drbqs/node/task_client.rb +7 -7
- data/lib/drbqs/server/history.rb +16 -0
- data/lib/drbqs/server/message.rb +80 -15
- data/lib/drbqs/server/node_list.rb +16 -3
- data/lib/drbqs/server/prof.rb +48 -0
- data/lib/drbqs/server/queue.rb +20 -2
- data/lib/drbqs/server/server.rb +112 -70
- data/lib/drbqs/server/server_hook.rb +26 -6
- data/lib/drbqs/server/test/node.rb +34 -0
- data/lib/drbqs/server/test/server.rb +74 -0
- data/lib/drbqs/setting/base.rb +120 -0
- data/lib/drbqs/setting/data_container.rb +39 -0
- data/lib/drbqs/setting/execute.rb +71 -0
- data/lib/drbqs/setting/manage.rb +163 -0
- data/lib/drbqs/setting/node.rb +84 -0
- data/lib/drbqs/setting/server.rb +230 -0
- data/lib/drbqs/setting/setting.rb +14 -0
- data/lib/drbqs/setting/source.rb +220 -0
- data/lib/drbqs/setting/ssh.rb +165 -0
- data/lib/drbqs/task/task_generator.rb +4 -2
- data/lib/drbqs/utility/misc.rb +15 -1
- data/lib/drbqs/utility/temporary.rb +4 -2
- data/lib/drbqs.rb +3 -2
- data/spec/command_line/command_base_spec.rb +47 -0
- data/spec/{utility/command_line → command_line}/commands_spec.rb +3 -3
- data/spec/command_line/option_setting_spec.rb +29 -0
- data/spec/execute/def/execute1.rb +24 -0
- data/spec/execute/def/no_def.rb +2 -0
- data/spec/execute/process_define_spec.rb +167 -0
- data/spec/execute/register_spec.rb +77 -0
- data/spec/{utility → execute}/server_define_spec.rb +0 -0
- data/spec/integration_test/01_basic_usage_spec.rb +1 -1
- data/spec/integration_test/02_use_generator_spec.rb +1 -1
- data/spec/integration_test/03_use_temporary_file_spec.rb +1 -1
- data/spec/integration_test/04_use_unix_domain_spec.rb +1 -1
- data/spec/integration_test/05_server_exit_signal_spec.rb +1 -1
- data/spec/integration_test/06_node_exit_after_task_spec.rb +1 -1
- data/spec/integration_test/07_command_server_with_node_spec.rb +19 -16
- data/spec/integration_test/08_shutdown_unused_nodes_spec.rb +38 -0
- data/spec/integration_test/09_server_process_data_spec.rb +74 -0
- data/spec/integration_test/10_test_server_spec.rb +18 -0
- data/spec/integration_test/definition/task_obj_definition.rb +14 -0
- data/spec/manage/send_signal_spec.rb +8 -0
- data/spec/manage/ssh_shell_spec.rb +1 -1
- data/spec/node/state_spec.rb +148 -0
- data/spec/node/task_client_spec.rb +15 -0
- data/spec/server/history_spec.rb +51 -20
- data/spec/server/message_spec.rb +7 -2
- data/spec/server/node_list_spec.rb +1 -1
- data/spec/server/queue_spec.rb +93 -4
- data/spec/server/server_hook_spec.rb +62 -0
- data/spec/setting/base_spec.rb +35 -0
- data/spec/setting/data_container_spec.rb +92 -0
- data/spec/setting/execute_spec.rb +51 -0
- data/spec/setting/manage_spec.rb +63 -0
- data/spec/setting/node_spec.rb +43 -0
- data/spec/setting/server_spec.rb +46 -0
- data/spec/setting/source_spec.rb +245 -0
- data/spec/spec_helper.rb +17 -10
- data/spec/utility/argument_spec.rb +7 -7
- metadata +179 -146
- data/lib/drbqs/utility/argument.rb +0 -27
- data/lib/drbqs/utility/command_line/command_base.rb +0 -27
- data/lib/drbqs/utility/command_line/command_manage.rb +0 -121
- data/lib/drbqs/utility/command_line/command_node.rb +0 -103
- data/lib/drbqs/utility/command_line/command_server.rb +0 -165
- data/lib/drbqs/utility/command_line/command_ssh.rb +0 -126
- data/lib/drbqs/utility/command_line.rb +0 -15
- data/spec/utility/command_line/command_base_spec.rb +0 -33
@@ -0,0 +1,39 @@
|
|
1
|
+
module DRbQS
|
2
|
+
class Setting
|
3
|
+
class Source
|
4
|
+
class DataContainer < BasicObject
|
5
|
+
attr_accessor :argument
|
6
|
+
attr_reader :__data__
|
7
|
+
|
8
|
+
def initialize(array_class)
|
9
|
+
@argument = []
|
10
|
+
@__data__ = {}
|
11
|
+
@__array__ = array_class
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(name, *args)
|
15
|
+
if args.size > 0
|
16
|
+
s = name.to_s
|
17
|
+
key = (/=$/ =~ s ? s[0...-1].intern : name.intern)
|
18
|
+
@__data__[key] = (@__array__ === args[0] ? args[0] : args)
|
19
|
+
else
|
20
|
+
@__data__[name]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def __delete__(name)
|
25
|
+
@__data__.delete(name.intern)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.clone_container(obj)
|
30
|
+
cl = DRbQS::Setting::Source::DataContainer.new(Array)
|
31
|
+
cl.argument = obj.argument.clone
|
32
|
+
obj.__data__.each do |key, val|
|
33
|
+
cl.__data__[key] = val
|
34
|
+
end
|
35
|
+
cl
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'drbqs/execute/process_define'
|
2
|
+
|
3
|
+
module DRbQS
|
4
|
+
class Setting
|
5
|
+
class Execute < DRbQS::Setting::Base
|
6
|
+
attr_accessor :server_argument
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super(:all_keys_defined => true) do
|
10
|
+
[:port, :server, :node].each do |key|
|
11
|
+
register_key(key, :check => 1)
|
12
|
+
end
|
13
|
+
[:no_server, :no_node, :information, :help].each do |key|
|
14
|
+
register_key(key, :bool => true)
|
15
|
+
end
|
16
|
+
set_argument_condition(:<=, 1)
|
17
|
+
end
|
18
|
+
@server_argument = []
|
19
|
+
end
|
20
|
+
|
21
|
+
# If there are invalid arguments,
|
22
|
+
# this method raises an error.
|
23
|
+
def parse!
|
24
|
+
super
|
25
|
+
@port = get_first(:port) do |val|
|
26
|
+
val.to_i
|
27
|
+
end
|
28
|
+
@no_server = get_first(:no_server)
|
29
|
+
@server = get_first(:server) do |val|
|
30
|
+
val.intern
|
31
|
+
end
|
32
|
+
@no_node = get_first(:no_node)
|
33
|
+
@node = get_first(:node) do |val|
|
34
|
+
val.split(',').map do |s|
|
35
|
+
s.intern
|
36
|
+
end
|
37
|
+
end
|
38
|
+
@definition = get_argument[0]
|
39
|
+
if get_first(:help)
|
40
|
+
@mode = :help
|
41
|
+
elsif get_first(:information)
|
42
|
+
@mode = :information
|
43
|
+
else
|
44
|
+
@mode = nil
|
45
|
+
end
|
46
|
+
if !@output_help && !@definition
|
47
|
+
raise DRbQS::Setting::InvalidArgument, "Definition file must be specified."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def exec(io = nil)
|
52
|
+
process_def = DRbQS::ProcessDefinition.new(@server, @node, @port, io)
|
53
|
+
process_def.load(@definition) if @definition
|
54
|
+
case @mode
|
55
|
+
when :help
|
56
|
+
io.puts process_def.usage if io
|
57
|
+
when :information
|
58
|
+
io.puts process_def.information_string if io
|
59
|
+
else
|
60
|
+
unless @no_server
|
61
|
+
process_def.execute_server(@server_argument)
|
62
|
+
end
|
63
|
+
unless @no_node
|
64
|
+
process_def.execute_node
|
65
|
+
end
|
66
|
+
end
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
module DRbQS
|
2
|
+
class Setting
|
3
|
+
class Manage < DRbQS::Setting::Base
|
4
|
+
include DRbQS::Command::Argument
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super(:all_keys_defined => true) do
|
8
|
+
set_argument_condition(:>, 0)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_all_arguments
|
13
|
+
case @mode
|
14
|
+
when 'initialize'
|
15
|
+
check_argument_size(@argv, :>=, 0, :<=, 1)
|
16
|
+
when 'process'
|
17
|
+
check_argument_size(@argv, :>=, 0, :<=, 1)
|
18
|
+
if @argv[0] && !['clear', 'list'].include?(@argv[0])
|
19
|
+
raise DRbQS::Setting::InvalidArgument, "Invalid command 'process #{@argv[0]}'"
|
20
|
+
end
|
21
|
+
when 'status', 'history'
|
22
|
+
check_argument_size(@argv, :==, 1)
|
23
|
+
when 'signal'
|
24
|
+
case @argv[1]
|
25
|
+
when 'server-exit'
|
26
|
+
check_argument_size(@argv, :==, 2)
|
27
|
+
when 'node-exit-after-task', 'node-wake', 'node-sleep'
|
28
|
+
check_argument_size(@argv, :==, 3)
|
29
|
+
else
|
30
|
+
raise DRbQS::Setting::InvalidArgument, "Invalid signal type '#{@argv[1]}'"
|
31
|
+
end
|
32
|
+
when 'send'
|
33
|
+
check_argument_size(@argv, :==, 3)
|
34
|
+
case @argv[0]
|
35
|
+
when 'string'
|
36
|
+
unless @argv[2]
|
37
|
+
raise DRbQS::Setting::InvalidArgument, "String data is not set"
|
38
|
+
end
|
39
|
+
when 'file'
|
40
|
+
unless File.exist?(@argv[2])
|
41
|
+
raise DRbQS::Setting::InvalidArgument, "File '#{@argv[2]}' does not exist"
|
42
|
+
end
|
43
|
+
else
|
44
|
+
raise DRbQS::Setting::InvalidArgument, "Invalid option '#{argv[2]}' for 'send'"
|
45
|
+
end
|
46
|
+
else
|
47
|
+
raise DRbQS::Setting::InvalidArgument, "Invalid command '#{@mode}'"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
private :check_all_arguments
|
51
|
+
|
52
|
+
# If there are invalid arguments,
|
53
|
+
# this method raises an error.
|
54
|
+
def parse!
|
55
|
+
super
|
56
|
+
ary = get_argument
|
57
|
+
@mode = ary[0].to_s
|
58
|
+
@argv = ary[1..-1]
|
59
|
+
check_all_arguments
|
60
|
+
end
|
61
|
+
|
62
|
+
def command_initialize
|
63
|
+
@manage.set_home_directory(@argv[0])
|
64
|
+
@manage.create_config
|
65
|
+
end
|
66
|
+
private :command_initialize
|
67
|
+
|
68
|
+
def command_process(io)
|
69
|
+
if @argv[0] == 'clear'
|
70
|
+
@manage.clear_process
|
71
|
+
return true
|
72
|
+
end
|
73
|
+
result = ''
|
74
|
+
list = @manage.list_process
|
75
|
+
result << "Server\n"
|
76
|
+
list[:server].each do |uri, data|
|
77
|
+
result << "#{uri}\n"
|
78
|
+
data.each do |k, v|
|
79
|
+
result << sprintf(" %-10s %s\n", k, v)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
result << "\nNode\n"
|
83
|
+
list[:node].each do |pid, data|
|
84
|
+
result << "#{pid}\n"
|
85
|
+
data.each do |k, v|
|
86
|
+
result << sprintf(" %-10s %s\n", k, v)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
io.print result if io
|
90
|
+
end
|
91
|
+
private :command_process
|
92
|
+
|
93
|
+
def request_to_server(io, method_name)
|
94
|
+
@manage.set_uri(@argv[0])
|
95
|
+
if status = @manage.__send__(method_name)
|
96
|
+
io.puts status if io
|
97
|
+
end
|
98
|
+
end
|
99
|
+
private :request_to_server
|
100
|
+
|
101
|
+
def command_status(io)
|
102
|
+
request_to_server(io, :get_status)
|
103
|
+
end
|
104
|
+
private :command_status
|
105
|
+
|
106
|
+
def command_history
|
107
|
+
request_to_server(io, :get_history)
|
108
|
+
end
|
109
|
+
private :command_history
|
110
|
+
|
111
|
+
def signal_to_node(method_name)
|
112
|
+
node_id = @argv[2].to_i
|
113
|
+
@manage.__send__(method_name, node_id)
|
114
|
+
end
|
115
|
+
private :signal_to_node
|
116
|
+
|
117
|
+
def command_signal
|
118
|
+
@manage.set_uri(@argv[0])
|
119
|
+
case @argv[1]
|
120
|
+
when 'server-exit'
|
121
|
+
@manage.send_exit_signal
|
122
|
+
when 'node-exit-after-task'
|
123
|
+
signal_to_node(:send_node_exit_after_task)
|
124
|
+
when 'node-wake'
|
125
|
+
signal_to_node(:send_node_wake)
|
126
|
+
when 'node-sleep'
|
127
|
+
signal_to_node(:send_node_sleep)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
private :command_signal
|
131
|
+
|
132
|
+
def command_send
|
133
|
+
@manage.set_uri(@argv[1])
|
134
|
+
case @argv[0]
|
135
|
+
when 'string'
|
136
|
+
data = @argv[2]
|
137
|
+
when 'file'
|
138
|
+
data = File.read(@argv[2])
|
139
|
+
end
|
140
|
+
@manage.send_data(data)
|
141
|
+
end
|
142
|
+
private :command_send
|
143
|
+
|
144
|
+
def exec(io = nil)
|
145
|
+
@manage = DRbQS::Manage.new
|
146
|
+
case @mode
|
147
|
+
when 'initialize'
|
148
|
+
command_initialize
|
149
|
+
when 'process'
|
150
|
+
command_process(io)
|
151
|
+
when 'status'
|
152
|
+
command_status(io)
|
153
|
+
when 'history'
|
154
|
+
command_history(io)
|
155
|
+
when 'signal'
|
156
|
+
command_signal
|
157
|
+
when 'send'
|
158
|
+
command_send
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module DRbQS
|
2
|
+
class Setting
|
3
|
+
class Node < DRbQS::Setting::Base
|
4
|
+
LOG_PREFIX_DEFAULT = 'drbqs_node'
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super(:all_keys_defined => true, :log_level => true, :daemon => true) do
|
8
|
+
register_key(:load, :check => [:>, 0], :add => true)
|
9
|
+
register_key(:process, :check => 1, :default => [1])
|
10
|
+
register_key(:loadavg, :check => 1)
|
11
|
+
register_key(:log_prefix, :check => 1, :default => [LOG_PREFIX_DEFAULT])
|
12
|
+
register_key(:log_stdout, :bool => true)
|
13
|
+
register_key(:connect, :check => 1)
|
14
|
+
set_argument_condition(:==, 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def preprocess!
|
19
|
+
if connect = get_first(:connect)
|
20
|
+
value.argument.unshift(connect)
|
21
|
+
clear(:connect)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
private :preprocess!
|
25
|
+
|
26
|
+
# If there are invalid arguments,
|
27
|
+
# this method raises an error.
|
28
|
+
def parse!
|
29
|
+
super
|
30
|
+
parse_load
|
31
|
+
parse_loadavg
|
32
|
+
if !get(:log_stdout)
|
33
|
+
@options[:log_prefix] = get_first(:log_prefix) do |val|
|
34
|
+
str = val.to_s
|
35
|
+
str += 'out' if /\/$/ =~ str
|
36
|
+
str
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@process_num = get_first(:process)
|
40
|
+
@uri = get_argument[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_load
|
44
|
+
@options[:load] = []
|
45
|
+
get(:load).to_a.each do |path|
|
46
|
+
@options[:load] << File.expand_path(path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
private :parse_load
|
50
|
+
|
51
|
+
def parse_loadavg
|
52
|
+
@options[:node_opts] = {}
|
53
|
+
if args = get(:loadavg)
|
54
|
+
max_loadavg, sleep_time = args[0].split(':', -1)
|
55
|
+
@options[:node_opts][:max_loadavg] = max_loadavg && max_loadavg.size > 0 ? max_loadavg.to_f : nil
|
56
|
+
@options[:node_opts][:sleep_time] = sleep_time && sleep_time.size > 0 ? sleep_time.to_i : nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
private :parse_loadavg
|
60
|
+
|
61
|
+
def exec(io = nil)
|
62
|
+
return true if exec_as_daemon
|
63
|
+
|
64
|
+
@options[:load].each do |path|
|
65
|
+
io.puts "load #{path}" if io
|
66
|
+
unless File.exist?(path)
|
67
|
+
raise DRbQS::Setting::InvalidArgument, "#{path} does not exist."
|
68
|
+
end
|
69
|
+
load path
|
70
|
+
end
|
71
|
+
|
72
|
+
if io
|
73
|
+
io.puts "Connect to #{@uri}"
|
74
|
+
io.puts "Execute #{@process_num} processes"
|
75
|
+
end
|
76
|
+
|
77
|
+
exec_node = DRbQS::ExecuteNode.new(@uri, @options[:log_prefix], @options[:log_level], @options[:node_opts])
|
78
|
+
exec_node.execute(@process_num)
|
79
|
+
exec_node.wait
|
80
|
+
true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
module DRbQS
|
2
|
+
class Setting
|
3
|
+
class Server < DRbQS::Setting::Base
|
4
|
+
include DRbQS::Misc
|
5
|
+
|
6
|
+
NODE_INTERVAL_TIME = 1
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super(:all_keys_defined => true, :log_level => true, :daemon => true) do
|
10
|
+
[:port, :unix, :acl, :sftp_user, :sftp_host,
|
11
|
+
:profile_printer, :test, :execute_node].each do |key|
|
12
|
+
register_key(key, :check => 1)
|
13
|
+
end
|
14
|
+
register_key(:log_file, :check => 1, :default => [STDOUT])
|
15
|
+
register_key(:profile, :bool => true)
|
16
|
+
register_key(:load, :add => true)
|
17
|
+
register_key(:help, :bool => true)
|
18
|
+
set_argument_condition(:>, 0)
|
19
|
+
end
|
20
|
+
@server_argument = DRbQS::Setting::Source.new(nil)
|
21
|
+
@command_type = :server_start
|
22
|
+
@test_opts = {}
|
23
|
+
@execute_node_number = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_test
|
27
|
+
@test_opts[:profile] = get(:profile)
|
28
|
+
@test_opts[:printer] = get_first(:printer) do |val|
|
29
|
+
val.intern
|
30
|
+
end
|
31
|
+
if test = get_first(:test)
|
32
|
+
@command_type = "test_#{test.to_s}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
private :parse_test
|
36
|
+
|
37
|
+
def parse_execute_node
|
38
|
+
@execute_node_number = get_first(:execute_node) do |val|
|
39
|
+
val.to_i
|
40
|
+
end
|
41
|
+
end
|
42
|
+
private :parse_execute_node
|
43
|
+
|
44
|
+
def preprocess!
|
45
|
+
if files = get(:load)
|
46
|
+
value.argument.concat(files)
|
47
|
+
clear(:load)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
private :preprocess!
|
51
|
+
|
52
|
+
def parse!
|
53
|
+
if get(:help)
|
54
|
+
@command_type = :help
|
55
|
+
return true
|
56
|
+
end
|
57
|
+
super
|
58
|
+
parse_test
|
59
|
+
parse_execute_node
|
60
|
+
@options[:port] = get_first(:port) do |val|
|
61
|
+
val.to_i
|
62
|
+
end
|
63
|
+
@options[:unix] = get_first(:unix)
|
64
|
+
@options[:acl] = get_first(:acl)
|
65
|
+
@options[:sftp_user] = get_first(:sftp_user)
|
66
|
+
@options[:sftp_host] = get_first(:sftp_host)
|
67
|
+
@options[:log_file] = get_first(:log_file)
|
68
|
+
@options.delete_if do |key, val|
|
69
|
+
!val
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_server_argument(*args)
|
74
|
+
@server_argument.set_argument(*args)
|
75
|
+
end
|
76
|
+
|
77
|
+
def command_line_argument(escape = nil)
|
78
|
+
ary = super(escape)
|
79
|
+
server_args = @server_argument.command_line_argument(escape)
|
80
|
+
if server_args.size > 0
|
81
|
+
ary << '--'
|
82
|
+
ary.concat(server_args)
|
83
|
+
end
|
84
|
+
ary
|
85
|
+
end
|
86
|
+
|
87
|
+
def command_test(io)
|
88
|
+
args = @command_type.split('_')[1].split(',')
|
89
|
+
type = args.shift.intern
|
90
|
+
limit = args[0] ? args[0].to_i : nil
|
91
|
+
server = DRbQS.create_test_server(@options)
|
92
|
+
case type
|
93
|
+
when :task
|
94
|
+
server.test_task_generator(:limit => limit, :progress => true)
|
95
|
+
when :exec
|
96
|
+
data = server.test_exec(:limit => limit, :profile => @test_opts[:profile], :printer => @test_opts[:printer])
|
97
|
+
if io
|
98
|
+
s = sprintf("Results: %d tasks; total %.4fs", data[:task], data[:end] - data[:start])
|
99
|
+
s << sprintf("; %.4fs per one task", (data[:end] - data[:start]) / data[:task]) if data[:task] > 0
|
100
|
+
s << "\nOutput the profile data to #{data[:profile]}" if data[:profile]
|
101
|
+
io.puts s
|
102
|
+
end
|
103
|
+
else
|
104
|
+
raise DRbQS::Setting::InvalidArgument, "Not yet implemented test '#{type}'"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
private :command_test
|
108
|
+
|
109
|
+
def command_start_server
|
110
|
+
DRbQS.start_server(@options)
|
111
|
+
end
|
112
|
+
private :command_start_server
|
113
|
+
|
114
|
+
def current_server_uri
|
115
|
+
DRbQS::Misc.create_uri(@options)
|
116
|
+
end
|
117
|
+
private :current_server_uri
|
118
|
+
|
119
|
+
def wait_server_process(uri, server_pid = nil)
|
120
|
+
manage = DRbQS::Manage.new(:uri => uri)
|
121
|
+
unless manage.wait_server_process(server_pid)
|
122
|
+
raise "The process of the server of #{uri} does not exist."
|
123
|
+
end
|
124
|
+
rescue DRbQS::Manage::NoServerRespond => err
|
125
|
+
raise DRbQS::Manage::NoServerRespond, "The server of #{uri} does not respond."
|
126
|
+
end
|
127
|
+
private :wait_server_process
|
128
|
+
|
129
|
+
def execute_node_and_wait(uri)
|
130
|
+
node_log_file = nil
|
131
|
+
unless IO === @options[:log_file]
|
132
|
+
node_log_file = FileName.create(@options[:log_file], :add => :always, :position => :middle, :delimiter => '', :format => "_node_%02d")
|
133
|
+
end
|
134
|
+
exec_node = DRbQS::ExecuteNode.new(uri, node_log_file, @options[:log_level])
|
135
|
+
exec_node.execute(@execute_node_number, NODE_INTERVAL_TIME)
|
136
|
+
exec_node.wait
|
137
|
+
end
|
138
|
+
private :execute_node_and_wait
|
139
|
+
|
140
|
+
def command_server_with_nodes
|
141
|
+
server_pid = fork do
|
142
|
+
begin
|
143
|
+
DRbQS.start_server(@options)
|
144
|
+
rescue SystemExit
|
145
|
+
rescue Exception => err
|
146
|
+
$stderr.puts "*** Error occurs on server process #{Process.pid}. ***"
|
147
|
+
output_error(err)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
uri = current_server_uri
|
151
|
+
wait_server_process(uri, server_pid)
|
152
|
+
execute_node_and_wait(uri)
|
153
|
+
end
|
154
|
+
private :command_server_with_nodes
|
155
|
+
|
156
|
+
def command_server_help(io)
|
157
|
+
if io
|
158
|
+
begin
|
159
|
+
get_argument.each do |path|
|
160
|
+
if File.exist?(path)
|
161
|
+
Kernel.load(path)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if mes = DRbQS.option_help_message
|
165
|
+
io.print "\n" << mes
|
166
|
+
end
|
167
|
+
rescue => err
|
168
|
+
new_err = err.class.new("Error in loading #{path}: #{err.to_s}")
|
169
|
+
new_err.set_backtrace(err.backtrace)
|
170
|
+
raise new_err
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
private :command_server_help
|
175
|
+
|
176
|
+
def setup_arguments
|
177
|
+
get_argument.each do |path|
|
178
|
+
if File.exist?(path)
|
179
|
+
Kernel.load(path)
|
180
|
+
else
|
181
|
+
raise DRbQS::Setting::InvalidArgument, "#{path} does not exist."
|
182
|
+
end
|
183
|
+
end
|
184
|
+
unless @options[:acl]
|
185
|
+
@options[:acl] = DRbQS::Config.new.get_acl_file
|
186
|
+
end
|
187
|
+
DRbQS.parse_option(@server_argument.get_argument)
|
188
|
+
end
|
189
|
+
private :setup_arguments
|
190
|
+
|
191
|
+
def fork_daemon_process
|
192
|
+
if @__daemon__
|
193
|
+
case @command_type
|
194
|
+
when /^test/
|
195
|
+
raise DRbQS::Setting::InvalidArgument, "Test of server does not support daemon"
|
196
|
+
else
|
197
|
+
fork do
|
198
|
+
exec_as_daemon
|
199
|
+
end
|
200
|
+
uri = current_server_uri
|
201
|
+
wait_server_process(uri)
|
202
|
+
end
|
203
|
+
true
|
204
|
+
else
|
205
|
+
nil
|
206
|
+
end
|
207
|
+
end
|
208
|
+
private :fork_daemon_process
|
209
|
+
|
210
|
+
def exec(io = nil)
|
211
|
+
if @command_type == :help
|
212
|
+
command_server_help(io)
|
213
|
+
elsif !fork_daemon_process
|
214
|
+
setup_arguments
|
215
|
+
case @command_type
|
216
|
+
when /^test/
|
217
|
+
command_test(io)
|
218
|
+
else
|
219
|
+
if @execute_node_number
|
220
|
+
command_server_with_nodes
|
221
|
+
else
|
222
|
+
command_start_server
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
true
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'drbqs/command_line/argument'
|
2
|
+
require 'drbqs/setting/data_container'
|
3
|
+
require 'drbqs/setting/source'
|
4
|
+
require 'drbqs/setting/base'
|
5
|
+
|
6
|
+
module DRbQS
|
7
|
+
class Setting
|
8
|
+
autoload :Server, 'drbqs/setting/server'
|
9
|
+
autoload :Node, 'drbqs/setting/node'
|
10
|
+
autoload :Manage, 'drbqs/setting/manage'
|
11
|
+
autoload :SSH, 'drbqs/setting/ssh'
|
12
|
+
autoload :Execute, 'drbqs/setting/execute'
|
13
|
+
end
|
14
|
+
end
|