Hello community, here is the log from the commit of package webyast-status-ws for openSUSE:Factory checked in at Wed May 4 10:42:46 CEST 2011. -------- --- webyast-status-ws/webyast-status-ws.changes 2011-02-09 09:28:27.000000000 +0100 +++ /mounts/work_src_done/STABLE/webyast-status-ws/webyast-status-ws.changes 2011-05-02 14:45:24.000000000 +0200 @@ -1,0 +2,12 @@ +Mon May 2 12:45:10 UTC 2011 - schubi@novell.com + +- adapt caching to the new job handling +- 0.2.7 + +------------------------------------------------------------------- +Tue Apr 12 13:30:44 UTC 2011 - schubi@novell.com + +- new caching +- 0.2.6 + +------------------------------------------------------------------- calling whatdependson for head-i586 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ webyast-status-ws.spec ++++++ --- /var/tmp/diff_new_pack.Ra6I1b/_old 2011-05-04 10:39:21.000000000 +0200 +++ /var/tmp/diff_new_pack.Ra6I1b/_new 2011-05-04 10:39:21.000000000 +0200 @@ -27,7 +27,7 @@ Group: Productivity/Networking/Web/Utilities Url: http://en.opensuse.org/Portal:WebYaST AutoReqProv: on -Version: 0.2.5 +Version: 0.2.7 Release: 1 Summary: WebYaST - system status service Source: www.tar.bz2 ++++++ www.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/app/controllers/graphs_controller.rb new/www/app/controllers/graphs_controller.rb --- old/www/app/controllers/graphs_controller.rb 2011-02-01 10:49:25.000000000 +0100 +++ new/www/app/controllers/graphs_controller.rb 2011-04-11 12:49:05.000000000 +0200 @@ -62,11 +62,7 @@ def index permission_check("org.opensuse.yast.system.status.read") # RORSCAN_ITL init_translation - - bgr = params['background'] == 'true' - Rails.logger.info "Reading status in background" if bgr - - @graph = Graph.find(:all, params[:checklimits] || false, {:background => bgr}) + @graph = Graph.find(:all, params[:checklimits] || true) render :show end @@ -76,6 +72,6 @@ def show permission_check("org.opensuse.yast.system.status.read") # RORSCAN_ITL init_translation - @graph = Graph.find(params[:id], params[:checklimits] || false) + @graph = Graph.find(params[:id], params[:checklimits] || true) end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/app/controllers/plugins_controller.rb new/www/app/controllers/plugins_controller.rb --- old/www/app/controllers/plugins_controller.rb 2011-02-01 10:49:25.000000000 +0100 +++ new/www/app/controllers/plugins_controller.rb 2011-04-11 12:49:05.000000000 +0200 @@ -63,8 +63,9 @@ # def index permission_check("org.opensuse.yast.system.status.read") # RORSCAN_ITL - load_translations - @plugins = Plugin.find(:all) + what = :all + load_translations unless Rails.cache.exist?("plugin:find:#{what.inspect}") + @plugins = Plugin.find(what) render :show end @@ -73,7 +74,7 @@ # def show permission_check("org.opensuse.yast.system.status.read") # RORSCAN_ITL - load_translations + load_translations unless Rails.cache.exist?("plugin:find:#{params[:id]}") @plugins = Plugin.find(params[:id]) render :show end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/app/models/graph.rb new/www/app/models/graph.rb --- old/www/app/models/graph.rb 2011-02-01 10:49:11.000000000 +0100 +++ new/www/app/models/graph.rb 2011-04-29 18:23:25.000000000 +0200 @@ -38,10 +38,6 @@ attr_reader :y_decimal_places attr_reader :single_graphs - CONFIGURATION_FILE = "status_configuration.yaml" - TRANSLATE = true - - private # avoid race conditions when creating the config file @@ -49,10 +45,14 @@ # @@mutex = Mutex.new + #global variables + @@configuration_file = "status_configuration.yaml" + @@translate = true + # # reading data from Metric # - def read_data(id) + def self.read_data(id) data = {} metric = Metric.find(id) data = metric.data() if metric @@ -66,7 +66,7 @@ def check_limits(metric_id, metric_column, limits) id = Metric.default_host + "+" + metric_id metric_column ||= "value" - data = read_data(id) + data = Graph.read_data(id) limit_reached = false data.each do |key, values| if key == metric_column @@ -84,7 +84,7 @@ end break if limit_reached end - return limit_reached + limit_reached end # @@ -244,7 +244,7 @@ # reading configuration file # def self.parse_config(translate = false, path = nil) - path = File.join(Graph.plugin_config_dir(), CONFIGURATION_FILE ) if path == nil + path = File.join(Graph.plugin_config_dir(), @@configuration_file ) if path == nil #create default configuration file Graph.create_config(path) unless File.exists?(path) @@ -258,7 +258,7 @@ end # initialize on element - def initialize(group_id,value,limitcheck=false) + def initialize(group_id,value,limitcheck=true ) @group_name = group_id @headline = value["headline"] @y_scale = value["y_scale"] @@ -275,75 +275,18 @@ @single_graphs = value["single_graphs"] end - # just a short cut for accessing the singleton object - def self.bm - BackgroundManager.instance - end - # create unique id for the background manager def self.id(what) "system_status_#{what}" end - def self.find(what, limitcheck = false, opts = {}) - background = opts[:background] - - # background reading doesn't work correctly if class reloading is active - # (static class members are lost between requests) - if background && !bm.background_enabled? - Rails.logger.info "Class reloading is active, cannot use background thread (set config.cache_classes = true)" - background = false - end - - if background - #checking if collectd is running - raise ServiceNotRunning.new('collectd') unless Metric.collectd_running? - - proc_id = id(what) - if bm.process_finished? proc_id - Rails.logger.debug "Request #{proc_id} is done" - - ret = bm.get_value proc_id - - # rethrow the exception from the background thread - if ret.kind_of?(Exception) - Rails.logger.info "Rethrowing the exception caught in the background thread: #{ret.inspect}" - raise ret - end - - return ret - end + def self.find(what, limitcheck = true, opts = {}) + #checking if collectd is running + raise ServiceNotRunning.new('collectd') unless Metric.collectd_running? - running = bm.get_progress proc_id - if running - Rails.logger.debug "Request #{proc_id} is already running: #{running.inspect}" - return [running] - end - - bm.add_process proc_id - Rails.logger.info "Starting background thread for reading status..." - - # read the status in a separate thread - Thread.new do - begin - res = do_find what, limitcheck, bm - rescue Exception => ex - Rails.logger.info "Status background thread: Caught exception: #{ex}" - # remember the exception and rethrow it in the main thread later - res = ex - end - - bm.finish_process(proc_id, res) - end - process = bm.get_progress(proc_id) - if process - return [ process ] - else - return [] - end - else - return do_find(what, limitcheck) - end + YastCache.fetch(self,what) { + do_find(what, limitcheck) + } end # @@ -354,8 +297,8 @@ # (e.g. cpu-0+cpu-system) # "limitcheck" checking if limit has been reached (default: false) # - def self.do_find(what, limitcheck = false, bg = nil) - config = parse_config(TRANSLATE) + def self.do_find(what, limitcheck = true, bg = nil) + config = parse_config(@@translate) return nil if config==nil unless what == :all @@ -413,8 +356,7 @@ # return array of hashes of {"max"=>0, "min"=>0, "metric_column"=>nil} or nil # def self.find_limits(metric_id, group_id=nil ) - config = parse_config(TRANSLATE) - return nil if config==nil + config = parse_config(@@translate) || {} limits = [] config.each {|key,value| next if group_id != nil && key != group_id @@ -442,7 +384,7 @@ end # avoid race condition in writing the config @@mutex.synchronize do - f = File.open(File.join(Graph.plugin_config_dir(), CONFIGURATION_FILE), "w") + f = File.open(File.join(Graph.plugin_config_dir(), @@configuration_file), "w") f.write(config.to_yaml) f.close end @@ -474,7 +416,7 @@ xml.limits do xml.max line["limits"]["max"] xml.min line["limits"]["min"] - xml.reached check_limits(line["metric_id"], line["metric_column"], line["limits"]) if line["limits"].has_key? "reached" + xml.reached line["limits"]["reached"] if line["limits"].has_key? "reached" end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/app/models/log.rb new/www/app/models/log.rb --- old/www/app/models/log.rb 2011-02-01 10:49:11.000000000 +0100 +++ new/www/app/models/log.rb 2011-04-29 18:23:25.000000000 +0200 @@ -25,7 +25,6 @@ # require 'yast/config_file' -require 'yast_service' class Log attr_reader :id @@ -66,21 +65,22 @@ # "id" could be the log group (system,...) # def self.find(what) - config = parse_config - ret = [] - return ret if config==nil - - config.each {|key,value| - ret << Log.new(key,value) if key==what || what==:all + YastCache.fetch(self,what) { + config = parse_config || {} + ret = [] + config.each {|key,value| + ret << Log.new(key,value) if key==what || what==:all + } + unless what==:all + if ret.size >= 1 + Rails.logger.error "There are more results for #{what} -> #{ret.inspect} Taking the first one..." + ret = ret.first + else + ret = nil + end + end + ret } - - if what == :all || ret.blank? - return ret - else - raise "#{what} not found in configuration file" if ret.blank? - Rails.logger.error "There are more results for #{what} -> #{ret.inspect} Taking the first one..." if ret.size > 1 - return ret.first - end end # diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/app/models/metric.rb new/www/app/models/metric.rb --- old/www/app/models/metric.rb 2011-02-01 10:49:25.000000000 +0100 +++ new/www/app/models/metric.rb 2011-04-29 18:23:25.000000000 +0200 @@ -205,24 +205,29 @@ # Metric.find(id) # Where id is host:group:name (whithout rrd extension) def self.find(what, opts={}) - case what - when :all then opts.empty? ? find_all : find_multiple(opts) - # in this case, the options are the first - # parameter - when Hash then find_multiple(what.merge(opts)) - when String - find_multiple({:id => what}).first rescue nil - else nil - end + return find_all if what == :all && opts.empty? + YastCache.fetch(self,what,opts) { + case what + when :all then opts.empty? ? find_all : find_multiple(opts) + # in this case, the options are the first + # parameter + when Hash then find_multiple(what.merge(opts)) + when String + find_multiple({:id => what}).first rescue nil + else nil + end + } end # find all values def self.find_all - ret = [] - rrd_files.each do |path| - ret << Metric.new(path) - end - ret + YastCache.fetch(self, :all) { + ret = [] + rrd_files.each do |path| + ret << Metric.new(path) + end + ret + } end def self.find_multiple(opts) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/app/models/plugin.rb new/www/app/models/plugin.rb --- old/www/app/models/plugin.rb 2011-02-01 10:49:11.000000000 +0100 +++ new/www/app/models/plugin.rb 2011-04-29 18:23:25.000000000 +0200 @@ -63,25 +63,27 @@ # "id" is the plugin name # def self.find(what) - models = [] - ret = [] - resources = Resource.find :all - resources.each {|resource| - name = resource.href.split("/").last - models << (name+"_state").classify if name==what || what==:all - } + YastCache.fetch(self,what) { + models = [] + ret = [] + resources = Resource.find :all + resources.each {|resource| + name = resource.href.split("/").last + models << (name+"_state").classify if name==what || what==:all + } - models.each {|model| - status = Object.const_get(model) rescue $! - if status.class != NameError && status.respond_to?(:read) - stat = status.read - ret << Plugin.new(stat[:level], stat[:message_id], - stat[:short_description], stat[:long_description], stat[:details], - stat[:confirmation_host], stat[:confirmation_link], - stat[:confirmation_label], stat[:confirmation_kind] ) unless stat.blank? - end + models.each {|model| + status = Object.const_get(model) rescue $! + if status.class != NameError && status.respond_to?(:read) + stat = status.read + ret << Plugin.new(stat[:level], stat[:message_id], + stat[:short_description], stat[:long_description], stat[:details], + stat[:confirmation_host], stat[:confirmation_link], + stat[:confirmation_label], stat[:confirmation_kind] ) unless stat.blank? + end + } + ret } - return ret end # converts the status to xml diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/config/resources/graphs.yml new/www/config/resources/graphs.yml --- old/www/config/resources/graphs.yml 2010-08-27 14:58:55.000000000 +0200 +++ new/www/config/resources/graphs.yml 2011-04-19 11:37:42.000000000 +0200 @@ -2,4 +2,12 @@ controller: graphs singular: false policy: org.opensuse.yast.system.status +#cache: +# enabled: true/false +# priority: -100..100 +# reload_after: seconds (0 == do not reload) +cache: + enabled: true + priority: 20 + reload_after: 360 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/config/resources/metrics.yml new/www/config/resources/metrics.yml --- old/www/config/resources/metrics.yml 2010-08-27 14:58:55.000000000 +0200 +++ new/www/config/resources/metrics.yml 2011-04-19 11:37:48.000000000 +0200 @@ -2,4 +2,11 @@ controller: metrics singular: false policy: org.opensuse.yast.system.status - +#cache: +# enabled: true/false +# priority: -100..100 +# reload_after: seconds (0 == do not reload) +cache: + enabled: true + priority: 20 + reload_after: 360 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/config/resources/plugins.yml new/www/config/resources/plugins.yml --- old/www/config/resources/plugins.yml 2010-08-27 14:58:55.000000000 +0200 +++ new/www/config/resources/plugins.yml 2011-04-19 11:37:55.000000000 +0200 @@ -3,3 +3,11 @@ singular: false policy: org.opensuse.yast.system.status +#cache: +# enabled: true/false +# priority: -100..100 +# reload_after: seconds (0 == do not reload) +cache: + enabled: true + priority: 20 + reload_after: 360 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/test/unit/graph_test.rb new/www/test/unit/graph_test.rb --- old/www/test/unit/graph_test.rb 2010-08-27 14:58:55.000000000 +0200 +++ new/www/test/unit/graph_test.rb 2011-04-14 09:39:35.000000000 +0200 @@ -64,6 +64,7 @@ end def test_finders + Metric.stubs(:collectd_running?).returns(true) Graph.stubs(:parse_config).returns(PARSE_CONFIG_1) ret = Graph.find(:all) @@ -82,6 +83,7 @@ end def test_find_limits + Metric.stubs(:collectd_running?).returns(true) Graph.stubs(:parse_config).returns(PARSE_CONFIG_2) ret = Graph.find_limits('cpu-0+cpu-user') assert_equal 1, ret.size @@ -99,10 +101,9 @@ end def test_check_limits_and_xml + Metric.stubs(:collectd_running?).returns(true) Graph.stubs(:parse_config).returns(PARSE_CONFIG_3) - graph = Graph.find('CPU', true) - - graph.stubs(:read_data).with('waerden+cpu-0+cpu-idle').returns({ "value"=> + Graph.stubs(:read_data).with('waerden+cpu-0+cpu-idle').returns({ "value"=> {Time.at(1252071700) =>"6.1514301440e+01".to_f, Time.at(1252071690) =>"6.1518643200e+01".to_f, Time.at(1252071680) =>"6.1513154560e+01".to_f, @@ -112,11 +113,10 @@ Time.at(1252071660) =>"6.1664133120e+01".to_f, Time.at(1252071750) =>"6.1545021440e+01".to_f, Time.at(1252071760) =>"6.1678837760e+01".to_f}, - "interval" => 10, "starttime" => Time.at(1252071660) }) - graph.stubs(:read_data).with('waerden+cpu-0+cpu-user').returns({ "value"=> + Graph.stubs(:read_data).with('waerden+cpu-0+cpu-user').returns({ "value"=> {Time.at(1252071700) =>"6.1514301440e+01".to_f, Time.at(1252071690) =>"6.1518643200e+01".to_f, Time.at(1252071680) =>"6.1513154560e+01".to_f, @@ -126,10 +126,12 @@ Time.at(1252071660) =>"6.1664133120e+01".to_f, Time.at(1252071750) =>"6.1545021440e+01".to_f, Time.at(1252071760) =>"6.1678837760e+01".to_f}, - "interval" => 10, "starttime" => Time.at(1252071660) }) + graph = Graph.find('CPU', true) + + xml = Builder::XmlMarkup.new xml.instruct! diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/www/test/unit/log_test.rb new/www/test/unit/log_test.rb --- old/www/test/unit/log_test.rb 2010-08-27 14:58:55.000000000 +0200 +++ new/www/test/unit/log_test.rb 2011-04-11 12:49:05.000000000 +0200 @@ -62,7 +62,7 @@ assert ret.description == 'System messages' ret = Log.find('notfound') - assert_equal 0, ret.size + assert_equal nil, ret end def test_read_log_file ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org