forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
closeOutWorkflowsWeb.py
executable file
·267 lines (244 loc) · 12.2 KB
/
closeOutWorkflowsWeb.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env python
import json
import urllib2,urllib, httplib, sys, re, os
import time, shutil
from closeOutWorkflows import *
from xml.dom.minidom import getDOMImplementation
"""
Runs Closeout script generating the output to a Web Page.
Useful for sharing close out script information
"""
outputfile = '/afs/cern.ch/user/j/jbadillo/www/closeout.html'
tempfile = '/afs/cern.ch/user/j/jbadillo/www/temp.html'
def closeOutReRecoWorkflowsWeb(url, workflows, output):
"""
Closeout ReReco workflows. Generates web output.
"""
noSiteWorkflows = []
for workflow in workflows:
if 'RelVal' in workflow:
continue
if 'TEST' in workflow:
continue
datasets = reqMgrClient.outputdatasetsWorkflow(url, workflow)
inputDataset = reqMgrClient.getInputDataSet(url, workflow)
closeOutWorkflow = True
#check if dataset is ready
for dataset in datasets:
duplicate = False
closeOutDataset = True
percentage = percentageCompletion(url, workflow, dataset)
phedexSubscription = phedexClient.hasCustodialSubscription(dataset)
closeOutDataset = False
#dataset can be closed out only with 100% of events
if percentage == 1 and phedexSubscription and not duplicate:
closeOutDataset = True
else:
closeOutDataset = False
#validate when percentage is ok but has not phedex subscription
if percentage == 1 and not phedexSubscription:
noSiteWorkflows.append(workflow)
#if at least one dataset is not ready wf cannot be closed out
closeOutWorkflow = closeOutWorkflow and closeOutDataset
print '| %80s | %100s | %4s | %5s| %3s | %5s|%5s| ' % (workflow, dataset,str(int(percentage*100)),
str(phedexSubscription), 100, duplicate, closeOutDataset)
#web output
output.write('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%
(workflow, dataset,str(int(percentage*100)),str(phedexSubscription), 100, duplicate, closeOutDataset))
#workflow can only be closed out if all datasets are ready
if closeOutWorkflow:
reqMgrClient.closeOutWorkflowCascade(url, workflow)
print '-'*180
return noSiteWorkflows
def closeOutRedigiWorkflowsWeb(url, workflows, output):
"""
Closes out a list of redigi workflows. generates web output
"""
noSiteWorkflows = []
for workflow in workflows:
closeOutWorkflow = True
inputDataset = reqMgrClient.getInputDataSet(url, workflow)
datasets = reqMgrClient.outputdatasetsWorkflow(url, workflow)
for dataset in datasets:
closeOutDataset = False
percentage = percentageCompletion(url, workflow, dataset)
phedexSubscription = phedexClient.hasCustodialSubscription(dataset)
duplicate = None
# if dataset has subscription and more than 95% events we check
# duplicates
if phedexSubscription and percentage >= float(0.95):
duplicate = dbs3Client.duplicateRunLumi(dataset)
#if not duplicate events, dataset is ready
if not duplicate:
closeOutDataset = True
else:
closeOutDataset = False
#validate when percentage is ok but has not phedex subscription
if percentage >= float(0.95) and not phedexSubscription:
noSiteWorkflows.append(workflow)
#if at least one dataset is not ready wf cannot be closed out
closeOutWorkflow = closeOutWorkflow and closeOutDataset
print '| %80s | %100s | %4s | %5s| %3s | %5s|%5s| ' % (workflow, dataset,str(int(percentage*100)),
str(phedexSubscription), 100, duplicate, closeOutDataset)
#web output
output.write('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%
(workflow, dataset,str(int(percentage*100)),str(phedexSubscription), 100, duplicate, closeOutDataset))
#workflow can only be closed out if all datasets are ready
if closeOutWorkflow:
reqMgrClient.closeOutWorkflowCascade(url, workflow)
print '-'*180
return noSiteWorkflows
def closeOutMonterCarloRequestsWeb(url, workflows,output):
"""
Closes either montecarlo or montecarlo from gen
workflows
"""
noSiteWorkflows = []
for workflow in workflows:
datasets = reqMgrClient.outputdatasetsWorkflow(url, workflow)
closeOutWorkflow = True
#skip montecarlos on a special queue
if reqMgrClient.getRequestTeam(url, workflow) == 'analysis':
continue
for dataset in datasets:
closePercentage = 0.95
# validation for SMS montecarlos
if 'SMS' in dataset:
closePercentage= 1.00
percentage = percentageCompletion(url, workflow, dataset)
phedexSubscription = phedexClient.getCustodialMoveSubscriptionSite(dataset)
transPerc = 0
closedBlocks = None
duplicate = None
# if dataset has subscription and enough events we check
# duplicates, transfer percentage and closed blocks
if phedexSubscription and percentage >= float(closePercentage):
transPerc = phedexClient.getTransferPercentage(url, dataset, phedexSubscription)
duplicate = dbs3Client.duplicateLumi(dataset)
if not duplicate:
closeOutDataset = True
else:
closeOutDataset = False
else:
closeOutDataset = False
#validate when percentage is ok but has not phedex subscription
if percentage >= float(closePercentage) and not phedexSubscription:
noSiteWorkflows.append(workflow)
#if at least one dataset is not ready wf cannot be closed out
closeOutWorkflow = closeOutWorkflow and closeOutDataset
print '| %80s | %100s | %4s | %5s| %3s | %5s| %5s|' % (workflow, dataset,str(int(percentage*100)),
str(phedexSubscription), str(int(transPerc*100)), duplicate, closeOutDataset)
#web output
output.write('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%
(workflow, dataset,str(int(percentage*100)),str(phedexSubscription),
str(int(transPerc*100)), duplicate, closeOutDataset))
#workflow can only be closed out if all datasets are ready
if closeOutWorkflow:
reqMgrClient.closeOutWorkflowCascade(url, workflow)
#separation line
print '-'*180
return noSiteWorkflows
def closeOutStep0RequestsWeb(url, workflows, output):
"""
Closes either montecarlo step0 requests
"""
noSiteWorkflows = []
for workflow in workflows:
datasets = reqMgrClient.outputdatasetsWorkflow(url, workflow)
closeOutWorkflow = True
#skip montecarlos on a special queue
if reqMgrClient.getRequestTeam(url, workflow) == 'analysis':
continue
for dataset in datasets:
closeOutDataset = False
percentage = percentageCompletion(url, workflow, dataset)
phedexSubscription = phedexClient.getCustodialMoveSubscriptionSite(dataset)
transPerc = 0
closedBlocks = None
duplicate = None
correctLumis = None
# if dataset has subscription and enough events we check
# duplicates, transfer percentage, closed blocks and lumis
if phedexSubscription and percentage >= float(0.95):
transPerc = phedexClient.getTransferPercentage(url, dataset, phedexSubscription)
duplicate = dbs3Client.duplicateLumi(dataset)
correctLumis = checkCorrectLumisEventGEN(dataset)
#TODO validate closed blocks
if not duplicate and correctLumis:
closeOutDataset = True
else:
closeOutDataset = False
#validate when percentage is ok but has not phedex subscription
if percentage >= float(0.95) and not phedexSubscription:
noSiteWorkflows.append(workflow)
#if at least one dataset is not ready wf cannot be closed out
closeOutWorkflow = closeOutWorkflow and closeOutDataset
print '| %80s | %100s | %4s | %5s| %3s | %5s| %5s| ' % (workflow, dataset,str(int(percentage*100)),
str(phedexSubscription), str(correctLumis), duplicate, closeOutDataset)
#web output
output.write('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%
(workflow, dataset,str(int(percentage*100)),str(phedexSubscription), str(correctLumis), duplicate, closeOutDataset))
#workflow can only be closed out if all datasets are ready
if closeOutWorkflow:
reqMgrClient.closeOutWorkflowCascade(url, workflow)
print '-'*180
return noSiteWorkflows
def writeHTMLHeader(output):
output.write('<html>')
output.write('<head>')
output.write('<link rel="stylesheet" type="text/css" href="style.css" />')
output.write('</head>')
output.write('<body>')
def listWorkflows(workflows, output):
for wf in workflows:
print wf
output.write('<tr><td>'+wf+'</td></tr>')
output.write('<tr><td></td></tr>')
def main():
output = open(tempfile,'w')
url='cmsweb.cern.ch'
print "Gathering Requests"
requests=getOverviewRequestsWMStats(url)
print "Classifying Requests"
workflowsCompleted=classifyCompletedRequests(url, requests)
#header
writeHTMLHeader(output)
#print header
print '-'*220
print '| Request'+(' '*74)+'| OutputDataSet'+(' '*86)+'|%Compl|Subscr|Tran|Dupl|ClosOu|'
print '-'*220
output.write('<table border=1> <tr><th>Request</th><th>OutputDataSet</th><th>%Compl</th>'
'<th>Subscr</th><th>Tran</th><th>Dupl</th><th>ClosOu</th></tr>')
output.write('<tr><th colspan="7">ReReco </th></tr>')
noSiteWorkflows = closeOutReRecoWorkflowsWeb(url, workflowsCompleted['ReReco'], output)
workflowsCompleted['NoSite-ReReco'] = noSiteWorkflows
output.write('<tr><th colspan="7">ReDigi </th></tr>')
noSiteWorkflows = closeOutRedigiWorkflowsWeb(url, workflowsCompleted['ReDigi'], output)
workflowsCompleted['NoSite-ReDigi'] = noSiteWorkflows
output.write('<tr><th colspan="7">MonteCarlo </th></tr>')
noSiteWorkflows = closeOutMonterCarloRequestsWeb(url, workflowsCompleted['MonteCarlo'], output)
workflowsCompleted['NoSite-MonteCarlo'] = noSiteWorkflows
output.write('<tr><th colspan="7">MonteCarloFromGEN </th></tr>')
noSiteWorkflows = closeOutMonterCarloRequestsWeb(url, workflowsCompleted['MonteCarloFromGEN'], output)
workflowsCompleted['NoSite-MonteCarloFromGEN'] = noSiteWorkflows
output.write('<tr><th colspan="7">LHEStepZero </th></tr>')
noSiteWorkflows = closeOutStep0RequestsWeb(url, workflowsCompleted['LHEStepZero'],output)
workflowsCompleted['NoSite-LHEStepZero'] = noSiteWorkflows
output.write('</table><br><br>')
print "MC Workflows for which couldn't find Custodial Tier1 Site"
output.write("<table border=1> <tr><th>MC Workflows for which couldn't find Custodial Tier1 Site</th></tr>")
listWorkflows(workflowsCompleted['NoSite-ReReco'], output)
listWorkflows(workflowsCompleted['NoSite-ReDigi'], output)
listWorkflows(workflowsCompleted['NoSite-MonteCarlo'], output)
listWorkflows(workflowsCompleted['NoSite-MonteCarloFromGEN'], output)
listWorkflows(workflowsCompleted['NoSite-LHEStepZero'], output)
output.write('</table>')
output.write('<p>Last update: '+time.strftime("%c")+' CERN time</p>')
output.write('</body>')
output.write('</html>')
output.close()
#copy temporal to definitive file, avoid unavailability when running
shutil.copy(tempfile, outputfile)
sys.exit(0);
if __name__ == "__main__":
main()