Class: OodCore::Job::Adapter Abstract

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

Overview

This class is abstract.

A class that handles the communication with a resource manager for submitting/statusing/holding/deleting jobs

Instance Method Summary collapse

Instance Method Details

#accountsArray<AccountInfo>

Retrieve the accounts available to use for the current user.

Subclasses that do not implement this will return empty arrays.

Returns:

  • (Array<AccountInfo>)

    the accounts available to the user.



205
206
207
# File 'lib/ood_core/job/adapter.rb', line 205

def accounts
  []
end

#cluster_infoClusterInfo

This method is abstract.

Subclass is expected to implement #cluster_stats

Retrieve the number of active and total cpus, nodes, and gpus

Returns:

  • (ClusterInfo)

    Object containing quantified statistics about the cluster’s active/total cpus, nodes, and gpus

Raises:

  • (NotImplementedError)

    if subclass did not define #cluster_stats



41
42
43
# File 'lib/ood_core/job/adapter.rb', line 41

def cluster_info
  raise NotImplementedError, "subclass did not define #cluster_stats"
end

#delete(id) ⇒ void

This method is abstract.

Subclass is expected to implement #delete

This method returns an undefined value.

Delete the submitted job

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (NotImplementedError)

    if subclass did not define #delete



166
167
168
# File 'lib/ood_core/job/adapter.rb', line 166

def delete(id)
  raise NotImplementedError, "subclass did not define #delete"
end

#directive_prefixString

This method is abstract.

Subclass is expected to implement #directive_prefix

Return the scheduler-specific directive prefix

Examples of directive prefixes include #QSUB, #BSUB and allow placing what would otherwise be command line options inside the job launch script.

The method should return nil if the adapter does not support prefixes

Returns:

  • (String)

Raises:



180
181
182
# File 'lib/ood_core/job/adapter.rb', line 180

def directive_prefix
  raise NotImplementedError, "subclass did not define #directive_prefix"
end

#hold(id) ⇒ void

This method is abstract.

Subclass is expected to implement #hold

This method returns an undefined value.

Put the submitted job on hold

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (NotImplementedError)

    if subclass did not define #hold



148
149
150
# File 'lib/ood_core/job/adapter.rb', line 148

def hold(id)
  raise NotImplementedError, "subclass did not define #hold"
end

#info(id) ⇒ Info

This method is abstract.

Subclass is expected to implement #info

Retrieve job info from the resource manager

Parameters:

  • id (#to_s)

    the id of the job

Returns:

  • (Info)

    information describing submitted job

Raises:

  • (NotImplementedError)

    if subclass did not define #info



129
130
131
# File 'lib/ood_core/job/adapter.rb', line 129

def info(id)
  raise NotImplementedError, "subclass did not define #info"
end

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

This method is abstract.

Subclass is expected to implement #info_all

Retrieve info for all jobs from the resource manager

Parameters:

  • attrs (Array<symbol>) (defaults to: nil)

    defaults to nil (and all attrs are provided) This array specifies only attrs you want, in addition to id and status. If an array, the Info object that is returned to you is not guarenteed to have a value for any attr besides the ones specified and id and status.

    For certain adapters this may speed up the response since adapters can get by without populating the entire Info object

Returns:

  • (Array<Info>)

    information describing submitted jobs

Raises:

  • (NotImplementedError)

    if subclass did not define #info_all



56
57
58
# File 'lib/ood_core/job/adapter.rb', line 56

def info_all(attrs: nil)
  raise NotImplementedError, "subclass did not define #info_all"
end

#info_all_each(attrs: nil) {|Info| ... } ⇒ Enumerator

Iterate over each job Info object

Parameters:

  • attrs (Array<symbol>) (defaults to: nil)

    defaults to nil (and all attrs are provided) This array specifies only attrs you want, in addition to id and status. If an array, the Info object that is returned to you is not guarenteed to have a value for any attr besides the ones specified and id and status.

    For certain adapters this may speed up the response since adapters can get by without populating the entire Info object

Yields:

  • (Info)

    of each job to block

Returns:

  • (Enumerator)

    if no block given



90
91
92
93
94
95
96
# File 'lib/ood_core/job/adapter.rb', line 90

def info_all_each(attrs: nil)
  return to_enum(:info_all_each, attrs: attrs) unless block_given?

  info_all(attrs: attrs).each do |job|
    yield job
  end
end

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

Retrieve info for all jobs for a given owner or owners from the resource manager

Parameters:

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

    the owner(s) of the jobs

  • attrs (Array<symbol>) (defaults to: nil)

    defaults to nil (and all attrs are provided) This array specifies only attrs you want, in addition to id and status. If an array, the Info object that is returned to you is not guarenteed to have a value for any attr besides the ones specified and id and status.

    For certain adapters this may speed up the response since adapters can get by without populating the entire Info object

Returns:

  • (Array<Info>)

    information describing submitted jobs



71
72
73
74
75
76
77
78
# File 'lib/ood_core/job/adapter.rb', line 71

def info_where_owner(owner, attrs: nil)
  owner = Array.wrap(owner).map(&:to_s)

  # must at least have job_owner to filter by job_owner
  attrs = Array.wrap(attrs) | [:job_owner] unless attrs.nil?

  info_all(attrs: attrs).select { |info| owner.include? info.job_owner }
end

#info_where_owner_each(owner, attrs: nil) {|Info| ... } ⇒ Enumerator

Iterate over each job Info object

Parameters:

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

    the owner(s) of the jobs

  • attrs (Array<symbol>) (defaults to: nil)

    defaults to nil (and all attrs are provided) This array specifies only attrs you want, in addition to id and status. If an array, the Info object that is returned to you is not guarenteed to have a value for any attr besides the ones specified and id and status.

    For certain adapters this may speed up the response since adapters can get by without populating the entire Info object

Yields:

  • (Info)

    of each job to block

Returns:

  • (Enumerator)

    if no block given



109
110
111
112
113
114
115
# File 'lib/ood_core/job/adapter.rb', line 109

def info_where_owner_each(owner, attrs: nil)
  return to_enum(:info_where_owner_each, owner, attrs: attrs) unless block_given?

  info_where_owner(owner, attrs: attrs).each do |job|
    yield job
  end
end

#job_name_illegal_charsString

Illegal chars that should not be used in a job name A dash is assumed to be legal in job names in all batch schedulers

Returns:

  • (String)

    string of chars



197
198
199
# File 'lib/ood_core/job/adapter.rb', line 197

def job_name_illegal_chars
  ENV["OOD_JOB_NAME_ILLEGAL_CHARS"].to_s
end

#nodesArray<NodeInfo>

Return the list of nodes for this scheduler.

Subclasses that do not implement this will return empty arrays.

Returns:



221
222
223
# File 'lib/ood_core/job/adapter.rb', line 221

def nodes
  []
end

#queuesArray<QueueInfo>

Return the list of queues for this scheduler.

Subclasses that do not implement this will return empty arrays.

Returns:



213
214
215
# File 'lib/ood_core/job/adapter.rb', line 213

def queues
  []
end

#release(id) ⇒ void

This method is abstract.

Subclass is expected to implement #release

This method returns an undefined value.

Release the job that is on hold

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (NotImplementedError)

    if subclass did not define #release



157
158
159
# File 'lib/ood_core/job/adapter.rb', line 157

def release(id)
  raise NotImplementedError, "subclass did not define #release"
end

#sanitize_job_name(job_name) ⇒ String

Replace illegal chars in job name with a dash

Returns:

  • (String)

    job name with dashes replacing illegal chars



187
188
189
190
191
# File 'lib/ood_core/job/adapter.rb', line 187

def sanitize_job_name(job_name)
  # escape ^ and omit -
  chars = job_name_illegal_chars.to_s.gsub("^", "\\^").gsub("-", "")
  job_name.tr(chars, "-")
end

#status(id) ⇒ Status

This method is abstract.

Subclass is expected to implement #status

Note:

Optimized slightly over retrieving complete job information from server

Retrieve job status from resource manager

Parameters:

  • id (#to_s)

    the id of the job

Returns:

Raises:

  • (NotImplementedError)

    if subclass did not define #status



139
140
141
# File 'lib/ood_core/job/adapter.rb', line 139

def status(id)
  raise NotImplementedError, "subclass did not define #status"
end

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

This method is abstract.

Subclass is expected to implement #submit

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

Examples:

Submit job template to cluster

solver_id = job_adapter.submit(solver_script)
#=> "1234.server"

Submit job that depends on previous job

post_id = job_adapter.submit(
  post_script,
  afterok: solver_id
)
#=> "1235.server"

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:

  • (NotImplementedError)

    if subclass did not define #submit



32
33
34
# File 'lib/ood_core/job/adapter.rb', line 32

def submit(script, after: [], afterok: [], afternotok: [], afterany: [])
  raise NotImplementedError, "subclass did not define #submit"
end

#supports_job_arrays?Boolean

Whether the adapter supports job arrays

Returns:

  • (Boolean)
    • assumes true; but can be overridden by adapters that

    explicitly do not



120
121
122
# File 'lib/ood_core/job/adapter.rb', line 120

def supports_job_arrays?
  true
end