Class: OodCore::Job::Adapters::Slurm::Batch Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/slurm.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 with a Slurm batch server

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster: nil, bin: nil, conf: nil) ⇒ Batch

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 Batch

Parameters:

  • cluster (#to_s, nil)

    the cluster name

  • conf (#to_s, nil)

    path to the slurm conf

  • bin (#to_s)

    path to slurm installation binaries



58
59
60
61
62
# File 'lib/ood_core/job/adapters/slurm.rb', line 58

def initialize(cluster: nil, bin: nil, conf: nil)
  @cluster = cluster && cluster.to_s
  @conf    = conf    && Pathname.new(conf.to_s)
  @bin     = Pathname.new(bin.to_s)
end

Instance Attribute Details

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

The path to the Slurm client installation binaries

Examples:

For Slurm 10.0.0

my_batch.bin.to_s #=> "/usr/local/slurm/10.0.0/bin

Returns:

  • (Pathname)

    path to slurm binaries



49
50
51
# File 'lib/ood_core/job/adapters/slurm.rb', line 49

def bin
  @bin
end

#clusterString? (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.

The cluster of the Slurm batch server

Examples:

CHPC's kingspeak cluster

my_batch.cluster #=> "kingspeak"

Returns:

  • (String, nil)

    the cluster name



37
38
39
# File 'lib/ood_core/job/adapters/slurm.rb', line 37

def cluster
  @cluster
end

#confPathname? (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.

The path to the Slurm configuration file

Examples:

For Slurm 10.0.0

my_batch.conf.to_s #=> "/usr/local/slurm/10.0.0/etc/slurm.conf

Returns:

  • (Pathname, nil)

    path to slurm conf



43
44
45
# File 'lib/ood_core/job/adapters/slurm.rb', line 43

def conf
  @conf
end

Instance Method Details

#delete_job(id) ⇒ void

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.

This method returns an undefined value.

Delete a specified job from batch server

Examples:

Delete job “1234”

my_batch.delete_job("1234")

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (Error)

    if `scancel` command exited unsuccessfully



124
125
126
# File 'lib/ood_core/job/adapters/slurm.rb', line 124

def delete_job(id)
  call("scancel", id.to_s)
end

#get_jobs(id: "", filters: []) ⇒ Array<Hash>

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.

Get a list of hashes detailing each of the jobs on the batch server

Examples:

Status info for all jobs

my_batch.get_jobs
#=>
#[
#  {
#    :account => "account",
#    :job_id => "my_job",
#    ...
#  },
#  {
#    :account => "account",
#    :job_id => "my_other_job",
#    ...
#  },
#  ...
#]

Parameters:

  • id (#to_s)

    the id of the job

  • filters (Array<Symbol>)

    list of attributes to filter on

Returns:

  • (Array<Hash>)

    list of details for jobs

Raises:

  • (Error)

    if `squeue` command exited unsuccessfully



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ood_core/job/adapters/slurm.rb', line 85

def get_jobs(id: "", filters: [])
  delim = "\x1F"     # don't use "|" because FEATURES uses this
  options = filters.empty? ? fields : fields.slice(*filters)
  args  = ["--all", "--states=all", "--noconvert"]
  args += ["-o", "#{options.values.join(delim)}"]
  args += ["-j", id.to_s] unless id.to_s.empty?
  lines = call("squeue", *args).split("\n").map(&:strip)

  lines.drop(cluster ? 2 : 1).map do |line|
    Hash[options.keys.zip(line.split(delim))]
  end
end

#hold_job(id) ⇒ void

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.

This method returns an undefined value.

Put a specified job on hold

Examples:

Put job “1234” on hold

my_batch.hold_job("1234")

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (Error)

    if `scontrol` command exited unsuccessfully



104
105
106
# File 'lib/ood_core/job/adapters/slurm.rb', line 104

def hold_job(id)
  call("scontrol", "hold", id.to_s)
end

#release_job(id) ⇒ void

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.

This method returns an undefined value.

Release a specified job that is on hold

Examples:

Release job “1234” from on hold

my_batch.release_job("1234")

Parameters:

  • id (#to_s)

    the id of the job

Raises:

  • (Error)

    if `scontrol` command exited unsuccessfully



114
115
116
# File 'lib/ood_core/job/adapters/slurm.rb', line 114

def release_job(id)
  call("scontrol", "release", id.to_s)
end

#submit_string(str, args: [], env: {}) ⇒ String

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.

Submit a script expanded as a string to the batch server

Parameters:

  • str (#to_s)

    script as a string

  • args (Array<#to_s>)

    arguments passed to `sbatch` command

  • env (Hash{#to_s => #to_s})

    environment variables set

Returns:

  • (String)

    the id of the job that was created

Raises:

  • (Error)

    if `sbatch` command exited unsuccessfully



134
135
136
137
138
# File 'lib/ood_core/job/adapters/slurm.rb', line 134

def submit_string(str, args: [], env: {})
  args = args.map(&:to_s) + ["--parsable"]
  env = {"SBATCH_EXPORT" => "NONE"}.merge env.each_with_object({}) { |(k, v), h| h[k.to_s] = v.to_s }
  call("sbatch", *args, env: env, stdin: str.to_s).strip.split(";").first
end