1 |
nsmirnov |
1.1 |
from Actor import *
|
2 |
nsmirnov |
1.6 |
from crab_util import *
|
3 |
nsmirnov |
1.2 |
import common
|
4 |
corvo |
1.9 |
from ApmonIf import ApmonIf
|
5 |
slacapra |
1.60 |
#from random import random
|
6 |
corvo |
1.30 |
import time
|
7 |
slacapra |
1.60 |
from ProgressBar import ProgressBar
|
8 |
|
|
from TerminalController import TerminalController
|
9 |
nsmirnov |
1.1 |
|
10 |
|
|
class Submitter(Actor):
|
11 |
slacapra |
1.84 |
def __init__(self, cfg_params, parsed_range, val):
|
12 |
nsmirnov |
1.1 |
self.cfg_params = cfg_params
|
13 |
slacapra |
1.84 |
|
14 |
|
|
# get user request
|
15 |
|
|
nsjobs = -1
|
16 |
|
|
chosenJobsList = None
|
17 |
|
|
if val:
|
18 |
slacapra |
1.91 |
if val=='range': # for Resubmitter
|
19 |
|
|
chosenJobsList = parsed_range
|
20 |
ewv |
1.92 |
elif val=='all':
|
21 |
slacapra |
1.84 |
pass
|
22 |
|
|
elif (type(eval(val)) is int) and eval(val) > 0:
|
23 |
|
|
# positive number
|
24 |
|
|
nsjobs = eval(val)
|
25 |
|
|
elif (type(eval(val)) is tuple)or( type(eval(val)) is int and eval(val)<0 ) :
|
26 |
|
|
chosenJobsList = parsed_range
|
27 |
ewv |
1.92 |
nsjobs = len(chosenJobsList)
|
28 |
slacapra |
1.84 |
else:
|
29 |
|
|
msg = 'Bad submission option <'+str(val)+'>\n'
|
30 |
|
|
msg += ' Must be an integer or "all"'
|
31 |
|
|
msg += ' Generic range is not allowed"'
|
32 |
|
|
raise CrabException(msg)
|
33 |
|
|
pass
|
34 |
ewv |
1.92 |
|
35 |
slacapra |
1.84 |
common.logger.debug(5,'nsjobs '+str(nsjobs))
|
36 |
|
|
# total jobs
|
37 |
|
|
nj_list = []
|
38 |
|
|
# get the first not already submitted
|
39 |
spiga |
1.94 |
common.logger.debug(5,'Total jobs '+str(common._db.nJobs()))
|
40 |
slacapra |
1.84 |
jobSetForSubmission = 0
|
41 |
|
|
jobSkippedInSubmission = []
|
42 |
|
|
datasetpath=self.cfg_params['CMSSW.datasetpath']
|
43 |
slacapra |
1.97 |
if string.lower(datasetpath)=='none':
|
44 |
fanzago |
1.104 |
datasetpath = None
|
45 |
spiga |
1.98 |
tmp_jList = common._db.nJobs('list')
|
46 |
slacapra |
1.84 |
if chosenJobsList != None:
|
47 |
|
|
tmp_jList = chosenJobsList
|
48 |
|
|
# build job list
|
49 |
|
|
from BlackWhiteListParser import BlackWhiteListParser
|
50 |
|
|
self.blackWhiteListParser = BlackWhiteListParser(self.cfg_params)
|
51 |
spiga |
1.98 |
dlsDest=common._db.queryJob('dlsDestination',tmp_jList)
|
52 |
|
|
jStatus=common._db.queryRunJob('status',tmp_jList)
|
53 |
|
|
for nj in range(len(tmp_jList)):
|
54 |
|
|
cleanedBlackWhiteList = self.blackWhiteListParser.cleanForBlackWhiteList(dlsDest[nj])
|
55 |
slacapra |
1.97 |
if (cleanedBlackWhiteList != '') or (datasetpath == None): ## Matty's fix
|
56 |
spiga |
1.100 |
##if ( jStatus[nj] not in ['R','S','K','Y','A','D','Z']): ## here the old flags
|
57 |
spiga |
1.101 |
if ( jStatus[nj] not in ['SS','SU','SR','R','S','K','Y','A','D','Z']):
|
58 |
|
|
#nj_list.append(nj+1)## Warning added +1 for jobId BL--DS
|
59 |
slacapra |
1.84 |
jobSetForSubmission +=1
|
60 |
spiga |
1.100 |
nj_list.append(tmp_jList[nj])## Warning added +1 for jobId BL--DS
|
61 |
ewv |
1.92 |
else:
|
62 |
slacapra |
1.84 |
continue
|
63 |
|
|
else :
|
64 |
spiga |
1.100 |
jobSkippedInSubmission.append(tmp_jList[nj])
|
65 |
slacapra |
1.84 |
if nsjobs >0 and nsjobs == jobSetForSubmission:
|
66 |
|
|
break
|
67 |
|
|
pass
|
68 |
fanzago |
1.104 |
|
69 |
slacapra |
1.84 |
if nsjobs>jobSetForSubmission:
|
70 |
|
|
common.logger.message('asking to submit '+str(nsjobs)+' jobs, but only '+str(jobSetForSubmission)+' left: submitting those')
|
71 |
|
|
if len(jobSkippedInSubmission) > 0 :
|
72 |
|
|
mess =""
|
73 |
|
|
for jobs in jobSkippedInSubmission:
|
74 |
|
|
mess += str(jobs) + ","
|
75 |
|
|
common.logger.message("Jobs: " +str(mess) + "\n skipped because no sites are hosting this data\n")
|
76 |
slacapra |
1.89 |
self.submissionError()
|
77 |
|
|
pass
|
78 |
slacapra |
1.84 |
# submit N from last submitted job
|
79 |
|
|
common.logger.debug(5,'nj_list '+str(nj_list))
|
80 |
ewv |
1.92 |
|
81 |
ewv |
1.93 |
if common.scheduler.name().upper() == 'CONDOR_G':
|
82 |
gutsche |
1.58 |
# create hash of cfg file
|
83 |
|
|
self.hash = makeCksum(common.work_space.cfgFileName())
|
84 |
|
|
else:
|
85 |
|
|
self.hash = ''
|
86 |
corvo |
1.30 |
|
87 |
slacapra |
1.84 |
self.nj_list = nj_list
|
88 |
nsmirnov |
1.1 |
return
|
89 |
ewv |
1.92 |
|
90 |
nsmirnov |
1.1 |
def run(self):
|
91 |
nsmirnov |
1.2 |
"""
|
92 |
slacapra |
1.53 |
The main method of the class: submit jobs in range self.nj_list
|
93 |
nsmirnov |
1.2 |
"""
|
94 |
|
|
common.logger.debug(5, "Submitter::run() called")
|
95 |
slacapra |
1.24 |
|
96 |
spiga |
1.94 |
totalCreatedJobs = 0
|
97 |
corvo |
1.33 |
start = time.time()
|
98 |
spiga |
1.98 |
jList=common._db.nJobs('list')
|
99 |
|
|
st = common._db.queryRunJob('status',jList)
|
100 |
|
|
for nj in range(len(jList)):
|
101 |
|
|
if ( st[nj] in ['C','RC']):totalCreatedJobs +=1
|
102 |
slacapra |
1.24 |
pass
|
103 |
|
|
|
104 |
|
|
if (totalCreatedJobs==0):
|
105 |
|
|
common.logger.message("No jobs to be submitted: first create them")
|
106 |
slacapra |
1.28 |
return
|
107 |
slacapra |
1.60 |
|
108 |
gutsche |
1.70 |
# submit pre DashBoard information
|
109 |
|
|
params = {'jobId':'TaskMeta'}
|
110 |
ewv |
1.92 |
|
111 |
slacapra |
1.83 |
fl = open(common.work_space.shareDir() + '/' + common.apmon.fName, 'r')
|
112 |
gutsche |
1.70 |
for i in fl.readlines():
|
113 |
ewv |
1.92 |
try:
|
114 |
|
|
key, val = i.split(':')
|
115 |
|
|
params[key] = string.strip(val)
|
116 |
|
|
except ValueError: # Not in the right format
|
117 |
|
|
pass
|
118 |
slacapra |
1.85 |
fl.close()
|
119 |
gutsche |
1.70 |
|
120 |
|
|
common.logger.debug(5,'Submission DashBoard Pre-Submission report: '+str(params))
|
121 |
ewv |
1.92 |
|
122 |
slacapra |
1.83 |
common.apmon.sendToML(params)
|
123 |
gutsche |
1.70 |
|
124 |
spiga |
1.94 |
### define here the list of distinct destinations sites list
|
125 |
|
|
# distinct_dests = common._db.queryDistJob('dlsDestination')
|
126 |
|
|
distinct_dests = common._db.queryDistJob_Attr('dlsDestination', 'jobId' ,self.nj_list)
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
### define here the list of jobs Id for each distinct list of sites
|
130 |
|
|
sub_jobs =[] # list of jobs Id list to submit
|
131 |
spiga |
1.95 |
jobs_to_match =[] # list of jobs Id to match
|
132 |
spiga |
1.94 |
all_jobs=[]
|
133 |
|
|
count=0
|
134 |
fanzago |
1.104 |
njs=0
|
135 |
spiga |
1.94 |
for distDest in distinct_dests:
|
136 |
|
|
all_jobs.append(common._db.queryAttrJob({'dlsDestination':distDest},'jobId'))
|
137 |
|
|
sub_jobs_temp=[]
|
138 |
|
|
for i in self.nj_list:
|
139 |
spiga |
1.103 |
if i in all_jobs[count]: sub_jobs_temp.append(i)
|
140 |
spiga |
1.94 |
if len(sub_jobs_temp)>0:
|
141 |
|
|
sub_jobs.append(sub_jobs_temp)
|
142 |
spiga |
1.95 |
jobs_to_match.append(sub_jobs[count][0])
|
143 |
spiga |
1.103 |
count +=1
|
144 |
spiga |
1.94 |
sel=0
|
145 |
|
|
matched=[]
|
146 |
spiga |
1.95 |
|
147 |
|
|
task=common._db.getTask()
|
148 |
|
|
|
149 |
|
|
for id_job in jobs_to_match :
|
150 |
slacapra |
1.110 |
match = common.scheduler.listMatch(distinct_dests[sel])
|
151 |
slacapra |
1.111 |
if len(match)>0:
|
152 |
|
|
common.logger.message("Found "+str(len(match))+" compatible site(s) for job "+str(id_job))
|
153 |
slacapra |
1.110 |
matched.append(sel)
|
154 |
spiga |
1.77 |
else:
|
155 |
slacapra |
1.110 |
common.logger.message("No compatible site found, will not submit jobs "+str(sub_jobs[sel]))
|
156 |
|
|
self.submissionError()
|
157 |
spiga |
1.94 |
sel += 1
|
158 |
ewv |
1.92 |
|
159 |
spiga |
1.94 |
### Progress Bar indicator, deactivate for debug
|
160 |
|
|
if not common.logger.debugLevel() :
|
161 |
slacapra |
1.110 |
term = TerminalController()
|
162 |
spiga |
1.94 |
|
163 |
|
|
if len(matched)>0:
|
164 |
|
|
common.logger.message(str(len(matched))+" blocks of jobs will be submitted")
|
165 |
|
|
for ii in matched:
|
166 |
|
|
common.logger.debug(1,'Submitting jobs '+str(sub_jobs[ii]))
|
167 |
slacapra |
1.110 |
|
168 |
|
|
try:
|
169 |
|
|
common.scheduler.submit(sub_jobs[ii],task)
|
170 |
|
|
except CrabException:
|
171 |
|
|
raise CrabException("Job not submitted")
|
172 |
|
|
|
173 |
corvo |
1.74 |
if not common.logger.debugLevel() :
|
174 |
spiga |
1.94 |
try: pbar = ProgressBar(term, 'Submitting '+str(len(sub_jobs[ii]))+' jobs')
|
175 |
corvo |
1.74 |
except: pbar = None
|
176 |
spiga |
1.94 |
if not common.logger.debugLevel():
|
177 |
|
|
if pbar :
|
178 |
|
|
pbar.update(float(ii+1)/float(len(sub_jobs)),'please wait')
|
179 |
|
|
### check the if the submission succeded Maybe not neede
|
180 |
|
|
if not common.logger.debugLevel():
|
181 |
|
|
if pbar :
|
182 |
|
|
pbar.update(float(ii+1)/float(len(sub_jobs)),'please wait')
|
183 |
ewv |
1.92 |
|
184 |
spiga |
1.94 |
### check the if the submission succeded Maybe not needed or at least simplified
|
185 |
fanzago |
1.104 |
#njs=0
|
186 |
spiga |
1.102 |
sched_Id = common._db.queryRunJob('schedulerId', sub_jobs[ii])
|
187 |
spiga |
1.95 |
listId=[]
|
188 |
spiga |
1.94 |
run_jobToSave = {'status' :'S'}
|
189 |
spiga |
1.108 |
listRunField = []
|
190 |
spiga |
1.102 |
for j in range(len(sub_jobs[ii])): # Add loop over SID returned from group submission DS
|
191 |
|
|
if str(sched_Id[j]) != '':
|
192 |
spiga |
1.94 |
#if (st[j]=='S'):
|
193 |
spiga |
1.102 |
listId.append(sub_jobs[ii][j])
|
194 |
spiga |
1.108 |
listRunField.append(run_jobToSave)
|
195 |
spiga |
1.102 |
common.logger.debug(5,"Submitted job # "+ str(sub_jobs[ii][j]))
|
196 |
spiga |
1.94 |
njs += 1
|
197 |
spiga |
1.108 |
common._db.updateRunJob_(listId, listRunField) ## New BL--DS
|
198 |
spiga |
1.107 |
#
|
199 |
|
|
# ##### DashBoard report #####################
|
200 |
|
|
# Sub_Type = 'Direct'
|
201 |
|
|
#
|
202 |
|
|
# # OLI: JobID treatment, special for Condor-G scheduler
|
203 |
|
|
# jobId = ''
|
204 |
|
|
# localId = ''
|
205 |
|
|
# if common.scheduler.name().upper() == 'CONDOR_G':
|
206 |
|
|
# rb = 'OSG'
|
207 |
|
|
# jobId = str(jj) + '_' + self.hash + '_' + jid
|
208 |
|
|
# common.logger.debug(5,'JobID for ML monitoring is created for CONDOR_G scheduler:'+jobId)
|
209 |
|
|
# elif common.scheduler.name() == 'lsf' or common.scheduler.name() == 'caf':
|
210 |
|
|
# jobId="https://"+common.scheduler.name()+":/"+jid+"-"+string.replace(common.taskDB.dict('taskId'),"_","-")+"-"+str(jj)
|
211 |
|
|
# common.logger.debug(5,'JobID for ML monitoring is created for LSF scheduler:'+jobId)
|
212 |
|
|
# rb = common.scheduler.name()
|
213 |
|
|
# localId = jid
|
214 |
|
|
# else:
|
215 |
|
|
# jobId = str(jj) + '_' + jid
|
216 |
|
|
# common.logger.debug(5,'JobID for ML monitoring is created for EDG scheduler'+jobId)
|
217 |
|
|
# rb = jid.split(':')[1]
|
218 |
|
|
# rb = rb.replace('//', '')
|
219 |
|
|
#
|
220 |
|
|
# if len(common.jobDB.destination(tmpNj)) <= 2 :
|
221 |
|
|
# T_SE=string.join((common.jobDB.destination(tmpNj)),",")
|
222 |
|
|
# else :
|
223 |
|
|
# T_SE=str(len(common.jobDB.destination(tmpNj)))+'_Selected_SE'
|
224 |
|
|
#
|
225 |
|
|
# params = {'jobId': jobId, \
|
226 |
|
|
# 'sid': jid, \
|
227 |
|
|
# 'broker': rb, \
|
228 |
|
|
# 'bossId': jj, \
|
229 |
|
|
# 'SubmissionType': Sub_Type, \
|
230 |
|
|
# 'TargetSE': T_SE, \
|
231 |
|
|
# 'localId' : localId}
|
232 |
|
|
# common.logger.debug(5,str(params))
|
233 |
|
|
#
|
234 |
|
|
# fl = open(common.work_space.shareDir() + '/' + common.apmon.fName, 'r')
|
235 |
|
|
# for i in fl.readlines():
|
236 |
|
|
# key, val = i.split(':')
|
237 |
|
|
# params[key] = string.strip(val)
|
238 |
|
|
# fl.close()
|
239 |
|
|
#
|
240 |
|
|
# common.logger.debug(5,'Submission DashBoard report: '+str(params))
|
241 |
|
|
#
|
242 |
|
|
# common.apmon.sendToML(params)
|
243 |
|
|
# pass
|
244 |
|
|
# pass
|
245 |
|
|
#
|
246 |
spiga |
1.94 |
else:
|
247 |
|
|
common.logger.message("The whole task doesn't found compatible site ")
|
248 |
ewv |
1.92 |
|
249 |
corvo |
1.30 |
stop = time.time()
|
250 |
gutsche |
1.47 |
common.logger.debug(1, "Submission Time: "+str(stop - start))
|
251 |
slacapra |
1.60 |
common.logger.write("Submission time :"+str(stop - start))
|
252 |
ewv |
1.92 |
|
253 |
nsmirnov |
1.6 |
msg = '\nTotal of %d jobs submitted'%njs
|
254 |
|
|
if njs != len(self.nj_list) :
|
255 |
spiga |
1.99 |
msg += ' (from %d requested).'%(len(self.nj_list))
|
256 |
nsmirnov |
1.6 |
else:
|
257 |
spiga |
1.99 |
msg += '.'
|
258 |
|
|
common.logger.message(msg)
|
259 |
|
|
|
260 |
|
|
if (njs < len(self.nj_list) or len(self.nj_list)==0):
|
261 |
|
|
self.submissionError()
|
262 |
|
|
return
|
263 |
|
|
|
264 |
|
|
def submissionError(self):
|
265 |
|
|
## add some more verbose message in case submission is not complete
|
266 |
|
|
msg = 'Submission performed using the Requirements: \n'
|
267 |
|
|
### TODO_ DS--BL
|
268 |
|
|
#msg += common.taskDB.dict("jobtype")+' version: '+common.taskDB.dict("codeVersion")+'\n'
|
269 |
|
|
#msg += '(Hint: please check if '+common.taskDB.dict("jobtype")+' is available at the Sites)\n'
|
270 |
|
|
if self.cfg_params.has_key('EDG.se_white_list'):
|
271 |
|
|
msg += 'SE White List: '+self.cfg_params['EDG.se_white_list']+'\n'
|
272 |
|
|
if self.cfg_params.has_key('EDG.se_black_list'):
|
273 |
|
|
msg += 'SE Black List: '+self.cfg_params['EDG.se_black_list']+'\n'
|
274 |
|
|
if self.cfg_params.has_key('EDG.ce_white_list'):
|
275 |
|
|
msg += 'CE White List: '+self.cfg_params['EDG.ce_white_list']+'\n'
|
276 |
|
|
if self.cfg_params.has_key('EDG.ce_black_list'):
|
277 |
|
|
msg += 'CE Black List: '+self.cfg_params['EDG.ce_black_list']+'\n'
|
278 |
|
|
msg += '(Hint: By whitelisting you force the job to run at this particular site(s).\nPlease check if the dataset is available at this site!)\n'
|
279 |
|
|
|
280 |
slacapra |
1.89 |
common.logger.message(msg)
|
281 |
ewv |
1.92 |
|
282 |
|
|
|
283 |
nsmirnov |
1.1 |
return
|