Class: OodCore::Job::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/factory.rb,
lib/ood_core/job/adapters/lsf.rb,
lib/ood_core/job/adapters/slurm.rb,
lib/ood_core/job/adapters/torque.rb

Overview

A factory that builds job adapter objects from a configuration.

Class Method Summary collapse

Class Method Details

.build(config) ⇒ Adapter

Build a job adapter from a configuration

Parameters:

  • config (#to_h)

    configuration describing job adapter

Options Hash (config):

  • :adapter (#to_s)

    The job adapter to use

Returns:

  • (Adapter)

    the job adapter object

Raises:


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ood_core/job/factory.rb', line 16

def build(config)
  c = config.to_h.symbolize_keys

  adapter = c.fetch(:adapter) { raise AdapterNotSpecified, "job configuration does not specify adapter" }.to_s

  path_to_adapter = "ood_core/job/adapters/#{adapter}"
  begin
    require path_to_adapter
  rescue Gem::LoadError => e
    raise Gem::LoadError, "Specified '#{adapter}' for job adapter, but the gem is not loaded."
  rescue LoadError => e
    raise LoadError, "Could not load '#{adapter}'. Make sure that the job adapter in the configuration file is valid."
  end

  adapter_method = "build_#{adapter}"

  unless respond_to?(adapter_method)
    raise AdapterNotFound, "job configuration specifies nonexistent #{adapter} adapter"
  end

  send(adapter_method, c)
end

.build_lsf(config) ⇒ Object

Build the Lsf adapter from a configuration

Parameters:

  • config (#to_h)

    the configuration for job adapter

Options Hash (config):

  • :bindir (#to_s) — default: ''

    Path to lsf client bin dir

  • :libdir (#to_s) — default: ''

    Path to lsf client lib dir

  • :envdir (#to_s) — default: ''

    Path to lsf client conf dir

  • :serverdir (#to_s) — default: ''

    Path to lsf client etc dir


14
15
16
17
# File 'lib/ood_core/job/adapters/lsf.rb', line 14

def self.build_lsf(config)
  batch = Adapters::Lsf::Batch.new(config.to_h.symbolize_keys)
  Adapters::Lsf.new(batch: batch)
end

.build_slurm(config) ⇒ Object

Build the Slurm adapter from a configuration

Parameters:

  • config (#to_h)

    the configuration for job adapter

Options Hash (config):

  • :cluster (Object) — default: nil

    The cluster to communicate with

  • :conf (Object) — default: nil

    Path to the slurm conf

  • :bin (Object) — default: nil

    Path to slurm client binaries


14
15
16
17
18
19
20
21
# File 'lib/ood_core/job/adapters/slurm.rb', line 14

def self.build_slurm(config)
  c = config.to_h.symbolize_keys
  cluster = c.fetch(:cluster, nil)
  conf    = c.fetch(:conf, nil)
  bin     = c.fetch(:bin, nil)
  slurm = Adapters::Slurm::Batch.new(cluster: cluster, conf: conf, bin: bin)
  Adapters::Slurm.new(slurm: slurm)
end

.build_torque(config) ⇒ Object

Build the Torque adapter from a configuration

Parameters:

  • config (#to_h)

    the configuration for job adapter

Options Hash (config):

  • :host (#to_s)

    The batch server host

  • :lib (#to_s) — default: ''

    Path to torque client libraries

  • :bin (#to_s) — default: ''

    Path to torque client binaries


16
17
18
19
20
21
22
23
# File 'lib/ood_core/job/adapters/torque.rb', line 16

def self.build_torque(config)
  c = config.to_h.symbolize_keys
  host = c.fetch(:host) { raise ArgumentError, "No host specified. Missing argument: host" }.to_s
  lib  = c.fetch(:lib, "").to_s
  bin  = c.fetch(:bin, "").to_s
  pbs  = PBS::Batch.new(host: host, lib: lib, bin: bin)
  Adapters::Torque.new(pbs: pbs)
end