From 12ac653e93b6562ac2ce3c963dc89212273e157a Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 4 Oct 2024 12:27:47 -0400 Subject: [PATCH 01/13] add buttons to the top and bottom of job info --- apps/dashboard/app/helpers/projects_helper.rb | 12 +++++++++++- .../app/views/projects/_job_details_content.html.erb | 2 ++ .../views/projects/buttons/_bottom_buttons.html.erb | 5 +++++ .../views/projects/buttons/_queued_buttons.html.erb | 8 ++++++++ .../views/projects/buttons/_running_buttons.html.erb | 8 ++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb create mode 100644 apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb create mode 100644 apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb index c725ac7b8b..d4e22c2a46 100644 --- a/apps/dashboard/app/helpers/projects_helper.rb +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -14,4 +14,14 @@ def render_readme(readme_location) simple_format(file_content) end end -end \ No newline at end of file + + def top_buttons(status) + return if status == 'completed' + + render(partial: "projects/buttons/#{button_category(status)}_buttons") + end + + def button_category(status) + status + end +end diff --git a/apps/dashboard/app/views/projects/_job_details_content.html.erb b/apps/dashboard/app/views/projects/_job_details_content.html.erb index 3cb30b6821..1b925fb574 100644 --- a/apps/dashboard/app/views/projects/_job_details_content.html.erb +++ b/apps/dashboard/app/views/projects/_job_details_content.html.erb @@ -11,6 +11,7 @@
+ <%= top_buttons(job.status.to_s) %> <% job.to_human_display.each do |name, value| %> @@ -19,6 +20,7 @@ <% end %>
+ <%= render(partial: 'projects/buttons/bottom_buttons') %>
diff --git a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb new file mode 100644 index 0000000000..03b691bc34 --- /dev/null +++ b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb @@ -0,0 +1,5 @@ +
+ +
\ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb new file mode 100644 index 0000000000..43497246ac --- /dev/null +++ b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb @@ -0,0 +1,8 @@ +
+ + +
\ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb new file mode 100644 index 0000000000..43497246ac --- /dev/null +++ b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb @@ -0,0 +1,8 @@ +
+ + +
\ No newline at end of file From ae7d9797ca588b6d9f5d594dc31d46460b9a5d67 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 18 Oct 2024 10:06:03 -0400 Subject: [PATCH 02/13] working delete button --- .../app/controllers/projects_controller.rb | 8 ++++++++ apps/dashboard/app/models/concerns/job_logger.rb | 13 +++++++++++++ apps/dashboard/app/models/project.rb | 7 ++++++- .../views/projects/_job_details_content.html.erb | 2 +- .../views/projects/buttons/_bottom_buttons.html.erb | 8 +++++--- apps/dashboard/config/routes.rb | 1 + 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index 13ffd1f2a7..cd808a9fe0 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -113,6 +113,14 @@ def job_details render(partial: 'job_details', locals: { job: hpc_job }) end + # DELETE /projects/:project_id/jobs/:cluster/:jobid + def delete_job + project = Project.find(job_details_params[:project_id]) + cluster_str = job_details_params[:cluster].to_s + + project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) + end + private def templates diff --git a/apps/dashboard/app/models/concerns/job_logger.rb b/apps/dashboard/app/models/concerns/job_logger.rb index e62d0d0c10..ba235dfae0 100644 --- a/apps/dashboard/app/models/concerns/job_logger.rb +++ b/apps/dashboard/app/models/concerns/job_logger.rb @@ -16,6 +16,19 @@ def upsert_job!(directory, job) JobLoggerHelper.write_log(directory, new_jobs) end + def delete_job!(directory, job) + existing_jobs = jobs(directory) + stored_job = existing_jobs.detect { |j| j.id == job.id && j.cluster == job.cluster } + + return if stored_job.nil? + + new_jobs = existing_jobs.map(&:to_h) + idx = existing_jobs.index(stored_job) + new_jobs.delete_at(idx) + + JobLoggerHelper.write_log(directory, new_jobs) + end + # def write_job_log!(directory, jobs) # JobLoggerHelper.write_log!(directory, jobs) # endd diff --git a/apps/dashboard/app/models/project.rb b/apps/dashboard/app/models/project.rb index 254b43bd7c..937372f56b 100644 --- a/apps/dashboard/app/models/project.rb +++ b/apps/dashboard/app/models/project.rb @@ -219,6 +219,11 @@ def job(job_id, cluster) job end + def remove_logged_job(job_id, cluster) + old_job = jobs.detect { |j| j.id == job_id && j.cluster == cluster } + Project.delete_job!(directory, old_job) + end + def adapter(cluster_id) cluster = OodAppkit.clusters[cluster_id] || raise(StandardError, "Job specifies nonexistent '#{cluster_id}' cluster id.") cluster.job_adapter @@ -230,7 +235,7 @@ def readme_path end private - + def update_attrs(attributes) [:name, :description, :icon].each do |attribute| instance_variable_set("@#{attribute}".to_sym, attributes.fetch(attribute, '')) diff --git a/apps/dashboard/app/views/projects/_job_details_content.html.erb b/apps/dashboard/app/views/projects/_job_details_content.html.erb index 1b925fb574..02648de80d 100644 --- a/apps/dashboard/app/views/projects/_job_details_content.html.erb +++ b/apps/dashboard/app/views/projects/_job_details_content.html.erb @@ -20,7 +20,7 @@ <% end %> - <%= render(partial: 'projects/buttons/bottom_buttons') %> + <%= render(partial: 'projects/buttons/bottom_buttons', locals: { project_id: @project.id, id: job.id, cluster: job.cluster }) %> diff --git a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb index 03b691bc34..2e643812fc 100644 --- a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb @@ -1,5 +1,7 @@
- + <%= button_to( + 'Delete', + project_delete_job_path(project_id: project_id, cluster: cluster.to_sym, jobid: id), + method: :delete + ) %>
\ No newline at end of file diff --git a/apps/dashboard/config/routes.rb b/apps/dashboard/config/routes.rb index 4c570cd653..0f41091fb4 100644 --- a/apps/dashboard/config/routes.rb +++ b/apps/dashboard/config/routes.rb @@ -7,6 +7,7 @@ resources :projects do root 'projects#index' get '/jobs/:cluster/:jobid' => 'projects#job_details', :defaults => { :format => 'turbo_stream' }, :as => 'job_details' + delete '/jobs/:cluster/:jobid' => 'projects#delete_job', :as => 'delete_job' resources :launchers do post 'submit', on: :member From 8dcbb56569e0ab47b32335e7b4ea5db2f84ae220 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 18 Oct 2024 11:01:53 -0400 Subject: [PATCH 03/13] redirect after delete and only enable delete button for completed jobs --- apps/dashboard/app/controllers/projects_controller.rb | 1 + apps/dashboard/app/helpers/projects_helper.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index cd808a9fe0..2759362f51 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -119,6 +119,7 @@ def delete_job cluster_str = job_details_params[:cluster].to_s project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) + redirect_to project_path(job_details_params[:project_id]) end private diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb index d4e22c2a46..cb0ad338bd 100644 --- a/apps/dashboard/app/helpers/projects_helper.rb +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -15,6 +15,13 @@ def render_readme(readme_location) end end + def bottom_buttons(status) + return unless status == 'completed' + + locals = { project_id: @project.id, id: job.id, cluster: job.cluster } + render(partial: 'projects/buttons/bottom_buttons', locals: locals) + end + def top_buttons(status) return if status == 'completed' From dc09e18f3855bfac6e33ce07b2e39b5694142bb8 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 18 Oct 2024 11:21:15 -0400 Subject: [PATCH 04/13] better delete button formatting --- apps/dashboard/app/helpers/projects_helper.rb | 2 +- .../app/views/projects/_job_details_content.html.erb | 2 +- .../app/views/projects/buttons/_bottom_buttons.html.erb | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb index cb0ad338bd..609108b1ea 100644 --- a/apps/dashboard/app/helpers/projects_helper.rb +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -15,7 +15,7 @@ def render_readme(readme_location) end end - def bottom_buttons(status) + def bottom_buttons(status, job) return unless status == 'completed' locals = { project_id: @project.id, id: job.id, cluster: job.cluster } diff --git a/apps/dashboard/app/views/projects/_job_details_content.html.erb b/apps/dashboard/app/views/projects/_job_details_content.html.erb index 02648de80d..8461df3699 100644 --- a/apps/dashboard/app/views/projects/_job_details_content.html.erb +++ b/apps/dashboard/app/views/projects/_job_details_content.html.erb @@ -20,7 +20,7 @@ <% end %> - <%= render(partial: 'projects/buttons/bottom_buttons', locals: { project_id: @project.id, id: job.id, cluster: job.cluster }) %> + <%= bottom_buttons(job.status.to_s, job) %> diff --git a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb index 2e643812fc..f2b1a0c194 100644 --- a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb @@ -1,7 +1,8 @@ -
+
<%= button_to( 'Delete', - project_delete_job_path(project_id: project_id, cluster: cluster.to_sym, jobid: id), - method: :delete + project_delete_job_path(project_id: project_id, cluster: cluster, jobid: id), + method: :delete, + class: 'btn btn-danger' ) %>
\ No newline at end of file From 866909aa345f9b834ca56887b7c5104afcceeab7 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 18 Oct 2024 12:16:41 -0400 Subject: [PATCH 05/13] button formatting and create routes to hold and stop jobs --- .../app/controllers/projects_controller.rb | 11 ++++++++++ apps/dashboard/app/helpers/projects_helper.rb | 15 ++++---------- .../projects/_job_details_content.html.erb | 5 +++-- .../projects/buttons/_bottom_buttons.html.erb | 8 -------- .../buttons/_completed_buttons.html.erb | 6 ++++++ .../projects/buttons/_queued_buttons.html.erb | 20 +++++++++++-------- .../buttons/_running_buttons.html.erb | 20 +++++++++++-------- .../app/views/projects/show.html.erb | 2 +- apps/dashboard/config/routes.rb | 2 ++ 9 files changed, 51 insertions(+), 38 deletions(-) delete mode 100644 apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb create mode 100644 apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index 2759362f51..85297944fe 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -110,6 +110,7 @@ def job_details hpc_job = project.job(job_details_params[:jobid].to_s, cluster_str) + @project = project render(partial: 'job_details', locals: { job: hpc_job }) end @@ -122,6 +123,16 @@ def delete_job redirect_to project_path(job_details_params[:project_id]) end + # PATCH /projects/:project_id/jobs/:cluster/:jobid/hold + def hold_job + + end + + # PATCH /projects/:project_id/jobs/:cluster/:jobid/stop + def stop_job + + end + private def templates diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb index 609108b1ea..48d295cef1 100644 --- a/apps/dashboard/app/helpers/projects_helper.rb +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -15,17 +15,10 @@ def render_readme(readme_location) end end - def bottom_buttons(status, job) - return unless status == 'completed' - - locals = { project_id: @project.id, id: job.id, cluster: job.cluster } - render(partial: 'projects/buttons/bottom_buttons', locals: locals) - end - - def top_buttons(status) - return if status == 'completed' - - render(partial: "projects/buttons/#{button_category(status)}_buttons") + def job_details_buttons(status, job) + locals = { project_id: @project&.id, id: job&.id, cluster: job&.cluster } + button_partial = button_category(status) + render(partial: "projects/buttons/#{button_category(status)}_buttons", locals: locals) unless button_partial.nil? end def button_category(status) diff --git a/apps/dashboard/app/views/projects/_job_details_content.html.erb b/apps/dashboard/app/views/projects/_job_details_content.html.erb index 8461df3699..2917618a4a 100644 --- a/apps/dashboard/app/views/projects/_job_details_content.html.erb +++ b/apps/dashboard/app/views/projects/_job_details_content.html.erb @@ -11,7 +11,6 @@
- <%= top_buttons(job.status.to_s) %> <% job.to_human_display.each do |name, value| %> @@ -20,7 +19,9 @@ <% end %>
- <%= bottom_buttons(job.status.to_s, job) %> +
+ <%= job_details_buttons(job.status.to_s, job) %> +
diff --git a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb deleted file mode 100644 index f2b1a0c194..0000000000 --- a/apps/dashboard/app/views/projects/buttons/_bottom_buttons.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -
- <%= button_to( - 'Delete', - project_delete_job_path(project_id: project_id, cluster: cluster, jobid: id), - method: :delete, - class: 'btn btn-danger' - ) %> -
\ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb new file mode 100644 index 0000000000..7d09e06fef --- /dev/null +++ b/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb @@ -0,0 +1,6 @@ +<%= button_to( + 'Delete', + project_delete_job_path(project_id: project_id, cluster: cluster, jobid: id), + method: :delete, + class: 'btn btn-danger' +) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb index 43497246ac..4f5a23cd8d 100644 --- a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb @@ -1,8 +1,12 @@ -
- - -
\ No newline at end of file +<%= button_to( + 'Stop', + project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), + method: :patch, + class: 'btn btn-danger' +) %> +<%= button_to( + 'Hold', + project_hold_job_path(project_id: project_id, cluster: cluster, jobid: id), + method: :patch, + class: 'btn btn-info mx-2' +) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb index 43497246ac..4f5a23cd8d 100644 --- a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb @@ -1,8 +1,12 @@ -
- - -
\ No newline at end of file +<%= button_to( + 'Stop', + project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), + method: :patch, + class: 'btn btn-danger' +) %> +<%= button_to( + 'Hold', + project_hold_job_path(project_id: project_id, cluster: cluster, jobid: id), + method: :patch, + class: 'btn btn-info mx-2' +) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/show.html.erb b/apps/dashboard/app/views/projects/show.html.erb index b394d7703e..2d3db7aff5 100644 --- a/apps/dashboard/app/views/projects/show.html.erb +++ b/apps/dashboard/app/views/projects/show.html.erb @@ -59,7 +59,7 @@

Active Jobs

- <%= render(partial: 'job_details', collection: @project.active_jobs, as: :job) %> + <%= render(partial: 'job_details', collection: @project.active_jobs, as: :job ) %>
diff --git a/apps/dashboard/config/routes.rb b/apps/dashboard/config/routes.rb index 0f41091fb4..9516ea0d56 100644 --- a/apps/dashboard/config/routes.rb +++ b/apps/dashboard/config/routes.rb @@ -8,6 +8,8 @@ root 'projects#index' get '/jobs/:cluster/:jobid' => 'projects#job_details', :defaults => { :format => 'turbo_stream' }, :as => 'job_details' delete '/jobs/:cluster/:jobid' => 'projects#delete_job', :as => 'delete_job' + patch '/jobs/:cluster/:jobid/hold' => 'projects#hold_job', :as => 'hold_job' + patch '/jobs/:cluster/:jobid/stop' => 'projects#stop_job', :as => 'stop_job' resources :launchers do post 'submit', on: :member From 90acf35ead9d616b04b57a853d5d05bc4b015ada Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 24 Oct 2024 10:14:30 -0400 Subject: [PATCH 06/13] remove hold buttons for now and make stop button functional --- apps/dashboard/app/controllers/projects_controller.rb | 10 +++++----- apps/dashboard/app/helpers/application_helper.rb | 2 +- apps/dashboard/app/helpers/projects_helper.rb | 9 ++++++++- .../views/projects/buttons/_queued_buttons.html.erb | 6 ------ .../views/projects/buttons/_running_buttons.html.erb | 6 ------ apps/dashboard/config/routes.rb | 1 - 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index 85297944fe..77b7798952 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -123,14 +123,14 @@ def delete_job redirect_to project_path(job_details_params[:project_id]) end - # PATCH /projects/:project_id/jobs/:cluster/:jobid/hold - def hold_job - - end - # PATCH /projects/:project_id/jobs/:cluster/:jobid/stop def stop_job + cluster_str = job_details_params[:cluster].to_s + cluster = OodAppkit.clusters[cluster_str.to_sym] + + cluster.job_adapter.delete(job_details_params[:jobid].to_s) + redirect_to project_path(job_details_params[:project_id]) end private diff --git a/apps/dashboard/app/helpers/application_helper.rb b/apps/dashboard/app/helpers/application_helper.rb index bb169ef07c..4e99aecb10 100644 --- a/apps/dashboard/app/helpers/application_helper.rb +++ b/apps/dashboard/app/helpers/application_helper.rb @@ -120,7 +120,7 @@ def status_text(status) 'Running' when 'queued' 'Queued' - when 'qued_held' + when 'queued_held' 'Hold' when 'suspended' 'Suspend' diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb index 48d295cef1..56a464f89e 100644 --- a/apps/dashboard/app/helpers/projects_helper.rb +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -22,6 +22,13 @@ def job_details_buttons(status, job) end def button_category(status) - status + case status + when 'queued_held' + 'held' + when 'suspended' + 'held' + else + status + end end end diff --git a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb index 4f5a23cd8d..dbc4e117e5 100644 --- a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb @@ -3,10 +3,4 @@ project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), method: :patch, class: 'btn btn-danger' -) %> -<%= button_to( - 'Hold', - project_hold_job_path(project_id: project_id, cluster: cluster, jobid: id), - method: :patch, - class: 'btn btn-info mx-2' ) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb index 4f5a23cd8d..dbc4e117e5 100644 --- a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb @@ -3,10 +3,4 @@ project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), method: :patch, class: 'btn btn-danger' -) %> -<%= button_to( - 'Hold', - project_hold_job_path(project_id: project_id, cluster: cluster, jobid: id), - method: :patch, - class: 'btn btn-info mx-2' ) %> \ No newline at end of file diff --git a/apps/dashboard/config/routes.rb b/apps/dashboard/config/routes.rb index 9516ea0d56..35a33c305e 100644 --- a/apps/dashboard/config/routes.rb +++ b/apps/dashboard/config/routes.rb @@ -8,7 +8,6 @@ root 'projects#index' get '/jobs/:cluster/:jobid' => 'projects#job_details', :defaults => { :format => 'turbo_stream' }, :as => 'job_details' delete '/jobs/:cluster/:jobid' => 'projects#delete_job', :as => 'delete_job' - patch '/jobs/:cluster/:jobid/hold' => 'projects#hold_job', :as => 'hold_job' patch '/jobs/:cluster/:jobid/stop' => 'projects#stop_job', :as => 'stop_job' resources :launchers do From ef811af14a90a6ab8703cf66c82007f757355ae5 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 25 Oct 2024 08:18:49 -0400 Subject: [PATCH 07/13] handle case where job is already completed but not updated on page --- apps/dashboard/app/controllers/projects_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index 77b7798952..ca12aae88a 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -118,9 +118,14 @@ def job_details def delete_job project = Project.find(job_details_params[:project_id]) cluster_str = job_details_params[:cluster].to_s + hpc_job = project.job(job_details_params[:jobid].to_s, cluster_str) - project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) - redirect_to project_path(job_details_params[:project_id]) + if hpc_job.status.to_s == 'completed' + redirect_to project_path(job_details_params[:project_id]) if hpc_job.status.to_s == 'completed' + else + project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) + redirect_to project_path(job_details_params[:project_id]) + end end # PATCH /projects/:project_id/jobs/:cluster/:jobid/stop From 77f4355e68a54196cbe7fe161013773f855437ad Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 25 Oct 2024 10:21:05 -0400 Subject: [PATCH 08/13] change PATCH to POST --- apps/dashboard/app/controllers/projects_controller.rb | 2 +- .../app/views/projects/buttons/_queued_buttons.html.erb | 2 +- .../app/views/projects/buttons/_running_buttons.html.erb | 2 +- apps/dashboard/config/routes.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index ca12aae88a..a36c3101c0 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -128,7 +128,7 @@ def delete_job end end - # PATCH /projects/:project_id/jobs/:cluster/:jobid/stop + # POST /projects/:project_id/jobs/:cluster/:jobid/stop def stop_job cluster_str = job_details_params[:cluster].to_s cluster = OodAppkit.clusters[cluster_str.to_sym] diff --git a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb index dbc4e117e5..d1db5d31ce 100644 --- a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb @@ -1,6 +1,6 @@ <%= button_to( 'Stop', project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), - method: :patch, + method: :post, class: 'btn btn-danger' ) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb index dbc4e117e5..d1db5d31ce 100644 --- a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb @@ -1,6 +1,6 @@ <%= button_to( 'Stop', project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), - method: :patch, + method: :post, class: 'btn btn-danger' ) %> \ No newline at end of file diff --git a/apps/dashboard/config/routes.rb b/apps/dashboard/config/routes.rb index 35a33c305e..54c639252c 100644 --- a/apps/dashboard/config/routes.rb +++ b/apps/dashboard/config/routes.rb @@ -8,7 +8,7 @@ root 'projects#index' get '/jobs/:cluster/:jobid' => 'projects#job_details', :defaults => { :format => 'turbo_stream' }, :as => 'job_details' delete '/jobs/:cluster/:jobid' => 'projects#delete_job', :as => 'delete_job' - patch '/jobs/:cluster/:jobid/stop' => 'projects#stop_job', :as => 'stop_job' + post '/jobs/:cluster/:jobid/stop' => 'projects#stop_job', :as => 'stop_job' resources :launchers do post 'submit', on: :member From 6a3cb3480320717b0ea775590e4a04740a64e014 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Mon, 28 Oct 2024 13:50:46 -0400 Subject: [PATCH 09/13] add flash message and render instead of redirecting --- .../app/controllers/projects_controller.rb | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index a36c3101c0..2ac74a36c9 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -111,31 +111,44 @@ def job_details hpc_job = project.job(job_details_params[:jobid].to_s, cluster_str) @project = project + render(partial: 'job_details', locals: { job: hpc_job }) end # DELETE /projects/:project_id/jobs/:cluster/:jobid def delete_job - project = Project.find(job_details_params[:project_id]) + @project = Project.find(job_details_params[:project_id]) + cluster_str = job_details_params[:cluster].to_s - hpc_job = project.job(job_details_params[:jobid].to_s, cluster_str) - if hpc_job.status.to_s == 'completed' - redirect_to project_path(job_details_params[:project_id]) if hpc_job.status.to_s == 'completed' - else - project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) - redirect_to project_path(job_details_params[:project_id]) - end + @project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) + + @valid_project = Launcher.clusters? + @valid_scripts = Launcher.scripts?(@project.directory) + @scripts = Launcher.all(@project.directory) + + render :show end # POST /projects/:project_id/jobs/:cluster/:jobid/stop def stop_job + @project = Project.find(job_details_params[:project_id]) cluster_str = job_details_params[:cluster].to_s cluster = OodAppkit.clusters[cluster_str.to_sym] - cluster.job_adapter.delete(job_details_params[:jobid].to_s) + hpc_job = @project.job(job_details_params[:jobid].to_s, cluster_str) + + begin + cluster.job_adapter.delete(job_details_params[:jobid].to_s) unless hpc_job.status.to_s == 'completed' + rescue StandardError => e + flash.now[:alert] = I18n.t('dashboard.jobs_project_generic_error', error: e.message.to_s) + end + + @valid_project = Launcher.clusters? + @valid_scripts = Launcher.scripts?(@project.directory) + @scripts = Launcher.all(@project.directory) - redirect_to project_path(job_details_params[:project_id]) + render :show end private From 815fbb954edb86993c0e25d9ef038b6ff4372cba Mon Sep 17 00:00:00 2001 From: Ashton South Date: Mon, 28 Oct 2024 15:31:42 -0400 Subject: [PATCH 10/13] pass project instead of using safe navigation --- apps/dashboard/app/controllers/projects_controller.rb | 4 ++-- apps/dashboard/app/helpers/projects_helper.rb | 4 ++-- .../app/views/projects/_job_details.turbo_stream.erb | 2 +- .../app/views/projects/_job_details_content.html.erb | 2 +- apps/dashboard/app/views/projects/show.html.erb | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index 2ac74a36c9..4693471461 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -111,8 +111,8 @@ def job_details hpc_job = project.job(job_details_params[:jobid].to_s, cluster_str) @project = project - - render(partial: 'job_details', locals: { job: hpc_job }) + + render(partial: 'job_details', locals: { job: hpc_job, project: @project }) end # DELETE /projects/:project_id/jobs/:cluster/:jobid diff --git a/apps/dashboard/app/helpers/projects_helper.rb b/apps/dashboard/app/helpers/projects_helper.rb index 56a464f89e..87df4858d4 100644 --- a/apps/dashboard/app/helpers/projects_helper.rb +++ b/apps/dashboard/app/helpers/projects_helper.rb @@ -15,8 +15,8 @@ def render_readme(readme_location) end end - def job_details_buttons(status, job) - locals = { project_id: @project&.id, id: job&.id, cluster: job&.cluster } + def job_details_buttons(status, job, project) + locals = { project_id: project.id, id: job.id, cluster: job.cluster } button_partial = button_category(status) render(partial: "projects/buttons/#{button_category(status)}_buttons", locals: locals) unless button_partial.nil? end diff --git a/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb b/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb index b85c80f7b8..838f73339e 100644 --- a/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb +++ b/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb @@ -5,6 +5,6 @@ diff --git a/apps/dashboard/app/views/projects/_job_details_content.html.erb b/apps/dashboard/app/views/projects/_job_details_content.html.erb index 2917618a4a..ac39ff326c 100644 --- a/apps/dashboard/app/views/projects/_job_details_content.html.erb +++ b/apps/dashboard/app/views/projects/_job_details_content.html.erb @@ -20,7 +20,7 @@ <% end %>
- <%= job_details_buttons(job.status.to_s, job) %> + <%= job_details_buttons(job.status.to_s, job, project) %>
diff --git a/apps/dashboard/app/views/projects/show.html.erb b/apps/dashboard/app/views/projects/show.html.erb index 2d3db7aff5..6d4e82b56b 100644 --- a/apps/dashboard/app/views/projects/show.html.erb +++ b/apps/dashboard/app/views/projects/show.html.erb @@ -59,7 +59,7 @@

Active Jobs

- <%= render(partial: 'job_details', collection: @project.active_jobs, as: :job ) %> + <%= render(partial: 'job_details', collection: @project.active_jobs, as: :job, locals: { project: @project }) %>
@@ -67,7 +67,7 @@
<%- @project.completed_jobs.each do |job| -%>
"> - <%= render(partial: 'job_details_content', locals: { job: job }) %> + <%= render(partial: 'job_details_content', locals: { job: job, project: @project }) %>
<%- end -%>
From 8ed04a7ee931f421302e1291a9069424f7ff8e2c Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 8 Nov 2024 10:22:11 -0500 Subject: [PATCH 11/13] add notices and alerts when stopping or deleting jobs --- .../app/controllers/projects_controller.rb | 39 ++++++++++++------- apps/dashboard/config/locales/en.yml | 4 ++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index 4693471461..f7d8f85542 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -121,13 +121,19 @@ def delete_job cluster_str = job_details_params[:cluster].to_s - @project.remove_logged_job(job_details_params[:jobid].to_s, cluster_str) + jobid = job_details_params[:jobid] - @valid_project = Launcher.clusters? - @valid_scripts = Launcher.scripts?(@project.directory) - @scripts = Launcher.all(@project.directory) - - render :show + if @project.remove_logged_job(jobid.to_s, cluster_str) + redirect_to( + project_path(job_details_params[:project_id]), + notice: I18n.t('dashboard.jobs_project_job_deleted', job_id: jobid) + ) + else + redirect_to( + project_path(job_details_params[:project_id]), + alert: I18n.t('dashboard.jobs_project_job_not_deleted', jobid: jobid) + ) + end end # POST /projects/:project_id/jobs/:cluster/:jobid/stop @@ -136,19 +142,22 @@ def stop_job cluster_str = job_details_params[:cluster].to_s cluster = OodAppkit.clusters[cluster_str.to_sym] - hpc_job = @project.job(job_details_params[:jobid].to_s, cluster_str) + jobid = job_details_params[:jobid] + + hpc_job = @project.job(jobid.to_s, cluster_str) begin - cluster.job_adapter.delete(job_details_params[:jobid].to_s) unless hpc_job.status.to_s == 'completed' + cluster.job_adapter.delete(jobid.to_s) unless hpc_job.status.to_s == 'completed' + redirect_to( + project_path(job_details_params[:project_id]), + notice: I18n.t('dashboard.jobs_project_job_stopped', job_id: jobid) + ) rescue StandardError => e - flash.now[:alert] = I18n.t('dashboard.jobs_project_generic_error', error: e.message.to_s) + redirect_to( + project_path(job_details_params[:project_id]), + alert: I18n.t('dashboard.jobs_project_generic_error', error: e.message.to_s) + ) end - - @valid_project = Launcher.clusters? - @valid_scripts = Launcher.scripts?(@project.directory) - @scripts = Launcher.all(@project.directory) - - render :show end private diff --git a/apps/dashboard/config/locales/en.yml b/apps/dashboard/config/locales/en.yml index 68331777cc..829c460d9e 100644 --- a/apps/dashboard/config/locales/en.yml +++ b/apps/dashboard/config/locales/en.yml @@ -249,6 +249,10 @@ en: jobs_project_invalid_configuration_clusters: "An HPC cluster is required. Contact your administrator to add one to the system." jobs_project_invalid_configuration_scripts: "An executable script is required for your project. Upload a script using the file application." + jobs_project_job_stopped: "Successfully stopped job %{job_id}" + jobs_project_job_deleted: "Successfully deleted job %{job_id}" + jobs_project_job_not_deleted: "Cannot delete job %{job_id}" + jobs_scripts_created: "Script successfully created!" jobs_scripts_default_created: "A 'hello_world.sh' was also added to this project." jobs_scripts_updated: "Script manifest updated!" From bee998d134d89e0232a9c87fe2ef7444d8a65361 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Fri, 8 Nov 2024 10:28:24 -0500 Subject: [PATCH 12/13] remove_logged_job returns boolean --- apps/dashboard/app/models/project.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/dashboard/app/models/project.rb b/apps/dashboard/app/models/project.rb index 937372f56b..236170db0f 100644 --- a/apps/dashboard/app/models/project.rb +++ b/apps/dashboard/app/models/project.rb @@ -222,6 +222,8 @@ def job(job_id, cluster) def remove_logged_job(job_id, cluster) old_job = jobs.detect { |j| j.id == job_id && j.cluster == cluster } Project.delete_job!(directory, old_job) + + jobs.none? { |j| j.id == job_id && j.cluster == cluster } end def adapter(cluster_id) From 152333ae2db38b0a15446a0367a3058f410a6634 Mon Sep 17 00:00:00 2001 From: Ashton South Date: Thu, 14 Nov 2024 08:46:12 -0500 Subject: [PATCH 13/13] add data confirm to destructive buttons --- .../app/views/projects/buttons/_completed_buttons.html.erb | 1 + .../app/views/projects/buttons/_queued_buttons.html.erb | 1 + .../app/views/projects/buttons/_running_buttons.html.erb | 1 + apps/dashboard/app/views/shared/_path_selector_table.html.erb | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb index 7d09e06fef..0df5fa9711 100644 --- a/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_completed_buttons.html.erb @@ -2,5 +2,6 @@ 'Delete', project_delete_job_path(project_id: project_id, cluster: cluster, jobid: id), method: :delete, + data: { confirm: t('dashboard.batch_connect_sessions_delete_confirm') }, class: 'btn btn-danger' ) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb index d1db5d31ce..8ff57cb0d0 100644 --- a/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_queued_buttons.html.erb @@ -2,5 +2,6 @@ 'Stop', project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), method: :post, + data: { confirm: t('dashboard.batch_connect_sessions_delete_confirm') }, class: 'btn btn-danger' ) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb index d1db5d31ce..8ff57cb0d0 100644 --- a/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb +++ b/apps/dashboard/app/views/projects/buttons/_running_buttons.html.erb @@ -2,5 +2,6 @@ 'Stop', project_stop_job_path(project_id: project_id, cluster: cluster, jobid: id), method: :post, + data: { confirm: t('dashboard.batch_connect_sessions_delete_confirm') }, class: 'btn btn-danger' ) %> \ No newline at end of file diff --git a/apps/dashboard/app/views/shared/_path_selector_table.html.erb b/apps/dashboard/app/views/shared/_path_selector_table.html.erb index 6b91e58be5..127159f2c8 100644 --- a/apps/dashboard/app/views/shared/_path_selector_table.html.erb +++ b/apps/dashboard/app/views/shared/_path_selector_table.html.erb @@ -1,7 +1,7 @@