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

support setting the job name in the launchers #3411

Merged
merged 4 commits into from
Mar 12, 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
3 changes: 2 additions & 1 deletion apps/dashboard/app/controllers/launchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class LaunchersController < ApplicationController
: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,
:bc_num_hours, :bc_num_hours_fixed, :bc_num_hours_min, :bc_num_hours_max
:bc_num_hours, :bc_num_hours_fixed, :bc_num_hours_min, :bc_num_hours_max,
:auto_job_name
].freeze

def new
Expand Down
7 changes: 7 additions & 0 deletions apps/dashboard/app/helpers/launchers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def create_editable_widget(form, attrib, format: nil)
render(partial: editable_partial('editable_number'), locals: locals)
when 'select'
render(partial: editable_partial('editable_select'), locals: locals)
when 'text_field'
render(partial: editable_partial('editable_text_field'), locals: locals)
else
render(partial: editable_partial('generic'), locals: locals)
end
Expand Down Expand Up @@ -53,6 +55,11 @@ def auto_accounts_template
create_editable_widget(script_form_double, attrib)
end

def auto_job_name_template
attrib = SmartAttributes::AttributeFactory.build_auto_job_name
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 @@ -15,6 +15,10 @@ const newFieldData = {
label: "Account",
help: "The account the job will be submitted with."
},
auto_job_name: {
label: "Job Name",
help: "The name the job will have."
},
bc_num_slots: {
label: "Nodes",
help: "How many nodes 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 @@ -8,6 +8,7 @@ module SmartAttributes
require 'smart_attributes/attributes/auto_accounts'
require 'smart_attributes/attributes/auto_batch_clusters'
require 'smart_attributes/attributes/auto_groups'
require 'smart_attributes/attributes/auto_job_name'
require 'smart_attributes/attributes/auto_modules'
require 'smart_attributes/attributes/auto_primary_group'
require 'smart_attributes/attributes/auto_queues'
Expand Down
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. Must specify a valid directory in opts
#
# @param opts [Hash] attribute's options
# @return [Attributes::AutoJobName] the attribute object
def self.build_auto_job_name(opts = {})
Attributes::AutoJobName.new('auto_job_name', opts)
end
end

module Attributes
class AutoJobName < Attribute
# Value of auto_job_name attribute
# Defaults to ondemand/[dev,sys]/projects
# @return [String] attribute value
def value
env = Rails.env.production? ? 'sys' : 'dev'
opts[:value] || "ondemand/#{env}/projects"
end

def widget
'text_field'
end

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

# Submission hash describing how to submit this attribute
# @param fmt [String, nil] formatting of hash
# @return [Hash] submission hash
def submit(*)
{ script: { job_name: value } }
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 @@ -30,3 +30,7 @@
<template id="auto_accounts_template">
<%= auto_accounts_template %>
</template>

<template id="auto_job_name_template">
<%= auto_job_name_template %>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%-
field_id = "#{form.object_name}_#{attrib.id}"
-%>

<div class="editable-form-field">
<%= create_widget(form, attrib, format: format, hide_fixed: false) %>

<div class="d-none edit-group mb-3">
<%= render(partial: 'launchers/editable_form_fields/edit_fixed_field', locals: { form: form, attrib: attrib, fixed: fixed }) %>
</div>

<%= render(partial: 'launchers/editable_form_fields/edit_field_buttons', locals: { field_id: field_id }) %>
</div>
57 changes: 54 additions & 3 deletions apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setup_script(project_id)
script_element[:id]
end

def add_account(project_id, script_id)
def add_account(project_id, script_id, save: true)
visit project_path(project_id)
edit_launcher_path = edit_project_launcher_path(project_id, script_id)
find("[href='#{edit_launcher_path}']").click
Expand All @@ -59,7 +59,7 @@ def add_account(project_id, script_id)
click_on('Add new option')
select('Account', from: 'add_new_field_select')
click_on(I18n.t('dashboard.add'))
click_on(I18n.t('dashboard.save'))
click_on(I18n.t('dashboard.save')) if save
end

def add_bc_num_hours(project_id, script_id)
Expand Down Expand Up @@ -344,6 +344,54 @@ def add_bc_num_hours(project_id, script_id)
end
end

# super similar to test above, only it adds auto_job_name
test 'submitting a script with job name' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
script_dir = File.join(project_dir, '.ondemand', 'scripts', script_id)
add_account(project_id, script_id, save: false)

click_on('Add new option')
select('Job Name', from: 'add_new_field_select')
click_on(I18n.t('dashboard.add'))
fill_in('launcher_auto_job_name', with: 'my cool job name')
click_on(I18n.t('dashboard.save'))

launcher_path = project_launcher_path(project_id, script_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)

# assert defaults
assert_equal 'oakley', find('#launcher_auto_batch_clusters').value
assert_equal 'pzs0715', find('#launcher_auto_accounts').value
assert_equal "#{project_dir}/my_cool_script.sh", find('#launcher_auto_scripts').value
assert_nil YAML.safe_load(File.read("#{script_dir}/job_history.log"))

select('owens', from: 'launcher_auto_batch_clusters')
select('pas2051', from: 'launcher_auto_accounts')
select('my_cooler_script.bash', from: 'launcher_auto_scripts')

Open3
.stubs(:capture3)
.with({}, 'sbatch', '-J', 'my cool job name', '-A', 'pas2051', '--export',
'NONE', '--parsable', '-M', 'owens',
stdin_data: "hostname\n")
.returns(['job-id-123', '', exit_success])

OodCore::Job::Adapters::Slurm.any_instance
.stubs(:info).returns(OodCore::Job::Info.new(id: 'job-id-123', status: :running))

click_on 'Launch'
assert_selector('.alert-success', text: 'job-id-123')
assert_equal [{ 'id' => 'job-id-123',
'submit_time' => @expected_now,
'cluster' => 'owens' }],
YAML.safe_load(File.read("#{script_dir}/job_history.log"))
end
end

test 'submitting a script with auto attributes that fails' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
Expand Down Expand Up @@ -392,7 +440,10 @@ def add_bc_num_hours(project_id, script_id)
new_field_id = 'add_new_field_select'

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