kitchen_hooks 1.7.4 → 1.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/etc/config.json +1 -0
- data/lib/kitchen_hooks/app.rb +11 -4
- data/lib/kitchen_hooks/helpers.rb +0 -4
- data/lib/kitchen_hooks/helpers/sync_servers.rb +48 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef6e686e12474334dac278347907e0217f4c6988
|
4
|
+
data.tar.gz: bffb695626d6390acaf5d20aeacdc10900d819fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cce1b540f68b1c9b5c29001dc973e9237a16c02cfa5ce9c725f5169b9794dc29e09999842b4140d22c52ba741530315773b9769fe27117a9131f3c86709da66
|
7
|
+
data.tar.gz: 53b7d4986200d24f82cdac784045506583e3b0a90e3808b2f94f2880215cb8095386f7485d7e34c7e755d4fe0f65b9c8da1af02600d9ee4316612ec6cc8f21db
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.7.
|
1
|
+
1.7.5
|
data/etc/config.json
CHANGED
data/lib/kitchen_hooks/app.rb
CHANGED
@@ -43,8 +43,8 @@ module KitchenHooks
|
|
43
43
|
def self.sync!
|
44
44
|
@@sync_worker = Thread.new do
|
45
45
|
loop do
|
46
|
-
sleep @@sync_interval
|
47
46
|
process_sync
|
47
|
+
sleep @@sync_interval
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -144,13 +144,21 @@ module KitchenHooks
|
|
144
144
|
|
145
145
|
def self.process_release version=KitchenHooks::VERSION
|
146
146
|
return if db['meta_version'] == version
|
147
|
-
db.
|
147
|
+
db.lock do
|
148
|
+
db.set! 'meta_version', version
|
149
|
+
end
|
148
150
|
mark version, 'release'
|
149
151
|
end
|
150
152
|
|
151
153
|
|
152
154
|
def self.process_sync
|
153
|
-
|
155
|
+
cached_nodes = db['meta_cached_nodes']
|
156
|
+
cached_nodes ||= {}
|
157
|
+
sync_servers = SyncServers.new knives, cached_nodes
|
158
|
+
db.lock do
|
159
|
+
db.set! 'meta_cached_nodes', sync_servers.cached_nodes
|
160
|
+
end
|
161
|
+
sync = sync_servers.status
|
154
162
|
|
155
163
|
if sync.nil?
|
156
164
|
mark "Couldn't sync Chef servers (unknown issue)", 'unsynced'
|
@@ -158,7 +166,6 @@ module KitchenHooks
|
|
158
166
|
end
|
159
167
|
|
160
168
|
sync_tag = sync[:num_failures].zero? ? 'synced' : 'unsynced'
|
161
|
-
|
162
169
|
mark sync, sync_tag
|
163
170
|
end
|
164
171
|
|
@@ -6,14 +6,18 @@ require 'set'
|
|
6
6
|
class SyncServers
|
7
7
|
attr_reader :status
|
8
8
|
|
9
|
-
|
10
|
-
def initialize knives
|
9
|
+
def initialize knives, cached_nodes={}
|
11
10
|
@knives = knives
|
12
11
|
@started = Time.now
|
13
|
-
@
|
12
|
+
@cached_nodes = Hash.new { |h,k| h[k] = 0.0 }
|
13
|
+
@cached_nodes.merge! cached_nodes
|
14
|
+
@status = sync_servers.merge \
|
14
15
|
elapsed: Time.now - @started rescue nil
|
15
16
|
end
|
16
17
|
|
18
|
+
def cached_nodes
|
19
|
+
Hash[@cached_nodes]
|
20
|
+
end
|
17
21
|
|
18
22
|
|
19
23
|
private
|
@@ -25,11 +29,11 @@ private
|
|
25
29
|
end
|
26
30
|
|
27
31
|
|
28
|
-
def
|
29
|
-
@clients
|
32
|
+
def search_nodes
|
33
|
+
@clients = {}
|
30
34
|
bad_ridleys = []
|
31
35
|
|
32
|
-
@
|
36
|
+
@search_nodes ||= ridleys.each_with_index.pmap(4) do |ridley, i|
|
33
37
|
clients = ridley.client.all
|
34
38
|
|
35
39
|
begin
|
@@ -51,25 +55,33 @@ private
|
|
51
55
|
@ridleys.delete_at idx
|
52
56
|
end
|
53
57
|
|
54
|
-
return @
|
58
|
+
return @search_nodes
|
55
59
|
end
|
56
60
|
|
57
61
|
|
58
|
-
def
|
59
|
-
@
|
62
|
+
def updated_and_deleted_nodes
|
63
|
+
@all_nodes ||= search_nodes.group_by(&:name).pmap do |name, copies|
|
60
64
|
copies.sort_by do |c|
|
61
65
|
time = c.automatic.ohai_time
|
62
66
|
time.is_a?(Float) ? time : -1.0
|
63
67
|
end.last
|
64
68
|
end
|
69
|
+
|
70
|
+
@updated_nodes ||= @all_nodes.select do |n|
|
71
|
+
n.automatic.ohai_time.to_f > @cached_nodes[n.name]
|
72
|
+
end
|
73
|
+
|
74
|
+
@deleted_nodes ||= @cached_nodes.keys - @all_nodes.map(&:name)
|
75
|
+
|
76
|
+
return @updated_nodes, @deleted_nodes
|
65
77
|
end
|
66
78
|
|
67
79
|
|
68
80
|
def sync_servers
|
69
|
-
nodes =
|
81
|
+
nodes, deleted = updated_and_deleted_nodes
|
70
82
|
failures = Set.new
|
71
83
|
|
72
|
-
nodes.peach(8) do |n|
|
84
|
+
nodes.shuffle.peach(8) do |n|
|
73
85
|
n.reload
|
74
86
|
|
75
87
|
ridleys.peach(4) do |ridley|
|
@@ -84,18 +96,40 @@ private
|
|
84
96
|
rescue puts('WARNING: Client sync failed for node "%s"' % n.name)
|
85
97
|
end
|
86
98
|
|
87
|
-
|
99
|
+
if failures.include? n.name
|
100
|
+
puts 'ERROR: Node sync failed for node "%s"' % n.name
|
101
|
+
else
|
102
|
+
puts 'Synced node "%s"' % n.name
|
103
|
+
end
|
88
104
|
end unless @ridleys.length == 1
|
89
105
|
|
106
|
+
successes = []
|
107
|
+
nodes.each do |n|
|
108
|
+
next if failures.include? n.name
|
109
|
+
@cached_nodes[n.name] = n.automatic.ohai_time.to_f
|
110
|
+
successes << n
|
111
|
+
end
|
112
|
+
|
113
|
+
deleted.each do |n|
|
114
|
+
puts 'Deleting node "%s"' % n
|
115
|
+
ridleys.peach(4) do |ridley|
|
116
|
+
ridley.node.delete n rescue \
|
117
|
+
puts('WARNING: Could not delete node "%s"' % n)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
90
121
|
puts 'Sync completed'
|
91
122
|
return {
|
123
|
+
deleted: deleted,
|
92
124
|
failures: failures,
|
125
|
+
successes: successes,
|
93
126
|
num_successes: nodes.length - failures.length,
|
94
127
|
num_failures: failures.length,
|
128
|
+
num_deletions: deleted.length,
|
95
129
|
num_nodes: nodes.length
|
96
130
|
}
|
97
|
-
rescue
|
98
|
-
|
131
|
+
# rescue
|
132
|
+
# return nil
|
99
133
|
end
|
100
134
|
|
101
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen_hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Clemmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hipchat
|