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.
-
#source_node_properties ⇒ Object
readonly
Returns the value of attribute source_node_properties.
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
update node update information.
Methods included from Logging
Constructor Details
#initialize(source, destination) ⇒ Updater
12 13 14 15 16 |
# File 'lib/puppetdb_query/updater.rb', line 12 def initialize(source, destination) @source = source @destination = destination @source_node_properties = {} 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 |
#source_node_properties ⇒ Object (readonly)
Returns the value of attribute source_node_properties.
10 11 12 |
# File 'lib/puppetdb_query/updater.rb', line 10 def source_node_properties @source_node_properties end |
Instance Method Details
#update1 ⇒ Object
update by deleting missing nodes and iterating over all nodes and update or insert facts for each one
mongo: 1598 nodes in 63.46 seconds
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppetdb_query/updater.rb', line 22 def update1 update_node_properties logger.info "update1 started (full update)" tsb = Time.now source_nodes = source_node_properties.keys destination_nodes = destination.all_nodes delete_missing(destination_nodes, source_nodes) errors = false source_nodes.each do |node| begin destination.node_update(node, source.single_node_facts(node)) rescue errors = true logger.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
mongo: 1597 nodes in 35.31 seconds
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppetdb_query/updater.rb', line 47 def update2 update_node_properties logger.info "update2 started (full update)" tsb = Time.now source_nodes = source_node_properties.keys destination_nodes = destination.all_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 logger.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
mongo: 56 nodes in 2.62 seconds
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/puppetdb_query/updater.rb', line 73 def update3() update_node_properties logger.info "update3 started (incremental)" tsb = Time.now source_nodes = source_node_properties.keys destination_nodes = destination.all_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.single_node_facts(node)) rescue errors = true logger.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
update node update information
mongo: 1602 nodes in 0.42 seconds
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/puppetdb_query/updater.rb', line 98 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 got #{source_node_properties.size} nodes " \ "in #{tse - tsb}" destination.(tsb, tse) end |