Skip to content

Commit b13305e

Browse files
committed
handle collection release
1 parent fdb058e commit b13305e

File tree

6 files changed

+155
-103
lines changed

6 files changed

+155
-103
lines changed

src-colladmin/actions/ingest_collection_locks_action.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def table_headers
3737
end
3838

3939
def table_types
40-
['', 'colllist', '', '', 'colllock', 'dataint', 'collqitems']
40+
if ZookeeperListAction.migration_m1?
41+
['', 'colllist', '', '', 'colllock', 'dataint', 'collqitems-mrtzk']
42+
else
43+
['', 'colllist', '', '', 'colllock', 'dataint', 'collqitems-legacy']
44+
end
4145
end
4246

4347
def table_rows(_body)

src-colladmin/actions/queue_action.rb

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,81 +11,4 @@ def initialize(config, action, path, myparams, endpoint)
1111
endpoint = endpoint.gsub(/coll$/, coll) unless coll.empty?
1212
super(config, action, path, myparams, endpoint)
1313
end
14-
end
15-
16-
# Collection Admin Task class - see config/actions.yml for description
17-
class CollIterateQueueAction < ZookeeperAction
18-
def initialize(config, action, path, myparams)
19-
super(config, action, path, myparams)
20-
@coll = myparams.fetch('coll', '')
21-
end
22-
23-
def perform_action
24-
if ZookeeperListAction.migration_m1?
25-
ql = QueueList.new(@zk, { deletable: true })
26-
puts "PROF: #{ql.profiles.keys}"
27-
else
28-
MerrittZK::LegacyIngestJob.list_jobs_as_json(@zk) do |job|
29-
puts "TEST COLL #{@coll}: #{job}"
30-
end
31-
end
32-
{ message: 'queue release submitted' }.to_json
33-
end
34-
end
35-
36-
# Collection Admin Task class - see config/actions.yml for description
37-
class IterateQueueAction < ZookeeperAction
38-
def initialize(config, action, path, myparams)
39-
super(config, action, path, myparams)
40-
@queue = myparams.fetch('queue', 'na')
41-
@reload_path = myparams.fetch('reload_path', 'na')
42-
end
43-
44-
def legacy_delete(job)
45-
status = job.fetch(:status, '')
46-
path = job.fetch(:path, '')
47-
return unless %w[Completed Deleted].include?(status)
48-
return if path.empty?
49-
50-
@zk.delete(path)
51-
end
52-
53-
def perform_action
54-
if @queue == 'queues-acc' && ZookeeperListAction.migration_m3?
55-
MerrittZK::Access.list_jobs_as_json(@zk).each do |job|
56-
qn = job.fetch(:queueNode, MerrittZK::Access::SMALL).gsub(%r{^/access/}, '')
57-
j = MerrittZK::Access.new(qn, job.fetch(:id, ''))
58-
j.load(@zk)
59-
next unless j.status.deletable?
60-
61-
j.delete(@zk)
62-
end
63-
elsif @queue == 'queues-acc'
64-
MerrittZK::LegacyAccessJob.list_jobs_as_json(@zk).each do |job|
65-
legacy_delete(job)
66-
end
67-
elsif @queue == 'queues-inv' && ZookeeperListAction.migration_m1?
68-
# no action
69-
elsif @queue == 'queues-inv'
70-
MerrittZK::LegacyInventoryJob.list_jobs_as_json(@zk).each do |job|
71-
legacy_delete(job)
72-
end
73-
elsif ZookeeperListAction.migration_m1?
74-
ql = QueueList.new(@zk, { deletable: true })
75-
ql.batches.each_key do |bid|
76-
batch = MerrittZK::Batch.find_batch_by_uuid(@zk, bid)
77-
batch.load(@zk)
78-
next unless batch.status.deletable?
79-
80-
batch.delete(@zk)
81-
end
82-
else
83-
MerrittZK::LegacyIngestJob.list_jobs_as_json(@zk).each do |job|
84-
legacy_delete(job)
85-
end
86-
end
87-
{
88-
redirect_location: "/web/collIndex.html?path=#{@reload_path}"
89-
}.to_json
90-
end
91-
end
14+
end

src-colladmin/actions/zookeeper_action.rb

Lines changed: 116 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,39 +194,39 @@ def prefix
194194

195195
attr_reader :qpath
196196

197-
def bytes
198-
data = @zk.get(qpath)
197+
def bytes(p)
198+
data = @zk.get(p)
199199
return if data.nil?
200200

201201
data[0].bytes
202202
end
203203

204-
def orig_stat
205-
return if bytes.nil?
204+
def orig_stat(p)
205+
return if bytes(p).nil?
206206

207-
bytes[0]
207+
bytes(p)[0]
208208
end
209209

210-
def orig_stat_name
211-
return if orig_stat.nil?
210+
def orig_stat_name(p)
211+
return if orig_stat(p).nil?
212212

213-
legacy_status_vals[orig_stat]
213+
legacy_status_vals[orig_stat(p)]
214214
end
215215

216-
def write_status(status)
217-
pbytes = bytes
216+
def write_status(p, status)
217+
pbytes = bytes(p)
218218
pbytes[0] = status
219-
@zk.set(qpath, pbytes.pack('CCCCCCCCCc*'))
219+
@zk.set(p, pbytes.pack('CCCCCCCCCc*'))
220220
end
221221

222-
def set_status(status)
222+
def set_legacy_status(p, status)
223223
i = legacy_status_vals.find_index(status)
224224
return if i.nil?
225225

226-
orig_name = orig_stat_name
226+
orig_name = orig_stat_name(p)
227227
return { message: 'Illegal status' }.to_json unless check_status(orig_name)
228228

229-
write_status(i)
229+
write_status(p, i)
230230
{ message: "Status #{orig_name} -- > #{status}" }.to_json
231231
end
232232

@@ -239,7 +239,7 @@ def check_status(_status)
239239
# Legacy Ingest queue action
240240
class ZkRequeueLegacyAction < LegacyZkAction
241241
def perform_action
242-
set_status('Pending')
242+
set_legacy_status(qpath, 'Pending')
243243
end
244244

245245
def check_status(status)
@@ -251,7 +251,7 @@ def check_status(status)
251251
# Legacy Ingest queue action
252252
class ZkDeleteLegacyAction < LegacyZkAction
253253
def perform_action
254-
set_status('Deleted')
254+
set_legacy_status(qpath, 'Deleted')
255255
end
256256

257257
def check_status(status)
@@ -263,7 +263,7 @@ def check_status(status)
263263
# Legacy Ingest queue action
264264
class ZkHoldLegacyAction < LegacyZkAction
265265
def perform_action
266-
set_status('Held')
266+
set_legacy_status(qpath, 'Held')
267267
end
268268

269269
def check_status(status)
@@ -275,7 +275,7 @@ def check_status(status)
275275
# Legacy Ingest queue action
276276
class ZkReleaseLegacyAction < LegacyZkAction
277277
def perform_action
278-
set_status('Pending')
278+
set_legacy_status(qpath, 'Pending')
279279
end
280280

281281
def check_status(status)
@@ -290,11 +290,108 @@ def perform_action
290290
if ZookeeperListAction.migration_m1?
291291
jobs = MerrittZK::Job.list_jobs_as_json(@zk)
292292
else
293-
MerrittZK::LegacyIngestJob.list_jobs_as_json(@zk)
293+
jobs = MerrittZK::LegacyIngestJob.list_jobs_as_json(@zk)
294294
end
295295
jobs.each do |po|
296296
register_item(QueueEntry.new(po))
297297
end
298298
convert_json_to_table('')
299299
end
300300
end
301+
302+
# Collection Admin Task class - see config/actions.yml for description
303+
class CollIterateQueueM1Action < ZkM1Action
304+
def initialize(config, action, path, myparams)
305+
super(config, action, path, myparams)
306+
@coll = myparams.fetch('coll', '')
307+
end
308+
309+
def perform_action
310+
count = 0
311+
ql = QueueList.new(@zk, { held: true })
312+
ql.jobs.each do |j|
313+
job = MerrittZK::Job.new(j.queueId)
314+
job.load(@zk)
315+
job.set_status(@zk, MerrittZK::JobState::Pending)
316+
count += 1
317+
end
318+
{ message: "queue release submitted for #{count}" }.to_json
319+
end
320+
end
321+
322+
# Collection Admin Task class - see config/actions.yml for description
323+
class CollIterateQueueLegacyAction < LegacyZkAction
324+
def initialize(config, action, path, myparams)
325+
super(config, action, path, myparams)
326+
@coll = myparams.fetch('coll', '')
327+
end
328+
329+
def perform_action
330+
count = 0
331+
MerrittZK::LegacyIngestJob.list_jobs_as_json(@zk).each do |j|
332+
job = QueueEntry.new(j)
333+
next unless job.qstatus == 'Held'
334+
next unless job.profile == @coll
335+
set_legacy_status("/ingest/#{job.queueId}", 'Pending')
336+
count += 1
337+
end
338+
{ message: "queue release submitted for #{count}" }.to_json
339+
end
340+
end
341+
342+
# Collection Admin Task class - see config/actions.yml for description
343+
class IterateQueueAction < ZookeeperAction
344+
def initialize(config, action, path, myparams)
345+
super(config, action, path, myparams)
346+
@queue = myparams.fetch('queue', 'na')
347+
@reload_path = myparams.fetch('reload_path', 'na')
348+
end
349+
350+
def legacy_delete(job)
351+
status = job.fetch(:status, '')
352+
path = job.fetch(:path, '')
353+
return unless %w[Completed Deleted].include?(status)
354+
return if path.empty?
355+
356+
@zk.delete(path)
357+
end
358+
359+
def perform_action
360+
if @queue == 'queues-acc' && ZookeeperListAction.migration_m3?
361+
MerrittZK::Access.list_jobs_as_json(@zk).each do |job|
362+
qn = job.fetch(:queueNode, MerrittZK::Access::SMALL).gsub(%r{^/access/}, '')
363+
j = MerrittZK::Access.new(qn, job.fetch(:id, ''))
364+
j.load(@zk)
365+
next unless j.status.deletable?
366+
367+
j.delete(@zk)
368+
end
369+
elsif @queue == 'queues-acc'
370+
MerrittZK::LegacyAccessJob.list_jobs_as_json(@zk).each do |job|
371+
legacy_delete(job)
372+
end
373+
elsif @queue == 'queues-inv' && ZookeeperListAction.migration_m1?
374+
# no action
375+
elsif @queue == 'queues-inv'
376+
MerrittZK::LegacyInventoryJob.list_jobs_as_json(@zk).each do |job|
377+
legacy_delete(job)
378+
end
379+
elsif ZookeeperListAction.migration_m1?
380+
ql = QueueList.new(@zk, { deletable: true })
381+
ql.batches.each_key do |bid|
382+
batch = MerrittZK::Batch.find_batch_by_uuid(@zk, bid)
383+
batch.load(@zk)
384+
next unless batch.status.deletable?
385+
386+
batch.delete(@zk)
387+
end
388+
else
389+
MerrittZK::LegacyIngestJob.list_jobs_as_json(@zk).each do |job|
390+
legacy_delete(job)
391+
end
392+
end
393+
{
394+
redirect_location: "/web/collIndex.html?path=#{@reload_path}"
395+
}.to_json
396+
end
397+
end

src-colladmin/config/actions.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,22 @@ lock-coll:
555555
documentation: |
556556
Ingest: POST /admin/submission/freeze/{coll}
557557
migration: m2
558-
release-coll-queue-items:
558+
release-coll-queue-items-m1:
559559
link-title: Release any held items for a collection
560-
class: CollIterateQueueAction
561-
params: ["admin/release-all/queue/coll"]
560+
class: CollIterateQueueM1Action
561+
category: Queue Management
562+
sensitivity: reversible change
563+
testing: automatable
564+
description: |
565+
Release any held items for a collection.
566+
report-datatypes:
567+
- collqitems
568+
documentation: |
569+
Ingest: POST /admin/release-all/queue/{coll}
570+
migration: m2
571+
release-coll-queue-items-legacy:
572+
link-title: Release any held items for a collection (legacy)
573+
class: CollIterateQueueLegacyAction
562574
category: Queue Management
563575
sensitivity: reversible change
564576
testing: automatable

src-colladmin/lib/queue.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def to_table_row
155155
arr
156156
end
157157

158+
def queueId
159+
get_value(:queueId)
160+
end
161+
158162
def bid
159163
get_value(:bid)
160164
end
@@ -233,6 +237,15 @@ def initialize(zk, filter = {})
233237
end
234238
jobs.each do |j|
235239
job = QueueEntry.new(j)
240+
if @filter.key?(:batch)
241+
next unless job.bid == @filter[:batch]
242+
end
243+
if @filter.fetch(:deletable, false)
244+
next unless %w[Completed Deleted].include?(job.qstatus)
245+
end
246+
if @filter.fetch(:held, false)
247+
next unless %w[Held].include?(job.qstatus)
248+
end
236249
@jobs << job
237250
qb = @batches.fetch(job.bid, QueueBatch.new(job.bid, job.user))
238251
qb.add_job(job)

src-common/template/api-table.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,11 @@ function format(cell, v, type, merritt_path) {
818818
} else if (type == 'release-legacy' && v != '') {
819819
p = colladmin_root + "/lambda?path=release-queue-item-legacy&queue-path="+v;
820820
makeLink(cell, 'Release', "javascript:ajax_invoke('"+encodeURIComponent(p)+"')").addClass("ajax");
821-
} else if (type == 'collqitems' && v != '') {
822-
p = colladmin_root + "/lambda?path=release-coll-queue-items&coll="+v;
821+
} else if (type == 'collqitems-mrtzk' && v != '') {
822+
p = colladmin_root + "/lambda?path=release-coll-queue-items-m1&coll="+v;
823+
makeLink(cell, 'Release Items', "javascript:ajax_invoke('"+encodeURIComponent(p)+"')").addClass("ajax");
824+
} else if (type == 'collqitems-legacy' && v != '') {
825+
p = colladmin_root + "/lambda?path=release-coll-queue-items-legacy&coll="+v;
823826
makeLink(cell, 'Release Items', "javascript:ajax_invoke('"+encodeURIComponent(p)+"')").addClass("ajax");
824827
} else if (type == 'colllock') {
825828
var arr = v.split(",");

0 commit comments

Comments
 (0)