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: "", cluster: "", bin_overrides: {}, submit_host: "", strict_host_checking: true, **_) ⇒ 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
19
20
21
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 12

def initialize(bindir: "", envdir: "", libdir: "", serverdir: "", cluster: "", bin_overrides: {}, submit_host: "", strict_host_checking: true, **_)
  @bindir = Pathname.new(bindir.to_s)
  @envdir = Pathname.new(envdir.to_s)
  @libdir = Pathname.new(libdir.to_s)
  @serverdir = Pathname.new(serverdir.to_s)
  @cluster = cluster.to_s
  @bin_overrides = bin_overrides
  @submit_host = submit_host.to_s
  @strict_host_checking = strict_host_checking
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.



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

def bin_overrides
  @bin_overrides
end

#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

#clusterObject (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 cluster
  @cluster
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

#strict_host_checkingObject (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 strict_host_checking
  @strict_host_checking
end

#submit_hostObject (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 submit_host
  @submit_host
end

Instance Method Details

#cluster_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.



133
134
135
136
137
138
139
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 133

def cluster_args
  if cluster.nil? || cluster.strip.empty?
    []
  else
    ["-m", cluster]
  end
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.



23
24
25
26
27
28
29
30
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 23

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



109
110
111
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 109

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



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

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

Parameters:

  • id (#to_s)

    the id of the job to check

Returns:

  • (Array<Hash>)

    details of specified job

Raises:

  • (Error)

    if ‘bjobs` command exited unsuccessfully



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

def get_job(id:)
  args = %W( -a -w -W #{id.to_s} )
  parse_bjobs_output(call("bjobs", *args))
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



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

def get_jobs
  get_jobs_for_user("all")
end

#get_jobs_for_user(user) ⇒ 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.



39
40
41
42
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 39

def get_jobs_for_user(user)
  args = %W( -u #{user} -a -w -W )
  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



89
90
91
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 89

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

Raises:



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

def parse_bjobs_output(response)
  return [] if response.nil? || response.strip.empty?

  lines = response.split("\n")
  raise Error, "bjobs output in different format than expected: #{lines.inspect}" unless lines.count > 1

  columns = lines.shift.split

  validate_bjobs_output_columns(columns)
  jobname_column_idx = columns.find_index("JOB_NAME")

  lines.map{ |job|
    values = split_bjobs_output_line(job, num_columns: columns.count, jobname_column_idx: jobname_column_idx)

    # 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



125
126
127
128
129
130
131
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 125

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



99
100
101
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 99

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>) (defaults to: [])

    arguments passed to ‘sbatch` command

  • env (Hash{#to_s => #to_s}) (defaults to: {})

    environment variables set

Returns:

  • (String)

    the id of the job that was created

Raises:

  • (Error)

    if ‘bsub` command exited unsuccessfully



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

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