lib/osc/machete/torque_helper.rb in osc-machete-2.0.0.pre2 vs lib/osc/machete/torque_helper.rb in osc-machete-2.0.0
- old
+ new
@@ -10,26 +10,31 @@
# FIXME: Use ood_cluster gem
LIB = ENV['TORQUE_LIB'] || '/opt/torque/lib64'
BIN = ENV['TORQUE_BIN'] || '/opt/torque/bin'
HOSTS = {
'oakley' => 'oak-batch.osc.edu',
- 'ruby' => 'ruby-batch.osc.edu',
- 'quick' => 'quick-batch.osc.edu',
- 'owens' => 'owens-batch.ten.osc.edu'
+ 'ruby' => 'ruby-batch.ten.osc.edu',
+ 'quick' => 'quick-batch.ten.osc.edu',
+ 'owens' => 'owens-batch.ten.osc.edu',
+ :default => 'oak-batch.osc.edu'
}
- # Alias to initialize a new object.
- def self.default
- self::new()
+ class << self
+ #@!attribute default
+ # @return [TorqueHelper] default TorqueHelper instance to use
+ attr_writer :default
+ def default
+ @default ||= self::new()
+ end
end
# Returns an OSC::Machete::Status ValueObject for a char
#
# @param [String] char The Torque status char
#
- # @example Completed
- # status_for_char("C") #=> OSC::Machete::Status.completed
+ # @example Passed
+ # status_for_char("C") #=> OSC::Machete::Status.passed
# @example Queued
# status_for_char("W") #=> OSC::Machete::Status.queued
#
# @return [OSC::Machete::Status] The status corresponding to the char
def status_for_char(char)
@@ -58,20 +63,10 @@
# Where depends_on is a hash with key being dependency type and array containing the
# arguments. See documentation on dependency_list in qsub man pages for details.
#
# Bills against the project specified by the primary group of the user.
def qsub(script, host: nil, depends_on: {}, account_string: nil)
- # if the script is set to run on Oakley in PBS headers
- # this is to obviate current torque filter defect in which
- # a script with PBS header set to specify oak-batch ends
- # isn't properly handled and the job gets limited to 4GB
- pbs = PBS::Batch.new(
- host: HOSTS.fetch( host || host_from_script_pbs_header(script) ),
- lib: LIB,
- bin: BIN
- )
-
headers = { depend: qsub_dependencies_header(depends_on) }
headers.clear if headers[:depend].empty?
# currently we set the billable project to the name of the primary group
# this will probably be both SUPERCOMPUTER CENTER SPECIFIC and must change
@@ -81,11 +76,11 @@
headers[PBS::ATTR[:A]] = account_string
elsif account_string_valid_project?(default_account_string)
headers[PBS::ATTR[:A]] = default_account_string
end
- pbs.submit_script(script, headers: headers, qsub: true)
+ pbs(host: host, script: script).submit_script(script, headers: headers, qsub: true)
end
# convert dependencies hash to a PBS header string
def qsub_dependencies_header(depends_on = {})
depends_on.map { |x|
@@ -115,17 +110,11 @@
# @param [String] pbsid The pbsid of the job to inspect.
#
# @return [Status] The job state
def qstat(pbsid, host: nil)
id = pbsid.to_s
- pbs = PBS::Batch.new(
- host: HOSTS.fetch( host || host_from_pbsid(id) ),
- lib: LIB,
- bin: BIN
- )
-
- status = pbs.get_job(id, filters: [:job_state])
+ status = pbs(host: host, id: id).get_job(id, filters: [:job_state])
status_for_char status[id][:job_state][0] # get status from status char value
rescue PBS::UnkjobidError
OSC::Machete::Status.passed
end
@@ -134,19 +123,32 @@
# @param [String] pbsid The pbsid of the job to be deleted.
#
# @return [nil]
def qdel(pbsid, host: nil)
id = pbsid.to_s
- pbs = PBS::Batch.new(
- host: HOSTS.fetch( host || host_from_pbsid(id) ),
+ pbs(host: host, id: id).delete_job(id)
+ rescue PBS::UnkjobidError
+ # Common use case where trying to delete a job that is no longer in the system.
+ end
+
+ def pbs(host: nil, id: nil, script: nil)
+ if host
+ # actually check if host is "oakley" i.e. a cluster key
+ host = HOSTS.fetch(host.to_s, host.to_s)
+ else
+ # try to determine host
+ key = host_from_pbsid(id) if id
+ key = host_from_script_pbs_header(script) if script && key.nil?
+
+ host = HOSTS.fetch(key, HOSTS.fetch(:default))
+ end
+
+ PBS::Batch.new(
+ host: host,
lib: LIB,
bin: BIN
)
-
- pbs.delete_job(id)
- rescue PBS::UnkjobidError
- # Common use case where trying to delete a job that is no longer in the system.
end
private
# return the name of the host to use based on the pbs header
# TODO: Think of a more efficient way to do this.
@@ -157,12 +159,10 @@
"ruby"
elsif (File.open(script) { |f| f.read =~ /#PBS -q @quick-batch/ })
"quick"
elsif (File.open(script) { |f| f.read =~ /#PBS -q @owens-batch/ })
"owens"
- else
- "oakley" # DEFAULT
end
end
# Return the PBS host string based on a full pbsid string
def host_from_pbsid(pbsid)
@@ -172,10 +172,8 @@
"ruby"
elsif (pbsid =~ /quick/ )
"quick"
elsif (pbsid =~ /owens/ )
"owens"
- else
- "oakley" # DEFAULT
end
end
end