Skip to content

Commit

Permalink
Merge pull request #5832 from vpereira/architecture_worker
Browse files Browse the repository at this point in the history
Move map_to_workers to the Architecture#worker
  • Loading branch information
vpereira committed Sep 12, 2018
2 parents 2d05136 + 57d9b70 commit d3c2840
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 27 additions & 21 deletions src/api/app/controllers/webui/monitor_controller.rb
Original file line number Diff line number Diff line change
@@ -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]

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/api/app/controllers/webui/webui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
9 changes: 9 additions & 0 deletions src/api/app/models/architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/api/spec/models/architecture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d3c2840

Please sign in to comment.