forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresubmit.py
executable file
·134 lines (119 loc) · 4.48 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
#!/usr/bin/env python
import os
import sys
import urllib
import httplib
import re
import Priorities
import json
import changePriorityWorkflow
import closeOutWorkflows
from WMCore.WMSpec.WMWorkload import WMWorkloadHelper
reqmgrCouchURL = "https://cmsweb.cern.ch/couchdb/reqmgr_workload_cache"
#reqmgrHostname = "vocms144"
#reqmgrPort = 8687
def getPriorityWorkflow(url, workflow):
conn = httplib.HTTPSConnection(url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
r1=conn.request("GET",'/reqmgr/reqMgr/request?requestName='+workflow)
r2=conn.getresponse()
request = json.loads(r2.read())
if 'RequestPriority' in request:
return request['RequestPriority']
else:
return 0
def approveRequest(url,workflow):
params = {"requestName": workflow,
"status": "assignment-approved"}
encodedParams = urllib.urlencode(params)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPSConnection(url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
#conn = httplib.HTTPConnection(url)
conn.request("PUT", "/reqmgr/reqMgr/request", encodedParams, headers)
response = conn.getresponse()
if response.status != 200:
print 'could not approve 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()
return
def retrieveSchema(workflowName, user, group ):
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_whole_tree_().iteritems():
for (key, value) in helper.data.request.schema.dictionary_().iteritems():
#print key, value
if key == 'ProcConfigCacheID':
schema['ConfigCacheID'] = value
elif key=='RequestSizeEvents':
schema['RequestSizeEvents'] = value
#schema['RequestNumEvents'] = int(value)
elif key=='Requestor':
schema['Requestor']=user
elif key=='Group':
schema['Group']=group
elif key=='SkimConfigs' and not value:
continue
elif key =='RequestorDN':
continue
elif key=='DataPileup' and not value:
continue
elif key=='MCPileup' and not value:
continue
elif key=='StepTwoOutputModuleName' and not value:
continue
elif key=='SizePerEvent':
schema['SizePerEvent']=1
#elif not value:
# continue
elif value != None:
schema[key] = value
return schema
def submitWorkflow(schema):
for schemaListItem in ["RunWhitelist", "RunBlacklist", "BlockWhitelist",
"BlockBlacklist"]:
if schemaListItem in schema.keys():
schema[schemaListItem] = str(schema[schemaListItem])
jsonEncodedParams = {}
for paramKey in schema.keys():
jsonEncodedParams[paramKey] = json.dumps(schema[paramKey])
encodedParams = urllib.urlencode(jsonEncodedParams, False)
#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'))
conn.request("POST", "/reqmgr/create/makeSchema", encodedParams, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data
details=re.search("details\/(.*)\'",data)
return details.group(1)
if __name__ == "__main__":
if len(sys.argv) != 4:
print "Usage:"
print " ./resubmit WORKFLOW_NAME USER GROUP"
sys.exit(0)
user=sys.argv[2]
group=sys.argv[3]
#print "Going to attempt to resubmit %s..." % sys.argv[1]
schema = retrieveSchema(sys.argv[1], user, group)
#print schema
newWorkflow=submitWorkflow(schema)
approveRequest('cmsweb.cern.ch',newWorkflow)
print 'Cloned workflow:',newWorkflow
newPriority=getPriorityWorkflow('cmsweb.cern.ch',sys.argv[1])
if newPriority>2:
changePriorityWorkflow.changePriorityWorkflow('cmsweb.cern.ch', newWorkflow, newPriority)
sys.exit(0)