forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resubmit_cmsweb2.py
142 lines (115 loc) · 5.57 KB
/
resubmit_cmsweb2.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
140
141
142
#!/usr/bin/env python
import os
import sys
import urllib
import httplib
import WMCore.Wrappers.JsonWrapper as json_wrap
from WMCore.WMSpec.WMWorkload import WMWorkloadHelper
reqmgrCouchURL = "https://cmsweb.cern.ch/couchdb/reqmgr_workload_cache"
def retrieveSchema(workflowName):
specURL = os.path.join(reqmgrCouchURL, workflowName, "spec")
helper = WMWorkloadHelper()
print " retrieving original workflow...",
helper.load(specURL)
print "done."
schema = {}
for (key, value) in helper.data.request.schema.dictionary_().iteritems():
if value != None:
schema[key] = value
schema["Requestor"] = "linacre"
schema["Group"] = "DATAOPS"
del schema["RequestName"]
del schema["CouchDBName"]
del schema["CouchURL"]
assign = {}
assign["unmergedLFNBase"] = helper.data.properties.unmergedLFNBase
assign["mergedLFNBase"] = helper.data.properties.mergedLFNBase
assign["processingVersion"] = helper.data.properties.processingVersion
assign["dashboardActivity"] = helper.data.properties.dashboardActivity
assign["acquisitionEra"] = helper.data.properties.acquisitionEra
topLevelTask = helper.getTopLevelTask()[0]
assign["SiteWhitelist"] = topLevelTask.siteWhitelist()
mergeTask = None
for mergeTask in topLevelTask.childTaskIterator():
if mergeTask.taskType() == "Merge":
if mergeTask.getPathName().find("DQM") == -1:
break
assign["MinMergeSize"] = mergeTask.jobSplittingParameters()["min_merge_size"]
assign["MaxMergeSize"] = mergeTask.jobSplittingParameters()["max_merge_size"]
assign["MaxMergeEvents"] = mergeTask.jobSplittingParameters().get("max_merge_events", 50000)
return (schema, assign)
def submitWorkflow(schema):
for schemaListItem in ["RunWhitelist", "RunBlacklist", "BlockWhitelist",
"BlockBlacklist"]:
if schemaListItem in schema.keys():
schema[schemaListItem] = str(schema[schemaListItem])
encodedParams = urllib.urlencode(schema, True)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPSConnection("cmsweb.cern.ch", cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
print " submitting new workflow..."
conn.request("POST", "/reqmgr/create/makeSchema", encodedParams, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
return data.split("'")[1][42:]
def assignRequest(workflow, site, era, procversion, mLFN, uLFN, minSize, maxSize, maxEvents, dashboard):
params = {"action": "Assign",
"Teamprocessing": "checked",
"SiteWhitelist": site[0],
"MergedLFNBase": mLFN,
"UnmergedLFNBase": uLFN,
"MinMergeSize": minSize,
"MaxMergeSize": maxSize,
"MaxMergeEvents": maxEvents,
"AcquisitionEra": era,
"ProcessingVersion": procversion,
"Dashboard": dashboard,
"MaxRSS": 3000000000,
"MaxVSize": 3100000000,
"checkbox"+workflow: "checked"}
encodedParams = urllib.urlencode(params)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPSConnection("cmsweb.cern.ch", cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
conn.request("POST", "/reqmgr/assign/handleAssignmentPage", encodedParams, headers)
response = conn.getresponse()
if response.status != 200:
print 'could not assign request with following parameters:'
for item in params.keys():
print item + ": " + str(params[item])
print 'Response from http call:'
print 'Status:',response.status,'Reason:',response.reason
print 'Explanation:'
data = response.read()
print data
print "Exiting!"
sys.exit(1)
conn.close()
print 'Assigned workflow:',workflow,'to site:',site,'with processing version',procversion
return
def abortRequest(requestName):
conn = httplib.HTTPConnection("vocms144.cern.ch:8687")
conn.request("GET", "/reqmgr/reqMgr/request?requestName=%s" % requestName)
resp = conn.getresponse()
status = json_wrap.loads(resp.read())["WMCore.RequestManager.DataStructs.Request.Request"]["RequestStatus"]
print "Status: %s" % status
if status == "acquired":
os.system("curl -X PUT -d \"requestName=%s&status=running\" \"http://vocms144:8687/reqmgr/reqMgr/request\"" % requestName)
os.system("curl -X PUT -d \"requestName=%s&status=aborted\" \"http://vocms144:8687/reqmgr/reqMgr/request\"" % requestName)
else:
os.system("curl -X PUT -d \"requestName=%s&status=rejected\" \"http://vocms144:8687/reqmgr/reqMgr/request\"" % requestName)
return
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage:"
print " ./resubmit WORKFLOW_NAME"
sys.exit(0)
print "Going to attempt to resubmit %s..." % sys.argv[1]
(schema, assign) = retrieveSchema(sys.argv[1])
newName = submitWorkflow(schema)
# assignRequest(newName, assign["SiteWhitelist"], assign["acquisitionEra"], assign["processingVersion"], assign["mergedLFNBase"],
# assign["unmergedLFNBase"], assign["MinMergeSize"], assign["MaxMergeSize"], assign["MaxMergeEvents"], assign["dashboardActivity"])
# abortRequest(sys.argv[1])
sys.exit(0)