forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
undealtWorkflows.py
152 lines (133 loc) · 5.07 KB
/
undealtWorkflows.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
#!/usr/bin/env python
import json
import urllib2,urllib, httplib, sys, re, os, phedexSubscription, dbsTest, duplicateEventsGen, shutil, time
from xml.dom.minidom import getDOMImplementation
import closeOutWorkflows
outputfile = '/afs/cern.ch/user/j/jbadillo/www/undealt.html'
tempfile = '/afs/cern.ch/user/j/jbadillo/www/temp_undealt.html'
def classifyRunningRequests(url, requests):
"""
Creates an index for running requests
The key is the request string
"""
workflows={}
for request in requests:
#name of the request
name=request['id']
if len(request['key'])<3:
print request
continue
#status
status=request['key'][1]
#add to the index
if status in ['running-closed', 'running-open', 'assigned','acquired','assignment-approved']:
#if it has the same request string add to a list
reqString = getRequestString(name)
if reqString not in workflows:
workflows[reqString] = [name]
else:
workflows[reqString].append(name)
return workflows
def filterUndealtWorkflows(workflowsCompleted, workflowsRunning, wfType):
"""
Filter's workflows that have no acdc running
"""
wfs = workflowsCompleted[wfType]
result = []
#check for everyone if it has one runnign with the same strng name
for wf in wfs:
reqString = getRequestString(wf)
#check how many acdcs have
#print wf
if reqString in workflowsRunning:
#print workflowsRunning[reqString]
pass
else:
#print 'no acdcs running'
result.append(wf)
return result
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>')
import re
p = re.compile(r'[a-z_]+(?:ACDC_|Merge_|EXT_)*([a-zA-Z0-9_\-]+)')
p2 = re.compile(r'_\d{6}_[0-9_]+')
def getRequestString(request):
"""
Extracts the request string from the request name
"""
m = p2.search(request)
if not m:
print request, 'NOT MATCH!!!'
return request
s = m.group(0)
s = request.replace(s,'')
m = p.match(s)
if not m:
print s
return request
return m.group(1)
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=closeOutWorkflows.getOverviewRequestsWMStats(url)
print "Classifying Requests"
workflowsCompleted = closeOutWorkflows.classifyCompletedRequests(url, requests)
workflowsRunning = classifyRunningRequests(url, requests)
writeHTMLHeader(output)
print "Getting no duplicated requests"
print "Workflows that are completed, but don't have ACDC's"
output.write("<table border=1> <tr><th>Workflows that are completed, but don't have ACDC's</th></tr>")
undealtWFs = filterUndealtWorkflows(workflowsCompleted, workflowsRunning,'ReReco')
print "---------------------------------------------------"
print "ReReco's"
print "---------------------------------------------------"
listWorkflows(undealtWFs,output)
undealtWFs = filterUndealtWorkflows(workflowsCompleted, workflowsRunning,'ReDigi')
print "---------------------------------------------------"
print "ReDigi's"
print "---------------------------------------------------"
output.write("<tr><th>ReDigi's</th></tr>")
listWorkflows(undealtWFs,output)
undealtWFs = filterUndealtWorkflows(workflowsCompleted, workflowsRunning,'MonteCarloFromGEN')
print "---------------------------------------------------"
print "MonteCarloFromGEN"
print "---------------------------------------------------"
output.write("<tr><th>MonteCarloFromGEN</th></tr>")
listWorkflows(undealtWFs,output)
undealtWFs = filterUndealtWorkflows(workflowsCompleted, workflowsRunning,'MonteCarlo')
print "---------------------------------------------------"
print "MonteCarlo"
print "---------------------------------------------------"
output.write("<tr><th>MonteCarlo</th></tr>")
listWorkflows(undealtWFs,output)
undealtWFs = filterUndealtWorkflows(workflowsCompleted, workflowsRunning,'LHEStepZero')
print "---------------------------------------------------"
print "LHEStepZero"
print "---------------------------------------------------"
output.write("<tr><th>LHEStepZero</th></tr>")
listWorkflows(undealtWFs,output)
output.write('</table>')
output.write('<p>Last update: '+time.strftime("%c")+' CERN time</p>')
output.write('</body>')
output.write('</html>')
output.close()
#copy from temp file
shutil.copy(tempfile, outputfile)
sys.exit(0);
if __name__ == "__main__":
main()
"""wfs = open('wfs')
for wf in wfs.readlines():
wf = wf.strip()
print wf, getRequestString(wf)
"""