Class: Moab::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/moab/scheduler.rb

Overview

Object used for simplified communication with a moab scheduler server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, lib: "", bin: "", moabhomedir: ENV['MOABHOMEDIR']) ⇒ Scheduler

Returns a new instance of Scheduler.

Parameters:

  • host (#to_s)

    the moab scheduler server

  • lib (#to_s) (defaults to: "")

    path to moab installation libraries

  • bin (#to_s) (defaults to: "")

    path to moab installation binaries

  • moabhomedir (#to_s) (defaults to: ENV['MOABHOMEDIR'])

    path to moab home dir



35
36
37
38
39
40
# File 'lib/moab/scheduler.rb', line 35

def initialize(host:, lib: "", bin: "", moabhomedir: ENV['MOABHOMEDIR'])
  @host        = host.to_s
  @lib         = Pathname.new(lib.to_s)
  @bin         = Pathname.new(bin.to_s)
  @moabhomedir = Pathname.new(moabhomedir.to_s)
end

Instance Attribute Details

#binPathname (readonly)

The path to the Moab client installation binaries

Examples:

For Moab 9.0.0

my_conn.bin.to_s #=> "/usr/local/moab/9.0.0/bin"

Returns:

  • (Pathname)

    path to moab binaries



23
24
25
# File 'lib/moab/scheduler.rb', line 23

def bin
  @bin
end

#hostString (readonly)

The host of the Moab scheduler server

Examples:

OSC’s Oakley scheduler server

my_conn.host #=> "oak-batch.osc.edu"

Returns:

  • (String)

    the scheduler server host



11
12
13
# File 'lib/moab/scheduler.rb', line 11

def host
  @host
end

#libPathname (readonly)

The path to the Moab client installation libraries

Examples:

For Moab 9.0.0

my_conn.lib.to_s #=> "/usr/local/moab/9.0.0/lib"

Returns:

  • (Pathname)

    path to moab libraries



17
18
19
# File 'lib/moab/scheduler.rb', line 17

def lib
  @lib
end

#moabhomedirPathname (readonly)

The path to the Moab home dir

Examples:

my_conn.moabhomedir.to_s #=> "/var/spool/batch/moab"

Returns:

  • (Pathname)

    path to moab home dir



29
30
31
# File 'lib/moab/scheduler.rb', line 29

def moabhomedir
  @moabhomedir
end

Instance Method Details

#==(other) ⇒ Boolean

The comparison operator

Parameters:

  • other (#to_h)

    object to compare against

Returns:

  • (Boolean)

    whether objects are equivalent



51
52
53
# File 'lib/moab/scheduler.rb', line 51

def ==(other)
  to_h == other.to_h
end

#call(cmd, *args, env: {}) ⇒ Nokogiri::Document

Call a binary command from the moab client installation

Parameters:

  • cmd (#to_s)

    command run from command line

  • *args (Array<#to_s>)

    any number of arguments for command

  • env (#to_h) (defaults to: {})

    environment to run command under

Returns:

  • (Nokogiri::Document)

    the xml output from command

Raises:



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/moab/scheduler.rb', line 75

def call(cmd, *args, env: {})
  cmd = bin.join(cmd.to_s).to_s
  args = ["--host=#{@host}", "--xml"] + args.map(&:to_s)
  env = {
    "LD_LIBRARY_PATH" => "#{lib}:#{ENV['LD_LIBRARY_PATH']}",
    "MOABHOMEDIR" => "#{moabhomedir}"
  }.merge(env.to_h)
  o, e, s = Open3.capture3(env, cmd, *args)
  s.success? ? Nokogiri::XML(o) : raise(CommandFailed, e)
rescue Errno::ENOENT => e
  raise InvalidCommand, e.message
end

#eql?(other) ⇒ Boolean

Check whether objects are identical to each other

Parameters:

  • other (#to_h)

    object to compare against

Returns:

  • (Boolean)

    whether objects are identical



58
59
60
# File 'lib/moab/scheduler.rb', line 58

def eql?(other)
  self.class == other.class && self == other
end

#hashFixnum

Generate a hash value for this object

Returns:

  • (Fixnum)

    hash value of object



64
65
66
# File 'lib/moab/scheduler.rb', line 64

def hash
  [self.class, to_h].hash
end

#to_hHash

Convert object to hash

Returns:

  • (Hash)

    the hash describing this object



44
45
46
# File 'lib/moab/scheduler.rb', line 44

def to_h
  {host: host, lib: lib, bin: bin, moabhomedir: moabhomedir}
end