Class: OodCore::Job::Adapters::LinuxSystemd

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

Overview

The adapter for using systemd timers as the scheduler.

Defined Under Namespace

Classes: Launcher

Instance Method Summary collapse

Methods inherited from OodCore::Job::Adapter

#accounts, #cluster_info, #job_name_illegal_chars, #nodes, #queues, #sanitize_job_name

Constructor Details

#initialize(ssh_hosts:, launcher:) ⇒ LinuxSystemd

Returns a new instance of LinuxSystemd.



49
50
51
52
# File 'lib/ood_core/job/adapters/systemd.rb', line 49

def initialize(ssh_hosts:, launcher:)
  @launcher = launcher
  @ssh_hosts = Set.new(ssh_hosts)
end

Instance Method Details

#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



184
185
186
187
188
189
# File 'lib/ood_core/job/adapters/systemd.rb', line 184

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_prefixObject



191
192
193
# File 'lib/ood_core/job/adapters/systemd.rb', line 191

def directive_prefix
  nil
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



164
165
166
167
# File 'lib/ood_core/job/adapters/systemd.rb', line 164

def hold(id)
  # Consider sending SIGSTOP?
  raise NotImplementedError, "subclass did not define #hold"
end

#info(id) ⇒ Info

Retrieve job info from the SSH host

Parameters:

  • id (#to_s)

    the id of the job

Returns:

  • (Info)

    information describing submitted job

Raises:

See Also:



136
137
138
139
140
141
142
# File 'lib/ood_core/job/adapters/systemd.rb', line 136

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) ⇒ Array<Info>

Retrieve info for all jobs from the resource manager

Returns:

  • (Array<Info>)

    information describing submitted jobs

Raises:

See Also:



79
80
81
82
83
84
85
86
87
# File 'lib/ood_core/job/adapters/systemd.rb', line 79

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) {|Info| ... } ⇒ Enumerator

Iterate over each job Info object

Parameters:

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

    attrs is present only to complete the interface and is ignored

Yields:

  • (Info)

    of each job to block

Returns:

  • (Enumerator)

    if no block given



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

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) ⇒ Array<Info>

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

Parameters:

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

    the owner(s) of the jobs

Returns:

  • (Array<Info>)

    information describing submitted jobs

Raises:



96
97
98
# File 'lib/ood_core/job/adapters/systemd.rb', line 96

def info_where_owner(_, attrs: nil)
  info_all
end

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

Iterate over each job Info object

Parameters:

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

    owner is present only to complete the interface and is ignored

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

    attrs is present only to complete the interface and is ignored

Yields:

  • (Info)

    of each job to block

Returns:

  • (Enumerator)

    if no block given



117
118
119
120
121
122
123
# File 'lib/ood_core/job/adapters/systemd.rb', line 117

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) ⇒ 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



174
175
176
177
# File 'lib/ood_core/job/adapters/systemd.rb', line 174

def release(id)
  # Consider sending SIGCONT
  raise NotImplementedError, "subclass did not define #release"
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



150
151
152
153
154
155
156
157
# File 'lib/ood_core/job/adapters/systemd.rb', line 150

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: []) ⇒ 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: [])

    No scheduling is available is used; setting raises JobAdapterError

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

    No scheduling is available is used; setting raises JobAdapterError

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

    No scheduling is available is used; setting raises JobAdapterError

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

    No scheduling is available is used; setting raises JobAdapterError

Returns:

  • (String)

    the job id returned after successfully submitting a job

Raises:

See Also:



65
66
67
68
69
70
71
72
73
# File 'lib/ood_core/job/adapters/systemd.rb', line 65

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?Boolean

Whether the adapter supports job arrays

Returns:

  • (Boolean)
    • false



127
128
129
# File 'lib/ood_core/job/adapters/systemd.rb', line 127

def supports_job_arrays?
  false
end