Skip to content

Commit 1ad6dec

Browse files
author
Jeremy Nicklas
committed
Torque adapter takes native arrays
Fixes #65
1 parent 597e996 commit 1ad6dec

File tree

4 files changed

+328
-84
lines changed

4 files changed

+328
-84
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Changed
10+
- Updated Torque adapter to take into account the new `Script#native` format
11+
allowing for arrays. [#65](https://github.com/OSC/ood_core/issues/65)
912

1013
## [0.3.0] - 2018-04-05
1114
### Added

lib/ood_core/job/adapters/torque.rb

Lines changed: 78 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -71,54 +71,94 @@ def submit(script, after: [], afterok: [], afternotok: [], afterany: [])
7171
afternotok = Array(afternotok).map(&:to_s)
7272
afterany = Array(afterany).map(&:to_s)
7373

74-
# Set headers
75-
headers = {}
76-
headers.merge!(job_arguments: script.args.join(' ')) unless script.args.nil?
77-
headers.merge!(Hold_Types: :u) if script.submit_as_hold
78-
headers.merge!(Rerunable: script.rerunnable ? 'y' : 'n') unless script.rerunnable.nil?
79-
headers.merge!(init_work_dir: script.workdir) unless script.workdir.nil?
80-
headers.merge!(Mail_Users: script.email.join(',')) unless script.email.nil?
81-
mail_points = ''
82-
mail_points += 'b' if script.email_on_started
83-
mail_points += 'e' if script.email_on_terminated
84-
headers.merge!(Mail_Points: mail_points) unless mail_points.empty?
85-
headers.merge!(Job_Name: script.job_name) unless script.job_name.nil?
86-
headers.merge!(Shell_Path_List: script.shell_path) unless script.shell_path.nil?
87-
# ignore input_path (not defined in Torque)
88-
headers.merge!(Output_Path: script.output_path) unless script.output_path.nil?
89-
headers.merge!(Error_Path: script.error_path) unless script.error_path.nil?
90-
# If error_path is not specified we join stdout & stderr (as this
91-
# mimics what the other resource managers do)
92-
headers.merge!(Join_Path: 'oe') if script.error_path.nil?
93-
headers.merge!(reservation_id: script.reservation_id) unless script.reservation_id.nil?
94-
headers.merge!(Priority: script.priority) unless script.priority.nil?
95-
headers.merge!(Execution_Time: script.start_time.localtime.strftime("%C%y%m%d%H%M.%S")) unless script.start_time.nil?
96-
headers.merge!(Account_Name: script.accounting_id) unless script.accounting_id.nil?
97-
9874
# Set dependencies
9975
depend = []
10076
depend << "after:#{after.join(':')}" unless after.empty?
10177
depend << "afterok:#{afterok.join(':')}" unless afterok.empty?
10278
depend << "afternotok:#{afternotok.join(':')}" unless afternotok.empty?
10379
depend << "afterany:#{afterany.join(':')}" unless afterany.empty?
104-
headers.merge!(depend: depend.join(',')) unless depend.empty?
10580

106-
# Set resources
107-
resources = {}
108-
resources.merge!(walltime: seconds_to_duration(script.wall_time)) unless script.wall_time.nil?
81+
# Set mailing options
82+
mail_points = ""
83+
mail_points += "b" if script.email_on_started
84+
mail_points += "e" if script.email_on_terminated
10985

110-
# Set environment variables
111-
envvars = script.job_environment || {}
86+
# FIXME: Remove the Hash option once all Interactive Apps are
87+
# converted to Array format
88+
if script.native.is_a?(Hash)
89+
# Set headers
90+
headers = {}
91+
headers.merge!(job_arguments: script.args.join(' ')) unless script.args.nil?
92+
headers.merge!(Hold_Types: :u) if script.submit_as_hold
93+
headers.merge!(Rerunable: script.rerunnable ? 'y' : 'n') unless script.rerunnable.nil?
94+
headers.merge!(init_work_dir: script.workdir) unless script.workdir.nil?
95+
headers.merge!(Mail_Users: script.email.join(',')) unless script.email.nil?
96+
headers.merge!(Mail_Points: mail_points) unless mail_points.empty?
97+
headers.merge!(Job_Name: script.job_name) unless script.job_name.nil?
98+
headers.merge!(Shell_Path_List: script.shell_path) unless script.shell_path.nil?
99+
# ignore input_path (not defined in Torque)
100+
headers.merge!(Output_Path: script.output_path) unless script.output_path.nil?
101+
headers.merge!(Error_Path: script.error_path) unless script.error_path.nil?
102+
# If error_path is not specified we join stdout & stderr (as this
103+
# mimics what the other resource managers do)
104+
headers.merge!(Join_Path: 'oe') if script.error_path.nil?
105+
headers.merge!(reservation_id: script.reservation_id) unless script.reservation_id.nil?
106+
headers.merge!(Priority: script.priority) unless script.priority.nil?
107+
headers.merge!(Execution_Time: script.start_time.localtime.strftime("%C%y%m%d%H%M.%S")) unless script.start_time.nil?
108+
headers.merge!(Account_Name: script.accounting_id) unless script.accounting_id.nil?
109+
headers.merge!(depend: depend.join(',')) unless depend.empty?
112110

113-
# Set native options
114-
if script.native
115-
headers.merge! script.native.fetch(:headers, {})
116-
resources.merge! script.native.fetch(:resources, {})
117-
envvars.merge! script.native.fetch(:envvars, {})
118-
end
111+
# Set resources
112+
resources = {}
113+
resources.merge!(walltime: seconds_to_duration(script.wall_time)) unless script.wall_time.nil?
114+
115+
# Set environment variables
116+
envvars = script.job_environment || {}
117+
118+
# Set native options
119+
if script.native
120+
headers.merge! script.native.fetch(:headers, {})
121+
resources.merge! script.native.fetch(:resources, {})
122+
envvars.merge! script.native.fetch(:envvars, {})
123+
end
119124

120-
# Submit job
121-
@pbs.submit_string(script.content, queue: script.queue_name, headers: headers, resources: resources, envvars: envvars)
125+
# Submit job
126+
@pbs.submit_string(script.content, queue: script.queue_name, headers: headers, resources: resources, envvars: envvars)
127+
else
128+
# Set qsub arguments
129+
args = []
130+
args += ["-F", script.args.join(" ")] unless script.args.nil?
131+
args += ["-h"] if script.submit_as_hold
132+
args += ["-r", script.rerunnable ? "y" : "n"] unless script.rerunnable.nil?
133+
args += ["-M", script.email.join(",")] unless script.email.nil?
134+
args += ["-m", mail_points] unless mail_points.empty?
135+
args += ["-N", script.job_name] unless script.job_name.nil?
136+
args += ["-S", script.shell_path] unless script.shell_path.nil?
137+
# ignore input_path (not defined in Torque)
138+
args += ["-o", script.output_path] unless script.output_path.nil?
139+
args += ["-e", script.error_path] unless script.error_path.nil?
140+
args += ["-W", "x=advres:#{script.reservation_id}"] unless script.reservation_id.nil?
141+
args += ["-q", script.queue_name] unless script.queue_name.nil?
142+
args += ["-p", script.priority] unless script.priority.nil?
143+
args += ["-a", script.start_time.localtime.strftime("%C%y%m%d%H%M.%S")] unless script.start_time.nil?
144+
args += ["-A", script.accounting_id] unless script.accounting_id.nil?
145+
args += ["-W", "depend=#{depend.join(",")}"] unless depend.empty?
146+
args += ["-l", "walltime=#{seconds_to_duration(script.wall_time)}"] unless script.wall_time.nil?
147+
148+
# Set environment variables
149+
env = script.job_environment.to_h
150+
args += ["-v", env.keys.join(",")] unless env.empty?
151+
152+
# If error_path is not specified we join stdout & stderr (as this
153+
# mimics what the other resource managers do)
154+
args += ["-j", "oe"] if script.error_path.nil?
155+
156+
# Set native options
157+
args += script.native if script.native
158+
159+
# Submit job
160+
@pbs.submit(script.content, args: args, env: env, chdir: script.workdir)
161+
end
122162
rescue PBS::Error => e
123163
raise JobAdapterError, e.message
124164
end

ood_core.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
spec.required_ruby_version = ">= 2.2.0"
2424

2525
spec.add_runtime_dependency "ood_support", "~> 0.0.2"
26-
spec.add_development_dependency "pbs", "~> 2.1", ">= 2.1.0"
26+
spec.add_development_dependency "pbs", "~> 2.1", ">= 2.2.0"
2727
spec.add_development_dependency "bundler", "~> 1.7"
2828
spec.add_development_dependency "rake", "~> 10.0"
2929
spec.add_development_dependency "rspec", "~> 3.0"

0 commit comments

Comments
 (0)