drbqs 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/VERSION +1 -1
  2. data/bin/drbqs-execute +6 -0
  3. data/bin/drbqs-manage +2 -2
  4. data/bin/drbqs-node +2 -2
  5. data/bin/drbqs-server +2 -2
  6. data/bin/drbqs-ssh +2 -2
  7. data/drbqs.gemspec +53 -16
  8. data/example/error_server/error.rb +6 -0
  9. data/example/error_server/server_def.rb +7 -0
  10. data/example/{error → error_task}/error.rb +0 -0
  11. data/example/{error → error_task}/server_def.rb +0 -0
  12. data/example/sum2/execute_def.rb +27 -0
  13. data/lib/drbqs/command_line/argument.rb +29 -0
  14. data/lib/drbqs/command_line/command_base.rb +81 -0
  15. data/lib/drbqs/command_line/command_execute.rb +33 -0
  16. data/lib/drbqs/command_line/command_line.rb +19 -0
  17. data/lib/drbqs/command_line/command_manage.rb +34 -0
  18. data/lib/drbqs/command_line/command_node.rb +26 -0
  19. data/lib/drbqs/command_line/command_server.rb +41 -0
  20. data/lib/drbqs/command_line/command_ssh.rb +51 -0
  21. data/lib/drbqs/command_line/option_setting.rb +42 -0
  22. data/lib/drbqs/execute/process_define.rb +213 -0
  23. data/lib/drbqs/execute/register.rb +147 -0
  24. data/lib/drbqs/{utility → execute}/server_define.rb +7 -14
  25. data/lib/drbqs/manage/execute_node.rb +4 -2
  26. data/lib/drbqs/manage/manage.rb +23 -16
  27. data/lib/drbqs/manage/send_signal.rb +31 -4
  28. data/lib/drbqs/manage/ssh_execute.rb +50 -6
  29. data/lib/drbqs/manage/ssh_shell.rb +95 -50
  30. data/lib/drbqs/node/connection.rb +1 -1
  31. data/lib/drbqs/node/node.rb +67 -17
  32. data/lib/drbqs/node/state.rb +109 -0
  33. data/lib/drbqs/node/task_client.rb +7 -7
  34. data/lib/drbqs/server/history.rb +16 -0
  35. data/lib/drbqs/server/message.rb +80 -15
  36. data/lib/drbqs/server/node_list.rb +16 -3
  37. data/lib/drbqs/server/prof.rb +48 -0
  38. data/lib/drbqs/server/queue.rb +20 -2
  39. data/lib/drbqs/server/server.rb +112 -70
  40. data/lib/drbqs/server/server_hook.rb +26 -6
  41. data/lib/drbqs/server/test/node.rb +34 -0
  42. data/lib/drbqs/server/test/server.rb +74 -0
  43. data/lib/drbqs/setting/base.rb +120 -0
  44. data/lib/drbqs/setting/data_container.rb +39 -0
  45. data/lib/drbqs/setting/execute.rb +71 -0
  46. data/lib/drbqs/setting/manage.rb +163 -0
  47. data/lib/drbqs/setting/node.rb +84 -0
  48. data/lib/drbqs/setting/server.rb +230 -0
  49. data/lib/drbqs/setting/setting.rb +14 -0
  50. data/lib/drbqs/setting/source.rb +220 -0
  51. data/lib/drbqs/setting/ssh.rb +165 -0
  52. data/lib/drbqs/task/task_generator.rb +4 -2
  53. data/lib/drbqs/utility/misc.rb +15 -1
  54. data/lib/drbqs/utility/temporary.rb +4 -2
  55. data/lib/drbqs.rb +3 -2
  56. data/spec/command_line/command_base_spec.rb +47 -0
  57. data/spec/{utility/command_line → command_line}/commands_spec.rb +3 -3
  58. data/spec/command_line/option_setting_spec.rb +29 -0
  59. data/spec/execute/def/execute1.rb +24 -0
  60. data/spec/execute/def/no_def.rb +2 -0
  61. data/spec/execute/process_define_spec.rb +167 -0
  62. data/spec/execute/register_spec.rb +77 -0
  63. data/spec/{utility → execute}/server_define_spec.rb +0 -0
  64. data/spec/integration_test/01_basic_usage_spec.rb +1 -1
  65. data/spec/integration_test/02_use_generator_spec.rb +1 -1
  66. data/spec/integration_test/03_use_temporary_file_spec.rb +1 -1
  67. data/spec/integration_test/04_use_unix_domain_spec.rb +1 -1
  68. data/spec/integration_test/05_server_exit_signal_spec.rb +1 -1
  69. data/spec/integration_test/06_node_exit_after_task_spec.rb +1 -1
  70. data/spec/integration_test/07_command_server_with_node_spec.rb +19 -16
  71. data/spec/integration_test/08_shutdown_unused_nodes_spec.rb +38 -0
  72. data/spec/integration_test/09_server_process_data_spec.rb +74 -0
  73. data/spec/integration_test/10_test_server_spec.rb +18 -0
  74. data/spec/integration_test/definition/task_obj_definition.rb +14 -0
  75. data/spec/manage/send_signal_spec.rb +8 -0
  76. data/spec/manage/ssh_shell_spec.rb +1 -1
  77. data/spec/node/state_spec.rb +148 -0
  78. data/spec/node/task_client_spec.rb +15 -0
  79. data/spec/server/history_spec.rb +51 -20
  80. data/spec/server/message_spec.rb +7 -2
  81. data/spec/server/node_list_spec.rb +1 -1
  82. data/spec/server/queue_spec.rb +93 -4
  83. data/spec/server/server_hook_spec.rb +62 -0
  84. data/spec/setting/base_spec.rb +35 -0
  85. data/spec/setting/data_container_spec.rb +92 -0
  86. data/spec/setting/execute_spec.rb +51 -0
  87. data/spec/setting/manage_spec.rb +63 -0
  88. data/spec/setting/node_spec.rb +43 -0
  89. data/spec/setting/server_spec.rb +46 -0
  90. data/spec/setting/source_spec.rb +245 -0
  91. data/spec/spec_helper.rb +17 -10
  92. data/spec/utility/argument_spec.rb +7 -7
  93. metadata +179 -146
  94. data/lib/drbqs/utility/argument.rb +0 -27
  95. data/lib/drbqs/utility/command_line/command_base.rb +0 -27
  96. data/lib/drbqs/utility/command_line/command_manage.rb +0 -121
  97. data/lib/drbqs/utility/command_line/command_node.rb +0 -103
  98. data/lib/drbqs/utility/command_line/command_server.rb +0 -165
  99. data/lib/drbqs/utility/command_line/command_ssh.rb +0 -126
  100. data/lib/drbqs/utility/command_line.rb +0 -15
  101. data/spec/utility/command_line/command_base_spec.rb +0 -33
@@ -0,0 +1,213 @@
1
+ require 'drbqs/execute/register'
2
+
3
+ module DRbQS
4
+ class ProcessDefinition
5
+ class InvalidServerDefinition < StandardError
6
+ end
7
+
8
+ class InvalidNodeDefinition < StandardError
9
+ end
10
+
11
+ attr_reader :register
12
+
13
+ def initialize(server, node, port, io = nil)
14
+ @server = server
15
+ @node = node
16
+ @port = port
17
+ @register = DRbQS::ProcessDefinition::Register.new
18
+ @io = io
19
+ end
20
+
21
+ def puts_progress(str)
22
+ @io.puts str if @io
23
+ end
24
+ private :puts_progress
25
+
26
+ # Log directory for processes on localhost.
27
+ # Processes over ssh does not use this directory.
28
+ def local_log_directory
29
+ @logal_log_directory ||= FileName.create(default_value(:log) || 'drbqs_execute_log')
30
+ end
31
+
32
+ def load(path)
33
+ @register.__load__(path)
34
+ end
35
+
36
+ def get_server_setting(name = nil)
37
+ if data = (name ? @register.__server__.assoc(name.intern) : @register.__server__[0])
38
+ { :name => data[0], :type => data[1][:type], :setting => data[1][:setting], :hostname => data[1][:args][0] }
39
+ elsif name
40
+ get_server_setting(nil)
41
+ else
42
+ nil
43
+ end
44
+ end
45
+ private :get_server_setting
46
+
47
+ def get_node_data(name)
48
+ if ary = @register.__node__.assoc(name)
49
+ ary[1]
50
+ else
51
+ nil
52
+ end
53
+ end
54
+ private :get_node_data
55
+
56
+ def each_node(names = nil, &block)
57
+ if names
58
+ names.each do |name|
59
+ if data = get_node_data(name)
60
+ yield(name, data)
61
+ end
62
+ end
63
+ else
64
+ @register.__node__.each do |name, data|
65
+ yield(name, data)
66
+ end
67
+ end
68
+ end
69
+ private :each_node
70
+
71
+ def default_value(key)
72
+ @register.__default__[key]
73
+ end
74
+ private :default_value
75
+
76
+ def server_port
77
+ @port || default_value(:port) || ROOT_DEFAULT_PORT
78
+ end
79
+ private :server_port
80
+
81
+ def server_uri(name)
82
+ data = get_server_setting(name)
83
+ DRbQS::Misc.create_uri(:host => data[:hostname], :port => server_port)
84
+ end
85
+ private :server_uri
86
+
87
+ def execute_server(server_args)
88
+ if data = get_server_setting(@server)
89
+ name = data[:name].to_s
90
+ puts_progress "Execute server '#{name}' (#{data[:type]})"
91
+ setting = data[:setting]
92
+ hostname = data[:hostname]
93
+ type = data[:type]
94
+ if type == :ssh
95
+ setting.value.connect name
96
+ server_setting = setting.mode_setting
97
+ else
98
+ server_setting = setting
99
+ server_setting.value.daemon FileName.create(local_log_directory, "server_execute.log", :position => :middle)
100
+ end
101
+ server_setting.set_server_argument(*server_args)
102
+ server_setting.value.port server_port
103
+ unless server_setting.set?(:sftp_host)
104
+ server_setting.value.sftp_host hostname
105
+ end
106
+ setting.parse!
107
+ unless type == :ssh
108
+ server_setting.value.argument.each do |path|
109
+ unless File.exist?(path)
110
+ raise "File '#{path}' does not exist."
111
+ end
112
+ end
113
+ end
114
+ setting.exec
115
+ end
116
+ rescue Exception => err
117
+ puts_progress "Fail to execute server '#{data[:name].to_s}'"
118
+ mes = "#{err.to_s} (#{err.class.to_s})"
119
+ mes = "#{setting.string_for_shell}; " << mes if setting.respond_to?(:string_for_shell)
120
+ new_err = InvalidServerDefinition.new(mes)
121
+ new_err.set_backtrace(err.backtrace)
122
+ raise new_err
123
+ end
124
+
125
+ def execute_one_node(name, data, uri)
126
+ puts_progress "Execute node '#{name}' (#{data[:type]})"
127
+ setting = data[:setting]
128
+ node_setting = (data[:type] == :ssh ? setting.mode_setting : setting)
129
+ node_setting.value.argument.clear
130
+ node_setting.value.connect uri
131
+ if data[:type] == :ssh
132
+ unless setting.set?(:connect)
133
+ setting.value.connect name.to_s
134
+ end
135
+ else
136
+ node_log_dir = FileName.create(local_log_directory, 'node_execute_log', :directory => :self)
137
+ setting.clear :log_stdout
138
+ setting.value.log_prefix File.join(node_log_dir, 'node')
139
+ setting.value.daemon File.join(node_log_dir, 'execute.log')
140
+ end
141
+ setting.parse!
142
+ setting.exec
143
+ rescue Exception => err
144
+ puts_progress "Fail to execute node '#{name.to_s}'"
145
+ mes = "#{err.to_s} (#{err.class.to_s})"
146
+ mes = "#{setting.string_for_shell}; " << mes if setting.respond_to?(:string_for_shell)
147
+ new_err = InvalidNodeDefinition.new(mes)
148
+ new_err.set_backtrace(err.backtrace)
149
+ raise new_err
150
+ end
151
+ private :execute_one_node
152
+
153
+ def execute_node
154
+ uri = server_uri(@server)
155
+ each_node(@node) do |name, data|
156
+ execute_one_node(name, data, uri)
157
+ end
158
+ end
159
+
160
+ def information
161
+ info = {}
162
+ info[:server] = @register.__server__.map do |name, data|
163
+ [name, data[:type]]
164
+ end
165
+ info[:node] = @register.__node__.map do |name, data|
166
+ [name, data[:type]]
167
+ end
168
+ if data = get_server_setting(@server)
169
+ default_server = data[:name]
170
+ else
171
+ default_server = nil
172
+ end
173
+ info[:default] = {
174
+ :server => default_server,
175
+ :node => @node || info[:node].map { |ary| ary[0]},
176
+ :port => server_port
177
+ }
178
+ info
179
+ end
180
+
181
+ def information_string
182
+ info = information
183
+ str = "Server:\n"
184
+ info[:server].each do |name, type|
185
+ s = sprintf("%- 16s %s\n", name, (type == :ssh ? 'ssh' : 'local'))
186
+ str << (info[:default][:server] == name ? "* " : " ")
187
+ str << s
188
+ end
189
+ str << "Node:\n"
190
+ info[:node].each do |name, type|
191
+ s = sprintf("%- 16s %s\n", name, (type == :ssh ? 'ssh' : 'local'))
192
+ str << (info[:default][:node].include?(name) ? " " : "- ")
193
+ str << s
194
+ end
195
+ str << "Port: #{info[:default][:port]}"
196
+ end
197
+
198
+ def usage
199
+ if data = @register.__usage__
200
+ str = data[:message] ? "\nDescription:\n#{data[:message]}" : ""
201
+ if (server_file = data[:server]) && File.exist?(server_file)
202
+ Kernel.load(server_file)
203
+ if server_help = DRbQS.option_help_message
204
+ str << "\n\n" << server_help
205
+ end
206
+ end
207
+ str
208
+ else
209
+ ''
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,147 @@
1
+ module DRbQS
2
+ class ProcessDefinition
3
+ class Register
4
+ attr_reader :__server__, :__node__, :__default__, :__usage__
5
+
6
+ def initialize
7
+ @__server__ = []
8
+ @__node__ = []
9
+ @__default__ = {}
10
+ @__usage__ = nil
11
+ end
12
+
13
+ def __register__(type, name, *args, &block)
14
+ if block_given?
15
+ type = type.intern
16
+ case type
17
+ when :server
18
+ setting = DRbQS::Setting::Server.new
19
+ when :node
20
+ setting = DRbQS::Setting::Node.new
21
+ else
22
+ raise ArgumentError, "Invalid type of setting '#{type.to_s}'"
23
+ end
24
+ case block.arity
25
+ when 2
26
+ ssh_setting = DRbQS::Setting::SSH.new
27
+ ssh_setting.value.argument << type.to_s
28
+ yield(setting.value, ssh_setting.value)
29
+ ssh_setting.mode_setting = setting
30
+ unless ssh_setting.value.argument[0] == type.to_s
31
+ ssh_setting.value.argument.unshift(type.to_s)
32
+ end
33
+ ary = [name.intern, { :type => :ssh, :setting => ssh_setting, :args => args }]
34
+ when 1
35
+ yield(setting.value)
36
+ ary = [name.intern, { :type => type, :setting => setting, :args => args }]
37
+ else
38
+ raise ArgumentError, "Block must take one or two arguments."
39
+ end
40
+ instance_variable_get("@__#{type.to_s}__") << ary
41
+ else
42
+ raise ArgumentError, "Block to define settings is not given."
43
+ end
44
+ end
45
+ private :__register__
46
+
47
+ # To set properties of server we can use the similar options to the command 'drbqs-server'.
48
+ # When we execute a server over ssh, we can use the similar options to the command 'drbqs-ssh'
49
+ # Exceptionally, we can set files to load by 'load' method
50
+ # and set a ssh server by 'connect' method.
51
+ # If we omit the 'connect' method then the program tries to connect
52
+ # the name specified as first argument.
53
+ #
54
+ # * Example of a server on localhost
55
+ # register_server(:server_local, "example.com") do |server|
56
+ # server.load "server_definition.rb"
57
+ # server.acl "/path/to/acl"
58
+ # server.log_file "/path/to/log"
59
+ # server.log_level Logger::ERROR
60
+ # server.sftp_user "username"
61
+ # server.sftp_host "example.com"
62
+ # end
63
+ #
64
+ # * Example of a server over ssh
65
+ # register_server(:server_ssh, "example.co.jp") do |server, ssh|
66
+ # server.load "server_definition.rb"
67
+ # server.acl "/path/to/acl"
68
+ # server.log_level Logger::ERROR
69
+ # server.sftp_user "username"
70
+ # server.sftp_host "example.com"
71
+ #
72
+ # ssh.connect "hostname"
73
+ # ssh.directory "/path/to/dir"
74
+ # ssh.shell "bash"
75
+ # ssh.rvm "ruby-head"
76
+ # ssh.rvm_init "/path/to/scripts/rvm"
77
+ # ssh.output "/path/to/output"
78
+ # ssh.nice 10
79
+ # end
80
+ def register_server(name, hostname = nil, &block)
81
+ __register__(:server, name, hostname || name.to_s, &block)
82
+ end
83
+
84
+ # To set properties of nodes we can use the similar options to the command 'drbqs-node'.
85
+ # When we execute a server over ssh, we can use the similar options to the command 'drbqs-ssh'
86
+ # Exceptionally, we can set a ssh server by 'connect' method.
87
+ # If we omit the 'connect' method then the program tries to connect
88
+ # the name specified as first argument.
89
+ #
90
+ # * Example of nodes on localhost
91
+ # register_node(:node_local) do |node|
92
+ # node.process 3
93
+ # node.load "load_lib.rb"
94
+ # node.log_prefix "/path/to/log"
95
+ # node.log_level Logger::DEBUG
96
+ # end
97
+ #
98
+ # * Example of nodes over ssh
99
+ # register_node(:node_ssh) do |node, ssh|
100
+ # node.process 3
101
+ # node.load "load_lib.rb"
102
+ # node.log_level Logger::DEBUG
103
+ #
104
+ # ssh.connect "hostname"
105
+ # ssh.directory "/path/to/dir"
106
+ # ssh.shell "bash"
107
+ # ssh.rvm "ruby-head"
108
+ # ssh.rvm_init "/path/to/scripts/rvm"
109
+ # ssh.output "/path/to/output"
110
+ # ssh.nice 10
111
+ # end
112
+ def register_node(name, &block)
113
+ __register__(:node, name, &block)
114
+ end
115
+
116
+ # We can set default server, default port, and default directory to output log.
117
+ # * Example of usage
118
+ # default :port => 13456, :server => :server_local, :log => "/tmp/drbqs_execute_log"
119
+ def default(val = {})
120
+ val.delete_if { |key, v| !v }
121
+ @__default__.merge!(val)
122
+ if @__default__[:server]
123
+ @__default__[:server] = @__default__[:server].intern
124
+ end
125
+ if @__default__[:port]
126
+ @__default__[:port] = @__default__[:port].to_i
127
+ end
128
+ end
129
+
130
+ def default_clear(key)
131
+ @__default__.delete(key)
132
+ end
133
+
134
+ # We can set messages of usage and path of definition file of server
135
+ # to output help of server on showing help.
136
+ # * Example of usage
137
+ # usage(:message => 'Calculate some value', :server => 'server.rb')
138
+ def usage(opts = {})
139
+ @__usage__ = opts
140
+ end
141
+
142
+ def __load__(path)
143
+ instance_eval(File.read(path), path)
144
+ end
145
+ end
146
+ end
147
+ end
@@ -55,8 +55,8 @@ HELP
55
55
  @default_server_opts = nil
56
56
  end
57
57
 
58
- def create_server(options)
59
- server = DRbQS::Server.new(@default_server_opts.merge(options))
58
+ def create_server(options, klass = DRbQS::Server)
59
+ server = klass.new(@default_server_opts.merge(options))
60
60
  @server_create.call(server, @argv, @opts)
61
61
  server.set_signal_trap
62
62
  server
@@ -72,17 +72,10 @@ HELP
72
72
  server.wait
73
73
  end
74
74
 
75
- def test_server(options, type, arg = [], test_opts = {})
76
- server = create_server(options)
77
- case type
78
- when :task
79
- puts "*** Test of Task Generators ***"
80
- server.test_task_generator(:limit => arg[0] ? arg[0].to_i : nil, :progress => true)
81
- when :exec
82
- server.test_exec(:limit => arg[0] ? arg[0].to_i : nil, :profile => test_opts[:profile])
83
- else
84
- puts "*** Not be yet implemented ***"
85
- end
75
+ def create_test_server(options)
76
+ require 'drbqs/server/test/server'
77
+ options[:finish_exit] = true
78
+ create_server(options, DRbQS::Test::Server)
86
79
  end
87
80
  end
88
81
 
@@ -90,7 +83,7 @@ HELP
90
83
 
91
84
  class << self
92
85
  [:define_server, :option_parser, :parse_option, :option_help_message, :clear_definition,
93
- :start_server, :test_server].each do |m|
86
+ :start_server, :create_test_server].each do |m|
94
87
  define_method(m, &@@server_def.method(m))
95
88
  end
96
89
  end
@@ -3,7 +3,7 @@ module DRbQS
3
3
  class ExecuteNode
4
4
  attr_reader :pid
5
5
 
6
- def initialize(uri, log_prefix, log_level)
6
+ def initialize(uri, log_prefix, log_level, node_opts = {})
7
7
  @uri = uri
8
8
  @log_level = log_level
9
9
  if log_prefix
@@ -14,6 +14,7 @@ module DRbQS
14
14
  @fname = nil
15
15
  end
16
16
  @pid = []
17
+ @node_opts = node_opts
17
18
  end
18
19
 
19
20
  def get_log_file
@@ -26,7 +27,8 @@ module DRbQS
26
27
 
27
28
  def create_process
28
29
  @pid << fork do
29
- node = DRbQS::Node.new(@uri, :log_level => @log_level, :log_file => get_log_file)
30
+ opts = @node_opts.merge({ :log_level => @log_level, :log_file => get_log_file })
31
+ node = DRbQS::Node.new(@uri, opts)
30
32
  node.connect
31
33
  node.calculate
32
34
  end
@@ -1,13 +1,18 @@
1
+ require 'forwardable'
1
2
  require 'drbqs/manage/ssh_execute'
2
3
  require 'drbqs/manage/send_signal'
3
4
 
4
5
  module DRbQS
5
6
  class Manage
7
+ extend Forwardable
8
+
6
9
  class NotSetURI < StandardError
7
10
  end
11
+ class NoServerRespond < StandardError
12
+ end
8
13
 
9
- WAIT_SERVER_TIME = 0.3
10
- WAIT_MAX_NUMBER = 200
14
+ WAIT_SERVER_TIME = 0.2
15
+ WAIT_MAX_NUMBER = 150
11
16
 
12
17
  # +opts+ has keys :home and :uri.
13
18
  def initialize(opts = {})
@@ -51,16 +56,9 @@ module DRbQS
51
56
  config.save_sample
52
57
  end
53
58
 
54
- def send_exit_signal
55
- signal_sender.send_exit_signal
56
- end
57
-
58
- def send_node_exit_after_task(node_id)
59
- signal_sender.send_node_exit_after_task(node_id)
60
- end
61
-
62
- def get_status
63
- signal_sender.get_status
59
+ [:get_status, :get_history, :send_exit_signal, :send_node_exit_after_task,
60
+ :send_node_wake, :send_node_sleep, :send_data].each do |method_name|
61
+ def_delegator :signal_sender, method_name, method_name
64
62
  end
65
63
 
66
64
  def server_respond?
@@ -74,16 +72,25 @@ module DRbQS
74
72
  end
75
73
  end
76
74
 
77
- def wait_server_process(pid)
75
+ # If the server responds, this method returns true.
76
+ # If the server process does not exist, this method return nil.
77
+ # If the server process exists and there is no response,
78
+ # this method raises error.
79
+ def wait_server_process(pid = nil)
78
80
  i = 0
79
81
  begin
80
82
  sleep(WAIT_SERVER_TIME)
81
- unless DRbQS::Misc.process_running_normally?(pid)
82
- return nil
83
+ if pid
84
+ unless DRbQS::Misc.process_running_normally?(pid)
85
+ return nil
86
+ end
87
+ elsif server_data = config.list.server.get(@opts[:uri])
88
+ pid = server_data[:pid]
83
89
  end
84
90
  i += 1
85
91
  if i > WAIT_MAX_NUMBER
86
- raise "Can not wait server process."
92
+ raise DRbQS::Manage::NoServerRespond,
93
+ "We are waiting for #{WAIT_SERVER_TIME * WAIT_MAX_NUMBER} seconds, but the server of #{@opts[:uri]} does not respond."
87
94
  end
88
95
  end while !server_respond?
89
96
  true
@@ -24,13 +24,23 @@ module DRbQS
24
24
  send_signal_to_server(:exit_after_task, node_id)
25
25
  end
26
26
 
27
- def get_status
28
- send_signal_to_server(:request_status, sender_id)
27
+ def send_node_wake(node_id)
28
+ send_signal_to_server(:wake_node, node_id)
29
+ end
30
+
31
+ def send_node_sleep(node_id)
32
+ send_signal_to_server(:sleep_node, node_id)
33
+ end
34
+
35
+ def send_data(data)
36
+ send_signal_to_server(:new_data, data)
37
+ end
38
+
39
+ def wait_response(message_cond)
29
40
  i = 0
30
41
  loop do
31
42
  begin
32
- mes = @message.take([:status, String], 0)
33
- return mes[1]
43
+ return @message.take(message_cond, 0)
34
44
  rescue Rinda::RequestExpiredError
35
45
  i += 1
36
46
  if i > MAX_WAIT_TIME
@@ -40,6 +50,23 @@ module DRbQS
40
50
  end
41
51
  end
42
52
  end
53
+ private :wait_response
54
+
55
+ def get_status
56
+ send_signal_to_server(:request_status, sender_id)
57
+ if mes = wait_response([:status, String])
58
+ return mes[1]
59
+ end
60
+ nil
61
+ end
62
+
63
+ def get_history
64
+ send_signal_to_server(:request_history, sender_id)
65
+ if mes = wait_response([:history, String])
66
+ return mes[1]
67
+ end
68
+ nil
69
+ end
43
70
  end
44
71
  end
45
72
  end
@@ -6,17 +6,61 @@ module DRbQS
6
6
  def initialize(dest, opts = {})
7
7
  @ssh_host = DRbQS::Config.new.ssh_host
8
8
  path, options = @ssh_host.get_options(dest)
9
- # $stdout.puts "Use configuration: #{path}" if path
10
- dest = options[:dest] || dest
11
- @ssh = DRbQS::Manage::SSHShell.new(dest, options.merge(opts))
9
+ dest = options.delete(:dest) || dest
10
+ @ssh_shell = DRbQS::Manage::SSHShell.new(dest, options.merge(opts))
12
11
  end
13
12
 
14
- def execute(command)
15
- @ssh.start(command)
13
+ def command(command)
14
+ @ssh_shell.execute_all(command)
16
15
  end
17
16
 
18
17
  def get_environment
19
- @ssh.get_environment
18
+ @ssh_shell.get_environment
19
+ end
20
+
21
+ # Keys are :nice and :daemon.
22
+ def add_command_options(cmd, daemon, nice)
23
+ if nice
24
+ s = "nice "
25
+ s << "-n #{nice.to_s} " if Integer === nice
26
+ else
27
+ s = ''
28
+ end
29
+ s << cmd << " --daemon " << daemon
30
+ end
31
+ private :add_command_options
32
+
33
+ def create_new_directory(sh, dir)
34
+ process, result = sh.exec("filename-create new -a always -D self -t time #{dir}", :check => true)
35
+ result.strip!
36
+ end
37
+ private :create_new_directory
38
+
39
+ # Add options --daemon and --log-file.
40
+ def server(cmd_options, opts = {})
41
+ ret = nil
42
+ @ssh_shell.start do |sh|
43
+ dir = create_new_directory(sh, opts[:daemon] || 'drbqs_server_log')
44
+ cmd = add_command_options('drbqs-server', File.join(dir, 'daemon_server.log'), opts[:nice])
45
+ cmd << " --log-file " << File.join(dir, 'server.log') << ' '
46
+ cmd << cmd_options.join(' ')
47
+ process, result = sh.exec(cmd)
48
+ ret = (process.exit_status == 0)
49
+ end
50
+ ret
51
+ end
52
+
53
+ # Add options --daemon and --log-prefix.
54
+ def node(cmd_options, opts = {})
55
+ ret = nil
56
+ @ssh_shell.start do |sh|
57
+ dir = create_new_directory(sh, opts[:daemon] || 'drbqs_node_log')
58
+ cmd = add_command_options('drbqs-node', File.join(dir, 'daemon_node.log'), opts[:nice])
59
+ cmd << ' --log-prefix ' << File.join(dir, 'node') << ' ' << cmd_options.join(' ')
60
+ process, result = sh.exec(cmd)
61
+ ret = (process.exit_status == 0)
62
+ end
63
+ ret
20
64
  end
21
65
  end
22
66
  end