Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a #nodes api to the job adapters #830

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ood_core/job/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def accounts
def queues
[]
end

# Return the list of nodes for this scheduler.
#
# Subclasses that do not implement this will return empty arrays.
# @return [Array<NodeInfo>]
def nodes
[]
end
end
end
end
28 changes: 28 additions & 0 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,30 @@ def queues
end
end

def all_sinfo_node_fields
{
procs: '%c',
name: '%n',
features: '%f'
}
end

def nodes
args = all_sinfo_node_fields.values.join(UNIT_SEPARATOR)
output = call('sinfo', '-ho', "#{RECORD_SEPARATOR}#{args}")

output.each_line(RECORD_SEPARATOR).map do |line|
values = line.chomp(RECORD_SEPARATOR).strip.split(UNIT_SEPARATOR)

next if values.empty?

data = Hash[all_sinfo_node_fields.keys.zip(values)]
data[:name] = data[:name].to_s.split(',').first
data[:features] = data[:features].to_s.split(',')
NodeInfo.new(**data)
end.compact
end

private
def str_to_acct_info(line)
hsh = line.split(' ').map do |token|
Expand Down Expand Up @@ -669,6 +693,10 @@ def queues
@slurm.queues
end

def nodes
@slurm.nodes
end

private
# Convert duration to seconds
def duration_in_seconds(time)
Expand Down
13 changes: 11 additions & 2 deletions lib/ood_core/job/node_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ class NodeInfo
# @return [Integer, nil] number of procs
attr_reader :procs

# The features associated with this node.
# @return [Array<String>, []]
attr_reader :features

# @param name [#to_s] node name
# @param procs [#to_i, nil] number of procs
def initialize(name:, procs: nil, **_)
# @param features [#to_a, []] list of features
def initialize(name:, procs: nil, features: [], **_)
@name = name.to_s
@procs = procs && procs.to_i
@features = features.to_a
end

# Convert object to hash
# @return [Hash] object as hash
def to_h
{ name: name, procs: procs }
instance_variables.map do |var|
name = var.to_s.gsub('@', '').to_sym
[name, send(name)]
end.to_h
end

# The comparison operator
Expand Down
Loading
Loading