Class: OodCore::Job::Adapters::PBSPro::Batch Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/pbspro.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Object used for simplified communication with a PBS Pro batch server

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: nil, submit_host: "", strict_host_checking: true, pbs_exec: nil, bin_overrides: {}) ⇒ Batch

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Batch.

Parameters:

  • host (#to_s, nil) (defaults to: nil)

    the batch server host

  • submit_host (#to_s, nil) (defaults to: "")

    the login node to ssh to

  • strict_host_checking (bool, true) (defaults to: true)

    wheter to use strict host checking when ssh to submit_host

  • exec (#to_s, nil)

    path to pbs executables



80
81
82
83
84
85
86
# 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

Instance Attribute Details

#bin_overridesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Optional overrides for PBS Pro client executables

Examples:

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


70
71
72
# File 'lib/ood_core/job/adapters/pbspro.rb', line 70

def bin_overrides
  @bin_overrides
end

#hostString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The host of the PBS Pro batch server

Examples:

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

Returns:

  • (String, nil)

    the batch server host



46
47
48
# File 'lib/ood_core/job/adapters/pbspro.rb', line 46

def host
  @host
end

#pbs_execPathname? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The path containing the PBS executables

Examples:

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

Returns:

  • (Pathname, nil)

    path to pbs executables



64
65
66
# File 'lib/ood_core/job/adapters/pbspro.rb', line 64

def pbs_exec
  @pbs_exec
end

#strict_host_checkingBool, true (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether to use strict host checking when ssh to submit_host

Examples:

my_batch.strict_host_checking #=> "false"

Returns:

  • (Bool, true)

    the login node; true if not present



58
59
60
# File 'lib/ood_core/job/adapters/pbspro.rb', line 58

def strict_host_checking
  @strict_host_checking
end

#submit_hostString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The login node to submit the job via ssh

Examples:

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

Returns:

  • (String, nil)

    the login node



52
53
54
# File 'lib/ood_core/job/adapters/pbspro.rb', line 52

def submit_host
  @submit_host
end

Instance Method Details

#delete_job(id) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Delete a specified job from batch server

Examples:

Delete job “1234”

my_batch.delete_job("1234")

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (Error)

    if `qdel` command exited unsuccessfully



162
163
164
# File 'lib/ood_core/job/adapters/pbspro.rb', line 162

def delete_job(id)
  call("qdel", id.to_s)
end

#get_jobs(id: "") ⇒ Array<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a list of hashes detailing each of the jobs on the batch server

Examples:

Status info for all jobs

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

Parameters:

  • id (#to_s) (defaults to: "")

    the id of the job

Returns:

  • (Array<Hash>)

    list of details for jobs

Raises:

  • (Error)

    if `qstat` command exited unsuccessfully



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Put a specified job on hold

Examples:

Put job “1234” on hold

my_batch.hold_job("1234")

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (Error)

    if `qhold` command exited unsuccessfully



142
143
144
# File 'lib/ood_core/job/adapters/pbspro.rb', line 142

def hold_job(id)
  call("qhold", id.to_s)
end

#release_job(id) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Release a specified job that is on hold

Examples:

Release job “1234” from on hold

my_batch.release_job("1234")

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (Error)

    if `qrls` command exited unsuccessfully



152
153
154
# File 'lib/ood_core/job/adapters/pbspro.rb', line 152

def release_job(id)
  call("qrls", id.to_s)
end

#select_jobs(args: []) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Select batch jobs from the batch server

Parameters:

  • args (Array<#to_s>) (defaults to: [])

    arguments passed to `qselect` command

Returns:

  • (Array<String>)

    list of job ids that match selection criteria

Raises:

  • (Error)

    if `qselect` command exited unsuccessfully



132
133
134
# 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) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Submit a script expanded as a string to the batch server

Parameters:

  • str (#to_s)

    script as a string

  • args (Array<#to_s>) (defaults to: [])

    arguments passed to `qsub` command

  • chdir (#to_s, nil) (defaults to: nil)

    working directory where `qsub` is called

Returns:

  • (String)

    the id of the job that was created

Raises:

  • (Error)

    if `qsub` command exited unsuccessfully



172
173
174
# 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