Skip to content

Commit

Permalink
Clusters set auto_cores max (#3778)
Browse files Browse the repository at this point in the history
Set data-max-auto-cores for auto-clusters.
  • Loading branch information
ashton22305 authored Sep 19, 2024
1 parent 822c0af commit c32048e
Show file tree
Hide file tree
Showing 9 changed files with 1,559 additions and 28 deletions.
2 changes: 1 addition & 1 deletion apps/dashboard/app/javascript/script_show.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeChangeHandlers } from './dynamic_forms';

jQuery(function() {
makeChangeHandlers('script');
makeChangeHandlers('launcher');
});
50 changes: 50 additions & 0 deletions apps/dashboard/app/lib/cluster_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

module ClusterCache
def cluster_options
Rails.cache.fetch('script_cluster_options', expires_in: 4.hours) do
max_cores_map = cluster_max_cores
batch_clusters.map do |cluster|
options = if max_cores_map[cluster.id]
{ 'data-max-auto-cores': max_cores_map[cluster.id] }
else
{}
end
[cluster.id.to_s, cluster.id.to_s, options]
end.sort_by { |option| option[0] }
end
end

def cluster_nodes
Rails.cache.fetch('script_cluster_nodes', expires_in: 4.hours) do
{}.tap do |hash|
batch_clusters.map do |cluster|
hash[cluster.id] = cluster.job_adapter.nodes if cluster.slurm?
end
end
end
end

def cluster_max_cores
Rails.cache.fetch('script_cluster_max_values', exipres_in: 4.hours) do
{}.tap do |hash|
cluster_nodes.each do |cluster_id, nodes|
max_node = nodes.max { |a, b| a.procs <=> b.procs }
hash[cluster_id] = max_node.procs if max_node
end
end
end
end

def batch_clusters
Rails.cache.fetch('script_batch_clusters', expires_in: 4.hours) do
Configuration.job_clusters.reject do |c|
reject_cluster?(c)
end
end
end

def reject_cluster?(cluster)
cluster.kubernetes? || cluster.linux_host? || cluster.systemd?
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@

module SmartAttributes
class AttributeFactory

extend ClusterCache
# Build this attribute object. Must specify a valid directory in opts
#
# @param opts [Hash] attribute's options
# @return [Attributes::AutoBatchClusters] the attribute object
def self.build_auto_batch_clusters(opts = {})
options = batch_clusters
options = cluster_options

static_opts = {
options: options
}.merge(opts.without(:options).to_h)

Attributes::AutoBatchClusters.new('auto_batch_clusters', static_opts)
end

def self.batch_clusters
Rails.cache.fetch('script_batch_clusters', expires_in: 4.hours) do
Configuration.job_clusters.reject do |c|
reject_cluster?(c)
end.map(&:id).map(&:to_s).sort
end
end

def self.reject_cluster?(cluster)
cluster.kubernetes? || cluster.linux_host? || cluster.systemd?
end
end

module Attributes
Expand All @@ -37,7 +25,7 @@ class AutoBatchClusters < Attribute
# Defaults to first cluster in the options
# @return [String] attribute value
def value
(opts[:value] || opts[:options].first).to_s
(opts[:value] || opts[:options].first.first).to_s
end

def widget
Expand Down
644 changes: 644 additions & 0 deletions apps/dashboard/test/fixtures/cmd_output/sinfo_nodes_oakley.txt

Large diffs are not rendered by default.

816 changes: 816 additions & 0 deletions apps/dashboard/test/fixtures/cmd_output/sinfo_nodes_owens.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require 'test_helper'

class SmartAttributes::AutoBatchClustersTest < ActiveSupport::TestCase
def setup
stub_sinfo
end

def fixture_dir
'test/fixtures/config/clusters.d'
Expand Down Expand Up @@ -45,10 +48,10 @@ def fixture_dir

assert_instance_of SmartAttributes::Attributes::AutoBatchClusters, attribute
assert_equal(4, attribute.select_choices.length)
assert_equal('oakley', attribute.select_choices[0])
assert_equal('owens', attribute.select_choices[1])
assert_equal('quick', attribute.select_choices[2])
assert_equal('ruby', attribute.select_choices[3])
assert_equal('oakley', attribute.select_choices[0].first)
assert_equal('owens', attribute.select_choices[1].first)
assert_equal('quick', attribute.select_choices[2].first)
assert_equal('ruby', attribute.select_choices[3].first)
end

test 'widget is select' do
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/test/models/launcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require 'test_helper'

class LauncherTest < ActiveSupport::TestCase
def setup
stub_sinfo
end

test 'supported field postfix' do
target = Launcher.new({ project_dir: '/path/project', id: 1234, title: 'Test Script' })
refute target.send('attribute_parameter?', nil)
Expand Down
33 changes: 25 additions & 8 deletions apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def setup
stub_sacctmgr
stub_scontrol
stub_du
stub_sinfo

# Stub Time.now for created_at field
@expected_now = 1_679_943_564
Expand Down Expand Up @@ -235,8 +236,12 @@ def add_auto_environment_variable(project_id, script_id, save: true)
attributes:
auto_batch_clusters:
options:
- oakley
- owens
- - oakley
- oakley
- data-max-auto-cores: 80
- - owens
- owens
- data-max-auto-cores: 48
label: Cluster
help: ''
required: false
Expand Down Expand Up @@ -280,8 +285,12 @@ def add_auto_environment_variable(project_id, script_id, save: true)
attributes:
auto_batch_clusters:
options:
- oakley
- owens
- - oakley
- oakley
- data-max-auto-cores: 80
- - owens
- owens
- data-max-auto-cores: 48
label: Cluster
help: ''
required: false
Expand Down Expand Up @@ -580,8 +589,12 @@ def add_auto_environment_variable(project_id, script_id, save: true)
required: false
auto_batch_clusters:
options:
- oakley
- owens
- - oakley
- oakley
- data-max-auto-cores: 80
- - owens
- owens
- data-max-auto-cores: 48
value: oakley
label: Cluster
help: ''
Expand Down Expand Up @@ -682,8 +695,12 @@ def add_auto_environment_variable(project_id, script_id, save: true)
required: false
auto_batch_clusters:
options:
- oakley
- owens
- - oakley
- oakley
- data-max-auto-cores: 80
- - owens
- owens
- data-max-auto-cores: 48
value: oakley
label: Cluster
help: ''
Expand Down
9 changes: 9 additions & 0 deletions apps/dashboard/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ def stub_du(directory = nil)
.returns(['2097152 /directory/path', '', exit_success])
end

def stub_sinfo
['oakley', 'owens'].each do |cluster|
Open3
.stubs(:capture3)
.with({}, 'sinfo', '-ho', "\u001E%c\u001F%n\u001F%f", '-M', cluster, stdin_data: '')
.returns([File.read("test/fixtures/cmd_output/sinfo_nodes_#{cluster}.txt"), '', exit_success])
end
end

def output_fixture(file)
File.read("#{Rails.root}/test/fixtures/file_output/#{file}")
end
Expand Down

0 comments on commit c32048e

Please sign in to comment.