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.
-
#update1 ⇒ 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.
- #update_node_properties ⇒ Object
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
#update1 ⇒ 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 34 35 36 37 38 |
# File 'lib/puppetdb_query/updater.rb', line 20 def update1 logger.info "update1 started (full update)" tsb = Time.now source_nodes = source.nodes destination_nodes = destination.nodes delete_missing(destination_nodes, source_nodes) errors = false source_nodes.each do |node| begin destination.node_update(node, source.node_facts(node)) rescue errors = true logging.error $! end end tse = Time.now logger.info "update1 updated #{source_nodes.size} nodes in #{tse - tsb}" destination.("update1", tsb, tse) unless errors 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppetdb_query/updater.rb', line 44 def update2 logger.info "update2 started (full update)" tsb = Time.now source_nodes = source.nodes destination_nodes = destination.nodes delete_missing(destination_nodes, source_nodes) errors = false complete = source.facts complete.each do |node, facts| begin destination.node_update(node, facts) rescue errors = true logging.error $! end end tse = Time.now logger.info "update2 updated #{source_nodes.size} nodes in #{tse - tsb}" destination.("update2", tsb, tse) unless errors 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puppetdb_query/updater.rb', line 69 def update3() logger.info "update3 started (incremental)" tsb = Time.now source_nodes = source.nodes destination_nodes = destination.nodes delete_missing(destination_nodes, source_nodes) errors = false modified = source.nodes_update_facts_since() modified.each do |node| begin destination.node_update(node, source.node_facts(node)) rescue errors = true logging.error $! end end tse = Time.now logger.info "update3 updated #{modified.size} nodes in #{tse - tsb}" destination.("update3", tsb, tse) unless errors end |
#update_node_properties ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppetdb_query/updater.rb', line 90 def update_node_properties logger.info "update_node_properties started" tsb = Time.now source_node_properties = source.node_properties destination.node_properties_update(source_node_properties) tse = Time.now logger.info "update_node_properties updated #{source_node_properties.size} nodes " \ "in #{tse - tsb}" destination.(tsb, tse) end |