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

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

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

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:


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

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.


23
24
25
# File 'lib/ood_core/job/adapters/lsf.rb', line 23

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.


23
24
25
# File 'lib/ood_core/job/adapters/lsf.rb', line 23

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:


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

def delete(id)
  batch.delete_job(id.to_s)
rescue Batch::Error => e
  raise JobAdapterError, e.message
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:


123
124
125
126
127
# File 'lib/ood_core/job/adapters/lsf.rb', line 123

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:


87
88
89
90
91
92
93
# File 'lib/ood_core/job/adapters/lsf.rb', line 87

def info(id)
  # TODO: handle job arrays
  job = batch.get_job(id: id)
  job ? info_for_batch_hash(job) : nil
rescue Batch::Error => e
  raise JobAdapterError, e.message
end

#info_allArray<Info>

Retrieve info for all jobs from the resource manager

Returns:

  • (Array<Info>)

    information describing submitted jobs

Raises:

See Also:


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

def info_all
  batch.get_jobs.map { |v| info_for_batch_hash(v) }
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:


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

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:


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

def status(id)
  job = batch.get_job(id: id)
  state = job ? get_state(job[:status]) : :completed
  Status.new(state: state)
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>)

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

  • afterok (#to_s, Array<#to_s>)

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

  • afternotok (#to_s, Array<#to_s>)

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

  • afterany (#to_s, Array<#to_s>)

    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:


68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ood_core/job/adapters/lsf.rb', line 68

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