drbqs 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/Gemfile +10 -7
  2. data/README.md +52 -11
  3. data/Rakefile +32 -10
  4. data/VERSION +1 -1
  5. data/bin/drbqs-manage +3 -93
  6. data/bin/drbqs-node +3 -89
  7. data/bin/drbqs-server +3 -117
  8. data/bin/drbqs-ssh +6 -0
  9. data/drbqs.gemspec +118 -97
  10. data/example/README.md +2 -2
  11. data/lib/drbqs/config/config.rb +88 -0
  12. data/lib/drbqs/config/process_list.rb +194 -0
  13. data/lib/drbqs/config/ssh_host.rb +41 -0
  14. data/lib/drbqs/{execute_node.rb → manage/execute_node.rb} +6 -4
  15. data/lib/drbqs/manage/manage.rb +100 -0
  16. data/lib/drbqs/manage/send_signal.rb +45 -0
  17. data/lib/drbqs/manage/ssh_execute.rb +23 -0
  18. data/lib/drbqs/manage/ssh_shell.rb +143 -0
  19. data/lib/drbqs/node/connection.rb +69 -0
  20. data/lib/drbqs/{client.rb → node/node.rb} +48 -18
  21. data/lib/drbqs/node/task_client.rb +94 -0
  22. data/lib/drbqs/server/acl_file.rb +15 -0
  23. data/lib/drbqs/server/check_alive.rb +23 -0
  24. data/lib/drbqs/server/history.rb +49 -0
  25. data/lib/drbqs/server/message.rb +142 -0
  26. data/lib/drbqs/server/node_list.rb +59 -0
  27. data/lib/drbqs/server/queue.rb +128 -0
  28. data/lib/drbqs/{server.rb → server/server.rb} +66 -74
  29. data/lib/drbqs/server/server_hook.rb +72 -0
  30. data/lib/drbqs/server/transfer_setting.rb +30 -0
  31. data/lib/drbqs/task/command_task.rb +43 -0
  32. data/lib/drbqs/{task.rb → task/task.rb} +18 -39
  33. data/lib/drbqs/{task_generator.rb → task/task_generator.rb} +2 -0
  34. data/lib/drbqs/utility/argument.rb +27 -0
  35. data/lib/drbqs/utility/command_line/command_base.rb +27 -0
  36. data/lib/drbqs/utility/command_line/command_manage.rb +121 -0
  37. data/lib/drbqs/utility/command_line/command_node.rb +103 -0
  38. data/lib/drbqs/utility/command_line/command_server.rb +165 -0
  39. data/lib/drbqs/utility/command_line/command_ssh.rb +126 -0
  40. data/lib/drbqs/utility/command_line.rb +15 -0
  41. data/lib/drbqs/utility/misc.rb +72 -0
  42. data/lib/drbqs/{server_define.rb → utility/server_define.rb} +23 -8
  43. data/lib/drbqs/utility/temporary.rb +49 -0
  44. data/lib/drbqs/{ssh/transfer.rb → utility/transfer/file_transfer.rb} +18 -58
  45. data/lib/drbqs/utility/transfer/transfer_client.rb +90 -0
  46. data/lib/drbqs.rb +10 -22
  47. data/spec/config/config_spec.rb +84 -0
  48. data/spec/config/process_list_spec.rb +149 -0
  49. data/spec/config/ssh_host_spec.rb +81 -0
  50. data/spec/integration_test/01_basic_usage_spec.rb +54 -0
  51. data/spec/integration_test/02_use_generator_spec.rb +53 -0
  52. data/spec/integration_test/03_use_temporary_file_spec.rb +26 -0
  53. data/spec/integration_test/04_use_unix_domain_spec.rb +34 -0
  54. data/spec/integration_test/05_server_exit_signal_spec.rb +23 -0
  55. data/spec/integration_test/06_node_exit_after_task_spec.rb +42 -0
  56. data/spec/integration_test/07_command_server_with_node_spec.rb +44 -0
  57. data/spec/integration_test/definition/server01.rb +20 -0
  58. data/spec/integration_test/definition/server02.rb +16 -0
  59. data/spec/integration_test/definition/task_obj_definition.rb +49 -0
  60. data/spec/manage/manage_spec.rb +33 -0
  61. data/spec/manage/send_signal_spec.rb +39 -0
  62. data/spec/{ssh_shell_spec.rb → manage/ssh_shell_spec.rb} +8 -8
  63. data/spec/node/connection_spec.rb +66 -0
  64. data/spec/node/task_client_spec.rb +212 -0
  65. data/spec/server/acl_file_spec.rb +9 -0
  66. data/spec/{server_check_alive_spec.rb → server/check_alive_spec.rb} +15 -11
  67. data/spec/{data → server/data}/acl.txt +0 -0
  68. data/spec/{history_spec.rb → server/history_spec.rb} +9 -5
  69. data/spec/server/message_spec.rb +195 -0
  70. data/spec/server/node_list_spec.rb +111 -0
  71. data/spec/server/queue_spec.rb +239 -0
  72. data/spec/{server_hook_spec.rb → server/server_hook_spec.rb} +23 -17
  73. data/spec/server/server_spec.rb +89 -0
  74. data/spec/server/transfer_setting_spec.rb +37 -0
  75. data/spec/spec_helper.rb +65 -0
  76. data/spec/task/file_transfer_spec.rb +107 -0
  77. data/spec/{task_generator_spec.rb → task/task_generator_spec.rb} +2 -2
  78. data/spec/{task_spec.rb → task/task_spec.rb} +3 -1
  79. data/spec/utility/argument_spec.rb +39 -0
  80. data/spec/utility/command_line/command_base_spec.rb +33 -0
  81. data/spec/utility/command_line/commands_spec.rb +15 -0
  82. data/spec/utility/misc_spec.rb +77 -0
  83. data/spec/utility/server_define_spec.rb +59 -0
  84. data/spec/utility/temporary_spec.rb +39 -0
  85. metadata +158 -93
  86. data/example/drbqs-manage-test.rb +0 -3
  87. data/example/drbqs-node-test.rb +0 -3
  88. data/example/drbqs-server-test.rb +0 -3
  89. data/lib/drbqs/acl_file.rb +0 -13
  90. data/lib/drbqs/config.rb +0 -98
  91. data/lib/drbqs/connection.rb +0 -67
  92. data/lib/drbqs/history.rb +0 -34
  93. data/lib/drbqs/manage.rb +0 -84
  94. data/lib/drbqs/message.rb +0 -119
  95. data/lib/drbqs/node_list.rb +0 -52
  96. data/lib/drbqs/queue.rb +0 -138
  97. data/lib/drbqs/server_hook.rb +0 -67
  98. data/lib/drbqs/ssh/host.rb +0 -26
  99. data/lib/drbqs/ssh/shell.rb +0 -139
  100. data/lib/drbqs/task_client.rb +0 -86
  101. data/lib/drbqs/utils.rb +0 -19
  102. data/spec/acl_file_spec.rb +0 -9
  103. data/spec/config_spec.rb +0 -14
  104. data/spec/connection_spec.rb +0 -49
  105. data/spec/manage_spec.rb +0 -57
  106. data/spec/message_spec.rb +0 -81
  107. data/spec/node_list_spec.rb +0 -68
  108. data/spec/queue_spec.rb +0 -59
  109. data/spec/server_define_spec.rb +0 -45
  110. data/spec/server_spec.rb +0 -56
  111. data/spec/task_client_spec.rb +0 -53
  112. data/spec/test/test1.rb +0 -13
  113. data/spec/test1_spec.rb +0 -80
  114. data/spec/test2_spec.rb +0 -69
  115. data/spec/transfer_spec.rb +0 -13
@@ -0,0 +1,30 @@
1
+ require 'drbqs/utility/transfer/transfer_client'
2
+
3
+ module DRbQS
4
+ class Server
5
+ class TransferSetting
6
+ attr_accessor :host, :user, :directory
7
+
8
+ def initialize(host, user, directory)
9
+ @host = host
10
+ @user = user
11
+ @directory = directory
12
+ @created = false
13
+ end
14
+
15
+ def create(directory, opts = {})
16
+ return nil if @created
17
+ @directory = directory || @directory
18
+ return nil if !@directory
19
+ @created = true
20
+ transfer_client = DRbQS::TransferClient.new(@directory)
21
+ transfer_client.make_directory
22
+ if host = opts[:host] || @host
23
+ user = opts[:user] || @user || ENV['USER']
24
+ transfer_client.set_sftp(user, host)
25
+ end
26
+ transfer_client
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ module DRbQS
2
+ # Execute a command and transfer files if needed.
3
+ class CommandExecute
4
+
5
+ # :transfer String or Array
6
+ # :compress true or false
7
+ def initialize(cmd, opts = {})
8
+ @cmd = cmd
9
+ unless (Array === @cmd || String === @cmd)
10
+ raise ArgumentError, "Invalid command: #{@cmd.inspect}"
11
+ end
12
+ @transfer = opts[:transfer]
13
+ @compress = opts[:compress]
14
+ end
15
+
16
+ def exec
17
+ case @cmd
18
+ when Array
19
+ @cmd.each { |c| system(c) }
20
+ when String
21
+ system(@cmd)
22
+ end
23
+ exit_status = $?.exitstatus
24
+ if @transfer
25
+ if @transfer.respond_to?(:each)
26
+ @transfer.each { |path| DRbQS::FileTransfer.enqueue(path, :compress => @compress) }
27
+ else
28
+ DRbQS::FileTransfer.enqueue(@transfer, :compress => @compress)
29
+ end
30
+ end
31
+ exit_status
32
+ end
33
+ end
34
+
35
+ # Class to define tasks such that we execute a command.
36
+ class CommandTask < Task
37
+
38
+ # &hook takes a server instance and exit number of command.
39
+ def initialize(cmd, opts = {}, &hook)
40
+ super(CommandExecute.new(cmd, opts), :exec, &hook)
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,6 @@
1
+ require 'drbqs/utility/transfer/file_transfer'
2
+ require 'drbqs/task/task_generator'
3
+
1
4
  module DRbQS
2
5
 
3
6
  # The tasks defined by this class are sent to nodes and
@@ -34,51 +37,22 @@ module DRbQS
34
37
  @args == other.instance_variable_get(:@args)
35
38
  end
36
39
 
37
- def self.execute_task(marshal_obj, method_sym, args)
38
- obj = Marshal.load(marshal_obj)
39
- obj.__send__(method_sym, *args)
40
- end
41
- end
42
-
43
- class CommandExecute
44
-
45
- # :transfer String or Array
46
- # :compress true or false
47
- def initialize(cmd, opts = {})
48
- @cmd = cmd
49
- unless (Array === @cmd || String === @cmd)
50
- raise ArgumentError, "Invalid command: #{@cmd.inspect}"
51
- end
52
- @transfer = opts[:transfer]
53
- @compress = opts[:compress]
54
- end
55
-
56
- def exec
57
- case @cmd
58
- when Array
59
- @cmd.each { |c| system(c) }
60
- when String
61
- system(@cmd)
40
+ def exec_hook(server, result)
41
+ if @hook
42
+ @hook.call(server, result)
43
+ true
44
+ else
45
+ nil
62
46
  end
63
- exit_status = $?.exitstatus
64
- if @transfer
65
- if Array === @transfer
66
- @transfer.each { |path| DRbQS::FileTransfer.enqueue(path, @compress) }
67
- else
68
- DRbQS::FileTransfer.enqueue(@transfer, @compress)
69
- end
70
- end
71
- exit_status
72
47
  end
73
- end
74
48
 
75
- class CommandTask < Task
76
- # &hook takes a server instance and exit number of command.
77
- def initialize(cmd, opts = {}, &hook)
78
- super(CommandExecute.new(cmd, {}), :exec, &hook)
49
+ def self.execute_task(marshal_obj, method_sym, args)
50
+ obj = Marshal.load(marshal_obj)
51
+ obj.__send__(method_sym, *args)
79
52
  end
80
53
  end
81
54
 
55
+ # Class to group a number of objects to process tasks.
82
56
  class TaskContainer
83
57
  def initialize(task_ary)
84
58
  @data = task_ary.map.with_index do |task, i|
@@ -104,6 +78,8 @@ module DRbQS
104
78
  end
105
79
  end
106
80
 
81
+ # Task to group a number of tasks,
82
+ # which uses TaskContainer and manages hooks of the tasks.
107
83
  class TaskSet < Task
108
84
  def initialize(task_ary)
109
85
  @original_hook = task_ary.map do |task|
@@ -118,4 +94,7 @@ module DRbQS
118
94
  end
119
95
  end
120
96
  end
97
+
121
98
  end
99
+
100
+ require 'drbqs/task/command_task'
@@ -68,6 +68,8 @@ module DRbQS
68
68
  end
69
69
  end
70
70
 
71
+ # Initialize fider to create tasks.
72
+ # This method must be called in thread to create tasks.
71
73
  def init
72
74
  @fiber_init.call if @fiber_init
73
75
  end
@@ -0,0 +1,27 @@
1
+ module DRbQS
2
+ module CommandLineArgument
3
+ def split_arguments(argv, split = '--')
4
+ if n = argv.index(split)
5
+ [argv[0..(n - 1)], argv[(n + 1)..-1]]
6
+ else
7
+ [argv, []]
8
+ end
9
+ end
10
+ module_function :split_arguments
11
+
12
+ def check_argument_size(argv, *args)
13
+ n = argv.size
14
+ args.each_slice(2).each do |ary|
15
+ if ary.size == 2
16
+ unless n.__send__(*ary)
17
+ raise "Invalid arguments number. Please refer to documents."
18
+ end
19
+ else
20
+ raise ArgumentError, "Invalid argument to check array size."
21
+ end
22
+ end
23
+ true
24
+ end
25
+ module_function :check_argument_size
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module DRbQS
2
+ class CommandBase
3
+ include DRbQS::CommandLineArgument
4
+ @@command_name = File.basename($PROGRAM_NAME)
5
+
6
+ def self.exec(argv)
7
+ obj = self.new
8
+ obj.parse_option(argv)
9
+ obj.exec
10
+ end
11
+
12
+ def exit_normally
13
+ Kernel.exit(0)
14
+ end
15
+ private :exit_normally
16
+
17
+ def exit_unusually
18
+ Kernel.exit(1)
19
+ end
20
+ private :exit_unusually
21
+
22
+ def exit_invalid_option
23
+ Kernel.exit(2)
24
+ end
25
+ private :exit_invalid_option
26
+ end
27
+ end
@@ -0,0 +1,121 @@
1
+ module DRbQS
2
+ class CommandManage < CommandBase
3
+ HELP_MESSAGE =<<HELP
4
+ Usage: #{@@command_name} <command> [arguments ...]
5
+ Manage DRbQS server by sending messages.
6
+ <command> is 'signal', 'status', 'process', or 'initialize'.
7
+
8
+ #{@@command_name} signal <uri> server-exit
9
+ #{@@command_name} signal <uri> node-exit-after-task <node_number>
10
+ #{@@command_name} status <uri>
11
+ #{@@command_name} process list
12
+ #{@@command_name} process clear
13
+ #{@@command_name} initialize
14
+
15
+ HELP
16
+
17
+ def parse_option(argv)
18
+ begin
19
+ OptionParser.new(HELP_MESSAGE) do |opt|
20
+ opt.on('--debug', 'Set $DEBUG true.') do |v|
21
+ $DEBUG = true
22
+ end
23
+ opt.parse!(argv)
24
+ end
25
+ rescue OptionParser::InvalidOption
26
+ $stderr.print "error: Invalid Option\n\n" << HELP_MESSAGE
27
+ exit_invalid_option
28
+ rescue OptionParser::InvalidArgument
29
+ $stderr.print "error: Invalid Argument\n\n" << HELP_MESSAGE
30
+ exit_invalid_option
31
+ end
32
+ @mode = argv.shift
33
+ @argv = argv
34
+ @manage = DRbQS::Manage.new
35
+ end
36
+
37
+ def command_initialize
38
+ check_argument_size(@argv, :>=, 0, :<=, 1)
39
+ @manage.set_home_directory(@argv[0])
40
+ @manage.create_config
41
+ exit_normally
42
+ end
43
+ private :command_initialize
44
+
45
+ def command_process
46
+ check_argument_size(@argv, :>=, 0, :<=, 1)
47
+ if @argv[0] == 'clear'
48
+ @manage.clear_process
49
+ exit_normally
50
+ end
51
+ list = @manage.list_process
52
+ $stdout.puts "Server"
53
+ list[:server].each do |uri, data|
54
+ $stdout.puts "#{uri}"
55
+ data.each do |k, v|
56
+ $stdout.puts sprintf(" %-10s %s", k, v)
57
+ end
58
+ end
59
+ $stdout.puts "\nNode"
60
+ list[:node].each do |pid, data|
61
+ $stdout.puts "#{pid}"
62
+ data.each do |k, v|
63
+ $stdout.puts sprintf(" %-10s %s", k, v)
64
+ end
65
+ end
66
+ exit_normally
67
+ end
68
+ private :command_process
69
+
70
+ def command_status
71
+ check_argument_size(@argv, :==, 1)
72
+ @manage.set_uri(@argv[0])
73
+ if status = @manage.get_status
74
+ $stdout.puts status
75
+ end
76
+ exit_normally
77
+ end
78
+ private :command_status
79
+
80
+ def command_signal
81
+ @manage.set_uri(@argv[0])
82
+ signal = @argv[1]
83
+ case signal
84
+ when 'server-exit'
85
+ check_argument_size(@argv, :==, 2)
86
+ @manage.send_exit_signal
87
+ exit_normally
88
+ when 'node-exit-after-task'
89
+ check_argument_size(@argv, :==, 3)
90
+ node_id = @argv[2].to_i
91
+ @manage.send_node_exit_after_task(node_id)
92
+ exit_normally
93
+ else
94
+ $stderr.print "error: Invalid signal '#{signal}'\n\n" << HELP_MESSAGE
95
+ exit_unusually
96
+ end
97
+ end
98
+ private :command_signal
99
+
100
+ def exec
101
+ case @mode
102
+ when 'initialize'
103
+ command_initialize
104
+ when 'process'
105
+ command_process
106
+ when 'status'
107
+ command_status
108
+ when 'signal'
109
+ command_signal
110
+ end
111
+ $stderr.print "error: Invalid command '#{@mode}'\n\n" << HELP_MESSAGE
112
+ exit_invalid_option
113
+ rescue DRb::DRbConnError => err
114
+ $stderr.puts "error: Can not connect server: #{err.to_s}"
115
+ exit_unusually
116
+ rescue => err
117
+ $stderr.print "error: #{err.to_s}\n" << err.backtrace.join("\n")
118
+ exit_unusually
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,103 @@
1
+ module DRbQS
2
+ class CommandNode < CommandBase
3
+ HELP_MESSAGE =<<HELP
4
+ Usage: #{@@command_name} [<uri>] [<process_number>] [options ...]
5
+ Start DRbQS nodes connecting to <uri>.
6
+
7
+ HELP
8
+
9
+ LOG_PREFIX_DEFAULT = 'drbqs_node'
10
+ LOG_LEVEL_DEFAULT = Logger::ERROR
11
+
12
+ def parse_option(argv)
13
+ options = {
14
+ :log_prefix => LOG_PREFIX_DEFAULT,
15
+ :log_level => LOG_LEVEL_DEFAULT,
16
+ :load => []
17
+ }
18
+
19
+ begin
20
+ OptionParser.new(HELP_MESSAGE) do |opt|
21
+ opt.on('-l', '--load FILE', String, 'Add a file to load.') do |v|
22
+ options[:load] << File.expand_path(v)
23
+ end
24
+ opt.on('--log-prefix STR', String, "Set the prefix of log files. The default is '#{LOG_PREFIX_DEFAULT}'.") do |v|
25
+ options[:log_prefix] = v
26
+ end
27
+ opt.on('--log-level LEVEL', String,
28
+ "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") do |v|
29
+ if /^(fatal)|(error)|(warn)|(info)|(debug)$/i =~ v
30
+ options[:log_level] = eval("Logger::#{v.upcase}")
31
+ else
32
+ $stderr.print "error: Invalid log level.\n\n" << HELP_MESSAGE
33
+ exit_invalid_option
34
+ end
35
+ end
36
+ opt.on('--log-stdout', 'Use stdout for outputting logs. This option cancels --log-prefix.') do |v|
37
+ options[:log_prefix] = nil
38
+ end
39
+ opt.on('--debug', 'Set $DEBUG true.') do |v|
40
+ $DEBUG = true
41
+ end
42
+ opt.parse!(argv)
43
+ end
44
+ rescue OptionParser::InvalidOption
45
+ $stderr.print "error: Invalid Option\n\n" << HELP_MESSAGE
46
+ exit_invalid_option
47
+ rescue OptionParser::InvalidArgument
48
+ $stderr.print "error: Invalid Argument\n\n" << HELP_MESSAGE
49
+ exit_invalid_option
50
+ end
51
+ @options = options
52
+ @argv = argv
53
+ end
54
+
55
+ def parse_argv_array
56
+ process_num = 1
57
+ uri = nil
58
+ @argv.each do |arg|
59
+ if /^\d+$/ =~ arg
60
+ process_num = arg.to_i
61
+ elsif uri
62
+ $stderr.print "error: More than one uris is set.\n\n" << HELP_MESSAGE
63
+ exit_invalid_option
64
+ else
65
+ uri = arg
66
+ end
67
+ end
68
+ uri ||= DRbQS::Misc.create_uri
69
+ [process_num, uri]
70
+ end
71
+ private :parse_argv_array
72
+
73
+ def exec
74
+ if @argv.size > 2
75
+ $stderr.print "error: Too many arguments.\n\n" << HELP_MESSAGE
76
+ exit_invalid_option
77
+ end
78
+ process_num, uri = parse_argv_array
79
+
80
+ @options[:load].each do |v|
81
+ $stdout.puts "load #{v}"
82
+ load v
83
+ end
84
+
85
+ $stdout.puts "Connect to #{uri}"
86
+ $stdout.puts "Execute #{process_num} processes"
87
+
88
+ if @options[:log_prefix]
89
+ if /\/$/ =~ @options[:log_prefix]
90
+ @options[:log_prefix] += 'out'
91
+ end
92
+ end
93
+
94
+ exec_node = DRbQS::ExecuteNode.new(uri, @options[:log_prefix], @options[:log_level])
95
+ exec_node.execute(process_num)
96
+ exec_node.wait
97
+ exit_normally
98
+ rescue => err
99
+ $stderr.print "error: #{err.to_s}\n" << err.backtrace.join("\n")
100
+ exit_unusually
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,165 @@
1
+ module DRbQS
2
+ class CommandServer < CommandBase
3
+ @@command_name = File.basename($PROGRAM_NAME)
4
+
5
+ HELP_MESSAGE =<<HELP
6
+ Usage: #{@@command_name} <definition.rb> [other files ...] [options ...]
7
+ #{@@command_name} <definition.rb> [other files ...] [options ...] -- [server options ...]
8
+ Start DRbQS server of definition files.
9
+
10
+ HELP
11
+
12
+ NODE_INTERVAL_TIME = 1
13
+
14
+ def parse_option(argv)
15
+ @options = {
16
+ :log_file => STDOUT
17
+ }
18
+ @command_type = :server_start
19
+
20
+ test_opts = {}
21
+ @execute_node_number = nil
22
+ @command_argv, @server_argv = split_arguments(argv)
23
+
24
+ begin
25
+ OptionParser.new(HELP_MESSAGE) do |opt|
26
+ opt.on('-p PORT', '--port', Integer, 'Set the port number of server.') do |v|
27
+ @options[:port] = v
28
+ end
29
+ opt.on('-u PATH', '--unix', String, 'Set the path of unix domain socket.') do |v|
30
+ @options[:unix] = v
31
+ end
32
+ opt.on('--acl FILE', String, 'Set a file to define ACL.') do |v|
33
+ @options[:acl] = v
34
+ end
35
+ opt.on('--log-file STR', String, "Set the path of log file. If this options is not set, use STDOUT.") do |v|
36
+ @options[:log_file] = v
37
+ end
38
+ opt.on('--log-level LEVEL', String,
39
+ "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") do |v|
40
+ if /^(fatal)|(error)|(warn)|(info)|(debug)$/i =~ v
41
+ @options[:log_level] = eval("Logger::#{v.upcase}")
42
+ else
43
+ $stderr.print "error: Invalid log level.\n\n" << HELP_MESSAGE
44
+ exit_invalid_option
45
+ end
46
+ end
47
+ opt.on('--file-directory DIR', String, 'Set the file archive directory.') do |v|
48
+ @options[:file_directory] = v
49
+ end
50
+ opt.on('--sftp-user USER', String, 'Set the user of sftp destination.') do |v|
51
+ @options[:sftp_user] = v
52
+ end
53
+ opt.on('--sftp-host HOST', String, 'Set the host of sftp destination.') do |v|
54
+ @options[:sftp_host] = v
55
+ end
56
+ opt.on('--profile', 'Use profile for test exec.') do |v|
57
+ @test_opts[:profile] = true
58
+ end
59
+ opt.on('--debug', 'Set $DEBUG true.') do |v|
60
+ $DEBUG = true
61
+ end
62
+ opt.on('--test STR', String, 'Execute test.') do |v|
63
+ @command_type = "test_#{v}"
64
+ end
65
+ opt.on('--execute-node NUM', Integer, 'Execute nodes.') do |v|
66
+ @execute_node_number = v
67
+ end
68
+ opt.on('-h', '--help', 'Show help.') do |v|
69
+ $stdout.print opt
70
+ @command_type = :help
71
+ end
72
+ opt.parse!(@command_argv)
73
+ end
74
+ rescue OptionParser::InvalidOption
75
+ $stderr.print "error: Invalid Option\n\n" << HELP_MESSAGE
76
+ exit_invalid_option
77
+ rescue OptionParser::InvalidArgument
78
+ $stderr.print "error: Invalid Argument\n\n" << HELP_MESSAGE
79
+ exit_invalid_option
80
+ end
81
+ end
82
+
83
+ def command_test
84
+ s = @command_type.split('_')[1].split(',')
85
+ type = s[0].intern
86
+ DRbQS.test_server(@options, type, s[1..-1], @test_opts)
87
+ end
88
+ private :command_test
89
+
90
+ def command_start_server
91
+ DRbQS.start_server(@options)
92
+ end
93
+ private :command_start_server
94
+
95
+ def command_server_with_nodes
96
+ server_pid = fork do
97
+ DRbQS.start_server(@options)
98
+ end
99
+ uri = DRbQS::Misc.create_uri(@options)
100
+ manage = DRbQS::Manage.new(:uri => uri)
101
+ if manage.wait_server_process(server_pid)
102
+ node_log_file = nil
103
+ unless IO === @options[:log_file]
104
+ node_log_file = FileName.create(@options[:log_file], :add => :always, :position => :middle, :delimiter => '', :format => "_node_%02d")
105
+ end
106
+ exec_node = DRbQS::ExecuteNode.new(uri, node_log_file, @options[:log_level])
107
+ exec_node.execute(@execute_node_number, NODE_INTERVAL_TIME)
108
+ exec_node.wait
109
+ else
110
+ $stderr.puts "error: Server has been terminated."
111
+ exit_unusually
112
+ end
113
+ end
114
+ private :command_server_with_nodes
115
+
116
+ def command_server_help
117
+ begin
118
+ @command_argv.each do |path|
119
+ if File.exist?(path)
120
+ load path
121
+ end
122
+ end
123
+ if mes = DRbQS.option_help_message
124
+ $stdout.print "\n" << mes
125
+ end
126
+ rescue => err
127
+ $stderr.print "error: Load invalid file.\n#{err.to_s}\n#{err.backtrace.join("\n")}"
128
+ exit_invalid_option
129
+ end
130
+ exit_normally
131
+ end
132
+ private :command_server_help
133
+
134
+ def exec
135
+ if @command_type == :help
136
+ command_server_help
137
+ end
138
+ if @command_argv.size == 0 || !(@command_argv.all? { |path| File.exist?(path) })
139
+ $stderr.print "error: There are nonexistent files.\n\n" << HELP_MESSAGE
140
+ exit_unusually
141
+ end
142
+ @command_argv.each do |path|
143
+ load path
144
+ end
145
+ unless @options[:acl]
146
+ @options[:acl] = DRbQS::Config.new.get_acl_file
147
+ end
148
+ DRbQS.parse_option(@server_argv)
149
+ case @command_type
150
+ when /^test/
151
+ command_test
152
+ else
153
+ if @execute_node_number
154
+ command_server_with_nodes
155
+ else
156
+ command_start_server
157
+ end
158
+ end
159
+ exit_normally
160
+ rescue => err
161
+ $stderr.print "error: #{err.to_s}\n" << err.backtrace.join("\n")
162
+ exit_unusually
163
+ end
164
+ end
165
+ end