class OodCore::Job::Adapters::PBSPro::Batch

Object used for simplified communication with a PBS Pro batch server @api private

Attributes

bin_overrides[R]

Optional overrides for PBS Pro client executables @example

{'qsub' => '/usr/local/bin/qsub'}

@return Hash<String, String>

host[R]

The host of the PBS Pro batch server @example

my_batch.host #=> "my_batch.server.edu"

@return [String, nil] the batch server host

pbs_exec[R]

The path containing the PBS executables @example

my_batch.pbs_exec.to_s #=> "/usr/local/pbspro/10.0.0

@return [Pathname, nil] path to pbs executables

strict_host_checking[R]

Whether to use strict host checking when ssh to submit_host @example

my_batch.strict_host_checking #=> "false"

@return [Bool, true] the login node; true if not present

submit_host[R]

The login node to submit the job via ssh @example

my_batch.submit_host #=> "my_batch.server.edu"

@return [String, nil] the login node

Public Class Methods

new(host: nil, submit_host: "", strict_host_checking: true, pbs_exec: nil, bin_overrides: {}) click to toggle source

@param host [#to_s, nil] the batch server host @param submit_host [#to_s, nil] the login node to ssh to @param strict_host_checking [bool, true] wheter to use strict host checking when ssh to submit_host @param exec [#to_s, nil] path to pbs executables

# File lib/ood_core/job/adapters/pbspro.rb, line 80
def initialize(host: nil, submit_host: "", strict_host_checking: true, pbs_exec: nil, bin_overrides: {})
  @host                 = host && host.to_s
  @submit_host          = submit_host && submit_host.to_s
  @strict_host_checking = strict_host_checking
  @pbs_exec             = pbs_exec && Pathname.new(pbs_exec.to_s)
  @bin_overrides        = bin_overrides
end

Public Instance Methods

delete_job(id) click to toggle source

Delete a specified job from batch server @example Delete job “1234”

my_batch.delete_job("1234")

@param id [#to_s] the id of the job @raise [Error] if `qdel` command exited unsuccessfully @return [void]

# File lib/ood_core/job/adapters/pbspro.rb, line 162
def delete_job(id)
  call("qdel", id.to_s)
end
get_jobs(id: "") click to toggle source

Get a list of hashes detailing each of the jobs on the batch server @example Status info for all jobs

my_batch.get_jobs
#=>
#[
#  {
#    :account => "account",
#    :job_id => "my_job",
#    ...
#  },
#  {
#    :account => "account",
#    :job_id => "my_other_job",
#    ...
#  },
#  ...
#]

@param id [#to_s] the id of the job @raise [Error] if `qstat` command exited unsuccessfully @return [Array<Hash>] list of details for jobs

# File lib/ood_core/job/adapters/pbspro.rb, line 108
def get_jobs(id: "")
  args = ["-f", "-t"]   # display all information
  args.concat [id.to_s] unless id.to_s.empty?
  lines = call("qstat", *args).gsub("\n\t", "").split("\n").map(&:strip)

  jobs = []
  lines.each do |line|
    if /^Job Id: (?<job_id>.+)$/ =~ line
      jobs << { job_id: job_id }
    elsif /^(?<key>[^\s]+) = (?<value>.+)$/ =~ line
      hsh = jobs.last
      k1, k2 = key.split(".").map(&:to_sym)
      k2 ? ( hsh[k1] ||= {} and hsh[k1][k2] = value ) : ( hsh[k1] = value )
    end
  end

  jobs
end
hold_job(id) click to toggle source

Put a specified job on hold @example Put job “1234” on hold

my_batch.hold_job("1234")

@param id [#to_s] the id of the job @raise [Error] if `qhold` command exited unsuccessfully @return [void]

# File lib/ood_core/job/adapters/pbspro.rb, line 142
def hold_job(id)
  call("qhold", id.to_s)
end
release_job(id) click to toggle source

Release a specified job that is on hold @example Release job “1234” from on hold

my_batch.release_job("1234")

@param id [#to_s] the id of the job @raise [Error] if `qrls` command exited unsuccessfully @return [void]

# File lib/ood_core/job/adapters/pbspro.rb, line 152
def release_job(id)
  call("qrls", id.to_s)
end
select_jobs(args: []) click to toggle source

Select batch jobs from the batch server @param args [Array<#to_s>] arguments passed to `qselect` command @raise [Error] if `qselect` command exited unsuccessfully @return [Array<String>] list of job ids that match selection

criteria
# File lib/ood_core/job/adapters/pbspro.rb, line 132
def select_jobs(args: [])
  call("qselect", *args).split("\n").map(&:strip)
end
submit_string(str, args: [], chdir: nil) click to toggle source

Submit a script expanded as a string to the batch server @param str [#to_s] script as a string @param args [Array<#to_s>] arguments passed to `qsub` command @param chdir [#to_s, nil] working directory where `qsub` is called @raise [Error] if `qsub` command exited unsuccessfully @return [String] the id of the job that was created

# File lib/ood_core/job/adapters/pbspro.rb, line 172
def submit_string(str, args: [], chdir: nil)
  call("qsub", *args, stdin: str.to_s, chdir: chdir).strip
end

Private Instance Methods

call(cmd, *args, env: {}, stdin: "", chdir: nil) click to toggle source

Call a forked PBS Pro command for a given batch server

# File lib/ood_core/job/adapters/pbspro.rb, line 178
def call(cmd, *args, env: {}, stdin: "", chdir: nil)
  cmd = cmd.to_s
  bindir = (!!pbs_exec) ? pbs_exec.join("bin").to_s : ''
  cmd = OodCore::Job::Adapters::Helper.bin_path(cmd, bindir, bin_overrides)
  env = env.to_h.each_with_object({}) { |(k, v), h| h[k.to_s] = v.to_s }
  env["PBS_DEFAULT"] = host.to_s if host
  env["PBS_EXEC"]    = pbs_exec.to_s if pbs_exec
  cmd, args = OodCore::Job::Adapters::Helper.ssh_wrap(submit_host, cmd, args, strict_host_checking)
  chdir ||= "."
  o, e, s = Open3.capture3(env, cmd, *(args.map(&:to_s)), stdin_data: stdin.to_s, chdir: chdir.to_s)
  s.success? ? o : raise(Error, e)
end