Skip to content

Commit

Permalink
[webui] remove architecture model and make main controller webui mode…
Browse files Browse the repository at this point in the history
…l free
  • Loading branch information
coolo committed Oct 25, 2013
1 parent 6a042c2 commit 1d61160
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 160 deletions.
2 changes: 1 addition & 1 deletion src/api/config/environments/development.rb
Expand Up @@ -27,7 +27,7 @@
config.assets.compress = false

# Expands the lines which load the assets
config.assets.logger = false
config.assets.logger = nil
config.assets.debug = false

# Enable debug logging by default
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/unit/code_quality_test.rb
Expand Up @@ -177,7 +177,7 @@ def setup
'Webui::Package#commit' => 71.56,
'Webui::PatchinfoController#new_tracker' => 68.43,
'Webui::ProjectController#status' => 67.37,
'Webui::MonitorController#events' => 65.34,
'Webui::MonitorController#events' => 59.75,
'Webui::ProjectHelper#show_status_comment' => 64.97,
'Webui::RequestController#set_bugowner_request' => 64.93,
'Webui::HomeController#running_patchinfos' => 64.05,
Expand Down
1 change: 1 addition & 0 deletions src/api/webui/app/assets/javascripts/webui/application.js
Expand Up @@ -29,6 +29,7 @@
//= require webui/request
//= require webui/patchinfo
//= require webui/comment
//= require webui/main

// toggle visibility of an element via the CSS "display" property
// -> does NOT reserve the needed space for the element when not displayed
Expand Down
10 changes: 10 additions & 0 deletions src/api/webui/app/assets/javascripts/webui/main.js
@@ -0,0 +1,10 @@
function plotbusyworkers(data) {
$.plot($("#overallgraph"), [
{ data: data, label: "Busy workers", color: 3}
],
{
series: { stack: true, lines: { show: true, steps: false, fill: true } },
xaxis: { mode: 'time' },
yaxis: { min: 0, position: "left" },
});
}
22 changes: 10 additions & 12 deletions src/api/webui/app/controllers/webui/configuration_controller.rb
Expand Up @@ -56,14 +56,14 @@ def save_instance

def update_configuration
if ! (params[:name] || params[:title] || params[:description])
flash[:error] = "Missing arguments (name, title or description)"
flash[:error] = 'Missing arguments (name, title or description)'
redirect_back_or_to :action => 'index' and return
end

begin
archs = params[:archs] || []
archs.each do |archname, value|
available = value == "1"
available = value == '1'
if old = Architecture.where(name: archname, available: !available).first
old.available = available
old.save
Expand All @@ -74,26 +74,24 @@ def update_configuration
c.description = params[:description]
c.name = params[:name]
c.save
flash[:notice] = "Updated configuration"
flash[:notice] = 'Updated configuration'
Rails.cache.delete('configuration')
rescue ActiveXML::Transport::Error
logger.debug "Failed to update configuration"
flash[:error] = "Failed to update configuration"
logger.debug 'Failed to update configuration'
flash[:error] = 'Failed to update configuration'
end
redirect_to :action => 'index'
end

def update_architectures
@available_architectures.each do |arch_elem|
arch = Webui::Architecture.find(arch_elem.name) # fetch a real 'Architecture' from 'directory' entry
if params[:arch_recommended] and params[:arch_recommended].include?(arch.name) and arch.recommended.text == 'false'
arch.recommended.text = 'true'
arch = Architecture.find_by_name(arch_elem.name) # fetch a real 'Architecture' from 'directory' entry
if params[:arch_recommended] and params[:arch_recommended].include?(arch.name) and !arch.recommended
arch.recommended = true
arch.save
Webui::Architecture.free_cache(:available)
elsif arch.recommended.text == 'true'
arch.recommended.text = 'false'
elsif arch.recommended
arch.recommended = false
arch.save
Webui::Architecture.free_cache(:available)
end
end
redirect_to :action => 'index'
Expand Down
60 changes: 21 additions & 39 deletions src/api/webui/app/controllers/webui/main_controller.rb
Expand Up @@ -6,44 +6,33 @@ class Webui::MainController < Webui::WebuiController
# permissions.status_message_create
before_filter :require_admin, only: [:delete_message, :add_news]

def index
@news = StatusMessage.alive.limit(4)
unless @spider_bot
@latest_updates = get_latest_updated(6)
def gather_busy
busy = []
archs = Architecture.where(available: 1).pluck(:name).map {|arch| map_to_workers(arch)}.uniq
archs.each do |arch|
starttime = Time.now.to_i - 168.to_i * 3600
rel = StatusHistory.where("time >= ? AND \`key\` = ?", starttime, 'building_' + arch)
values = rel.pluck(:time, :value).collect { |time, value| [time.to_i, value.to_f] }
busy = Webui::MonitorController.addarrays(busy, StatusHelper.resample(values, 400))
end
rescue ActiveXML::Transport::UnauthorizedError
@anonymous_forbidden = true
logger.error 'Could not load all frontpage data, probably due to forbidden anonymous access in the api.'
busy
end

# This action does the heavy lifting for the index method and is only invoked by an AJAX request
def systemstatus
check_ajax
if @spider_bot
@workerstatus = Xmlhash::XMLHash.new
else
@workerstatus = WorkerStatus.hidden.to_hash
end
def index
@news = StatusMessage.alive.limit(4).to_a
@workerstatus = WorkerStatus.hidden.to_hash
@latest_updates = get_latest_updated(6)
@waiting_packages = 0
@building_workers = @workerstatus.elements('building').length
@overall_workers = @workerstatus['clients']
@workerstatus.elements('waiting') {|waiting| @waiting_packages += waiting['jobs'].to_i}
@busy = nil
require_available_architectures unless @spider_bot
if @available_architectures
@available_architectures.each.map {|arch| map_to_workers(arch.name) }.uniq.each do |arch|
archret = frontend.gethistory('building_' + arch, 168).map {|time,value| [time,value]}
if archret.length > 0
if @busy
@busy = Webui::MonitorController.addarrays(@busy, archret)
else
@busy = archret
end
end
end
@busy = Rails.cache.fetch('mainpage_busy', expires_in: 10.minutes) do
gather_busy
end
render :partial => 'webui/main/systemstatus'
rescue ActiveXML::Transport::UnauthorizedError
@anonymous_forbidden = true
render :text => '' # AJAX-request means no 'flash' available, don't render anything if we aren't allowed
@project_count = Project.count
@package_count = Package.count
@repo_count = Repository.count
@user_count = User.count
end

def news
Expand Down Expand Up @@ -128,11 +117,4 @@ def delete_message
redirect_to(:action => 'index')
end

def require_available_architectures
super # Call ApplicationController implementation, but catch an additional exception
rescue ActiveXML::Transport::UnauthorizedError
@anonymous_forbidden = true
logger.error 'Could not load all frontpage data, probably due to forbidden anonymous access in the api.'
end

end
50 changes: 32 additions & 18 deletions src/api/webui/app/controllers/webui/monitor_controller.rb
Expand Up @@ -5,21 +5,22 @@ class Webui::MonitorController < Webui::WebuiController
before_filter :fetch_workerstatus, :only => [:old, :filtered_list, :update_building]

def fetch_workerstatus
@workerstatus = WorkerStatus.hidden.to_hash
@workerstatus = WorkerStatus.hidden.to_hash
end

private :fetch_workerstatus

def old
end

def index
if request.post? && ! params[:project].nil? && valid_project_name?( params[:project] )
if request.post? && !params[:project].nil? && valid_project_name?(params[:project])
redirect_to project: params[:project]
else
begin
fetch_workerstatus
fetch_workerstatus
rescue ActiveXML::Transport::NotFoundError
@workerstatus = {}
@workerstatus = {}
end

workers = Hash.new
Expand All @@ -38,8 +39,8 @@ def index
workers[hostname][subid] = id
end
@workers_sorted = {}
@workers_sorted = workers.sort {|a,b| a[0] <=> b[0] } if workers
@available_arch_list = @available_architectures.each.map{|arch| arch.name}
@workers_sorted = workers.sort { |a, b| a[0] <=> b[0] } if workers
@available_arch_list = @available_architectures.each.map { |arch| arch.name }
end
end

Expand All @@ -56,22 +57,36 @@ def update_building
id=b['workerid'].gsub(%r{[:./]}, '_')
delta = (Time.now - Time.at(b['starttime'].to_i)).round
if delta < 5
delta = 5
delta = 5
end
if delta > max_time
delta = max_time
end
delta = (100*Math.sin(Math.acos(1-(Float(delta)/max_time)))).round
if (delta > 100)
delta = 100
delta = 100
end
workers[id] = { 'delta' => delta, 'project' => b['project'], 'repository' => b['repository'],
'package' => b['package'], 'arch' => b['arch'], 'starttime' => b['starttime']}
'package' => b['package'], 'arch' => b['arch'], 'starttime' => b['starttime'] }
end
# logger.debug workers.inspect
render :json => workers
end

def gethistory(key, range, cache=1)
cachekey = key + "-#{range}"
Rails.cache.delete(cachekey, :shared => true) if !cache
return Rails.cache.fetch(cachekey, :expires_in => (range.to_i * 3600) / 150, :shared => true) do
hash = Hash.new
data = ActiveXML::api.direct_http(URI('/status/history?key=%s&hours=%d&samples=400' % [key, range]))
doc = Nokogiri::XML(data)
doc.root.elements.each do |value|
hash[value.attributes['time'].value.to_i] = value.attributes['value'].value.to_f
end
hash.sort { |a, b| a[0] <=> b[0] }
end
end

def events
check_ajax
data = Hash.new
Expand All @@ -80,35 +95,34 @@ def events
arch = params[:arch]
range = params[:range]
%w{waiting blocked squeue_high squeue_med}.each do |prefix|
data[prefix] = frontend.gethistory(prefix + '_' + arch, range, !discard_cache?).map {|time,value| [time*1000,value]}
data[prefix] = gethistory(prefix + '_' + arch, range, !discard_cache?).map { |time, value| [time*1000, value] }
end
%w{idle building}.each do |prefix|
data[prefix] = frontend.gethistory(prefix + '_' + map_to_workers(arch), range, !discard_cache?).map {|time,value| [time*1000,value]}
data[prefix] = gethistory(prefix + '_' + map_to_workers(arch), range, !discard_cache?).map { |time, value| [time*1000, value] }
end
low = Hash.new
frontend.gethistory("squeue_low_#{arch}", range).each do |time,value|
gethistory("squeue_low_#{arch}", range).each do |time, value|
low[time] = value
end
comb = Array.new
frontend.gethistory("squeue_next_#{arch}", range).each do |time,value|
gethistory("squeue_next_#{arch}", range).each do |time, value|
clow = low[time] || 0
comb << [1000*time, clow + value]
end
data['squeue_low'] = comb
max = Webui::MonitorController.addarrays(data['squeue_high'], data['squeue_med']).map{|time,value| value}.max || 0
max = Webui::MonitorController.addarrays(data['squeue_high'], data['squeue_med']).map { |time, value| value }.max || 0
data['events_max'] = max * 2
data['jobs_max'] = maximumvalue(data['waiting']) * 2
data['jobs_max'] = maximumvalue(data['waiting']) * 2
render :json => data
end

private

def maximumvalue(arr)
arr.map { |time,value| value }.max || 0
arr.map { |time, value| value }.max || 0
end

def self.addarrays(arr1, arr2)
logger.debug "1: #{arr1.length} 2: #{arr2.length}"
# we assert that both have the same size
ret = Array.new
arr1.length.times do |i|
Expand Down
8 changes: 2 additions & 6 deletions src/api/webui/app/controllers/webui/webui_controller.rb
Expand Up @@ -106,7 +106,7 @@ def authenticate
end

def authenticate_proxy
Rails.logger.debug "PROXY!!!"
Rails.logger.debug 'PROXY!!!'
mode = :off
mode = CONFIG['proxy_auth_host'] unless CONFIG['proxy_auth_host'].blank?
proxy_user = request.env['HTTP_X_USERNAME']
Expand Down Expand Up @@ -329,11 +329,7 @@ def clean_cache
end

def require_available_architectures
@available_architectures = Webui::Architecture.find(:available)
unless @available_architectures
flash[:error] = 'Available architectures not found'
redirect_to :controller => 'project', :action => 'list_public', :nextstatus => 404 and return
end
@available_architectures = Architecture.where(available: 1)
end

def mobile_request?
Expand Down
2 changes: 1 addition & 1 deletion src/api/webui/app/helpers/webui/main_helper.rb
Expand Up @@ -2,7 +2,7 @@ module Webui::MainHelper

def proceed_link(_image, _text, link_opts)
content_tag(:li,
(link_to(sprite_tag(_image), link_opts) + tag(:br) +
(link_to(sprite_tag(_image, title: _text), link_opts) + tag(:br) +
content_tag(:span, link_to(_text, link_opts), class: 'proceed_text')), id: "proceed-#{_image}")
end

Expand Down
21 changes: 6 additions & 15 deletions src/api/webui/app/helpers/webui/webui_helper.rb
Expand Up @@ -169,7 +169,7 @@ def flag_status(flagname, flags, repository, arch)
flag = determine_most_specific_flag(arch, flags, repository)
return '' unless flag

image = flag_image(flag, flagname)
image, title = flag_image(flag, flagname)

if (@package && User.current.can_modify_package?(@package.api_obj)) ||
(@project && User.current.can_modify_project?(@project.api_obj))
Expand Down Expand Up @@ -209,26 +209,17 @@ def flag_status(flagname, flags, repository, arch)
end
end
else
sprite_tag(image)
sprite_tag(image, title: title)
end
end

def flag_image(flag, flagname)
image = nil
if flag[1].has_key? :explicit
if flag[0] == 'disable'
image = "#{flagname}_disabled_blue"
else
image = "#{flagname}_enabled_blue"
end
suffix = flag[1].has_key?(:explicit) ? 'blue' : 'grey'
if flag[0] == 'disable'
["#{flagname}_disabled_#{suffix}", 'disabled']
else
if flag[0] == 'disable'
image = "#{flagname}_disabled_grey"
else
image = "#{flagname}_enabled_grey"
end
["#{flagname}_enabled_#{suffix}", 'enabled']
end
image
end

def determine_most_specific_flag(arch, flags, repository)
Expand Down
2 changes: 0 additions & 2 deletions src/api/webui/app/models/webui/architecture.rb

This file was deleted.

2 changes: 1 addition & 1 deletion src/api/webui/app/views/layouts/webui/webui.html.erb
Expand Up @@ -43,7 +43,7 @@

<div id="subheader" class="container_16">
<div id="breadcrump" class="grid_10 alpha">
<%= sprite_tag( "home_grey" ) %><%= link_to "#{@configuration ? @configuration['title'] : 'Open Build Service'}", :controller => 'main', :action => :index %>
<%= sprite_tag( "home_grey", title: 'Logo' ) %><%= link_to "#{@configuration ? @configuration['title'] : 'Open Build Service'}", :controller => 'main', :action => :index %>
<% if @crumb_list %>
<% @crumb_list.each do |link| %>
&gt;
Expand Down

0 comments on commit 1d61160

Please sign in to comment.