forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresubmit_ACDC_Montecarlo.py
executable file
·193 lines (170 loc) · 7.32 KB
/
resubmit_ACDC_Montecarlo.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
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
#!/usr/bin/env python
import os
import sys
import urllib
import httplib
import re
import Priorities
import json
import changePriorityWorkflow
import closeOutWorkflows
import dbsTest
import phedexSubscription
import pickle
import changeSplittingWorkflow
import assignWorkflowsAuto
import resubmitUnprocessedBlocks
from WMCore.WMSpec.WMWorkload import WMWorkloadHelper
from WMCore.Services.RequestManager.RequestManager import RequestManager
from WMCore.WMSpec.WMWorkload import WMWorkloadHelper
from WMCore.Database.CMSCouch import Database
reqmgrCouchURL = "https://cmsweb.cern.ch/couchdb/reqmgr_workload_cache"
def getOriginalCustodial(url, requestname):
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='+requestname)
r2=conn.getresponse()
request = json.loads(r2.read())
if 'SubscriptionInformation' in request:
for dataset in request['SubscriptionInformation']:
return request['SubscriptionInformation'][dataset]['CustodialSites'][0]
else:
return None
#Only works now for event splitting
def getSplitting(requestName):
reqmgrUrl='https://cmsweb.cern.ch/reqmgr/reqMgr/'
reqmgr = RequestManager(dict = {'endpoint' : reqmgrUrl})
result = reqmgr.getRequest(requestName)
workloadDB = Database(result['CouchWorkloadDBName'], result['CouchURL'])
workloadPickle = workloadDB.getAttachment(requestName, 'spec')
spec = pickle.loads(workloadPickle)
workload = WMWorkloadHelper(spec)
params = workload.getTopLevelTask()[0].jobSplittingParameters()
algo = workload.getTopLevelTask()[0].jobSplittingAlgorithm()
return params['events_per_job']
def getFinalRequestedNumEvents(url, workflow):
outputDataSets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
obtainedEvents=dbsTest.getOutputEvents(url, workflow, outputDataSets[0])
requestedEvents=dbsTest.getInputEvents(url, workflow)
return (requestedEvents-obtainedEvents)
def getMaxLumi(url, workflow):
outputDataSets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
dataset=outputDataSets[0]
output=os.popen("./dbssql --input='find run, max(lumi) where dataset="+dataset+"'| awk '{print $2}' | grep '[0-9]\{1,\}'").read()
try:
return int(output)
except ValueError:
return -1
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.read(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(url, 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=='RequestNumEvents':
schema['RequestNumEvents']=getFinalRequestedNumEvents(url, workflowName)
elif key=='FirstLumi':
schema['FirstLumi']=getMaxLumi(url, workflowName)*2
elif key=='FirstEvent':
schema['FirstEvent']=dbsTest.getInputEvents(url, workflowName)*2
elif key=='RequestString':
schema['RequestString']='ACDC_'+value
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)
oldworkflow=sys.argv[1]
user=sys.argv[2]
group=sys.argv[3]
#print "Going to attempt to resubmit %s..." % sys.argv[1]
url='cmsweb.cern.ch'
schema = retrieveSchema(url, oldworkflow, user, group)
newWorkflow=submitWorkflow(schema)
print 'Cloned workflow:',newWorkflow
approveRequest('cmsweb.cern.ch',newWorkflow)
originalSplitting=getSplitting(oldworkflow)
changeSplittingWorkflow.changeSplittingWorkflow(url, newWorkflow, int(originalSplitting/10))
team=resubmitUnprocessedBlocks.getTeamWorkflow(url,oldworkflow)
site=resubmitUnprocessedBlocks.getSiteWhitelist(url, oldworkflow)
#activity=resubmitUnprocessedBlocks.getDashboardActivity(url, oldworkflow)
activity='production'
era=resubmitUnprocessedBlocks.getAcquisitonEra(url, oldworkflow)
procversion=resubmitUnprocessedBlocks.getProcessingVersion(url, oldworkflow)
procstring=resubmitUnprocessedBlocks.getProcessingString(url, oldworkflow)
lfn=resubmitUnprocessedBlocks.getMergedLFNBaseWorkflow(url, oldworkflow)
siteCust=getOriginalCustodial(url, oldworkflow)
maxmergeevents = 50000
if 'Fall11_R1' in oldworkflow:
maxmergeevents = 6000
if 'DR61SLHCx' in oldworkflow:
maxmergeevents = 5000
assignWorkflowsAuto.assignRequest(url , newWorkflow ,team ,site ,era, procversion, procstring, activity, lfn, maxmergeevents, 2300000, 4100000000, 0, siteCust)
sys.exit(0)