Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 46c364f

Browse files
authored
Merge pull request #576 from CMSCompOps/rejector_changes
Rejector update
2 parents a2717bf + 01d6810 commit 46c364f

1 file changed

Lines changed: 63 additions & 33 deletions

File tree

Unified/rejector.py

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
username = getpass.getuser()
1414

1515
def rejector(url, specific, options=None):
16+
17+
if options.test:
18+
print "Test mode - no changes propagate to the production system"
1619

1720
if not componentInfo(soft=['wtc','jira']).check(): return
1821

@@ -62,19 +65,30 @@ def rejector(url, specific, options=None):
6265

6366
comment=""
6467
if options.comments: comment = ", reason: "+options.comments
65-
if options.keep:
66-
wfi.sendLog('rejector','invalidating the workflow by unified operator {}{}'.format(username, comment))
68+
if options.test:
69+
if options.keep:
70+
print 'invalidating the workflow by unified operator {}{}'.format(username, comment)
71+
else:
72+
print 'invalidating the workflow and outputs by unified operator {}{}'.format(username, comment)
73+
results = [True]
6774
else:
68-
wfi.sendLog('rejector','invalidating the workflow and outputs by unified operator {}{}'.format(username, comment))
75+
if options.keep:
76+
wfi.sendLog('rejector','invalidating the workflow by unified operator {}{}'.format(username, comment))
77+
else:
78+
wfi.sendLog('rejector','invalidating the workflow and outputs by unified operator {}{}'.format(username, comment))
6979

70-
results = invalidate(url, wfi, only_resub=True, with_output= (not options.keep))
80+
results = invalidate(url, wfi, only_resub=True, with_output= (not options.keep))
7181

7282
if all(results):
7383
print wfo.name,"rejected"
7484
if options and options.clone:
75-
wfo.status = 'trouble'
76-
session.commit()
85+
if not options.test:
86+
wfo.status = 'trouble'
87+
session.commit()
7788
schema = wfi.getSchema()
89+
if options.test:
90+
print "Original schema"
91+
print json.dumps( schema, indent=2 )
7892
schema['Requestor'] = os.getenv('USER')
7993
schema['Group'] = 'DATAOPS'
8094
schema['OriginalRequestName'] = wfo.name
@@ -206,11 +220,20 @@ def rejector(url, specific, options=None):
206220
if 'Task%d'%step in schema:
207221
sname = 'Step%d'%step
208222
schema[sname] = schema.pop('Task%d'%step)
209-
tmcore = schema[sname].pop('Multicore')
223+
if 'Multicore' in schema[sname] and schema[sname]['Multicore']==1:
224+
# enforce single-core mode assuming that all Tasks with
225+
# Multicore=1 are not thread-safe
226+
tmcore = schema[sname]['Multicore']
227+
else:
228+
# remove explicit assignment of the number of cores
229+
tmcore = schema[sname].pop('Multicore')
210230
tmem = schema[sname].pop('Memory')
211231
if mcore and tmcore != mcore:
212-
wfi.sendLog('rejector','the conversion to stepchain encoutered different value of Multicore %d != %d'%( tmcore, mcore))
213-
sendLog('rejector','the conversion of %s to stepchain encoutered different value of Multicore %d != %d'%( wfo.name, tmcore, mcore), level='critical')
232+
if options.test:
233+
print 'the conversion of %s to stepchain encoutered different value of Multicore %d != %d' % (wfo.name, tmcore, mcore)
234+
else:
235+
wfi.sendLog('rejector','the conversion to stepchain encoutered different value of Multicore %d != %d'%( tmcore, mcore))
236+
sendLog('rejector','the conversion of %s to stepchain encoutered different value of Multicore %d != %d'%( wfo.name, tmcore, mcore), level='critical')
214237
mcore = max(mcore, tmcore)
215238
mem = max(mem, tmem)
216239
schema[sname]['StepName'] = schema[sname].pop('TaskName')
@@ -239,40 +262,47 @@ def rejector(url, specific, options=None):
239262
break
240263
schema['Multicore'] = mcore
241264
schema['Memory'] = mem
265+
print "New request schema"
242266
print json.dumps( schema, indent=2 )
243-
newWorkflow = reqMgrClient.submitWorkflow(url, schema)
244-
if not newWorkflow:
245-
msg = "Error in cloning {}".format(wfo.name)
246-
print(msg)
247-
wfi.sendLog('rejector',msg)
248-
249-
# Get the error message
250-
time.sleep(5)
251-
data = reqMgrClient.requestManagerPost(url, "/reqmgr2/data/request", schema)
252-
wfi.sendLog('rejector',data)
253-
254-
print json.dumps( schema, indent=2 )
255-
return
256-
print newWorkflow
267+
if not options.test:
268+
newWorkflow = reqMgrClient.submitWorkflow(url, schema)
269+
if not newWorkflow:
270+
msg = "Error in cloning {}".format(wfo.name)
271+
print(msg)
272+
wfi.sendLog('rejector',msg)
273+
274+
# Get the error message
275+
time.sleep(5)
276+
data = reqMgrClient.requestManagerPost(url, "/reqmgr2/data/request", schema)
277+
wfi.sendLog('rejector',data)
257278

258-
data = reqMgrClient.setWorkflowApproved(url, newWorkflow)
259-
print data
260-
wfi.sendLog('rejector','Cloned into %s by unified operator %s'%( newWorkflow, comment ))
261-
#wfi.notifyRequestor('Cloned into %s by unified operator %s'%( newWorkflow, comment ),do_batch=False)
279+
print json.dumps( schema, indent=2 )
280+
return
281+
print newWorkflow
282+
283+
data = reqMgrClient.setWorkflowApproved(url, newWorkflow)
284+
print data
285+
wfi.sendLog('rejector','Cloned into %s by unified operator %s'%( newWorkflow, comment ))
286+
#wfi.notifyRequestor('Cloned into %s by unified operator %s'%( newWorkflow, comment ),do_batch=False)
262287
else:
263-
wfo.status = 'trouble' if options.set_trouble else 'forget'
264-
wfi.notifyRequestor('Rejected by unified operator %s'%( comment ),do_batch=False)
265-
session.commit()
288+
if options.test:
289+
print 'Rejected by unified operator %s'%( comment )
290+
else:
291+
wfo.status = 'trouble' if options.set_trouble else 'forget'
292+
wfi.notifyRequestor('Rejected by unified operator %s'%( comment ),do_batch=False)
293+
session.commit()
266294

267295
else:
268-
msg = "Error in rejecting {}: {}".format(wfo.name,results)
269-
print(msg)
270-
wfi.sendLog('rejector',msg)
296+
msg = "Error in rejecting {}: {}".format(wfo.name, results)
297+
print msg
298+
if not options.test:
299+
wfi.sendLog('rejector', msg)
271300

272301
if __name__ == "__main__":
273302
url = reqmgr_url
274303

275304
parser = optparse.OptionParser()
305+
parser.add_option('-t', '--test', help="test mode - no changes are made", default=False, action="store_true")
276306
parser.add_option('-c','--clone',help="clone the workflow",default=False,action="store_true")
277307
parser.add_option('--comments', help="Give a comment to the clone",default="")
278308
parser.add_option('-k','--keep',help="keep the outpuy in current status", default=False,action="store_true")

0 commit comments

Comments
 (0)