Class: OodCore::Job::Adapters::PBSPro::Batch Private
- Inherits:
-
Object
- Object
- OodCore::Job::Adapters::PBSPro::Batch
- Defined in:
- lib/ood_core/job/adapters/pbspro.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 PBS Pro batch server
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#bin_overrides ⇒ Object
readonly
private
Optional overrides for PBS Pro client executables.
-
#host ⇒ String?
readonly
private
The host of the PBS Pro batch server.
-
#pbs_exec ⇒ Pathname?
readonly
private
The path containing the PBS executables.
-
#strict_host_checking ⇒ Bool, true
readonly
private
Whether to use strict host checking when ssh to submit_host.
-
#submit_host ⇒ String?
readonly
private
The login node to submit the job via ssh.
Instance Method Summary collapse
-
#delete_job(id) ⇒ void
private
Delete a specified job from batch server.
-
#get_cluster_info ⇒ ClusterInfo
private
Get a ClusterInfo object containing information about the given cluster.
-
#get_jobs(id: "") ⇒ Array<Hash>
private
Get a list of hashes detailing each of the jobs on the batch server.
-
#hold_job(id) ⇒ void
private
Put a specified job on hold.
-
#initialize(host: nil, submit_host: "", strict_host_checking: true, pbs_exec: nil, bin_overrides: {}) ⇒ Batch
constructor
private
A new instance of Batch.
-
#release_job(id) ⇒ void
private
Release a specified job that is on hold.
-
#select_jobs(args: []) ⇒ Array<String>
private
Select batch jobs from the batch server.
-
#submit_string(str, args: [], chdir: nil) ⇒ String
private
Submit a script expanded as a string to the batch server.
Constructor Details
#initialize(host: nil, submit_host: "", strict_host_checking: true, pbs_exec: nil, bin_overrides: {}) ⇒ 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.
81 82 83 84 85 86 87 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 81 def initialize(host: nil, submit_host: "", strict_host_checking: true, pbs_exec: nil, bin_overrides: {}) @host = host && host.to_s @submit_host = submit_host && submit_host.to_s @strict_host_checking = strict_host_checking @pbs_exec = pbs_exec && Pathname.new(pbs_exec.to_s) @bin_overrides = bin_overrides 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.
Optional overrides for PBS Pro client executables
71 72 73 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 71 def bin_overrides @bin_overrides end |
#host ⇒ String? (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 host of the PBS Pro batch server
47 48 49 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 47 def host @host end |
#pbs_exec ⇒ Pathname? (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 containing the PBS executables
65 66 67 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 65 def pbs_exec @pbs_exec end |
#strict_host_checking ⇒ Bool, true (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.
Whether to use strict host checking when ssh to submit_host
59 60 61 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 59 def strict_host_checking @strict_host_checking end |
#submit_host ⇒ String? (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 login node to submit the job via ssh
53 54 55 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 53 def submit_host @submit_host 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
207 208 209 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 207 def delete_job(id) call("qdel", id.to_s) end |
#get_cluster_info ⇒ ClusterInfo
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 ClusterInfo object containing information about the given cluster
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 91 def get_cluster_info args = ["-a", "-F", "json"] stdout = call("pbsnodes", *args) node_info = JSON.parse(stdout) # Initialize cluster info values total_nodes = 0 allocated_nodes = 0 total_cpus = 0 allocated_cpus = 0 total_gpus = 0 allocated_gpus = 0 nodes = node_info.fetch('nodes', {}) nodes.each do |_node_name, node| total_nodes += 1 resources_avail = node.fetch('resources_available', {}) total_cpus += get_node_resource(resources_avail, 'ncpus') total_gpus += get_node_resource(resources_avail, 'ngpus') # Resources assigned (currently allocated to jobs) resources_assigned = node.fetch('resources_assigned', {}) ncpus_assigned = get_node_resource(resources_assigned, 'ncpus') ngpus_assigned = get_node_resource(resources_assigned, 'ngpus') allocated_cpus += ncpus_assigned allocated_gpus += ngpus_assigned # A node is allocated if at least one CPU has been assigned to a job allocated_nodes += 1 if ncpus_assigned > 0 end ClusterInfo.new(active_nodes: allocated_nodes, total_nodes: total_nodes, active_processors: allocated_cpus, total_processors: total_cpus, active_gpus: allocated_gpus, total_gpus: total_gpus ) end |
#get_jobs(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 a list of hashes detailing each of the jobs on the batch server
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 153 def get_jobs(id: "") args = ["-f", "-t"] # display all information args.concat [id.to_s] unless id.to_s.empty? lines = call("qstat", *args).gsub("\n\t", "").split("\n").map(&:strip) jobs = [] lines.each do |line| if /^Job Id: (?<job_id>.+)$/ =~ line jobs << { job_id: job_id } elsif /^(?<key>[^\s]+) = (?<value>.+)$/ =~ line hsh = jobs.last k1, k2 = key.split(".").map(&:to_sym) k2 ? ( hsh[k1] ||= {} and hsh[k1][k2] = value ) : ( hsh[k1] = value ) end end jobs 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
187 188 189 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 187 def hold_job(id) call("qhold", 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
197 198 199 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 197 def release_job(id) call("qrls", id.to_s) end |
#select_jobs(args: []) ⇒ Array<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.
Select batch jobs from the batch server
177 178 179 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 177 def select_jobs(args: []) call("qselect", *args).split("\n").map(&:strip) end |
#submit_string(str, args: [], chdir: nil) ⇒ 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
217 218 219 |
# File 'lib/ood_core/job/adapters/pbspro.rb', line 217 def submit_string(str, args: [], chdir: nil) call("qsub", *args, stdin: str.to_s, chdir: chdir).strip end |