Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 9112e55

Browse files
committed
time based orphan report
1 parent 171a73c commit 9112e55

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

src-colladmin/actions/zookeeper_action.rb

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,42 @@ def get_data(n)
130130
end
131131
end
132132

133+
def node_datetime(n)
134+
return 'na' unless @zk.exists?(n)
135+
ctime = @zk.stat(n).ctime
136+
ctime.nil? ? 'na' : Time.at(ctime / 1000).strftime('%Y-%m-%d %H:%M:%S')
137+
end
138+
139+
def node_stat(n)
140+
return 'FAIL' unless @zk.exists?(n)
141+
ctime = @zk.stat(n).ctime
142+
return 'FAIL' if ctime.nil?
143+
Time.now - Time.at(ctime / 1000) > 3600 ? 'FAIL' : 'WARN'
144+
end
145+
133146
def test_node(path, deleteable, n)
134147
return if @zk.exists?(n)
135148

136-
result = { path: path, test: "Test: #{n} should exist", status: 'FAIL' }
137-
@test_results.append([result[:path], deleteable ? result[:path] : '', result[:test], result[:status]])
149+
result = { path: path, test: "Test: #{n} should exist", status: node_stat(path) }
150+
@test_results.append([result[:path], node_datetime(path), deleteable ? result[:path] : '', result[:test], result[:status]])
151+
@buf << "\n #{result[:test]}: #{result[:status]}" unless @buf.nil?
152+
end
153+
154+
def test_has_children(path, deleteable, n)
155+
if @zk.exists?(n)
156+
return unless @zk.children(n).empty?
157+
end
158+
159+
result = { path: path, test: "Test: #{n} should have children", status: node_stat(path) }
160+
@test_results.append([result[:path], node_datetime(path), deleteable ? result[:path] : '', result[:test], result[:status]])
138161
@buf << "\n #{result[:test]}: #{result[:status]}" unless @buf.nil?
139162
end
140163

141164
def test_not_node(path, deleteable, n)
142165
return unless @zk.exists?(n)
143166

144-
result = { path: path, test: "Test: #{n} should NOT exist", status: 'FAIL' }
145-
@test_results.append([result[:path], deleteable ? result[:path] : '', result[:test], result[:status]])
167+
result = { path: path, test: "Test: #{n} should NOT exist", status: node_stat(path) }
168+
@test_results.append([result[:path], node_datetime(path), deleteable ? result[:path] : '', result[:test], result[:status]])
146169
@buf << "\n #{result[:test]}: #{result[:status]}" unless @buf.nil?
147170
end
148171

@@ -151,6 +174,7 @@ def show_test(n)
151174
rx2 = %r{^/jobs/(jid[0-9]+)/bid$}
152175
rx3 = %r{^/jobs/(jid[0-9]+)$}
153176
rx4 = %r{^/jobs/states/[^/]*/[0-9][0-9]-(jid[0-9]+)$}
177+
rx5 = %r{^/batches/bid[0-9]+/states$}
154178

155179
case n
156180
when %r{^/batch-uuids/(.*)}
@@ -195,6 +219,8 @@ def show_test(n)
195219
test_node(n, true, "/jobs/#{jid}")
196220
@job_states_count[jid] = [] unless @job_states_count.key?(jid)
197221
@job_states_count[jid].append(n)
222+
when rx5
223+
test_has_children(n, false, n)
198224
end
199225
end
200226

@@ -245,19 +271,19 @@ def initialize(config, action, path, myparams)
245271
end
246272

247273
def table_headers
248-
%w[Path OrphanPath Test Status]
274+
%w[Path Created OrphanPath Test Status]
249275
end
250276

251277
def table_types
252-
%w[name orphan name status]
278+
%w[name datetime orphan name status]
253279
end
254280

255281
def table_rows(_body)
256282
dump_node(@zkpath)
257283
@job_states_count.each_value do |states|
258284
next unless states.length > 1
259285

260-
@test_results.append([states.to_s, '', 'Duplicate JID', 'FAIL'])
286+
@test_results.append([states.to_s, '', '', 'Duplicate JID', 'FAIL'])
261287
end
262288
@test_results
263289
end

0 commit comments

Comments
 (0)