summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-03-02 12:36:37 +0200
committerSaku Ytti <saku@ytti.fi>2014-03-02 12:36:37 +0200
commit4baedb0667185fb899ad1c1f5a7782d1228807a9 (patch)
tree180d71eeeb06baaf16163aeee33b8ecd1d2e6b6e
parent465de586078eb40e6d0ae820d9da8a254c181021 (diff)
Change dynamic loading
If we use assignment method (#method=) we don't get return value, so we never know that manager fails to load. Also we do not want to rescue failures of input/output/source loading, they are catastrophic and should fail whole process, loading of model is not catastrophic.
-rw-r--r--lib/oxidized/manager.rb22
-rw-r--r--lib/oxidized/node.rb11
-rw-r--r--lib/oxidized/nodes.rb10
-rw-r--r--oxidized.gemspec2
4 files changed, 24 insertions, 21 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
diff --git a/oxidized.gemspec b/oxidized.gemspec
index 9e2e8cf..53574b3 100644
--- a/oxidized.gemspec
+++ b/oxidized.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'oxidized'
- s.version = '0.0.33'
+ s.version = '0.0.34'
s.platform = Gem::Platform::RUBY
s.authors = [ 'Saku Ytti' ]
s.email = %w( saku@ytti.fi )