Class: OodCore::Job::Adapters::Lsf::Batch Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/lsf/batch.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 LSF batch server

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bindir: "", envdir: "", libdir: "", serverdir: "", **_) ⇒ 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:

  • bin (#to_s)

    path to LSF installation binaries



12
13
14
15
16
17
18
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 12

def initialize(bindir: "", envdir: "", libdir: "", serverdir: "", **_)
  @bindir = Pathname.new(bindir.to_s)

  @envdir = Pathname.new(envdir.to_s)
  @libdir = Pathname.new(libdir.to_s)
  @serverdir = Pathname.new(serverdir.to_s)
end

Instance Attribute Details

#bindirObject (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.



5
6
7
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5

def bindir
  @bindir
end

#envdirObject (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.



5
6
7
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5

def envdir
  @envdir
end

#libdirObject (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.



5
6
7
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5

def libdir
  @libdir
end

#serverdirObject (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.



5
6
7
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5

def serverdir
  @serverdir
end

Instance Method Details

#bjobs_default_argsObject

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.



48
49
50
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 48

def bjobs_default_args
  %w( -u all -a -w -W )
end

#default_envObject

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.



20
21
22
23
24
25
26
27
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 20

def default_env
  {
    "LSF_BINDIR" => bindir.to_s,
    "LSF_LIBDIR" => libdir.to_s,
    "LSF_ENVDIR" => envdir.to_s,
    "LSF_SERVERDIR" => serverdir.to_s
  }.reject {|k,v| v.nil? || v.empty? }
end

#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 `bkill` command exited unsuccessfully



103
104
105
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 103

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

#fieldsObject

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.

status fields available from bjobs



53
54
55
56
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 53

def fields
  %i(id user status queue from_host exec_host name submit_time
      project cpu_used mem swap pids start_time finish_time)
end

#get_job(id:) ⇒ 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 hash detailing the specified job

Parameters:

  • id (#to_s)

    the id of the job to check

Returns:

  • (Hash)

    details of specified job

Raises:

  • (Error)

    if `bjobs` command exited unsuccessfully



42
43
44
45
46
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 42

def get_job(id:)
  args = bjobs_default_args
  args << id.to_s
  parse_bjobs_output(call("bjobs", *args)).first
end

#get_jobsArray<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

Returns:

  • (Array<Hash>)

    list of details for jobs

Raises:

  • (Error)

    if `bjobs` command exited unsuccessfully



32
33
34
35
36
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 32

def get_jobs
  #TODO: split into get_all_jobs, get_my_jobs
  args = bjobs_default_args
  parse_bjobs_output(call("bjobs", *args))
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 `bstop` command exited unsuccessfully



83
84
85
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 83

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

#parse_bjobs_output(response) ⇒ Object

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.

helper method



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 59

def parse_bjobs_output(response)
  return [] if response =~ /No job found/ || response.nil?

  lines = response.split("\n")
  validate_bjobs_output_columns(lines.first.split)

  lines.drop(1).map{ |job|
    values = split_bjobs_output_line(job)

    # make a hash of { field: "value", etc. }
    Hash[fields.zip(values)].each_with_object({}) { |(k,v),o|
      # if the value == "-", replace it with nil
      o[k] = (v == "-" ? nil : v)
    }
  }
end

#parse_bsub_output(response) ⇒ Object

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.

helper method



119
120
121
122
123
124
125
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 119

def parse_bsub_output(response)
  if response =~ /Job <(.*)> /
    $1
  else
    nil
  end
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 `bresume` command exited unsuccessfully



93
94
95
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 93

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

#submit_string(str, args: [], env: {}) ⇒ 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>)

    arguments passed to `sbatch` command

  • env (Hash{#to_s => #to_s})

    environment variables set

Returns:

  • (String)

    the id of the job that was created

Raises:

  • (Error)

    if `bsub` command exited unsuccessfully



113
114
115
116
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 113

def submit_string(str, args: [], env: {})
  args = args.map(&:to_s)
  parse_bsub_output(call("bsub", *args, env: env, stdin: str.to_s))
end