diff --git a/apps/dashboard/app/controllers/launchers_controller.rb b/apps/dashboard/app/controllers/launchers_controller.rb index 51d9f3575..a4465a649 100644 --- a/apps/dashboard/app/controllers/launchers_controller.rb +++ b/apps/dashboard/app/controllers/launchers_controller.rb @@ -4,9 +4,9 @@ class LaunchersController < ApplicationController before_action :find_project - before_action :find_script, only: [:show, :edit, :destroy, :submit, :save] + before_action :find_launcher, only: [:show, :edit, :destroy, :submit, :save] - SAVE_SCRIPT_KEYS = [ + SAVE_LAUNCHER_KEYS = [ :cluster, :auto_accounts, :auto_accounts_exclude, :auto_accounts_fixed, :auto_cores, :auto_cores_fixed, :auto_cores_min, :auto_cores_max, :auto_scripts, :auto_scripts_exclude, :auto_scripts_fixed, @@ -19,21 +19,21 @@ class LaunchersController < ApplicationController ].freeze def new - @script = Launcher.new(project_dir: @project.directory) + @launcher = Launcher.new(project_dir: @project.directory) end # POST /dashboard/projects/:project_id/launchers def create - opts = { project_dir: @project.directory }.merge(create_script_params[:launcher]) - @script = Launcher.new(opts) - default_script_created = @script.create_default_script + opts = { project_dir: @project.directory }.merge(create_launcher_params[:launcher]) + @launcher = Launcher.new(opts) + default_script_created = @launcher.create_default_script - if @script.save + if @launcher.save notice_messages = [I18n.t('dashboard.jobs_scripts_created')] notice_messages << I18n.t('dashboard.jobs_scripts_default_created') if default_script_created redirect_to project_path(params[:project_id]), notice: notice_messages.join(' ') else - redirect_to project_path(params[:project_id]), alert: @script.errors[:save].last + redirect_to project_path(params[:project_id]), alert: @launcher.errors[:save].last end end @@ -44,69 +44,69 @@ def edit # DELETE /projects/:project_id/launchers/:id def destroy - if @script.destroy + if @launcher.destroy redirect_to project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_deleted') else - redirect_to project_path(params[:project_id]), alert: @script.errors[:destroy].last + redirect_to project_path(params[:project_id]), alert: @launcher.errors[:destroy].last end end # POST /projects/:project_id/launchers/:id/save # save the launcher after editing def save - @script.update(save_script_params[:launcher]) + @launcher.update(save_launcher_params[:launcher]) - if @script.save + if @launcher.save redirect_to project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_updated') else - redirect_to project_path(params[:project_id]), alert: @script.errors[:save].last + redirect_to project_path(params[:project_id]), alert: @launcher.errors[:save].last end end # POST /projects/:project_id/launchers/:id/submit # submit the job def submit - opts = submit_script_params[:launcher].to_h.symbolize_keys + opts = submit_launcher_params[:launcher].to_h.symbolize_keys - if (job_id = @script.submit(opts)) + if (job_id = @launcher.submit(opts)) redirect_to(project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_submitted', job_id: job_id)) else - redirect_to(project_path(params[:project_id]), alert: @script.errors[:submit].last) + redirect_to(project_path(params[:project_id]), alert: @launcher.errors[:submit].last) end end private - def find_script - @script = Launcher.find(show_script_params[:id], @project.directory) - redirect_to(project_path(@project.id), alert: "Cannot find script #{show_script_params[:id]}") if @script.nil? + def find_launcher + @launcher = Launcher.find(show_launcher_params[:id], @project.directory) + redirect_to(project_path(@project.id), alert: "Cannot find launcher #{show_launcher_params[:id]}") if @launcher.nil? end - def create_script_params + def create_launcher_params params.permit({ launcher: [:title] }, :project_id) end - def show_script_params + def show_launcher_params params.permit(:id, :project_id) end - def submit_script_params - keys = @script.smart_attributes.map { |sm| sm.id.to_s } + def submit_launcher_params + keys = @launcher.smart_attributes.map { |sm| sm.id.to_s } params.permit({ launcher: keys }, :project_id, :id) end - def save_script_params + def save_launcher_params auto_env_params = params[:launcher].keys.select do |k| k.match?('auto_environment_variable') end - - allowlist = SAVE_SCRIPT_KEYS + auto_env_params + + allowlist = SAVE_LAUNCHER_KEYS + auto_env_params params.permit({ launcher: allowlist }, :project_id, :id) end def find_project - @project = Project.find(show_script_params[:project_id]) - redirect_to(projects_path, alert: "Cannot find project: #{show_script_params[:project_id]}") if @project.nil? + @project = Project.find(show_launcher_params[:project_id]) + redirect_to(projects_path, alert: "Cannot find project: #{show_launcher_params[:project_id]}") if @project.nil? end end diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index cb77117e7..d69c9838d 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -13,13 +13,13 @@ def show format.json { render json: { message: message }, status: :not_found } end else - @scripts = Launcher.all(@project.directory) + @launchers = Launcher.all(@project.directory) @valid_project = Launcher.clusters? @valid_scripts = Launcher.scripts?(@project.directory) alert_messages = [] alert_messages << I18n.t('dashboard.jobs_project_invalid_configuration_clusters') unless @valid_project - alert_messages << I18n.t('dashboard.jobs_project_invalid_configuration_scripts') if @scripts.any? && !@valid_scripts + alert_messages << I18n.t('dashboard.jobs_project_invalid_configuration_scripts') if @launchers.any? && !@valid_scripts flash.now[:alert] = alert_messages.join(' ') if alert_messages.any? respond_to do |format| format.html diff --git a/apps/dashboard/app/models/launcher.rb b/apps/dashboard/app/models/launcher.rb index c43319923..e06f3d778 100644 --- a/apps/dashboard/app/models/launcher.rb +++ b/apps/dashboard/app/models/launcher.rb @@ -14,8 +14,8 @@ def launchers_dir(project_dir) end def find(id, project_dir) - script_path = Launcher.script_path(project_dir, id) - file = script_form_file(script_path) + path = Launcher.path(project_dir, id) + file = launcher_form_file(path) Launcher.from_yaml(file, project_dir) end @@ -37,7 +37,7 @@ def from_yaml(file, project_dir) new(opts) rescue StandardError, Errno::ENOENT => e - Rails.logger.warn("Did not find script due to error #{e}") + Rails.logger.warn("Did not find launcher due to error #{e}") nil end @@ -149,26 +149,26 @@ def save return false unless valid?(:save) @created_at = Time.now.to_i if @created_at.nil? - script_path = Launcher.script_path(project_dir, id) + path = Launcher.path(project_dir, id) - script_path.mkpath unless script_path.exist? - File.write(Launcher.script_form_file(script_path), to_yaml) + path.mkpath unless path.exist? + File.write(Launcher.launcher_form_file(path), to_yaml) true rescue StandardError => e errors.add(:save, e.message) - Rails.logger.warn("Cannot save script due to error: #{e.class}:#{e.message}") + Rails.logger.warn("Cannot save launcher due to error: #{e.class}:#{e.message}") false end def destroy return true unless id - script_path = Launcher.script_path(project_dir, id) - FileUtils.remove_dir(Launcher.script_path(project_dir, id)) if script_path.exist? + path = Launcher.path(project_dir, id) + FileUtils.remove_dir(Launcher.path(project_dir, id)) if path.exist? true rescue StandardError => e errors.add(:destroy, e.message) - Rails.logger.warn("Cannot delete script #{id} due to error: #{e.class}:#{e.message}") + Rails.logger.warn("Cannot delete launcher #{id} due to error: #{e.class}:#{e.message}") false end @@ -221,20 +221,20 @@ def create_default_script private - def self.script_path(root_dir, script_id) - unless script_id.to_s.match?(ID_REX) - raise(StandardError, "#{script_id} is invalid. Does not match #{ID_REX.inspect}") + def self.path(root_dir, launcher_id) + unless launcher_id.to_s.match?(ID_REX) + raise(StandardError, "#{launcher_id} is invalid. Does not match #{ID_REX.inspect}") end - Pathname.new(File.join(Launcher.launchers_dir(root_dir), script_id.to_s)) + Pathname.new(File.join(Launcher.launchers_dir(root_dir), launcher_id.to_s)) end def default_script_path Pathname(File.join(project_dir, 'hello_world.sh')) end - def self.script_form_file(script_path) - File.join(script_path, "form.yml") + def self.launcher_form_file(path) + File.join(path, "form.yml") end # parameters you got from the controller that affect the attributes, not form. @@ -284,7 +284,7 @@ def write_job_options_to_cache(opts) end def cache_file_path - Pathname.new(File.join(Launcher.script_path(project_dir, id), "cache.json")) + Pathname.new(File.join(Launcher.path(project_dir, id), "cache.json")) end def cache_file_exists? diff --git a/apps/dashboard/app/models/project.rb b/apps/dashboard/app/models/project.rb index be2522091..9a7c39429 100644 --- a/apps/dashboard/app/models/project.rb +++ b/apps/dashboard/app/models/project.rb @@ -271,11 +271,11 @@ def sync_template # This creates them _and_ serializes them to yml in the new directory. def save_new_launchers dir = Launcher.launchers_dir(template) - Dir.glob("#{dir}/*/form.yml").map do |script_yml| - Launcher.from_yaml(script_yml, project_dataroot) - end.map do |script| - saved_successfully = script.save - errors.add(:save, script.errors.full_messages) unless saved_successfully + Dir.glob("#{dir}/*/form.yml").map do |launcher_yml| + Launcher.from_yaml(launcher_yml, project_dataroot) + end.map do |launcher| + saved_successfully = launcher.save + errors.add(:save, launcher.errors.full_messages) unless saved_successfully saved_successfully end.all? do |saved_successfully| diff --git a/apps/dashboard/app/views/launchers/edit.html.erb b/apps/dashboard/app/views/launchers/edit.html.erb index 25d79fb6f..d46bf5721 100644 --- a/apps/dashboard/app/views/launchers/edit.html.erb +++ b/apps/dashboard/app/views/launchers/edit.html.erb @@ -1,11 +1,11 @@ -