drbqs 0.0.14 → 0.0.15
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/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,220 @@
|
|
|
1
|
+
module DRbQS
|
|
2
|
+
class Setting
|
|
3
|
+
class InvalidArgument < StandardError
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Source
|
|
7
|
+
attr_reader :value, :default
|
|
8
|
+
|
|
9
|
+
def initialize(all_keys_defined = true)
|
|
10
|
+
@cond = {}
|
|
11
|
+
@default = {}
|
|
12
|
+
@value = DRbQS::Setting::Source::DataContainer.new(Array)
|
|
13
|
+
@argument_condition = nil
|
|
14
|
+
@all_keys_defined = all_keys_defined
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def clone
|
|
18
|
+
new_obj = self.class.new(!!@all_keys_defined)
|
|
19
|
+
args = [@cond.clone, @default.clone, DRbQS::Setting::Source.clone_container(@value), @argument_condition]
|
|
20
|
+
new_obj.instance_exec(*args) do |cond, default, value, arg_cond|
|
|
21
|
+
@cond = cond
|
|
22
|
+
@default = default
|
|
23
|
+
@value = value
|
|
24
|
+
@argument_condition = arg_cond
|
|
25
|
+
end
|
|
26
|
+
new_obj
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# For debug.
|
|
30
|
+
def registered_keys
|
|
31
|
+
@cond.keys
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def registered_key?(key)
|
|
35
|
+
@cond.has_key?(key)
|
|
36
|
+
end
|
|
37
|
+
private :registered_key?
|
|
38
|
+
|
|
39
|
+
def boolean_value?(key)
|
|
40
|
+
registered_key?(key) && @cond[key][:bool]
|
|
41
|
+
end
|
|
42
|
+
private :boolean_value?
|
|
43
|
+
|
|
44
|
+
def value_to_add?(key)
|
|
45
|
+
registered_key?(key) && @cond[key][:add]
|
|
46
|
+
end
|
|
47
|
+
private :value_to_add?
|
|
48
|
+
|
|
49
|
+
def check_argument_array_size(check, args, target = nil)
|
|
50
|
+
n = args.size
|
|
51
|
+
check.each_slice(2).each do |ary|
|
|
52
|
+
unless n.__send__(*ary)
|
|
53
|
+
mes = "Size"
|
|
54
|
+
if target
|
|
55
|
+
mes << " of #{target.inspect}"
|
|
56
|
+
end
|
|
57
|
+
mes << " must be " << ary.map(&:to_s).join(' ') << ", but #{n}"
|
|
58
|
+
raise DRbQS::Setting::InvalidArgument, mes
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
private :check_argument_array_size
|
|
63
|
+
|
|
64
|
+
def check!
|
|
65
|
+
if @argument_condition
|
|
66
|
+
check_argument_array_size(@argument_condition, get_argument, "argument array")
|
|
67
|
+
end
|
|
68
|
+
keys = @value.__data__.keys
|
|
69
|
+
keys.each do |key|
|
|
70
|
+
args = @value.__data__[key]
|
|
71
|
+
unless Symbol === key
|
|
72
|
+
key = key.intern
|
|
73
|
+
@value.__data__.delete(key)
|
|
74
|
+
end
|
|
75
|
+
if registered_key?(key)
|
|
76
|
+
if check = @cond[key][:check]
|
|
77
|
+
check_argument_array_size(check, args, key)
|
|
78
|
+
end
|
|
79
|
+
elsif @all_keys_defined
|
|
80
|
+
raise DRbQS::Setting::InvalidArgument, "Undefined key '#{key.inspect}' must not set."
|
|
81
|
+
end
|
|
82
|
+
if boolean_value?(key)
|
|
83
|
+
@value.__data__[key] = [(args.size == 0 || args[0] ? true : false)]
|
|
84
|
+
else
|
|
85
|
+
@value.__data__[key] = args
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def parse_condition(check)
|
|
91
|
+
if Fixnum === check
|
|
92
|
+
[:==, check]
|
|
93
|
+
elsif check.size == 1 && Fixnum === check[0]
|
|
94
|
+
[:==, check[0]]
|
|
95
|
+
elsif Array === check && check.size.even?
|
|
96
|
+
check
|
|
97
|
+
else
|
|
98
|
+
raise DRbQS::Setting::InvalidArgument, "Invalid argument condition."
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
private :parse_condition
|
|
102
|
+
|
|
103
|
+
# :check
|
|
104
|
+
# :add
|
|
105
|
+
# :bool
|
|
106
|
+
# :default
|
|
107
|
+
def register_key(key, opts = {})
|
|
108
|
+
k = key.intern
|
|
109
|
+
if registered_key?(k)
|
|
110
|
+
@cond[k].clear
|
|
111
|
+
else
|
|
112
|
+
@cond[k] = {}
|
|
113
|
+
end
|
|
114
|
+
if check = opts[:check]
|
|
115
|
+
@cond[k][:check] = parse_condition(check)
|
|
116
|
+
end
|
|
117
|
+
if default = opts[:default]
|
|
118
|
+
check_argument_array_size(@cond[k][:check], default, "default of #{k.inspect}") if @cond[k][:check]
|
|
119
|
+
@default[k] = default
|
|
120
|
+
end
|
|
121
|
+
@cond[k][:add] = opts[:add]
|
|
122
|
+
@cond[k][:bool] = opts[:bool]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def set_argument_condition(*checks)
|
|
126
|
+
@argument_condition = parse_condition(checks)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def set(key, *args)
|
|
130
|
+
k = key.intern
|
|
131
|
+
if value_to_add?(key) && @value.__data__[k]
|
|
132
|
+
@value.__data__[k].concat(args)
|
|
133
|
+
else
|
|
134
|
+
@value.__data__[k] = args
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def clear(key)
|
|
139
|
+
@value.__data__.delete(key.intern)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def get(key, &block)
|
|
143
|
+
k = key.intern
|
|
144
|
+
val = @value.__data__[k] || @default[k]
|
|
145
|
+
if block_given? && val
|
|
146
|
+
yield(val)
|
|
147
|
+
else
|
|
148
|
+
val
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def get_first(key, &block)
|
|
153
|
+
val = get(key) do |ary|
|
|
154
|
+
ary[0]
|
|
155
|
+
end
|
|
156
|
+
block_given? && val ? yield(val) : val
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def set?(key)
|
|
160
|
+
!!@value.__data__[key.intern]
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def set_argument(*args)
|
|
164
|
+
@value.argument = args
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def get_argument
|
|
168
|
+
@value.argument
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def escape_string_for_shell(str)
|
|
172
|
+
'"' << str.gsub(/"/, '\"') << '"'
|
|
173
|
+
end
|
|
174
|
+
private :escape_string_for_shell
|
|
175
|
+
|
|
176
|
+
def argument_array_for_command_line(escape)
|
|
177
|
+
ary = get_argument.map do |val|
|
|
178
|
+
val.to_s
|
|
179
|
+
end
|
|
180
|
+
if escape
|
|
181
|
+
ary.map! do |val|
|
|
182
|
+
escape_string_for_shell(val)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
ary
|
|
186
|
+
end
|
|
187
|
+
private :argument_array_for_command_line
|
|
188
|
+
|
|
189
|
+
def option_array_for_command_line(escape)
|
|
190
|
+
ary = []
|
|
191
|
+
@value.__data__.each do |k, val|
|
|
192
|
+
s = k.to_s
|
|
193
|
+
s.strip!
|
|
194
|
+
if s.size > 0
|
|
195
|
+
option_key = (s.size == 1 ? "-#{s}" : "--#{s}")
|
|
196
|
+
option_key.gsub!(/_/, '-')
|
|
197
|
+
if !@cond[k][:bool]
|
|
198
|
+
val.each do |v|
|
|
199
|
+
ary << option_key
|
|
200
|
+
value_string = v.to_s
|
|
201
|
+
if escape
|
|
202
|
+
value_string = escape_string_for_shell(value_string)
|
|
203
|
+
end
|
|
204
|
+
ary << value_string
|
|
205
|
+
end
|
|
206
|
+
elsif val
|
|
207
|
+
ary << option_key
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
ary
|
|
212
|
+
end
|
|
213
|
+
private :option_array_for_command_line
|
|
214
|
+
|
|
215
|
+
def command_line_argument(escape = nil)
|
|
216
|
+
argument_array_for_command_line(escape) + option_array_for_command_line(escape)
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
module DRbQS
|
|
2
|
+
class Setting
|
|
3
|
+
class SSH < DRbQS::Setting::Base
|
|
4
|
+
include DRbQS::Command::Argument
|
|
5
|
+
|
|
6
|
+
attr_accessor :mode_setting
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
super(:all_keys_defined => true) do
|
|
10
|
+
[:directory, :shell, :rvm, :rvm_init, :output, :connect].each do |key|
|
|
11
|
+
register_key(key, :check => 1)
|
|
12
|
+
end
|
|
13
|
+
register_key(:nice, :check => 1, :default => [10])
|
|
14
|
+
set_argument_condition(:>=, 0)
|
|
15
|
+
end
|
|
16
|
+
@mode_setting = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def configure_mode_setting(type = nil, &block)
|
|
20
|
+
if type ||= get_argument[0]
|
|
21
|
+
unless @mode_setting
|
|
22
|
+
case type.intern
|
|
23
|
+
when :server
|
|
24
|
+
@mode_setting = DRbQS::Setting::Server.new
|
|
25
|
+
when :node
|
|
26
|
+
@mode_setting = DRbQS::Setting::Node.new
|
|
27
|
+
else
|
|
28
|
+
@mode_setting = DRbQS::Setting::Base.new
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
yield(@mode_setting.value)
|
|
32
|
+
else
|
|
33
|
+
raise DRbQS::Setting::InvalidArgument, "Command mode is not determined."
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def command_line_argument(escape = nil)
|
|
38
|
+
ary = super(escape)
|
|
39
|
+
ssh_args = @mode_setting.command_line_argument(escape)
|
|
40
|
+
if ssh_args.size > 0
|
|
41
|
+
ary << '--'
|
|
42
|
+
ary.concat(ssh_args)
|
|
43
|
+
end
|
|
44
|
+
ary
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def preprocess!
|
|
48
|
+
if connect = get_first(:connect)
|
|
49
|
+
value.argument << connect
|
|
50
|
+
clear(:connect)
|
|
51
|
+
end
|
|
52
|
+
if type = get_argument[0]
|
|
53
|
+
case type.intern
|
|
54
|
+
when :server
|
|
55
|
+
@mode_setting.clear(:log_file)
|
|
56
|
+
@mode_setting.clear(:daemon)
|
|
57
|
+
when :node
|
|
58
|
+
@mode_setting.clear(:log_prefix)
|
|
59
|
+
@mode_setting.clear(:daemon)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
private :preprocess!
|
|
64
|
+
|
|
65
|
+
# If there are invalid arguments,
|
|
66
|
+
# this method raises an error.
|
|
67
|
+
def parse!
|
|
68
|
+
super
|
|
69
|
+
[:directory, :shell, :rvm, :rvm_init, :nice].each do |key|
|
|
70
|
+
if val = get_first(key)
|
|
71
|
+
@options[key] = val
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
@output = get_first(:output)
|
|
75
|
+
ary = get_argument
|
|
76
|
+
@command = ary[0]
|
|
77
|
+
@argv = ary[1..-1]
|
|
78
|
+
@mode_setting.parse!
|
|
79
|
+
@mode_argument_array = @mode_setting.command_line_argument
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def command_list(io)
|
|
83
|
+
if io
|
|
84
|
+
ssh_host = DRbQS::Config.new.ssh_host
|
|
85
|
+
io.puts ssh_host.config_names.join("\n")
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
private :command_list
|
|
89
|
+
|
|
90
|
+
def only_first_argument
|
|
91
|
+
check_argument_size(@argv, :==, 1)
|
|
92
|
+
@argv[0]
|
|
93
|
+
end
|
|
94
|
+
private :only_first_argument
|
|
95
|
+
|
|
96
|
+
def connecting_ssh_server
|
|
97
|
+
only_first_argument
|
|
98
|
+
end
|
|
99
|
+
private :connecting_ssh_server
|
|
100
|
+
|
|
101
|
+
def command_show(io)
|
|
102
|
+
if io
|
|
103
|
+
name = only_first_argument
|
|
104
|
+
ssh_host = DRbQS::Config.new.ssh_host
|
|
105
|
+
if path = ssh_host.get_path(name)
|
|
106
|
+
io.puts File.read(path)
|
|
107
|
+
else
|
|
108
|
+
raise DRbQS::Setting::InvalidArgument, "Can not find configuration file '#{name}'."
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
private :command_show
|
|
113
|
+
|
|
114
|
+
def manage_ssh(dest, io)
|
|
115
|
+
DRbQS::Manage::SSHExecute.new(dest, { :io => io }.merge(@options))
|
|
116
|
+
end
|
|
117
|
+
private :manage_ssh
|
|
118
|
+
|
|
119
|
+
def command_environment(io)
|
|
120
|
+
dest = only_first_argument
|
|
121
|
+
manage_ssh(dest, io).get_environment
|
|
122
|
+
end
|
|
123
|
+
private :command_environment
|
|
124
|
+
|
|
125
|
+
def command_execute(io)
|
|
126
|
+
mng_ssh = manage_ssh(connecting_ssh_server, io)
|
|
127
|
+
if @mode_argument_array.size > 0
|
|
128
|
+
mng_ssh.command(@mode_argument_array)
|
|
129
|
+
else
|
|
130
|
+
raise "There is no command for ssh."
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
private :command_execute
|
|
134
|
+
|
|
135
|
+
def command_server(io)
|
|
136
|
+
manage_ssh(connecting_ssh_server, io).server(@mode_argument_array, :nice => @nice, :daemon => @output)
|
|
137
|
+
end
|
|
138
|
+
private :command_server
|
|
139
|
+
|
|
140
|
+
def command_node(io)
|
|
141
|
+
manage_ssh(connecting_ssh_server, io).node(@mode_argument_array, :nice => @nice, :daemon => @output)
|
|
142
|
+
end
|
|
143
|
+
private :command_node
|
|
144
|
+
|
|
145
|
+
def exec(io = nil)
|
|
146
|
+
case @command
|
|
147
|
+
when 'list'
|
|
148
|
+
command_list(io)
|
|
149
|
+
when 'show'
|
|
150
|
+
command_show(io)
|
|
151
|
+
when 'environment'
|
|
152
|
+
command_environment(io)
|
|
153
|
+
when 'execute'
|
|
154
|
+
command_execute(io)
|
|
155
|
+
when 'server'
|
|
156
|
+
command_server(io)
|
|
157
|
+
when 'node'
|
|
158
|
+
command_node(io)
|
|
159
|
+
else
|
|
160
|
+
raise DRbQS::Setting::InvalidArgument, "Invalid command '#{@command}'."
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -54,14 +54,16 @@ module DRbQS
|
|
|
54
54
|
@iterate = opts[:generate] || 1
|
|
55
55
|
@task_set = opts[:collect]
|
|
56
56
|
if @iterate < 1 || (@task_set && @task_set < 1)
|
|
57
|
-
raise ArgumentError, "Invalid
|
|
57
|
+
raise ArgumentError, "Invalid options of task creation on generator."
|
|
58
58
|
end
|
|
59
59
|
@fiber_init = lambda do
|
|
60
60
|
@fiber = Fiber.new do
|
|
61
61
|
begin
|
|
62
62
|
@source.instance_eval(&block)
|
|
63
63
|
rescue => err
|
|
64
|
-
|
|
64
|
+
new_err = DRbQS::TaskCreatingError.new("#{err.to_s} (#{err.class}) when creating task")
|
|
65
|
+
new_err.set_backtrace(err.backtrace)
|
|
66
|
+
raise new_err
|
|
65
67
|
end
|
|
66
68
|
nil
|
|
67
69
|
end
|
data/lib/drbqs/utility/misc.rb
CHANGED
|
@@ -16,10 +16,15 @@ module DRbQS
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
module Misc
|
|
19
|
+
# :port
|
|
20
|
+
# :host
|
|
21
|
+
# :unix
|
|
19
22
|
def create_uri(opts = {})
|
|
20
23
|
if opts[:port] || !opts[:unix]
|
|
21
24
|
port = opts[:port] || ROOT_DEFAULT_PORT
|
|
22
|
-
"druby
|
|
25
|
+
"druby://#{opts[:host]}:#{port}"
|
|
26
|
+
elsif opts[:host]
|
|
27
|
+
raise ArgumentError, "We can not set hostname to unix domain socket."
|
|
23
28
|
else
|
|
24
29
|
path = File.expand_path(opts[:unix])
|
|
25
30
|
if !File.directory?(File.dirname(path))
|
|
@@ -67,6 +72,15 @@ module DRbQS
|
|
|
67
72
|
Integer === pid && (ps_table = Sys::ProcTable.ps(pid)) && (ps_table.state != 'Z')
|
|
68
73
|
end
|
|
69
74
|
module_function :process_running_normally?
|
|
75
|
+
|
|
76
|
+
def output_error(err, io = $stderr)
|
|
77
|
+
backtrace = err.backtrace
|
|
78
|
+
io.puts "#{backtrace[0]}: #{err.to_s} (#{err.class})"
|
|
79
|
+
if backtrace.size > 1
|
|
80
|
+
io.puts " from #{backtrace[1..-1].join("\n from ")}"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
module_function :output_error
|
|
70
84
|
end
|
|
71
85
|
|
|
72
86
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'tmpdir'
|
|
2
|
+
|
|
1
3
|
module DRbQS
|
|
2
4
|
module Temporary
|
|
3
5
|
@@root = nil
|
|
@@ -7,8 +9,8 @@ module DRbQS
|
|
|
7
9
|
def self.filename
|
|
8
10
|
unless @@filename
|
|
9
11
|
pid = Process.pid
|
|
10
|
-
@@root = sprintf("
|
|
11
|
-
FileUtils.mkdir_p(@@root)
|
|
12
|
+
@@root = File.join(Dir.tmpdir, sprintf("drbqs_%d_%d", pid, rand(10000)))
|
|
13
|
+
FileUtils.mkdir_p(@@root, :mode => 0700)
|
|
12
14
|
@@filename = FileName.new(File.join(@@root, sprintf("temp_%d_%d", pid, rand(10000))))
|
|
13
15
|
end
|
|
14
16
|
@@filename
|
data/lib/drbqs.rb
CHANGED
|
@@ -9,15 +9,16 @@ require 'fileutils'
|
|
|
9
9
|
|
|
10
10
|
require 'filename'
|
|
11
11
|
|
|
12
|
-
require 'drbqs/
|
|
12
|
+
require 'drbqs/execute/server_define'
|
|
13
13
|
require 'drbqs/utility/misc'
|
|
14
14
|
|
|
15
15
|
module DRbQS
|
|
16
16
|
autoload :Server, 'drbqs/server/server'
|
|
17
17
|
autoload :Node, 'drbqs/node/node'
|
|
18
18
|
autoload :Config, 'drbqs/config/config'
|
|
19
|
+
autoload :Setting, 'drbqs/setting/setting'
|
|
19
20
|
|
|
20
21
|
ROOT_DEFAULT_PORT = 13500
|
|
21
22
|
|
|
22
|
-
VERSION = '0.0.
|
|
23
|
+
VERSION = '0.0.15'
|
|
23
24
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
require 'drbqs/command_line/command_line'
|
|
4
|
+
|
|
5
|
+
describe DRbQS::Command::Base do
|
|
6
|
+
context "when executing" do
|
|
7
|
+
it "should execute." do
|
|
8
|
+
setting = mock('setting')
|
|
9
|
+
DRbQS::Setting::Base.stub(:new).and_return(setting)
|
|
10
|
+
setting.should_receive(:parse!)
|
|
11
|
+
setting.should_receive(:exec).with($stdout)
|
|
12
|
+
command_base = DRbQS::Command::Base.new(DRbQS::Setting::Base, 'help message')
|
|
13
|
+
command_base.should_receive(:exit_normally)
|
|
14
|
+
command_base.exec
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should define DRbQS::Command::Base.exec." do
|
|
18
|
+
argv = [1, 2, 3]
|
|
19
|
+
obj = mock
|
|
20
|
+
DRbQS::Command::Base.should_receive(:new).and_return(obj)
|
|
21
|
+
obj.should_receive(:parse_option)
|
|
22
|
+
obj.should_receive(:exec)
|
|
23
|
+
DRbQS::Command::Base.exec(argv)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when existing" do
|
|
28
|
+
subject do
|
|
29
|
+
DRbQS::Command::Base.new
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should exit with 0." do
|
|
33
|
+
Kernel.should_receive(:exit).with(0)
|
|
34
|
+
subject.__send__(:exit_normally)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should exit." do
|
|
38
|
+
Kernel.should_receive(:exit)
|
|
39
|
+
subject.__send__(:exit_unusually)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should exit." do
|
|
43
|
+
Kernel.should_receive(:exit)
|
|
44
|
+
subject.__send__(:exit_invalid_option)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
|
3
|
-
require 'drbqs/
|
|
3
|
+
require 'drbqs/command_line/command_line'
|
|
4
4
|
|
|
5
|
-
[DRbQS::
|
|
5
|
+
[DRbQS::Command::Server, DRbQS::Command::Node, DRbQS::Command::Manage, DRbQS::Command::SSH].each do |cls|
|
|
6
6
|
describe cls do
|
|
7
7
|
it "should have defined parse_option." do
|
|
8
8
|
cls.method_defined?(:parse_option).should be_true
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
require 'drbqs/command_line/command_line'
|
|
4
|
+
|
|
5
|
+
describe DRbQS::Command::OptionSetting do
|
|
6
|
+
subject do
|
|
7
|
+
DRbQS::Command::OptionSetting.new('help message', DRbQS::Setting::Base.new)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should set log_level option." do
|
|
11
|
+
subject.define(:log_level => true)
|
|
12
|
+
subject.parse!(['--log-level', 'debug']).should be_empty
|
|
13
|
+
subject.setting.get(:log_level).should == ['debug']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should set daemon option." do
|
|
17
|
+
subject.define(:daemon => true)
|
|
18
|
+
subject.parse!(['--daemon', '/path/to/log', 'other options']).should == ['other options']
|
|
19
|
+
subject.setting.get(:daemon).should == ['/path/to/log']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should set an arbitrary option." do
|
|
23
|
+
subject.define do
|
|
24
|
+
set(:new_opt, '--new-opt NUM', Integer, 'Set the number.')
|
|
25
|
+
end
|
|
26
|
+
subject.parse!(['--new-opt', '123', 'HELLO']).should == ['HELLO']
|
|
27
|
+
subject.setting.get(:new_opt).should == [123]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Use in process_define_spec.rb
|
|
2
|
+
|
|
3
|
+
server_file = File.join(File.dirname(__FILE__), '../../integration_test/definition/server02.rb')
|
|
4
|
+
usage message: "Usage of this definition.", server: server_file
|
|
5
|
+
|
|
6
|
+
default log: '/tmp/drbqs_tmp_log'
|
|
7
|
+
|
|
8
|
+
register_server 'server_local', 'localhost' do |server|
|
|
9
|
+
server.load server_file
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
register_server 'server_ssh', 'example.com' do |server, ssh|
|
|
13
|
+
ssh.connect "example.com"
|
|
14
|
+
server.load 'server.rb'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
register_node 'node_local' do |node|
|
|
18
|
+
node.log_level = Logger::DEBUG
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
register_node 'node_ssh' do |node, ssh|
|
|
22
|
+
ssh.connect "example.com"
|
|
23
|
+
node.log_level = Logger::DEBUG
|
|
24
|
+
end
|