From d1d73c5664efd360c8e6c6389f021c85489edd2d Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Mon, 17 Nov 2025 18:28:57 -0500 Subject: [PATCH 1/2] Improve the way we record the TOTAL max number of active tasks on a bourreau #1565 --- BrainPortal/app/controllers/quotas_controller.rb | 1 - BrainPortal/app/helpers/select_box_helper.rb | 11 ++++++++++- BrainPortal/app/models/cpu_quota.rb | 6 ++++++ .../app/views/quotas/_cpu_quotas_table.html.erb | 3 +++ BrainPortal/app/views/quotas/_show_cpu_quota.erb | 13 +++++++++++-- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/BrainPortal/app/controllers/quotas_controller.rb b/BrainPortal/app/controllers/quotas_controller.rb index db269b4b0..19b965a02 100644 --- a/BrainPortal/app/controllers/quotas_controller.rb +++ b/BrainPortal/app/controllers/quotas_controller.rb @@ -113,7 +113,6 @@ def new def update #:nodoc: id = params[:id].presence # can be nil if we create() a new quota object @mode = params[:mode].to_s == 'cpu' ? :cpu : :disk - @quota = Quota.find(id) unless id.blank? if @quota # Set mode to sane version no matter what diff --git a/BrainPortal/app/helpers/select_box_helper.rb b/BrainPortal/app/helpers/select_box_helper.rb index c0bc8869b..0561ed8c0 100644 --- a/BrainPortal/app/helpers/select_box_helper.rb +++ b/BrainPortal/app/helpers/select_box_helper.rb @@ -33,6 +33,8 @@ module SelectBoxHelper # [selector] used for default selection. This can be a User object, a user id (String or Integer), # or any model that has a user_id attribute. # [users] the array of User objects used to build the select box. Defaults to +current_user.available_users+. + # [include_blank] - include blank value with specific label + # [special_label] - inject special value and label def user_select(parameter_name = "user_id", options = {}, select_tag_options = {} ) options = { :selector => options } unless options.is_a?(Hash) selector = options[:selector] @@ -52,9 +54,16 @@ def user_select(parameter_name = "user_id", options = {}, select_tag_options = { # Final HTML rendering of the options for select user_by_lock_status = regroup_users_by_lock_status(users) grouped_options = grouped_options_for_select user_by_lock_status, selected + + special_label = select_tag_options.delete(:special_label) || options[:special_label] + if special_label + label, value = special_label + grouped_options = "".html_safe + grouped_options + end + blank_label = select_tag_options.delete(:include_blank) || options[:include_blank] if blank_label - blank_label = "" if blank_label == true + blank_label = "" if blank_label == true # todo remove redundand line, just sup grouped_options = "".html_safe + grouped_options end diff --git a/BrainPortal/app/models/cpu_quota.rb b/BrainPortal/app/models/cpu_quota.rb index 631d45c5a..ea59395b2 100644 --- a/BrainPortal/app/models/cpu_quota.rb +++ b/BrainPortal/app/models/cpu_quota.rb @@ -81,6 +81,11 @@ def is_for_user? #:nodoc: self.user_id != 0 end + # currently only for total task cap for all the users + def is_for_total? #:nodoc: + self.user_id == -7 && ! self.max_active_tasks.nil? && self.is_for_resource? + end + def is_for_resource? #:nodoc: self.remote_resource_id != 0 end @@ -284,6 +289,7 @@ def user_exec_group_are_reasonable #:nodoc: uid = self.user_id || 0 rrid = self.remote_resource_id || 0 gid = self.group_id || 0 + return true if uid == -7 && rrid > 0 && gid == 0 return true if uid > 0 && gid == 0 # case 1 and 4 return true if gid > 0 && uid == 0 # case 3 and 5 return true if rrid > 0 && uid == 0 && gid == 0 # case 2 diff --git a/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb b/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb index 265b44a7e..2f196af79 100644 --- a/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb +++ b/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb @@ -57,6 +57,9 @@ :sortable => true, :filters => default_filters_for(@base_scope, User) ) do |cq| + if cq.is_for_total? + html_colorize("(Total for all user)", 'orange') + end if ! cq.is_for_user? if cq.is_for_group? html_colorize("(For all users in project)", 'orange') diff --git a/BrainPortal/app/views/quotas/_show_cpu_quota.erb b/BrainPortal/app/views/quotas/_show_cpu_quota.erb index 8aa64ca0b..280e7e4a3 100644 --- a/BrainPortal/app/views/quotas/_show_cpu_quota.erb +++ b/BrainPortal/app/views/quotas/_show_cpu_quota.erb @@ -47,16 +47,25 @@ <% t.cell("User", :show_width => 2) do %> <% if @quota.new_record? %> - <%= user_select("quota[user_id]", { :selector => @quota.user_id, :include_blank => '(Default For All Users)' }) %> + + <%= user_select("quota[user_id]", { :selector => @quota.user_id, + :include_blank => '(Default For All Users)', + :special_label => ["Total tasks server-wide ", -7] + }) %>
You can leave the user field blank and instead specify a project, below. You can also leave them both blank.
<% else %> - <%= @quota.is_for_user? ? + <% if @quota.is_for_total? %> + <%= html_colorize("(Server-wide task total)", 'orange') %> + <% else %> + <%= @quota.is_for_user? ? link_to_user_if_accessible(@quota.user) : html_colorize("(Default for all users)", 'orange') %> + <% end %> <% end %> + <% end %> <% t.cell("Project", :show_width => 2) do %> From cb47917dbbee03bff6f68ce1317b1ab73e0a6bd5 Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Wed, 19 Nov 2025 16:16:04 -0500 Subject: [PATCH 2/2] Minor corrections for the TOTAL max number of active tasks on a bourreau #1565 --- BrainPortal/app/controllers/quotas_controller.rb | 1 - BrainPortal/app/helpers/select_box_helper.rb | 3 +-- BrainPortal/app/models/cpu_quota.rb | 5 +++-- BrainPortal/app/models/quota.rb | 2 ++ BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb | 3 +++ BrainPortal/app/views/quotas/_show_cpu_quota.erb | 5 ++--- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/BrainPortal/app/controllers/quotas_controller.rb b/BrainPortal/app/controllers/quotas_controller.rb index 19b965a02..975c3c95e 100644 --- a/BrainPortal/app/controllers/quotas_controller.rb +++ b/BrainPortal/app/controllers/quotas_controller.rb @@ -420,4 +420,3 @@ def guess_time_units(timestring) end end - diff --git a/BrainPortal/app/helpers/select_box_helper.rb b/BrainPortal/app/helpers/select_box_helper.rb index 0561ed8c0..7ab30bdf6 100644 --- a/BrainPortal/app/helpers/select_box_helper.rb +++ b/BrainPortal/app/helpers/select_box_helper.rb @@ -63,7 +63,7 @@ def user_select(parameter_name = "user_id", options = {}, select_tag_options = { blank_label = select_tag_options.delete(:include_blank) || options[:include_blank] if blank_label - blank_label = "" if blank_label == true # todo remove redundand line, just sup + blank_label = "" if blank_label == true grouped_options = "".html_safe + grouped_options end @@ -626,4 +626,3 @@ def uploadable_data_providers(user=current_user) end end - diff --git a/BrainPortal/app/models/cpu_quota.rb b/BrainPortal/app/models/cpu_quota.rb index ea59395b2..482fc9bf5 100644 --- a/BrainPortal/app/models/cpu_quota.rb +++ b/BrainPortal/app/models/cpu_quota.rb @@ -83,7 +83,7 @@ def is_for_user? #:nodoc: # currently only for total task cap for all the users def is_for_total? #:nodoc: - self.user_id == -7 && ! self.max_active_tasks.nil? && self.is_for_resource? + self.user_id == Quota::ALL_USERS end def is_for_resource? #:nodoc: @@ -285,11 +285,12 @@ def limits_are_reasonable # # - - y case 3 # # y y - case 4 # # - y y case 5 + # #Quota::ALL_USERSy - case 6 def user_exec_group_are_reasonable #:nodoc: uid = self.user_id || 0 rrid = self.remote_resource_id || 0 gid = self.group_id || 0 - return true if uid == -7 && rrid > 0 && gid == 0 + return true if uid == Quota::ALL_USERS && rrid > 0 && gid == 0 # case #6 return true if uid > 0 && gid == 0 # case 1 and 4 return true if gid > 0 && uid == 0 # case 3 and 5 return true if rrid > 0 && uid == 0 && gid == 0 # case 2 diff --git a/BrainPortal/app/models/quota.rb b/BrainPortal/app/models/quota.rb index ed02aa41b..2bf7e72d7 100644 --- a/BrainPortal/app/models/quota.rb +++ b/BrainPortal/app/models/quota.rb @@ -28,4 +28,6 @@ class Quota < ApplicationRecord cbrain_abstract_model! # objects of this class are not to be instantiated + ALL_USERS = -7 # indicate total quota for all the users togeter + end diff --git a/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb b/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb index 2f196af79..b1d363310 100644 --- a/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb +++ b/BrainPortal/app/views/quotas/_cpu_quotas_table.html.erb @@ -68,6 +68,9 @@ end else link_to_user_if_accessible(cq.user) + if cq.is_for_total? + html_colorize("(Total for all users)", 'orange') + end end end diff --git a/BrainPortal/app/views/quotas/_show_cpu_quota.erb b/BrainPortal/app/views/quotas/_show_cpu_quota.erb index 280e7e4a3..5eaa5bb22 100644 --- a/BrainPortal/app/views/quotas/_show_cpu_quota.erb +++ b/BrainPortal/app/views/quotas/_show_cpu_quota.erb @@ -50,7 +50,7 @@ <%= user_select("quota[user_id]", { :selector => @quota.user_id, :include_blank => '(Default For All Users)', - :special_label => ["Total tasks server-wide ", -7] + :special_label => ["Max for all users together", Quota::ALL_USERS ] }) %>
You can leave the user field blank and instead specify a project, below. @@ -129,8 +129,7 @@ Leave blank to not set a limit. A value of zero will prevent any tasks from being launched. Note that projects are ignored for these values, and that if several quota records apply to a user and differ only by project, the minimum value found in that set will be used. - The core Admin account is used to set a maximum number of tasks IN TOTAL for an Execution - server (thus, no limit specific to that admin user can be specified here). + It is possible to define a maximum number of tasks IN TOTAL for an Execution server.
<% end %>