Skip to content

Commit

Permalink
Auto cores (#3727)
Browse files Browse the repository at this point in the history
Support for the auto_cores smart attribute to be used in the project manager.
  • Loading branch information
ashton22305 authored Aug 26, 2024
1 parent b8b9674 commit 16eefb0
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/dashboard/app/controllers/launchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LaunchersController < ApplicationController

SAVE_SCRIPT_KEYS = [
:cluster, :auto_accounts, :auto_accounts_exclude, :auto_accounts_fixed,
:auto_scripts, :auto_scripts_exclude, :auto_scripts_fixed,
:auto_cores, :auto_scripts, :auto_scripts_exclude, :auto_scripts_fixed,
:auto_queues, :auto_queues_exclude, :auto_queues_fixed,
:auto_batch_clusters, :auto_batch_clusters_exclude, :auto_batch_clusters_fixed,
:bc_num_slots, :bc_num_slots_fixed, :bc_num_slots_min, :bc_num_slots_max,
Expand Down
5 changes: 5 additions & 0 deletions apps/dashboard/app/helpers/launchers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def auto_environment_variable_template
create_editable_widget(script_form_double, attrib)
end

def auto_cores_template
attrib = SmartAttributes::AttributeFactory.build_auto_cores
create_editable_widget(script_form_double, attrib)
end

# We need a form builder to build the template divs. These are
# templates so that they are not a part of the _actual_ form (yet).
# Otherwise you'd have required fields that you cannot actually edit
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/app/javascript/launcher_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const newFieldData = {
auto_environment_variable: {
label: 'Environment Variable',
help: 'Add an environment variable.'
},
auto_cores: {
label: 'Cores',
help: 'How many cores the job will run on.'
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/app/lib/smart_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ module SmartAttributes
require 'smart_attributes/attributes/bc_vnc_idle'
require 'smart_attributes/attributes/bc_vnc_resolution'
require 'smart_attributes/attributes/auto_environment_variable'
require 'smart_attributes/attributes/auto_cores'
end
41 changes: 41 additions & 0 deletions apps/dashboard/app/lib/smart_attributes/attributes/auto_cores.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module SmartAttributes
class AttributeFactory
# Build this attribute object. No options are used as this Attribute
# is meant to be dynamically generated
# @param opts [Hash] attribute's options
# @return [Attributes::AutoGroups] the attribute object
def self.build_auto_cores(opts = {})
Attributes::AutoCores.new('auto_cores', opts)
end
end

module Attributes
class AutoCores < Attribute
def opts
@opts.reverse_merge(min: 1, step: 1)
end

def widget
'number_field'
end

def value
(opts[:value] || '1').to_s
end

def label(*)
(opts[:label] || 'Cores').to_s
end

# Submission hash describing how to submit this attribute
# @return [Hash] submission hash
def submit(*)
cores = value.blank? ? 1 : value.to_i
{ script: { cores: cores } }
end
end
end
end

4 changes: 4 additions & 0 deletions apps/dashboard/app/views/launchers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@

<template id="auto_environment_variable_template">
<%= auto_environment_variable_template %>
</template>

<template id="auto_cores_template">
<%= auto_cores_template %>
</template>
2 changes: 1 addition & 1 deletion apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def add_auto_environment_variable(project_id, script_id, save: true)

actual_new_options = page.all("##{new_field_id} option").map(&:value).to_set
expected_new_options = [
'bc_num_hours', 'auto_queues', 'bc_num_slots',
'bc_num_hours', 'auto_queues', 'bc_num_slots', 'auto_cores',
'auto_accounts', 'auto_job_name', 'auto_environment_variable'
].to_set
assert_equal expected_new_options, actual_new_options
Expand Down

0 comments on commit 16eefb0

Please sign in to comment.