Class: OodCore::Job::Adapters::LinuxHost::Launcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/linux_host/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

Constant Summary collapse

UNIT_SEPARATOR =

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

","

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contain: false, debug: false, site_timeout: nil, singularity_bin:, singularity_bindpath: '/etc,/media,/mnt,/opt,/run,/srv,/usr,/var,/users', singularity_image:, ssh_hosts:, strict_host_checking: false, submit_host:, tmux_bin:, **_) ⇒ 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

  • singularity_bin

    Path to the Singularity executable

  • singularity_bindpath (defaults to: '/etc,/media,/mnt,/opt,/run,/srv,/usr,/var,/users')

    A comma delimited string of host paths to bindmount into the guest; sets SINGULARITY_BINDPATH environment variable

  • singularity_image (#to_s)

    Path to the Singularity image

  • 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

  • tmux_bin (#to_s)

    Path to the tmux executable



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ood_core/job/adapters/linux_host/launcher.rb', line 30

def initialize(
  contain: false,
  debug: false,
  site_timeout: nil,
  singularity_bin:,
  singularity_bindpath: '/etc,/media,/mnt,/opt,/run,/srv,/usr,/var,/users',
  singularity_image:,
  ssh_hosts:,
  strict_host_checking: false,
  submit_host:,
  tmux_bin:,
  **_
)
  @contain = !! contain
  @debug = !! debug
  @site_timeout = site_timeout.to_i
  @session_name_label = 'launched-by-ondemand'
  @singularity_bin = Pathname.new(singularity_bin)
  @site_singularity_bindpath = singularity_bindpath.to_s
  @default_singularity_image = Pathname.new(singularity_image)
  @ssh_hosts = ssh_hosts
  @strict_host_checking = strict_host_checking
  @submit_host = submit_host
  @tmux_bin = tmux_bin
  @username = Etc.getlogin
end

Instance Attribute Details

#containObject (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/linux_host/launcher.rb', line 12

def contain
  @contain
end

#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/linux_host/launcher.rb', line 12

def debug
  @debug
end

#default_singularity_imageObject (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/linux_host/launcher.rb', line 12

def default_singularity_image
  @default_singularity_image
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/linux_host/launcher.rb', line 12

def session_name_label
  @session_name_label
end

#singularity_binObject (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/linux_host/launcher.rb', line 12

def singularity_bin
  @singularity_bin
end

#site_singularity_bindpathObject (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/linux_host/launcher.rb', line 12

def site_singularity_bindpath
  @site_singularity_bindpath
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/linux_host/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/linux_host/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/linux_host/launcher.rb', line 12

def strict_host_checking
  @strict_host_checking
end

#tmux_binObject (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/linux_host/launcher.rb', line 12

def tmux_bin
  @tmux_bin
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/linux_host/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.



85
86
87
88
89
90
91
92
93
# File 'lib/ood_core/job/adapters/linux_host/launcher.rb', line 85

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

  host_list.map {
    |hostname| list_remote_tmux_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



59
60
61
62
63
64
65
66
# File 'lib/ood_core/job/adapters/linux_host/launcher.rb', line 59

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.



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

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

  kill_cmd = <<~SCRIPT
  # Get the tmux pane PID for the target session
  pane_pid=$(tmux list-panes -aF '\#{session_name} \#{pane_pid}' | grep '#{session_name}' | cut -f 2 -d ' ')
  # Find the Singularity sinit PID child of the pane process
  pane_sinit_pid=$(pstree -p -l "$pane_pid" | egrep -o 'sinit[(][[:digit:]]*|shim-init[(][[:digit:]]|appinit[(][[:digit:]]*' | grep -o '[[:digit:]]*')
  # Kill sinit which stops both Singularity-based processes and the tmux session
  kill "$pane_sinit_pid"
  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.



95
96
97
98
99
100
101
# File 'lib/ood_core/job/adapters/linux_host/launcher.rb', line 95

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