class OSC::VNC::Session

Provides a way for developers to create and submit VNC sessions to the OSC batch systems. Also, developers are now able to submit any server session to the batch systems whether it is VNC or not following the same principles as a VNC session.

Attributes

batch[R]

@return [PBS::Batch] The batch object used.

script[R]

@return [ScriptView] The batch script used.

Public Class Methods

new(batch, script, opts = {}) click to toggle source

@param job [PBS::Batch] The batch object used. @param script [ScriptView] The batch script used. @param opts [Hash] The options used to construct a session.

# File lib/osc/vnc/session.rb, line 21
def initialize(batch, script, opts = {})
  @batch = batch
  @script = script
end

Public Instance Methods

submit(opts = {}) click to toggle source

Submit the VNC job to the defined batch server.

@param opts [Hash] The options used in job submission. @option opts [Hash] :headers The headers for the PBS job. @option opts [Hash] :resources The resources for the PBS job. @option opts [Hash] :envvars The environment variables for the PBS job. @return [Session] the session object

# File lib/osc/vnc/session.rb, line 33
def submit(opts = {})
  script.valid? # check if script is valid (can raise errors here)

  h = opts.fetch(:headers, {})
  r = opts.fetch(:resources, {})
  e = opts.fetch(:envvars, {})

  # Create tcp listen server if requested
  listen_server = _create_listen_server(e) if script.tcp_server?

  id = batch.submit_string(
    script.render,
    headers: _get_headers(h),
    resources: _get_resources(r),
    envvars: _get_envvars(e)
  )

  _write_listen_conn_info(listen_server) if script.tcp_server?

  id
end

Private Instance Methods

_create_listen_server(envvars) click to toggle source

Create a tcp listen server and set appropriate environment variables. for batch script to phone home

# File lib/osc/vnc/session.rb, line 85
def _create_listen_server(envvars)
  listen_server = create_listen
  _, port, host, _ = listen_server.addr(:hostname)
  envvars.merge! LISTEN_HOST: host, LISTEN_PORT: port
  listen_server
end
_get_envvars(envvars) click to toggle source

The hash of environment variables passed to the job.

# File lib/osc/vnc/session.rb, line 78
def _get_envvars(envvars)
  {
  }.merge envvars
end
_get_headers(headers) click to toggle source

The hash of PBS header attributes for the job.

# File lib/osc/vnc/session.rb, line 58
def _get_headers(headers)
  h = {
    PBS::ATTR[:N] => "VNC_Job",
    PBS::ATTR[:o] => "#{script.outdir}/$PBS_JOBID.output",
    PBS::ATTR[:j] => "oe",
    PBS::ATTR[:S] => "/bin/bash",
    PBS::ATTR[:init_work_dir] => script.outdir
  }.merge headers
  h
end
_get_resources(resources) click to toggle source

The hash of PBS resources requested for the job.

# File lib/osc/vnc/session.rb, line 70
def _get_resources(resources)
  {
    :nodes => "1:ppn=1:#{script.cluster}",
    :walltime => "24:00:00",
  }.merge resources
end
_write_listen_conn_info(server) click to toggle source

Write connection information from a TCP listening server.

# File lib/osc/vnc/session.rb, line 93
def _write_listen_conn_info(server)
  # Wait until VNC conn info is created by PBS batch script
  # Timeout after 60 seconds if no info is sent
  Timeout::timeout(60) do
    File.open(conn_file, 'w', 0600) { |f| f.puts read_listen(server: server) }
  end
end