diff --git a/src/api/app/controllers/webui/main_controller.rb b/src/api/app/controllers/webui/main_controller.rb index 305a656d7a8..a728ddb95ba 100644 --- a/src/api/app/controllers/webui/main_controller.rb +++ b/src/api/app/controllers/webui/main_controller.rb @@ -5,7 +5,7 @@ class Webui::MainController < Webui::WebuiController def gather_busy busy = [] - archs = Architecture.where(available: 1).pluck(:name).map { |arch| map_to_workers(arch) }.uniq + archs = Architecture.where(available: 1).map(&:worker).uniq archs.each do |arch| starttime = Time.now.to_i - 168.to_i * 3600 rel = StatusHistory.where("time >= ? AND \`key\` = ?", starttime, 'building_' + arch) diff --git a/src/api/app/controllers/webui/monitor_controller.rb b/src/api/app/controllers/webui/monitor_controller.rb index 9e12adca08a..6e72ab339e4 100644 --- a/src/api/app/controllers/webui/monitor_controller.rb +++ b/src/api/app/controllers/webui/monitor_controller.rb @@ -1,4 +1,5 @@ class Webui::MonitorController < Webui::WebuiController + before_action :set_default_architecture before_action :require_settings, only: [:old, :index, :filtered_list, :update_building] before_action :fetch_workerstatus, only: [:old, :filtered_list, :update_building] @@ -23,8 +24,6 @@ def self.addarrays(arr1, arr2) def old; end def index - @default_architecture = 'x86_64' - if request.post? && !params[:project].nil? && valid_project_name?(params[:project]) redirect_to project: params[:project] else @@ -77,40 +76,34 @@ def update_building render json: workers end - def gethistory(key, range, cache = 1) - cachekey = key + "-#{range}" - Rails.cache.delete(cachekey, shared: true) unless cache - Rails.cache.fetch(cachekey, expires_in: (range.to_i * 3600) / 150, shared: true) do - hash = StatusHistory.history_by_key_and_hours(key, range) - hash.sort_by { |a| a[0] } - end - end - def events check_ajax data = {} - arch = params[:arch] || '' + arch = Architecture.find_by(name: params.fetch(:arch, @default_architecture)) + range = params[:range] + ['waiting', 'blocked', 'squeue_high', 'squeue_med'].each do |prefix| - data[prefix] = gethistory(prefix + '_' + arch, range, !discard_cache?).map { |time, value| [time * 1000, value] } + data[prefix] = gethistory("#{prefix}_#{arch.name}", range, !discard_cache?).map { |time, value| [time * 1000, value] } end + ['idle', 'building', 'away', 'down', 'dead'].each do |prefix| - data[prefix] = gethistory(prefix + '_' + map_to_workers(arch), range, !discard_cache?).map { |time, value| [time * 1000, value] } - end - low = {} - gethistory("squeue_low_#{arch}", range).each do |time, value| - low[time] = value + data[prefix] = gethistory("#{prefix}_#{arch.worker}", range, !discard_cache?).map { |time, value| [time * 1000, value] } end - comb = [] - gethistory("squeue_next_#{arch}", range).each do |time, value| + + low = Hash[gethistory("squeue_low_#{arch}", range)] + + comb = gethistory("squeue_next_#{arch}", range).collect do |time, value| clow = low[time] || 0 - comb << [1000 * time, clow + value] + [1000 * time, clow + value] end + data['squeue_low'] = comb max = Webui::MonitorController.addarrays(data['squeue_high'], data['squeue_med']).map { |_, value| value }.max || 0 data['events_max'] = max * 2 data['jobs_max'] = maximumvalue(data['waiting']) * 2 + render json: data end @@ -126,6 +119,19 @@ def discard_cache? private + def gethistory(key, range, cache = 1) + cachekey = "#{key}-#{range}" + Rails.cache.delete(cachekey, shared: true) unless cache + Rails.cache.fetch(cachekey, expires_in: (range.to_i * 3600) / 150, shared: true) do + hash = StatusHistory.history_by_key_and_hours(key, range) + hash.sort_by { |a| a[0] } + end + end + + def set_default_architecture + @default_architecture = 'x86_64' + end + def fetch_workerstatus @workerstatus = Xmlhash.parse(WorkerStatus.hidden.to_xml) end diff --git a/src/api/app/controllers/webui/webui_controller.rb b/src/api/app/controllers/webui/webui_controller.rb index 4f5fc31e8eb..9fa4759d935 100644 --- a/src/api/app/controllers/webui/webui_controller.rb +++ b/src/api/app/controllers/webui/webui_controller.rb @@ -192,15 +192,6 @@ def check_display_user @is_displayed_user = (!User.current.is_nobody? && User.current == @displayed_user) end - def map_to_workers(arch) - case arch - when 'i586' then 'x86_64' - when 'ppc' then 'ppc64' - when 's390' then 's390x' - else arch - end - end - # Don't show performance of database queries to users def peek_enabled? User.current && (User.current.is_admin? || User.current.is_staff?) diff --git a/src/api/app/models/architecture.rb b/src/api/app/models/architecture.rb index fbed5b16dff..4f961902ce3 100644 --- a/src/api/app/models/architecture.rb +++ b/src/api/app/models/architecture.rb @@ -33,6 +33,15 @@ def self.archcache end end + def worker + case name + when 'i586' then 'x86_64' + when 'ppc' then 'ppc64' + when 's390' then 's390x' + else name + end + end + #### To define class methods as private use private_class_method #### private diff --git a/src/api/spec/models/architecture_spec.rb b/src/api/spec/models/architecture_spec.rb index 248a8d1e61f..8c9b1178338 100644 --- a/src/api/spec/models/architecture_spec.rb +++ b/src/api/spec/models/architecture_spec.rb @@ -3,4 +3,10 @@ RSpec.describe Architecture do it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_uniqueness_of(:name) } + + describe '#worker' do + let(:i586) { Architecture.find_by(name: 'i586') } + + it { expect(i586.worker).to eq('x86_64') } + end end