summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-05-07 15:04:28 +0300
committerSaku Ytti <saku@ytti.fi>2014-05-07 15:04:28 +0300
commitf81050b7dd9cc6c9a41919f11d716a3ad71de8e9 (patch)
treea978d04b15c7048dc3843a69d7eae331e18f0c73
parent59aa0a256b1d521ac8f7fdb088a46580efa2f28c (diff)
Save stats/last status during Nodes#load0.0.58
We probably should just axe Node#last, as Node#stats contains all it does and more. However it would need changing web views and I'm too lazy for that right now. Perhaps Nodes/Node also needs some unique ID so two instances of Nodes can be compared exactly. Right now copying the old stats relies on name being identical, but can we trust name to be unique? Even with groups support?
-rw-r--r--lib/oxidized/nodes.rb21
-rw-r--r--oxidized.gemspec2
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb
index 46630b8..2ea1891 100644
--- a/lib/oxidized/nodes.rb
+++ b/lib/oxidized/nodes.rb
@@ -32,7 +32,7 @@ module Oxidized
Log.error "node %s is not resolvable, raised %s with message '%s'" % [node, err.class, err.message]
end
end
- replace new
+ size == 0 ? replace(new) : update_nodes(new)
end
end
@@ -124,5 +124,24 @@ module Oxidized
Nodes.new :nodes => select { |node| not node.running? }
end
+ # walks list of new nodes, if old node contains same name, adds last and
+ # stats information from old to new.
+ #
+ # @todo can we trust name to be unique identifier, what about when groups are used?
+ # @param [Array] nodes Array of nodes used to replace+update old
+ def update_nodes nodes
+ old = self.dup
+ replace(nodes)
+ each do |node|
+ begin
+ if i = old.find_node_index(node.name)
+ node.stats = old[i].stats
+ node.last = old[i].last
+ end
+ rescue Oxidized::NodeNotFound
+ end
+ end
+ end
+
end
end
diff --git a/oxidized.gemspec b/oxidized.gemspec
index 7e89ad7..86ef906 100644
--- a/oxidized.gemspec
+++ b/oxidized.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'oxidized'
- s.version = '0.0.57'
+ s.version = '0.0.58'
s.platform = Gem::Platform::RUBY
s.authors = [ 'Saku Ytti' ]
s.email = %w( saku@ytti.fi )