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
data/Gemfile CHANGED
@@ -6,12 +6,15 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem "rspec", ">= 2.5.0"
10
- gem "yard", "~> 0.6.0"
11
- gem "bundler", "~> 1.0.0"
12
- gem "jeweler", "~> 1.5.2"
9
+ gem "rspec", ">= 2.6.0"
10
+ gem "yard", ">= 0.7.2"
11
+ gem "bundler", ">= 1.0.15"
12
+ gem "jeweler", ">= 1.6.2"
13
13
  gem "rcov", ">= 0"
14
- gem "filename", ">= 0.0.5"
15
- gem "net-ssh", ">= 2.1.3"
16
- gem "net-ssh-shell", ">= 0.1.0"
14
+ gem "filename", ">= 0.1.0"
15
+ gem "user_config", ">= 0.0.1"
16
+ gem "net-ssh", ">= 2.1.4"
17
+ gem "net-ssh-shell", ">= 0.2.0"
18
+ gem "net-sftp", ">= 2.0.5"
19
+ gem "sys-proctable"
17
20
  end
data/README.md CHANGED
@@ -12,7 +12,7 @@ and connect the nodes to the server.
12
12
  The behavior of nodes requests tasks, gets tasks from a server, processes the tasks,
13
13
  and sends results of the tasks to the server.
14
14
  The nodes work repeatedly until they get exit signal from server.
15
- The server prepares tasks and checks that nodes are alive.
15
+ The server prepares tasks and signals to check that nodes are alive.
16
16
  If the server does not communicate with the nodes unexpectedly,
17
17
  the server deletes the nodes from node list and
18
18
  requeues their calculating tasks.
@@ -23,7 +23,7 @@ after the server accepts them from nodes.
23
23
  The tasks are made from objects, an instance method of them, and its arguments.
24
24
  Because we use Marshal.dump and Marshal.load for communication of a server and nodes,
25
25
  the objects and the arguments must be marshalized.
26
- And also we tell the server and the nodes the definision of class of the objects and the arguments.
26
+ And also we tell the server and the nodes the definition of class of the objects and the arguments.
27
27
 
28
28
  ## Requirements
29
29
 
@@ -37,7 +37,7 @@ And we use net-ssh and net-ssh-shell to execute servers and nodes over ssh.
37
37
  We prepare a class to send tasks over network,
38
38
  which has data and a method to deal with tasks.
39
39
 
40
- We make sum.rb as the following.
40
+ For example, we make sum.rb as the following.
41
41
 
42
42
  class Sum
43
43
  def initialize(start_num, end_num)
@@ -92,7 +92,8 @@ when task queue is empty.
92
92
 
93
93
  ### Task generator
94
94
 
95
- Arguments of DRbQS::TaskGenerator.new define instance variables.
95
+ Arguments of DRbQS::TaskGenerator.new define instance variables,
96
+ which is implemented by Fiber and is executed by server's requests.
96
97
 
97
98
  task_generator = DRbQS::TaskGenerator.new(:abc => 'ABC', :def => 123, :data => [1, 2, 3])
98
99
 
@@ -104,7 +105,7 @@ The above example defines the following instance variables.
104
105
 
105
106
  Then, DRbQS::TaskGenerator#set method defines generation of tasks.
106
107
  The block of the method is evaluated in the context of task_generator.
107
- For the above example we can use @abc, @def, and @data.
108
+ We can use @abc, @def, and @data on the above example.
108
109
 
109
110
  task_generator.set do
110
111
  @data.each do |i|
@@ -112,8 +113,8 @@ For the above example we can use @abc, @def, and @data.
112
113
  end
113
114
  end
114
115
 
115
- DRbQS::TaskGenerator#create_add_task creates a task
116
- and the task is returned by DRbQS::TaskGenerator#new_tasks.
116
+ DRbQS::TaskGenerator#create_add_task set a task
117
+ and DRbQS::TaskGenerator#new_tasks actually creates the task.
117
118
  The arguments of DRbQS::TaskGenerator#create_add_task is
118
119
  the same as DRbQS::Task.new.
119
120
 
@@ -122,18 +123,58 @@ we set the generator by DRbQS::Server#add_task_generator.
122
123
 
123
124
  ### Start node and connect server
124
125
 
125
- Because nodes needs class Sum,
126
+ Because nodes need class Sum,
126
127
  the nodes load sum.rb when they starts.
127
- Then, we type in terminal.
128
+ Then, we use '-l' option for command 'drbqs-node'.
129
+ That is, we type in terminal.
128
130
 
129
131
  drbqs-node druby://localhost:13500/ -l sum.rb
130
132
 
131
- To use two cpu cores we execute two processes by the following.
133
+ We execute two processes to use two CPU cores.
132
134
 
133
135
  drbqs-node 2 druby://localhost:13500/ -l sum.rb
134
136
 
135
137
  Then, if it succeeds, the calculation starts.
136
- If it finishes, the server and node ends.
138
+ If it finishes, the server and node end.
139
+
140
+ ## Provided task
141
+
142
+ ### DRbQS::Task
143
+
144
+ DRbQS::Task is the basic class to define tasks of DRbQS,
145
+ whose objects are consisted of a object having method to process a task
146
+ and hook for returned result.
147
+ Basically, we define objects of DRbQS::Task and
148
+ give the objects to a server.
149
+
150
+ ### DRbQS::TaskSet
151
+
152
+ DRbQS::TaskSet is a child class of DRbQS::Task and consists of group a number of tasks.
153
+ Objects of the class are generated when we set the option :collect to DRbQS::TaskGenerator#set
154
+ and therefore we are unaware of the objects of DRbQS::TaskSet
155
+ in many cases.
156
+
157
+ ### DRbQS::CommandTask
158
+
159
+ DRbQS::CommandTask is a class to create tasks to execute some command.
160
+
161
+ ## Temporary file
162
+
163
+ We can use temporary directories and files on nodes.
164
+ In methods to calculate tasks,
165
+ DRbQS::Temporary.file returns a name of temporary file and
166
+ DRbQS::Temporary.directory returns a name of temporary directory.
167
+ These temporary files and directories are deleted
168
+ after the task is completed.
169
+
170
+ ## File transfer
171
+
172
+ When a task is finished on a node,
173
+ we can transfer files from a server to a client.
174
+ To be more precise, we enqueue a file by DRbQS::FileTransfer.enqueue
175
+ in methods to calculate tasks and
176
+ files in the queue are automatically transferred.
177
+ Then, original files on nodes are deleted after transferring.
137
178
 
138
179
  ## Contributing to drbqs
139
180
 
data/Rakefile CHANGED
@@ -21,29 +21,43 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.authors = ["Takayuki YAMAGUCHI"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'filename', '>= 0.1.0'
25
+ gem.add_runtime_dependency "user_config", ">= 0.0.2"
24
26
  gem.add_runtime_dependency 'net-ssh', '>= 2.1.3'
25
27
  gem.add_runtime_dependency 'net-ssh-shell', '>= 0.1.0'
26
- gem.add_runtime_dependency 'filename', '>= 0.0.5'
27
- gem.add_development_dependency 'rspec', '>= 2.5.0'
28
+ gem.add_runtime_dependency "net-sftp", ">= 2.0.5"
29
+ gem.add_runtime_dependency "sys-proctable"
28
30
  end
29
31
  Jeweler::RubygemsDotOrgTasks.new
30
32
 
31
- require 'rspec/core'
32
- require 'rspec/core/rake_task'
33
- RSpec::Core::RakeTask.new(:spec) do |spec|
34
- spec.pattern = FileList['spec/**/*_spec.rb']
33
+ desc "Run all specs"
34
+ task 'spec:all' => ['spec:unit', 'spec:integration']
35
+
36
+ desc "Run specs of unit test"
37
+ task 'spec:unit' do
38
+ filelist = FileList['spec/**/*_spec.rb'].delete_if do |path|
39
+ /integration_test/ =~ path
40
+ end
41
+ filelist.each do |path|
42
+ sh "rspec #{path}"
43
+ end
44
+ Rake::Task['clean:temporary'].execute
35
45
  end
36
46
 
37
- RSpec::Core::RakeTask.new(:rcov) do |spec|
38
- spec.pattern = 'spec/**/*_spec.rb'
39
- spec.rcov = true
47
+ desc "Run specs of integration test"
48
+ task 'spec:integration' do
49
+ FileList['spec/integration_test/**/*_spec.rb'].sort.each do |path|
50
+ sh "rspec #{path}"
51
+ end
52
+ Rake::Task['clean:temporary'].execute
40
53
  end
41
54
 
42
- task :default => :spec
55
+ task :default => 'spec:all'
43
56
 
44
57
  require 'yard'
45
58
  YARD::Rake::YardocTask.new
46
59
 
60
+ desc "Update version of drbqs.rb"
47
61
  task "version:constant" do
48
62
  dir = File.dirname(__FILE__)
49
63
  path = File.join(dir, 'lib/drbqs.rb')
@@ -53,3 +67,11 @@ task "version:constant" do
53
67
  f.print data.sub(/^ VERSION = '.*'$/, " VERSION = '#{version}'")
54
68
  end
55
69
  end
70
+
71
+ desc "Remove temporary home directory for specs."
72
+ task "clean:temporary" do
73
+ dir = File.join(File.dirname(__FILE__), 'spec', 'home_for_spec')
74
+ if File.exist?(dir)
75
+ FileUtils.rm_r(dir)
76
+ end
77
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
data/bin/drbqs-manage CHANGED
@@ -1,96 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'drbqs'
4
- require 'optparse'
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ require 'drbqs/utility/command_line'
5
5
 
6
- Version = DRbQS::VERSION
7
-
8
- help_message =<<HELP
9
- Usage: #{File.basename(__FILE__)} <command> [arguments ...]
10
- Manage DRbQS server by sending messages.
11
- <command> is 'exit-signal', 'initialize', or 'ssh'.
12
-
13
- HELP
14
-
15
- def check_argument_size(argv, check_method, n)
16
- unless argv.size.__send__(check_method, n)
17
- raise "Invalid arguments number. Please refer '#{File.basename(__FILE__)} -h'."
18
- end
19
- end
20
-
21
- command = ARGV[0]
22
- argv, command_args = DRbQS::Manage.split_arguments(ARGV)
23
-
24
- options = {}
25
- if /^ssh/ =~ command
26
- check_argument_size(argv, :>=, 2)
27
- ssh_host =DRbQS::SSHHost.new
28
- path, options = ssh_host.get_options(argv[1])
29
- $stdout.puts "Use configuration: #{path}" if path
30
- argv[1] = options[:dest] if options[:dest]
31
- end
32
-
33
- begin
34
- OptionParser.new(help_message) do |opt|
35
- opt.on('--debug', 'Set $DEBUG true.') do |v|
36
- $DEBUG = true
37
- end
38
- opt.on('--dir DIR', String, 'Set the base directory over ssh.') do |v|
39
- options[:dir] = v
40
- end
41
- opt.on('--shell STR', String, 'Set the shell over ssh') do |v|
42
- options[:shell] = v
43
- end
44
- opt.on('--rvm STR', String, 'Ruby version to use on RVM over ssh.') do |v|
45
- options[:rvm] = v
46
- end
47
- opt.on('--rvm-init PATH', String, 'Path of script to initialize RVM over ssh.') do |v|
48
- options[:rvm_init] = v
49
- end
50
- opt.on('--output PATH', String, 'File path that stdout and stderr are output to over ssh.') do |v|
51
- options[:output] = v
52
- end
53
- opt.on('--nice NUM', Integer, 'Set the value for nice command.') do |v|
54
- options[:nice] = v
55
- end
56
- opt.on('--nohup', 'Use nohup command.') do |v|
57
- options[:nohup] = true
58
- end
59
- opt.parse!(argv)
60
- end
61
- rescue OptionParser::InvalidOption
62
- $stderr.print <<MES
63
- error: Invalid Option
64
- #{help_message}
65
- MES
66
- exit(2)
67
- rescue OptionParser::InvalidArgument
68
- $stderr.print <<MES
69
- error: Invalid Argument
70
- #{help_message}
71
- MES
72
- exit(2)
73
- end
74
-
75
- manage = DRbQS::Manage.new
76
-
77
- case command
78
- when 'exit-signal'
79
- check_argument_size(argv, :==, 2)
80
- uri = argv[1]
81
- manage.send_exit_signal(uri)
82
- when 'status'
83
- check_argument_size(argv, :==, 2)
84
- uri = argv[1]
85
- if status = manage.get_status(uri)
86
- $stdout.puts status
87
- end
88
- when 'initialize'
89
- check_argument_size(argv, :==, 1)
90
- manage.create_config
91
- when 'ssh'
92
- dest = argv[1]
93
- manage.execute_over_ssh(dest, options, command_args)
94
- else
95
- raise "Invalid command: #{command}"
96
- end
6
+ DRbQS::CommandManage.exec(ARGV)
data/bin/drbqs-node CHANGED
@@ -1,92 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'drbqs'
4
- require 'optparse'
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ require 'drbqs/utility/command_line'
5
5
 
6
- Version = DRbQS::VERSION
7
-
8
- help_message =<<HELP
9
- Usage: #{File.basename(__FILE__)} [<uri>] [<process_number>] [options ...]
10
- Start DRbQS nodes connecting to <uri>.
11
-
12
- HELP
13
-
14
- LOG_PREFIX_DEFAULT = 'drbqs_node'
15
- LOG_LEVEL_DEFAULT = Logger::ERROR
16
-
17
- options = {
18
- :log_prefix => LOG_PREFIX_DEFAULT,
19
- :log_level => LOG_LEVEL_DEFAULT,
20
- :load => []
21
- }
22
-
23
- begin
24
- OptionParser.new(help_message) do |opt|
25
- opt.on('-l', '--load FILE', String, 'Add a file to load.') do |v|
26
- options[:load] << File.expand_path(v)
27
- end
28
- opt.on('--log-prefix STR', String, "Set the prefix of log files. The default is '#{LOG_PREFIX_DEFAULT}'.") do |v|
29
- options[:log_prefix] = v
30
- end
31
- opt.on('--log-level LEVEL', String,
32
- "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") do |v|
33
- if /^(fatal)|(error)|(warn)|(info)|(debug)$/i =~ v
34
- options[:log_level] = eval("Logger::#{v.upcase}")
35
- else
36
- raise "Invalid log level."
37
- end
38
- end
39
- opt.on('--log-stdout', 'Use stdout for outputting logs. This option cancels --log-prefix.') do |v|
40
- options[:log_prefix] = nil
41
- end
42
- opt.on('--debug', 'Set $DEBUG true.') do |v|
43
- $DEBUG = true
44
- end
45
- opt.parse!(ARGV)
46
- end
47
- rescue OptionParser::InvalidOption
48
- $stderr.print <<MES
49
- error: Invalid Option
50
- #{help_message}
51
- MES
52
- exit(2)
53
- rescue OptionParser::InvalidArgument
54
- $stderr.print <<MES
55
- error: Invalid Argument
56
- #{help_message}
57
- MES
58
- exit(2)
59
- end
60
-
61
- if ARGV.size > 2
62
- raise "Too many arguments. Please refer '#{File.basename(__FILE__)} -h'."
63
- end
64
-
65
- process_num = 1
66
- uri = "druby://localhost:#{DRbQS::ROOT_DEFAULT_PORT}"
67
-
68
- ARGV.each do |arg|
69
- if /^\d+$/ =~ arg
70
- process_num = arg.to_i
71
- else
72
- uri = arg
73
- end
74
- end
75
-
76
- options[:load].each do |v|
77
- puts "load #{v}"
78
- load v
79
- end
80
-
81
- puts "Connect to #{uri}"
82
- puts "Execute #{process_num} processes"
83
-
84
- if options[:log_prefix]
85
- if /\/$/ =~ options[:log_prefix]
86
- options[:log_prefix] += 'out'
87
- end
88
- end
89
-
90
- exec_node = DRbQS::ExecuteNode.new(uri, options[:log_prefix], options[:log_level])
91
- exec_node.execute(process_num)
92
- exec_node.wait
6
+ DRbQS::CommandNode.exec(ARGV)
data/bin/drbqs-server CHANGED
@@ -1,120 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'drbqs'
4
- require 'optparse'
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ require 'drbqs/utility/command_line'
5
5
 
6
- Version = DRbQS::VERSION
7
-
8
- help_message =<<HELP
9
- Usage: #{File.basename(__FILE__)} <definition.rb> [other files ...] [options ...]
10
- #{File.basename(__FILE__)} <definition.rb> [other files ...] [options ...] -- [server options ...]
11
- Start DRbQS server of definition files.
12
-
13
- HELP
14
-
15
- options = {
16
- :log_file => STDOUT,
17
- :command_type => :server_start,
18
- :acl => DRbQS::Config.get_acl_file
19
- }
20
-
21
- test_opts = {}
22
- execute_node_number = nil
23
-
24
- command_argv, server_argv = DRbQS::Manage.split_arguments(ARGV)
25
-
26
- begin
27
- OptionParser.new(help_message) do |opt|
28
- opt.on('-p PORT', '--port', Integer, 'Set the port number of server.') do |v|
29
- options[:port] = v
30
- end
31
- opt.on('--acl FILE', String, 'Set a file to define ACL.') do |v|
32
- options[:acl] = v
33
- end
34
- opt.on('--log-file STR', String, "Set the path of log file. If this options is not set, use STDOUT.") do |v|
35
- options[:log_file] = v
36
- end
37
- opt.on('--log-level LEVEL', String,
38
- "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") do |v|
39
- if /^(fatal)|(error)|(warn)|(info)|(debug)$/i =~ v
40
- options[:log_level] = eval("Logger::#{v.upcase}")
41
- else
42
- raise "Invalid log level."
43
- end
44
- end
45
- opt.on('--file-directory DIR', String, 'Set the file archive directory.') do |v|
46
- options[:file_directory] = v
47
- end
48
- opt.on('--scp-user USER', String, 'Set the user of scp destination.') do |v|
49
- options[:scp_user] = v
50
- end
51
- opt.on('--scp-host HOST', String, 'Set the host of scp destination.') do |v|
52
- options[:scp_host] = v
53
- end
54
- opt.on('--profile', 'Use profile for test exec.') do |v|
55
- test_opts[:profile] = true
56
- end
57
- opt.on('--debug', 'Set $DEBUG true.') do |v|
58
- $DEBUG = true
59
- end
60
- opt.on('--test STR', String, 'Execute test.') do |v|
61
- options[:command_type] = "test_#{v}"
62
- end
63
- opt.on('--execute-node NUM', Integer, 'Execute nodes.') do |v|
64
- execute_node_number = v
65
- end
66
- opt.parse!(command_argv)
67
- end
68
- rescue OptionParser::InvalidOption
69
- $stderr.print <<MES
70
- error: Invalid Option
71
- #{help_message}
72
- MES
73
- exit(2)
74
- rescue OptionParser::InvalidArgument
75
- $stderr.print <<MES
76
- error: Invalid Argument
77
- #{help_message}
78
- MES
79
- exit(2)
80
- end
81
-
82
- if command_argv.size == 0 || !File.exist?(command_argv[0])
83
- raise "Invalid arguments. Please refer '#{File.basename(__FILE__)} -h'."
84
- end
85
-
86
- command_argv.each do |path|
87
- puts "load #{path}"
88
- load path
89
- end
90
-
91
- WAIT_SERVER_TIME = 0.3
92
- NODE_INTERVAL_TIME = 1
93
-
94
- DRbQS.parse_option(server_argv)
95
- case options[:command_type]
96
- when /^test/
97
- s = options[:command_type].split('_')[1].split(',')
98
- type = s[0].intern
99
- DRbQS.test_server(options, type, s[1..-1], test_opts)
100
- else
101
- if execute_node_number
102
- fork do
103
- DRbQS.start_server(options)
104
- end
105
- uri = "druby://:#{options[:port] || DRbQS::ROOT_DEFAULT_PORT}"
106
- manage = DRbQS::Manage.new
107
- begin
108
- sleep(WAIT_SERVER_TIME)
109
- end while !manage.get_status(uri)
110
- node_log_file = nil
111
- unless IO === options[:log_file]
112
- node_log_file = FileName.create(options[:log_file], :add => :always, :position => :middle, :delimiter => '', :format => "_node_%02d")
113
- end
114
- exec_node = DRbQS::ExecuteNode.new(uri, node_log_file, options[:log_level])
115
- exec_node.execute(execute_node_number, NODE_INTERVAL_TIME)
116
- exec_node.wait
117
- else
118
- DRbQS.start_server(options)
119
- end
120
- end
6
+ DRbQS::CommandServer.exec(ARGV)
data/bin/drbqs-ssh ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ require 'drbqs/utility/command_line'
5
+
6
+ DRbQS::CommandSSH.exec(ARGV)