puppetdb_query 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppetdb_query/mongodb.rb +27 -5
- data/lib/puppetdb_query/sync.rb +1 -1
- data/lib/puppetdb_query/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c321779c7c9b60e57efba9fda1a71e122770a77
|
4
|
+
data.tar.gz: 4740cdf7ac990def716168c2a4aad7bdef4bf30f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f25e946d438bedd94d26afcc27c11428fbffdf156d3279c6a914370b5378c6aee44af90fe15c1d428879cc808bd9ac541bad1aa4e5349e32d12382c1c02b7e5
|
7
|
+
data.tar.gz: ce06b58cb677afd03c073f49317325bdecc8352f7f47e07025f6d2e8fef4c376ab97d391cfe6a2e75da6f2a08b159fc6c374ef48300830894e4e8ebee5a38497
|
@@ -2,6 +2,18 @@ require 'time'
|
|
2
2
|
|
3
3
|
require_relative "logging"
|
4
4
|
|
5
|
+
# monkey patch mongodb to get rid of
|
6
|
+
# ".. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'. (BSON::String::IllegalKey)"
|
7
|
+
module Mongo
|
8
|
+
module Protocol
|
9
|
+
class Message
|
10
|
+
def validating_keys?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
module PuppetDBQuery
|
6
18
|
# access nodes and their facts from mongo database
|
7
19
|
# rubocop:disable Metrics/ClassLength
|
@@ -151,17 +163,27 @@ module PuppetDBQuery
|
|
151
163
|
# update or insert facts for given node name
|
152
164
|
#
|
153
165
|
# @param node [String] node name
|
154
|
-
# @param facts [
|
166
|
+
# @param facts [Hash] facts for the node
|
155
167
|
def node_update(node, facts)
|
156
|
-
|
168
|
+
logger.debug " updating #{node}"
|
169
|
+
connection[nodes_collection].find(_id: node).replace_one(facts, upsert: true,
|
170
|
+
bypass_document_validation: true, check_keys: false, validating_keys: false)
|
157
171
|
rescue ::Mongo::Error::OperationFailure => e
|
172
|
+
logger.warn " updating #{node} failed with: #{e.message}"
|
158
173
|
# mongodb doesn't support keys with a dot
|
159
174
|
# see https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
|
160
175
|
# as a dirty workaround we delete the document and insert it ;-)
|
161
176
|
# The dotted field .. in .. is not valid for storage. (57)
|
162
|
-
|
163
|
-
|
164
|
-
|
177
|
+
# .. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'. (BSON::String::IllegalKey)
|
178
|
+
raise e unless (e.message =~ /The dotted field / || e.message =~ /is an illegal key/)
|
179
|
+
logger.warn " we try again deleting and inserting the node"
|
180
|
+
begin
|
181
|
+
connection[nodes_collection].find(_id: node).delete_one
|
182
|
+
connection[nodes_collection].insert_one(facts.merge(_id: node),
|
183
|
+
bypass_document_validation: true, check_keys: false, validating_keys: false)
|
184
|
+
rescue
|
185
|
+
logger.error " updating #{node} failed with: #{e.message}"
|
186
|
+
end
|
165
187
|
end
|
166
188
|
|
167
189
|
# delete node data for given node name
|
data/lib/puppetdb_query/sync.rb
CHANGED
@@ -32,7 +32,7 @@ module PuppetDBQuery
|
|
32
32
|
updater.update3(timestamp - seconds_back)
|
33
33
|
timestamp = ts
|
34
34
|
rescue Timeout::Error
|
35
|
-
logger.info "syncing puppetdb nodes: now our time is up, we
|
35
|
+
logger.info "syncing puppetdb nodes: now our time is up, we finish"
|
36
36
|
return
|
37
37
|
rescue
|
38
38
|
logger.error $!
|