Class: OodCore::Job::Adapters::LinuxSystemd::Launcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/systemd/launcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Object used for simplified communication SSH hosts

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug: false, site_timeout: nil, ssh_hosts:, strict_host_checking: false, submit_host:, **_) ⇒ Launcher

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

Parameters:

  • debug (defaults to: false)

    Whether the adapter should be used in debug mode

  • site_timeout (#to_i) (defaults to: nil)

    A period after which the job should be killed or nil

  • ssh_hosts

    List of hosts to check when scanning for running jobs

  • strict_host_checking (defaults to: false)

    Allow SSH to perform strict host checking

  • submit_host

    The SSH-able host



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 23

def initialize(
  debug: false,
  site_timeout: nil,
  ssh_hosts:,
  strict_host_checking: false,
  submit_host:,
  **_
)
  @debug = !! debug
  @site_timeout = site_timeout.to_i
  @session_name_label = 'ondemand'
  @ssh_hosts = ssh_hosts
  @strict_host_checking = strict_host_checking
  @submit_host = submit_host
  @username = Etc.getlogin
end

Instance Attribute Details

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



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def debug
  @debug
end

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



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def session_name_label
  @session_name_label
end

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



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def site_timeout
  @site_timeout
end

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



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def ssh_hosts
  @ssh_hosts
end

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



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def strict_host_checking
  @strict_host_checking
end

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



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def username
  @username
end

Instance Method Details

#list_remote_sessions(host: nil) ⇒ Object

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.



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

def list_remote_sessions(host: nil)
  host_list = (host) ? [host] : ssh_hosts

  host_list.map {
    |hostname| list_remote_systemd_session(hostname)
  }.flatten.sort_by {
    |hsh| hsh[:session_name]
  }
end

#start_remote_session(script) ⇒ Object

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.

Parameters:

  • hostname (#to_s)

    The hostname to submit the work to

  • script (OodCore::Job::Script)

    The script object defining the work



42
43
44
45
46
47
48
49
50
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 42

def start_remote_session(script)
  cmd = ssh_cmd(submit_host(script), ['/usr/bin/env', 'bash'])

  session_name = unique_session_name
  output = call(*cmd, stdin: wrapped_script(script, session_name))
  hostname = parse_hostname(output)

  "#{session_name}@#{hostname}"
end

#stop_remote_session(session_name, hostname) ⇒ Object

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.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 52

def stop_remote_session(session_name, hostname)
  cmd = ssh_cmd(hostname, ['/usr/bin/env', 'bash'])

  kill_cmd = <<~SCRIPT
  # stop the session by name
  systemctl --user stop #{session_name}.service
  SCRIPT

  call(*cmd, stdin: kill_cmd)
rescue Error => e
  interpret_and_raise(e)
end

#submit_host(script = nil) ⇒ Object

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.



75
76
77
78
79
80
81
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 75

def submit_host(script = nil)
  if script && script.native && script.native['submit_host_override']
    script.native['submit_host_override']
  else
    @submit_host
  end
end