diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oxidized/manager.rb | 22 | ||||
-rw-r--r-- | lib/oxidized/node.rb | 11 | ||||
-rw-r--r-- | lib/oxidized/nodes.rb | 10 |
3 files changed, 23 insertions, 20 deletions
diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb index 5065617..9352eaf 100644 --- a/lib/oxidized/manager.rb +++ b/lib/oxidized/manager.rb @@ -6,11 +6,15 @@ module Oxidized class Manager class << self def load dir, file - require File.join dir, file+'.rb' - obj, Oxidized.mgr.loader = Oxidized.mgr.loader, nil - k = obj[:class].new - k.setup if k.respond_to? :setup - { file => obj[:class] } + begin + require File.join dir, file+'.rb' + obj, Oxidized.mgr.loader = Oxidized.mgr.loader, nil + k = obj[:class].new + k.setup if k.respond_to? :setup + { file => obj[:class] } + rescue LoadError + {} + end end end attr_reader :input, :output, :model, :source @@ -21,22 +25,22 @@ module Oxidized @model = {} @source = {} end - def input= method + def add_input method method = Manager.load Config::InputDir, method return false if method.empty? @input.merge! method end - def output= method + def add_output method method = Manager.load Config::OutputDir, method return false if method.empty? @output.merge! method end - def model= _model + def add_model _model _model = Manager.load Config::ModelDir, _model return false if _model.empty? @model.merge! _model end - def source= _source + def add_source _source return nil if @source.key? _source _source = Manager.load Config::SourceDir, _source return false if _source.empty? diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 3027ccd..5a8eb36 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -109,7 +109,7 @@ module Oxidized inputs = (opt[:input] or CFG.input[:default]) inputs.split(/\s*,\s*/).map do |input| if not Oxidized.mgr.input[input] - Oxidized.mgr.input = input or raise MethodNotFound, "#{input} not found" + Oxidized.mgr.add_input input or raise MethodNotFound, "#{input} not found for node #{ip}" end Oxidized.mgr.input[input] end @@ -118,18 +118,17 @@ module Oxidized def resolve_output opt output = (opt[:output] or CFG.output[:default]) if not Oxidized.mgr.output[output] - Oxidized.mgr.output = output or raise MethodNotFound, "#{output} not found" + Oxidized.mgr.add_output output or raise MethodNotFound, "#{output} not found for node #{ip}" end Oxidized.mgr.output[output] end def resolve_model opt model = (opt[:model] or CFG.model) - mgr = Oxidized.mgr - if not mgr.model[model] - mgr.model = model or raise ModelNotFound, "#{model} not found" + if not Oxidized.mgr.model[model] + Oxidized.mgr.add_model model or raise ModelNotFound, "#{model} not found for node #{ip}" end - mgr.model[model].new + Oxidized.mgr.model[model].new end end diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 9a3d3bd..0d9fb47 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -9,14 +9,14 @@ module Oxidized with_lock do new = [] @source = CFG.source[:default] - Oxidized.mgr.source = @source + Oxidized.mgr.add_source @source Oxidized.mgr.source[@source].new.load.each do |node| begin - n = Node.new node - rescue LoadError => err - Log.warn 'load error %s with node %s' % [err.message, node] + _node = Node.new node + new.push _node + rescue ModelNotFound => err + Log.error "node %s raised %s with message %s" % [node, err.class, err.message] end - new.push n if n end replace new end |