Class: PuppetDBQuery::Updater
- Inherits:
-
Object
- Object
- PuppetDBQuery::Updater
- Includes:
- Logging
- Defined in:
- lib/puppetdb_query/updater.rb
Overview
update nodes data from source to destination
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source, destination) ⇒ Updater
constructor
A new instance of Updater.
-
#update ⇒ Object
update by deleting missing nodes and iterating over all nodes and update or insert facts for each one.
-
#update2 ⇒ Object
update by deleting missing nodes and get a complete map of nodes with facts and update or insert facts for each one.
-
#update3(last_update_timestamp) ⇒ Object
update by deleting missing nodes and getting a list of nodes with changed facts, iterate over them and update or insert facts for each one.
Methods included from Logging
Constructor Details
#initialize(source, destination) ⇒ Updater
Returns a new instance of Updater.
11 12 13 14 |
# File 'lib/puppetdb_query/updater.rb', line 11 def initialize(source, destination) @source = source @destination = destination end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
9 10 11 |
# File 'lib/puppetdb_query/updater.rb', line 9 def destination @destination end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/puppetdb_query/updater.rb', line 8 def source @source end |
Instance Method Details
#update ⇒ Object
update by deleting missing nodes and iterating over all nodes and update or insert facts for each one
335.6 seconds: update time for 1561 nodes
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppetdb_query/updater.rb', line 20 def update source_nodes = source.nodes destination_nodes = destination.nodes (destination_nodes - source_nodes).each do |node| destination.node_delete(node) end source_nodes.each do |node| begin destination.node_update(node, source.node_facts(node)) rescue logging.error $! end end end |
#update2 ⇒ Object
update by deleting missing nodes and get a complete map of nodes with facts and update or insert facts for each one
166.4 seconds: update time for 1561 nodes
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppetdb_query/updater.rb', line 39 def update2 source_nodes = source.nodes destination_nodes = destination.nodes (destination_nodes - source_nodes).each do |node| destination.node_delete(node) end complete = source.facts complete.each do |node, facts| begin destination.node_update(node, facts) rescue logging.error $! end end end |
#update3(last_update_timestamp) ⇒ Object
update by deleting missing nodes and getting a list of nodes with changed facts, iterate over them and update or insert facts for each one
update time depends extremly on the number of changed nodes
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/puppetdb_query/updater.rb', line 59 def update3() source_nodes = source.nodes destination_nodes = destination.nodes (destination_nodes - source_nodes).each do |node| destination.node_delete(node) end modified = source.nodes_update_facts_since() modified.each do |node| begin destination.node_update(node, source.node_facts(node)) rescue logging.error $! end end modified.size end |