forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resubmit.py
executable file
·140 lines (122 loc) · 4.12 KB
/
resubmit.py
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
#!/usr/bin/env python
"""
This script clones a given workflow
*args must be: workflow_name user group
This script depends on WMCore code, so WMAgent environment
and libraries need to be loaded before running it.
"""
import os
import sys
import urllib
import httplib
import re
import json
import changePriorityWorkflow
import reqMgrClient
from WMCore.WMSpec.WMWorkload import WMWorkloadHelper
reqmgrCouchURL = "https://cmsweb.cern.ch/couchdb/reqmgr_workload_cache"
def retrieveSchema(workflowName):
"""
Creates the cloned specs for the original request
Updates parameters
"""
specURL = os.path.join(reqmgrCouchURL, workflowName, "spec")
helper = WMWorkloadHelper()
helper.load(specURL)
return helper
def modifySchema(helper, user, group):
"""
Adapts schema to right parameters
"""
result = {}
# Add AcquisitionEra, ProcessingString and increase ProcessingVersion by 1
result["ProcessingString"] = helper.getProcessingString()
result["ProcessingVersion"] = helper.getProcessingVersion() + 1
result["AcquisitionEra"] = helper.getAcquisitionEra()
for (key, value) in helper.data.request.schema.dictionary_().items():
#previous versions of tags
if key == 'ProcConfigCacheID':
result['ConfigCacheID'] = value
elif key == 'RequestSizeEvents':
result['RequestSizeEvents'] = value
#requestor info
elif key == 'Requestor':
result['Requestor'] = user
elif key == 'Group':
result['Group'] = group
#if emtpy
elif key in ["RunWhitelist", "RunBlacklist", "BlockWhitelist", "BlockBlacklist"] and not value:
result[key]=[]
#skip empty entries
elif not value:
continue
elif value != None:
result[key] = value
if 'LumisPerJob' not in result and result['RequestType']=='MonteCarlo':
#seek for lumis per job on helper
splitting = helper.listJobSplittingParametersByTask()
lumisPerJob = 300
for k, v in splitting.items():
if k.endswith('/Production'):
if 'lumis_per_job' in v:
lumisPerJob = v['lumis_per_job']
result['LumisPerJob'] = lumisPerJob
#TODO do this always?
if 'EventsPerJob' not in result and result['RequestType']=='MonteCarlo':
#seek for events per job on helper
splitting = helper.listJobSplittingParametersByTask()
eventsPerJob = 120000
for k, v in splitting.items():
if k.endswith('/Production'):
if 'events_per_job' in v:
eventsPerJob = v['events_per_job']
result['EventsPerJob'] = eventsPerJob
if 'MergedLFNBase' not in result:
result['MergedLFNBase'] = helper.getMergedLFNBase()
return result
def cloneWorkflow(workflow, user, group, verbose=False):
"""
clones a workflow
"""
# Get info about the workflow to be cloned
helper = retrieveSchema(workflow)
schema = modifySchema(helper, user, group)
print 'Submitting workflow'
# Sumbit cloned workflow to ReqMgr
response = reqMgrClient.submitWorkflow(url,schema)
#find the workflow name in response
m = re.search("details\/(.*)\'",response)
if m:
newWorkflow = m.group(1)
if verbose:
print 'Cloned workflow: '+newWorkflow
print response
print 'Approve request response:'
# Move the request to Assignment-approved
data = reqMgrClient.setWorkflowApproved(url, newWorkflow)
if verbose:
print data
#return the name of new workflow
return newWorkflow
else:
if verbose:
print response
return None
"""
__Main__
"""
url = 'cmsweb.cern.ch'
def main():
# Check the arguements, get info from them
if len(sys.argv) != 4:
print "Usage:"
print " ./resubmit WORKFLOW_NAME USER GROUP"
sys.exit(0)
workflow = sys.argv[1]
user = sys.argv[2]
group = sys.argv[3]
#Show verbose
cloneWorkflow(workflow, user, group, True)
sys.exit(0)
if __name__ == "__main__":
main()