class OodCore::Job::Adapters::LinuxHost

An adapter object that describes the communication with a remote host for job management.

Public Class Methods

new(ssh_hosts:, launcher:) click to toggle source
# File lib/ood_core/job/adapters/linux_host.rb, line 62
def initialize(ssh_hosts:, launcher:)
  @launcher = launcher
  @ssh_hosts = Set.new(ssh_hosts)
end

Public Instance Methods

delete(id) click to toggle source

Delete the submitted job @abstract Subclass is expected to implement {#delete} @raise [NotImplementedError] if subclass did not define {#delete} @param id [#to_s] the id of the job @return [void]

# File lib/ood_core/job/adapters/linux_host.rb, line 197
def delete(id)
  session_name, destination_host = parse_job_id(id)
  @launcher.stop_remote_session(session_name, destination_host)
rescue Launcher::Error => e
  raise JobAdapterError, e.message
end
directive_prefix() click to toggle source
# File lib/ood_core/job/adapters/linux_host.rb, line 204
def directive_prefix
  nil
end
hold(id) click to toggle source

Put the submitted job on hold @abstract Subclass is expected to implement {#hold} @raise [NotImplementedError] if subclass did not define {#hold} @param id [#to_s] the id of the job @return [void]

# File lib/ood_core/job/adapters/linux_host.rb, line 177
def hold(id)
  # Consider sending SIGSTOP?
  raise NotImplementedError, "subclass did not define #hold"
end
info(id) click to toggle source

Retrieve job info from the SSH host @param id [#to_s] the id of the job @raise [JobAdapterError] if something goes wrong getting job info @return [Info] information describing submitted job @see Adapter#info

# File lib/ood_core/job/adapters/linux_host.rb, line 149
def info(id)
  _, host = parse_job_id(id)
  job = info_all(host: host).select{|info| info.id == id}.first
  (job) ? job : Info.new(id: id, status: :completed)
rescue Launcher::Error => e
  raise JobAdapterError, e.message
end
info_all(attrs: nil, host: nil) click to toggle source

Retrieve info for all jobs from the resource manager @raise [JobAdapterError] if something goes wrong getting job info @return [Array<Info>] information describing submitted jobs @see Adapter#info_all

# File lib/ood_core/job/adapters/linux_host.rb, line 92
def info_all(attrs: nil, host: nil)
  host_permitted?(host) if host

  @launcher.list_remote_sessions(host: host).map{
    |ls_output| ls_to_info(ls_output)
  }
rescue Launcher::Error => e
  raise JobAdapterError, e.message
end
info_all_each(attrs: nil) { |job| ... } click to toggle source

Iterate over each job Info object @param attrs [Array<symbol>] attrs is present only to complete the interface and is ignored @yield [Info] of each job to block @return [Enumerator] if no block given

# File lib/ood_core/job/adapters/linux_host.rb, line 117
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(_, attrs: nil) click to toggle source

Retrieve info for all jobs for a given owner or owners from the resource manager Note: owner and attrs are present only to complete the interface and are ignored Note: since this API is used in production no errors or warnings are thrown / issued @param owner [#to_s, Array<#to_s>] the owner(s) of the jobs @raise [JobAdapterError] if something goes wrong getting job info @return [Array<Info>] information describing submitted jobs

# File lib/ood_core/job/adapters/linux_host.rb, line 109
def info_where_owner(_, attrs: nil)
  info_all
end
info_where_owner_each(owner, attrs: nil) { |job| ... } click to toggle source

Iterate over each job Info object @param owner [#to_s, Array<#to_s>] owner is present only to complete the interface and is ignored @param attrs [Array<symbol>] attrs is present only to complete the interface and is ignored @yield [Info] of each job to block @return [Enumerator] if no block given

# File lib/ood_core/job/adapters/linux_host.rb, line 130
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
release(id) click to toggle source

Release the job that is on hold @abstract Subclass is expected to implement {#release} @raise [NotImplementedError] if subclass did not define {#release} @param id [#to_s] the id of the job @return [void]

# File lib/ood_core/job/adapters/linux_host.rb, line 187
def release(id)
  # Consider sending SIGCONT
  raise NotImplementedError, "subclass did not define #release"
end
status(id) click to toggle source

Retrieve job status from resource manager @note Optimized slightly over retrieving complete job information from server @abstract Subclass is expected to implement {#status} @raise [NotImplementedError] if subclass did not define {#status} @param id [#to_s] the id of the job @return [Status] status of job

# File lib/ood_core/job/adapters/linux_host.rb, line 163
def status(id)
  _, host = parse_job_id(id)
  job = info_all(host: host).select{|info| info.id == id}.first

  Status.new(state: (job) ? :running : :completed)
rescue Launcher::Error => e
  raise JobAdapterError, e.message
end
submit(script, after: [], afterok: [], afternotok: [], afterany: []) click to toggle source

Submit a job with the attributes defined in the job template instance @param script [Script] script object that describes the script and

attributes for the submitted job

@param after [#to_s, Array<#to_s>] No scheduling is available is used; setting raises JobAdapterError @param afterok [#to_s, Array<#to_s>] No scheduling is available is used; setting raises JobAdapterError @param afternotok [#to_s, Array<#to_s>] No scheduling is available is used; setting raises JobAdapterError @param afterany [#to_s, Array<#to_s>] No scheduling is available is used; setting raises JobAdapterError @raise [JobAdapterError] if something goes wrong submitting a job @return [String] the job id returned after successfully submitting a

job

@see Adapter#submit

# File lib/ood_core/job/adapters/linux_host.rb, line 78
def submit(script, after: [], afterok: [], afternotok: [], afterany: [])
  unless (after.empty? && afterok.empty? && afternotok.empty? && afterany.empty?)
    raise JobAdapterError, 'Scheduling subsequent jobs is not available.'
  end

  @launcher.start_remote_session(script)
rescue Launcher::Error => e
  raise JobAdapterError, e.message
end
supports_job_arrays?() click to toggle source

Whether the adapter supports job arrays @return [Boolean] - false

# File lib/ood_core/job/adapters/linux_host.rb, line 140
def supports_job_arrays?
  false
end

Private Instance Methods

host_permitted?(destination_host) click to toggle source
# File lib/ood_core/job/adapters/linux_host.rb, line 210
def host_permitted?(destination_host)
  raise JobAdapterError, "Requested destination host (#{destination_host}) not permitted" unless @ssh_hosts.include?(destination_host)
end
ls_to_info(ls_output) click to toggle source

Convert the returned Hash into an Info object

# File lib/ood_core/job/adapters/linux_host.rb, line 221
def ls_to_info(ls_output)
  started = ls_output[:session_created].to_i
  now = Time.now.to_i
  ellapsed = now - started
  Info.new(
      accounting_id: nil,
      allocated_nodes: [NodeInfo.new(name: ls_output[:destination_host], procs: 1)],
      cpu_time: ellapsed,
      dispatch_time: started,
      id: ls_output[:id],
      job_name: nil,  # TODO
      job_owner: Etc.getlogin,
      native: ls_output,
      procs: 1,
      queue_name: "LinuxHost adapter for #{@submit_host}",
      status: :running,
      submission_time: ellapsed,
      submit_host: @submit_host,
      wallclock_time: ellapsed
  )
end
parse_job_id(id) click to toggle source
# File lib/ood_core/job/adapters/linux_host.rb, line 214
def parse_job_id(id)
  raise JobAdapterError, "#{id} is not a valid LinuxHost adapter id because it is missing the '@'." unless id.include?('@')

  return id.split('@')
end