condor 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +26 -0
  2. data/bin/condor-exec +75 -0
  3. data/lib/condor.rb +108 -0
  4. data/test/test_condor.rb +35 -0
  5. metadata +54 -0
data/README ADDED
@@ -0,0 +1,26 @@
1
+ = Ruby Wrapper for Condor
2
+
3
+ This is a Ruby wrapper for the {Condor}[http://www.cs.wisc.edu/condor/] distributed computing framework.
4
+
5
+ It consists of a wrapper for a Condor submit file and a program, <tt>condor-exec</tt>, that submits an arbitrary command line as a Condor job. For example:
6
+
7
+ condor-exec prog --option arg1 arg2
8
+
9
+ queues up a job for the +prog+ with arguments <tt>--option arg1 arg2</tt>. To pass options to <tt>condor-exec</tt> itself, place them before +prog+. For example:
10
+
11
+ condor-exec --universe=MPI prog --option arg1 arg2
12
+
13
+ = History
14
+
15
+ 1.0.0:: Basic submit file wrapper; <tt>condor-exec</tt> program
16
+
17
+ = Copyright
18
+
19
+ Copyright 2009, William Patrick McNeill
20
+
21
+ This program is distributed under the GNU General Public License.
22
+
23
+
24
+ = Author
25
+
26
+ W.P. McNeill mailto:billmcn@gmail.com
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Copyright 2009 William Patrick McNeill
4
+ #
5
+ # This file is part of the Condor Ruby Wrapper.
6
+ #
7
+ # The Condor Ruby Wrapper is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or (at your
10
+ # option) any later version.
11
+ #
12
+ # The Condor Ruby Wrapper is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
+ # Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along with
18
+ # editalign; if not, write to the Free Software Foundation, Inc., 51 Franklin
19
+ # St, Fifth Floor, Boston, MA 02110-1301 USA
20
+
21
+ # This program runs the specified command line as a Condor job.
22
+
23
+ require "condor"
24
+ require "optparse"
25
+
26
+ class CommandPassingOptionParser < OptionParser
27
+ # Treat all switches before the first non-switch as options for this
28
+ # program. Treat switches after as options to be passed down to the program
29
+ # run by Condor.
30
+ def parse_command_line(argv = default_argv)
31
+ first_non_option_index = 0
32
+ argv.each_with_index do |arg, i|
33
+ first_non_option_index = i
34
+ break if arg !~ /^-/
35
+ end
36
+ parse(argv[0..first_non_option_index])
37
+ argv[first_non_option_index..argv.length]
38
+ end
39
+ end
40
+
41
+ options = {}
42
+ p = CommandPassingOptionParser.new do |opts|
43
+ opts.banner = <<EOS
44
+ Usage: #{File.basename(__FILE__)} [options] command [arguments]
45
+
46
+ This program launches the specified command line as a Condor process by
47
+ writing a submit file and calling Condor submit.
48
+
49
+ It creates a condor_submit.nnn file in the current directory along with
50
+ *.output and *.error files named after the program being run. It also creates
51
+ a Condor log file in the system temporary directory.
52
+
53
+ Switch options appearing before the first non-switch argument are passed to
54
+ #{File.basename(__FILE__)}. Switch optios appearing after the first
55
+ non-switch argument are treated as arguments to the command.
56
+
57
+ Options:
58
+ EOS
59
+
60
+ opts.on("-gVALUE", "--getenv VALUE", "Get environment") do |value|
61
+ options[:getenv] = value
62
+ end
63
+
64
+ opts.on("-tVALUE", "--transfer-executable VALUE", "Transfer executable") do |value|
65
+ options[:transfer_executable] = value
66
+ end
67
+
68
+ opts.on("-uVALUE", "--universe VALUE", "Universe") do |value|
69
+ options[:universe] = value
70
+ end
71
+
72
+ end
73
+
74
+ command_line = p.parse_command_line
75
+ Condor.submit(command_line.shift, command_line, options)
@@ -0,0 +1,108 @@
1
+ # Copyright 2009 William Patrick McNeill
2
+ #
3
+ # This file is part of the Condor Ruby Wrapper.
4
+ #
5
+ # The Condor Ruby Wrapper is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # The Condor Ruby Wrapper is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13
+ # Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # editalign; if not, write to the Free Software Foundation, Inc., 51 Franklin
17
+ # St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "erb"
20
+ require "tempfile"
21
+
22
+ # Wrapper for the Condor distributed computing system.
23
+ module Condor
24
+
25
+ VERSION = "1.0.0"
26
+
27
+ # The text of a file that can be sent to the condor_submit program.
28
+ class SubmitFile < ERB
29
+ # Specify a single executable and a list of argument sets. Each element
30
+ # of argument_list is a set of arguments. One job will be queued up for
31
+ # each set of arguments.
32
+ def initialize(executable, argument_list, options = {})
33
+ # Get defaults for any unspecified options.
34
+ @options = {
35
+ :getenv => "true",
36
+ :transfer_executable => "false",
37
+ :universe => "vanilla"}.merge!(options)
38
+ # Create the submit file text.
39
+ @executable = executable
40
+ @argument_list = argument_list
41
+ @log = File.join(Dir::tmpdir, "#{ENV['USER']}.condor.$(Cluster).$(Process)")
42
+ @output = current_dir_log_file("output")
43
+ @error = current_dir_log_file("error")
44
+ # Create the header common to all the jobs.
45
+ template = <<-EOTEXT
46
+ Universe = <%= @options[:universe] %>
47
+ getenv = <%= @options[:getenv] %>
48
+ transfer_executable = <%= @options[:transfer_executable] %>
49
+ Log = <%= @log %>
50
+ Executable = <%= @executable %>
51
+ EOTEXT
52
+ # Queue up the arguments for each individual job.
53
+ argument_list.each_with_index do |arguments, i|
54
+ template += <<-EOTEXT
55
+
56
+ arguments = <%= @argument_list[#{i}].join(" ") %>
57
+ output = <%= @output %>
58
+ error = <%= @error %>
59
+ Queue
60
+ EOTEXT
61
+ end
62
+ super(template)
63
+ end
64
+
65
+ # Allocate the name of a temporary file in the current directory.
66
+ def current_dir_log_file(name)
67
+ "#{File.basename(@executable).strip}.$(Cluster).$(Process).#{name}"
68
+ end
69
+
70
+ # Return a string that can serve as a Condor submit file.
71
+ def to_s
72
+ result(binding)
73
+ end
74
+
75
+ private :current_dir_log_file
76
+ end
77
+
78
+
79
+ # This runs the specified executable and arguments as a Condor command. The
80
+ # function creates a condor_submit.nnn file in the current directory. STDOUT
81
+ # and STDERR are routed to *.output and *.error files with the names of the
82
+ # executable and the process ID in the name. The Condor log file is written
83
+ # to the system's temporary directory.
84
+ def Condor.submit(executable, arguments, options = {})
85
+ if executable.nil? or executable.empty?
86
+ raise "You must specify a command to run"
87
+ end
88
+ # Get full path to the command. BUGBUG This is UNIX specific.
89
+ executable = `which #{executable} 2> /dev/null`.strip
90
+ raise "Invalid executable #{executable}" if executable.empty?
91
+ # Create a unique submit file name of the form condor_submit.nnn.
92
+ n = 0
93
+ while n < 1000
94
+ ext = sprintf("%03d", n)
95
+ submit_name = "condor_submit.#{ext}"
96
+ break if not File.exists?(submit_name)
97
+ n += 1
98
+ end
99
+ raise "Cannot create unique submit file name" if n == 1000
100
+ # Write Condor information to the submit file.
101
+ File.open(submit_name, "w") do |file|
102
+ file << Condor::SubmitFile.new(executable, [arguments], options).to_s
103
+ end
104
+ # Submit the Condor job.
105
+ `condor_submit #{submit_name}`
106
+ end
107
+
108
+ end # Condor
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby
2
+
3
+ #--
4
+
5
+ # Copyright 2007-2008 William Patrick McNeill
6
+ #
7
+ # This file is part of the Condor Ruby Wrapper.
8
+ #
9
+ # The Condor Ruby Wrapper is free software; you can redistribute it and/or
10
+ # modify it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation; either version 2 of the License, or (at your
12
+ # option) any later version.
13
+ #
14
+ # The CondorRuby Wrapper is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17
+ # Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License along with
20
+ # editalign; if not, write to the Free Software Foundation, Inc., 51 Franklin
21
+ # St, Fifth Floor, Boston, MA 02110-1301 USA
22
+ #
23
+ #++
24
+
25
+ # Test cases for the Condor module
26
+
27
+ require "test/unit"
28
+ require "condor"
29
+
30
+
31
+ class CondorTestCase < Test::Unit::TestCase
32
+ def test_submit_file
33
+ s = Condor::SubmitFile.new("ruby", "arg1 arg2")
34
+ end
35
+ end # CondorTestCase
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: condor
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2009-01-16 00:00:00 -08:00
8
+ summary: Ruby wrapper for the Condor distributed computing system
9
+ require_paths:
10
+ - lib
11
+ email: billmcn@gmail.com
12
+ homepage: http://condor.rubyforge.org/
13
+ rubyforge_project: condor
14
+ description: This module is a Ruby wrapper for the Condor distributed computing system.
15
+ autorequire:
16
+ default_executable: bin/condor-exec
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - W.P. McNeill
31
+ files:
32
+ - test/test_condor.rb
33
+ - lib/condor.rb
34
+ - bin/condor-exec
35
+ - README
36
+ test_files:
37
+ - test/test_condor.rb
38
+ rdoc_options:
39
+ - - --title
40
+ - Condor -- distributed computing
41
+ - --main
42
+ - README
43
+ - --line-numbers
44
+ - --inline-source
45
+ extra_rdoc_files:
46
+ - README
47
+ executables:
48
+ - condor-exec
49
+ extensions: []
50
+
51
+ requirements: []
52
+
53
+ dependencies: []
54
+