Class: OodCore::Job::Adapters::Lsf::Batch Private
- Inherits:
-
Object
- Object
- OodCore::Job::Adapters::Lsf::Batch
- Defined in:
- lib/ood_core/job/adapters/lsf/batch.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 LSF batch server
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
- #bin_overrides ⇒ Object readonly private
- #bindir ⇒ Object readonly private
- #cluster ⇒ Object readonly private
- #envdir ⇒ Object readonly private
- #libdir ⇒ Object readonly private
- #serverdir ⇒ Object readonly private
- #strict_host_checking ⇒ Object readonly private
- #submit_host ⇒ Object readonly private
Instance Method Summary collapse
- #cluster_args ⇒ Object private
- #default_env ⇒ Object private
-
#delete_job(id) ⇒ void
private
Delete a specified job from batch server.
-
#fields ⇒ Object
private
status fields available from bjobs.
-
#get_job(id:) ⇒ Array<Hash>
private
Get hash detailing the specified job.
-
#get_jobs ⇒ Array<Hash>
private
Get a list of hashes detailing each of the jobs on the batch server.
- #get_jobs_for_user(user) ⇒ Object private
-
#hold_job(id) ⇒ void
private
Put a specified job on hold.
-
#initialize(bindir: "", envdir: "", libdir: "", serverdir: "", cluster: "", bin_overrides: {}, submit_host: "", strict_host_checking: true, **_) ⇒ Batch
constructor
private
A new instance of Batch.
-
#parse_bjobs_output(response) ⇒ Object
private
helper method.
-
#parse_bsub_output(response) ⇒ Object
private
helper method.
-
#release_job(id) ⇒ void
private
Release a specified job that is on hold.
-
#submit_string(str, args: [], env: {}) ⇒ String
private
Submit a script expanded as a string to the batch server.
Constructor Details
#initialize(bindir: "", envdir: "", libdir: "", serverdir: "", cluster: "", bin_overrides: {}, submit_host: "", strict_host_checking: true, **_) ⇒ 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.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 12 def initialize(bindir: "", envdir: "", libdir: "", serverdir: "", cluster: "", bin_overrides: {}, submit_host: "", strict_host_checking: true, **_) @bindir = Pathname.new(bindir.to_s) @envdir = Pathname.new(envdir.to_s) @libdir = Pathname.new(libdir.to_s) @serverdir = Pathname.new(serverdir.to_s) @cluster = cluster.to_s @bin_overrides = bin_overrides @submit_host = submit_host.to_s @strict_host_checking = strict_host_checking end |
Instance Attribute Details
#bin_overrides ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def bin_overrides @bin_overrides end |
#bindir ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def bindir @bindir end |
#cluster ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def cluster @cluster end |
#envdir ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def envdir @envdir end |
#libdir ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def libdir @libdir end |
#serverdir ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def serverdir @serverdir end |
#strict_host_checking ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def strict_host_checking @strict_host_checking end |
#submit_host ⇒ Object (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.
5 6 7 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 5 def submit_host @submit_host end |
Instance Method Details
#cluster_args ⇒ 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.
133 134 135 136 137 138 139 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 133 def cluster_args if cluster.nil? || cluster.strip.empty? [] else ["-m", cluster] end end |
#default_env ⇒ 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.
23 24 25 26 27 28 29 30 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 23 def default_env { "LSF_BINDIR" => bindir.to_s, "LSF_LIBDIR" => libdir.to_s, "LSF_ENVDIR" => envdir.to_s, "LSF_SERVERDIR" => serverdir.to_s }.reject {|k,v| v.nil? || v.empty? } end |
#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
109 110 111 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 109 def delete_job(id) call("bkill", id.to_s) end |
#fields ⇒ 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.
status fields available from bjobs
54 55 56 57 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 54 def fields %i(id user status queue from_host exec_host name submit_time project cpu_used mem swap pids start_time finish_time) end |
#get_job(id:) ⇒ 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 hash detailing the specified job
48 49 50 51 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 48 def get_job(id:) args = %W( -a -w -W #{id.to_s} ) parse_bjobs_output(call("bjobs", *args)) end |
#get_jobs ⇒ 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
35 36 37 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 35 def get_jobs get_jobs_for_user("all") end |
#get_jobs_for_user(user) ⇒ 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.
39 40 41 42 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 39 def get_jobs_for_user(user) args = %W( -u #{user} -a -w -W ) parse_bjobs_output(call("bjobs", *args)) 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
89 90 91 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 89 def hold_job(id) call("bstop", id.to_s) end |
#parse_bjobs_output(response) ⇒ 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.
helper method
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 60 def parse_bjobs_output(response) return [] if response.nil? || response.strip.empty? lines = response.split("\n") raise Error, "bjobs output in different format than expected: #{lines.inspect}" unless lines.count > 1 columns = lines.shift.split validate_bjobs_output_columns(columns) jobname_column_idx = columns.find_index("JOB_NAME") lines.map{ |job| values = split_bjobs_output_line(job, num_columns: columns.count, jobname_column_idx: jobname_column_idx) # make a hash of { field: "value", etc. } Hash[fields.zip(values)].each_with_object({}) { |(k,v),o| # if the value == "-", replace it with nil o[k] = (v == "-" ? nil : v) } } end |
#parse_bsub_output(response) ⇒ 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.
helper method
125 126 127 128 129 130 131 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 125 def parse_bsub_output(response) if response =~ /Job <(.*)> / $1 else nil end 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
99 100 101 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 99 def release_job(id) call("bresume", 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
119 120 121 122 |
# File 'lib/ood_core/job/adapters/lsf/batch.rb', line 119 def submit_string(str, args: [], env: {}) args = args.map(&:to_s) parse_bsub_output(call("bsub", *args, env: env, stdin: str.to_s)) end |