-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery_resolvers.rb
More file actions
382 lines (360 loc) · 12.7 KB
/
query_resolvers.rb
File metadata and controls
382 lines (360 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# frozen_string_literal: true
# Query module
module UC3Query
# Resolve special query columns in table displays
class QueryResolvers
def self.default_resolver(row)
row
end
def self.storage_mgt_disabled?
UC3::UC3Client.dbsnapshot_stack?
end
def self.object_delete_disabled?
UC3::UC3Client.dbsnapshot_stack?
end
def self.collection_purge_disabled?
UC3::UC3Client.dbsnapshot_stack? || UC3::UC3Client.prod_stack?
end
def self.obj_info_resolver(row)
row['metadata'] = []
row['metadata'] << "What: #{row['erc_what']}"
row['metadata'] << "Who: #{row['erc_who']}"
row['metadata'] << "When: #{row['erc_when']}"
row['metadata'] << "Own: #{row['name']}"
row['actions'] = []
row['actions'] << {
value: 'Trigger Replication',
href: "/queries-update/replic/trigger?inv_object_id=#{row['inv_object_id']}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
row
end
def self.obj_node_resolver(row)
pstr = "?inv_object_id=#{row['inv_object_id']}&inv_node_id=#{row['node_id']}"
row['description'] = [row['node_number'], row['description'], row['acceess_mode']]
row['actions'] = []
row['actions'] << {
value: 'Re-audit All Files',
href: "/queries-update/audit/reset#{pstr}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
row['actions'] << {
value: 'Re-audit Unverified',
href: "/queries-update/audit/reset-unverified#{pstr}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
if row['role'] == 'primary'
row['actions'] << {
value: 'Get Manifest',
href: "/ops/storage/manifest?node_number=#{row['node_number']}&ark=#{row['ark']}",
cssclass: 'button',
title: 'Download the XML *storage manifest* representation of a object on a specific storage node.' \
'This request will be forwarded to the storage service.',
disabled: storage_mgt_disabled?
}
row['actions'] << {
value: "Get Ingest Checkm (v#{row['version_number']})",
href: "/ops/storage/ingest-checkm?node_number=#{row['node_number']}" \
"&ark=#{row['ark']}&version_number=#{row['version_number']}",
cssclass: 'button',
title: 'Download an *ingest manifest checkm* representation of an object on a specific storage node. ' \
'This file could be utilized to re-ingest an object under a new ark.',
disabled: storage_mgt_disabled?
}
row['actions'] << {
value: 'Get Storage Manifest Yaml',
href: "/ops/storage/manifest-yaml?node_number=#{row['node_number']}&ark=#{row['ark']}",
cssclass: 'button',
title: 'Download the XML *storage manifest* representation of a object on a specific storage node. ' \
'This request will be forwarded to the storage service. ' \
'The manifest xml file will be converted to a user-friendly yaml format.',
disabled: storage_mgt_disabled?
}
row['actions'] << {
value: 'Rebuild Inventory',
href: "/ops/inventory/rebuild?node_number=#{row['node_number']}&ark=#{row['ark']}",
cssclass: 'button button_red',
confmsg: %(Are you sure you want to rebuild the INV entry for this ark?
A new inv_object_id will be assigned.),
post: true,
disabled: storage_mgt_disabled?
}
row['actions'] << {
value: 'Clear Scan Entries for Ark',
href: "/queries-update/storage-maints/clear-entries-for-ark?ark=#{row['ark']}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
row['actions'] << {
value: 'Delete Object',
href: "/ops/inventory/delete?node_number=#{row['node_number']}&ark=#{row['ark']}",
cssclass: 'button button_red',
confmsg: 'Have you consulted the Merritt Product Manager and received approval to perform the deletion?',
post: true,
disabled: object_delete_disabled?
}
end
row
end
def self.file_info_resolver(row)
row['actions'] = []
row['actions'] << {
value: 'Fixity Benchmark',
href: "/ops/storage/benchmark-fixity?inv_file_id=#{row['inv_file_id']}",
cssclass: 'button',
disabled: storage_mgt_disabled?
}
row
end
def self.collections_nodes_resolver(row)
prim = UC3S3::ConfigObjectsClient.client.storage_node_for_mnemonic(row['mnemonic'])
row['primary_node'] = prim
row['actions'] = []
row['actions'] << {
value: 'Manage Nodes',
href: "/ops/collections/storage-node-config/#{row['mnemonic']}_Storage_Nodes" \
"?inv_collection_id=#{row['id']}&primary=#{prim}&mnemonic=#{row['mnemonic']}",
cssclass: 'button',
disabled: storage_mgt_disabled? || prim.empty?
}
row['status'] = 'FAIL' if prim.empty?
row
end
def self.single_collection_nodes_resolver(row)
row['pct_complete'] = row['total'].to_i.zero? ? 100.0 : 100.0 * row['count'].to_i / row['total'].to_i
row['actions'] = []
if row['role'] == 'secondary'
row['actions'] << {
value: 'Remove Secondary Node',
href: "/queries-update/storage-nodes/delete?inv_collection_id=#{row['inv_collection_id']}" \
"&node_number=#{row['node_number']}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
end
if row['role'] == 'obsolete'
row['actions'] << {
value: 'Start Deletion Process',
title: 'Initiate a process to delete data from this node. Deletions will occur in batches of 50.',
href: "/ops/storage-nodes/remove-obsolete?inv_collection_id=#{row['inv_collection_id']}" \
"&node_number=#{row['node_number']}",
cssclass: 'button button_red',
post: true,
disabled: storage_mgt_disabled?
}
end
row
end
def self.audit_status_resolver(row)
row['actions'] = []
if row['acount'].positive? && !%w[processing unknown].include?(row['astatus'])
row['actions'] << {
value: 'Re-try Audit',
href: "/queries-update/audit/status-reset?status=#{row['astatus']}",
post: true,
cssclass: 'button',
disabled: storage_mgt_disabled?
}
end
if row['acount'].positive?
row['acount'] = {
value: row['acount'],
href: "/ops/db-queue/audit/counts-by-state/objlist?status=#{row['astatus']}"
}
end
row
end
def self.storage_scan_resolver(row)
row['nodedesc'] = [
row['node_number'],
row['description'],
row['access_mode'],
"Count: #{row['pcount']}"
]
row['actions'] = []
row['actions'] << {
value: 'Scan History',
href: "/ops/storage/scans/history?node_number=#{row['node_number']}",
cssclass: 'button'
}
status = row.fetch('scan_status', '')
status = '' if status.nil?
node = row.fetch('node_number', 0).to_i
if %w[completed cancelled].include?(status) || status.empty?
unless [9501, 9502].include?(node)
row['actions'] << {
value: 'Start Scan',
href: "/ops/storage/scans/start?node_number=#{node}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
end
if [9501, 9502, 7777].include?(node)
keylist = if node == 7777
'8888:scanlist/7777.log'
else
"7001:scanlist/#{node}.log"
end
row['actions'] << {
value: 'Start Scan Keylist',
href: "/ops/storage/scans/start?node_number=#{node}&keylist=#{keylist}",
title: "Start a scan using the scanlist file in cloud storage #{keylist}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
end
row['percent_complete'] = ''
end
if %w[pending].include?(status)
row['actions'] << {
value: 'Resume Scan',
href: "/ops/storage/scans/resume?inv_scan_id=#{row['inv_scan_id']}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
end
if %w[pending started].include?(status)
row['actions'] << {
value: 'Cancel Scan',
href: "/ops/storage/scans/cancel?inv_scan_id=#{row['inv_scan_id']}",
cssclass: 'button',
post: true,
disabled: storage_mgt_disabled?
}
end
if row.fetch('num_review', 0).positive?
row['num_review'] = {
value: row['num_review'],
href: "/ops/storage/scans/review-state?node_number=#{node}&status=review"
}
end
if row.fetch('num_hold', 0).positive?
row['num_hold'] = {
value: row['num_hold'],
href: "/ops/storage/scans/review-state?node_number=#{node}&status=hold"
}
end
if row.fetch('num_deletes', 0).positive?
row['num_deletes'] = {
value: row['num_deletes'],
href: "/ops/storage/scans/review-state?node_number=#{node}&status=delete"
}
end
if row.fetch('num_maints', 0).positive?
row['num_maints'] = {
value: row['num_maints'],
href: "/ops/storage/scans/review?node_number=#{node}"
}
end
row
end
def self.storage_scan_review_resolver(row)
row['s3key_annotated'] = [
row['s3key'],
"Node: #{row['node_number']}",
row['file_created'],
"Size: #{row['size']}"
]
if row['inv_object_id']
row['s3key_annotated'] << {
value: row['inv_object_id'],
href: "/queries/repository/object?inv_object_id=#{row['inv_object_id']}"
}
end
row['note'] = [
"Type: #{row['maint_type']}",
"Status: #{row['maint_status']}",
"Note: #{row['note']}"
]
row['actions'] = []
if row['maint_status'] != 'delete'
row['actions'] << {
value: 'Mark for Delete',
href: "/queries-update/storage-maints/update-status?maint_id=#{row['maint_id']}&status=delete",
post: true,
cssclass: 'button',
disabled: storage_mgt_disabled?
}
end
if row['maint_status'] != 'review'
row['actions'] << {
value: 'Mark for Review',
href: "/queries-update/storage-maints/update-status?maint_id=#{row['maint_id']}&status=review",
post: true,
cssclass: 'button',
disabled: storage_mgt_disabled?
}
end
if row['maint_status'] != 'hold'
row['actions'] << {
value: 'Mark for Hold',
href: "/queries-update/storage-maints/update-status?maint_id=#{row['maint_id']}&status=hold",
post: true,
cssclass: 'button',
disabled: storage_mgt_disabled?
}
end
if row['maint_status'] == 'delete'
row['actions'] << {
value: 'Process Delete',
href: "/ops/storage/scans/delete?maint_id=#{row['maint_id']}",
post: true,
cssclass: 'button button_red',
disabled: storage_mgt_disabled?
}
end
row
end
def self.storage_scan_csv_resolver(row)
arr = row.fetch('s3key', '').split('|')
row['key_ark'] = arr[0]
row['key_ver'] = arr[1]
m = %r{^(producer|system)/(.*)$}.match(arr[2])
if m
row['key_folder'] = m[1]
row['key_file'] = m[2]
else
row['key_file'] = arr[2]
end
row
end
def self.collections_resolver(row)
begin
return row unless UC3Queue::ZKClient.client.enabled
locked_coll = UC3Queue::ZKClient.client.locked_collections
row['locked'] = locked_coll.fetch("#{row['mnemonic']}_content", false)
row['actions'] = []
unless row['locked']
row['actions'] << {
value: 'Lock Collection',
href: "/ops/zk/collection/lock?mnemonic=#{row['mnemonic']}_content",
post: true,
cssclass: 'button'
}
end
if row['locked']
row['actions'] << {
value: 'Unlock Collection',
href: "/ops/zk/collection/unlock?mnemonic=#{row['mnemonic']}_content",
post: true,
cssclass: 'button'
}
end
rescue StandardError
# handle zk errors silently
end
row
end
end
end