Class: OodCore::Job::Adapters::Lsf

Inherits:
OodCore::Job::Adapter show all
Defined in:
lib/ood_core/job/adapters/lsf.rb

Overview

The adapter class for the LSF scheduler.

Defined Under Namespace

Classes: Batch, Helper

Constant Summary collapse

STATE_MAP =
{
  'RUN' => :running,
  'PEND' => :queued,
  'DONE' => :completed,
  'EXIT' => :completed,

  'PSUSP' => :queued_held, # supsended before job started, resumable via bresume
  'USUSP' => :suspended, # suspended after job started, resumable via bresume
  'SSUSP' => :suspended,

  'WAIT' => :queued, # FIXME: not sure what else to do here
  'ZOMBI' => :undetermined,
  'UNKWN' => :undetermined
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OodCore::Job::Adapter

#accounts, #cluster_info, #info_all_each, #info_where_owner_each, #job_name_illegal_chars, #nodes, #queues, #sanitize_job_name, #supports_job_arrays?

Constructor Details

#initialize(batch:) ⇒ Lsf

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 Lsf.

Parameters:

  • opts (#to_h)

    the options defining this adapter

See Also:



56
57
58
59
# File 'lib/ood_core/job/adapters/lsf.rb', line 56

def initialize(batch:)
  @batch = batch
  @helper = Lsf::Helper.new
end

Instance Attribute Details

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



31
32
33
# File 'lib/ood_core/job/adapters/lsf.rb', line 31

def batch
  @batch
end

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



31
32
33
# File 'lib/ood_core/job/adapters/lsf.rb', line 31

def helper
  @helper
end

Instance Method Details

#delete(id) ⇒ void

This method returns an undefined value.

Delete the submitted job

Parameters:

  • id (#to_s)

    the id of the job

Raises:

See Also:



167
168
169
170
171
# File 'lib/ood_core/job/adapters/lsf.rb', line 167

def delete(id)
  batch.delete_job(id.to_s)
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#directive_prefixObject



173
174
175
# File 'lib/ood_core/job/adapters/lsf.rb', line 173

def directive_prefix
  '#BSUB'
end

#hold(id) ⇒ void

This method returns an undefined value.

Put the submitted job on hold

Parameters:

  • id (#to_s)

    the id of the job

Raises:

See Also:



145
146
147
148
149
# File 'lib/ood_core/job/adapters/lsf.rb', line 145

def hold(id)
  batch.hold_job(id.to_s)
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#info(id) ⇒ Info

Retrieve job info from the resource manager

Parameters:

  • id (#to_s)

    the id of the job

Returns:

  • (Info)

    information describing submitted job

Raises:

See Also:



95
96
97
98
99
100
# File 'lib/ood_core/job/adapters/lsf.rb', line 95

def info(id)
  info_ary = batch.get_job(id: id).map{|v| info_for_batch_hash(v)}
  handle_job_array(info_ary, id)
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#info_all(attrs: nil) ⇒ Array<Info>

Retrieve info for all jobs from the resource manager

Returns:

  • (Array<Info>)

    information describing submitted jobs

Raises:

See Also:



106
107
108
109
110
# File 'lib/ood_core/job/adapters/lsf.rb', line 106

def info_all(attrs: nil)
  batch.get_jobs.map { |v| info_for_batch_hash(v) }
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#info_where_owner(owner, attrs: nil) ⇒ Array<Info>

Retrieve info for all of the owner's jobs from the resource manager

Returns:

  • (Array<Info>)

    information describing submitted jobs

Raises:

See Also:



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ood_core/job/adapters/lsf.rb', line 116

def info_where_owner(owner, attrs: nil)
  owners = Array.wrap(owner).map(&:to_s)
  if owners.count > 1
    super
  elsif owners.count == 0
    []
  else
    batch.get_jobs_for_user(owners.first).map { |v| info_for_batch_hash(v) }
  end
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#release(id) ⇒ void

This method returns an undefined value.

Release the job that is on hold

Parameters:

  • id (#to_s)

    the id of the job

Raises:

See Also:



156
157
158
159
160
# File 'lib/ood_core/job/adapters/lsf.rb', line 156

def release(id)
  batch.release_job(id.to_s)
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#status(id) ⇒ Status

Retrieve job status from resource manager

Parameters:

  • id (#to_s)

    the id of the job

Returns:

Raises:

See Also:



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

def status(id)
  info(id).status
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#submit(script, after: [], afterok: [], afternotok: [], afterany: []) ⇒ String

Submit a job with the attributes defined in the job template instance

Parameters:

  • script (Script)

    script object that describes the script and attributes for the submitted job

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

    this job may be scheduled for execution at any point after dependent jobs have started execution

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

    this job may be scheduled for execution only after dependent jobs have terminated with no errors

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

    this job may be scheduled for execution only after dependent jobs have terminated with errors

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

    this job may be scheduled for execution after dependent jobs have terminated

Returns:

  • (String)

    the job id returned after successfully submitting a job

Raises:

See Also:



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ood_core/job/adapters/lsf.rb', line 76

def submit(script, after: [], afterok: [], afternotok: [], afterany: [])
  # ensure dependencies are array of ids
  after      = Array(after).map(&:to_s)
  afterok    = Array(afterok).map(&:to_s)
  afternotok = Array(afternotok).map(&:to_s)
  afterany   = Array(afterany).map(&:to_s)

  kwargs = helper.batch_submit_args(script, after: after, afterok: afterok, afternotok: afternotok, afterany: afterany)

  batch.submit_string(script.content, **kwargs)
rescue Batch::Error => e
  raise JobAdapterError, e.message
end