diff --git a/apps/dashboard/app/controllers/launchers_controller.rb b/apps/dashboard/app/controllers/launchers_controller.rb index 519b7c7829..62c21ed2a3 100644 --- a/apps/dashboard/app/controllers/launchers_controller.rb +++ b/apps/dashboard/app/controllers/launchers_controller.rb @@ -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, diff --git a/apps/dashboard/app/helpers/launchers_helper.rb b/apps/dashboard/app/helpers/launchers_helper.rb index 0318099258..4ee86e1e6e 100644 --- a/apps/dashboard/app/helpers/launchers_helper.rb +++ b/apps/dashboard/app/helpers/launchers_helper.rb @@ -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 diff --git a/apps/dashboard/app/javascript/launcher_edit.js b/apps/dashboard/app/javascript/launcher_edit.js index fdd1c065dd..5ad24685e8 100644 --- a/apps/dashboard/app/javascript/launcher_edit.js +++ b/apps/dashboard/app/javascript/launcher_edit.js @@ -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.' } } diff --git a/apps/dashboard/app/lib/smart_attributes.rb b/apps/dashboard/app/lib/smart_attributes.rb index 86cdc5b435..87356b3f7c 100644 --- a/apps/dashboard/app/lib/smart_attributes.rb +++ b/apps/dashboard/app/lib/smart_attributes.rb @@ -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 diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_cores.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_cores.rb new file mode 100644 index 0000000000..b84c997e99 --- /dev/null +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_cores.rb @@ -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 + \ No newline at end of file diff --git a/apps/dashboard/app/views/launchers/edit.html.erb b/apps/dashboard/app/views/launchers/edit.html.erb index 3287b20bff..9f222c8ccf 100644 --- a/apps/dashboard/app/views/launchers/edit.html.erb +++ b/apps/dashboard/app/views/launchers/edit.html.erb @@ -39,4 +39,8 @@ <template id="auto_environment_variable_template"> <%= auto_environment_variable_template %> +</template> + +<template id="auto_cores_template"> + <%= auto_cores_template %> </template> \ No newline at end of file diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index 93eb9028d2..b79cd05393 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -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