1 |
elmer |
1.65 |
#!/usr/bin/env python
|
2 |
spiga |
1.151 |
import sys, os, time, string
|
3 |
farinafa |
1.133 |
|
4 |
spiga |
1.151 |
### Hopefully will be removed soon!!! DS
|
5 |
farinafa |
1.133 |
## pre-import env configuratin steps
|
6 |
spiga |
1.151 |
#def dropOutPy23dynLoads():
|
7 |
|
|
# # FEDE added -publish
|
8 |
|
|
# #if not ('-create' in sys.argv or '-publish' in sys.argv):
|
9 |
|
|
# if not ('-create' in sys.argv or '-publish' in sys.argv):
|
10 |
|
|
# return
|
11 |
|
|
# tmp = []
|
12 |
|
|
# for p in sys.path:
|
13 |
|
|
# if p.find( "python2.3/lib-dynload" ) == -1 :
|
14 |
|
|
# tmp.append(p)
|
15 |
|
|
# pass
|
16 |
|
|
#
|
17 |
|
|
# sys.path=tmp
|
18 |
|
|
# pass
|
19 |
slacapra |
1.144 |
|
20 |
farinafa |
1.133 |
# this is needed to remove interferences between LCG and CMSSW envs
|
21 |
spiga |
1.151 |
#dropOutPy23dynLoads()
|
22 |
farinafa |
1.133 |
|
23 |
|
|
## actual import session
|
24 |
nsmirnov |
1.1 |
from crab_util import *
|
25 |
|
|
from crab_exceptions import *
|
26 |
|
|
from crab_logger import Logger
|
27 |
|
|
from WorkSpace import WorkSpace
|
28 |
spiga |
1.151 |
from DBinterface import DBinterface ## added to interface with DB BL--DS
|
29 |
nsmirnov |
1.3 |
from JobList import JobList
|
30 |
corvo |
1.42 |
from ApmonIf import ApmonIf
|
31 |
nsmirnov |
1.1 |
import common
|
32 |
spiga |
1.107 |
|
33 |
nsmirnov |
1.1 |
###########################################################################
|
34 |
|
|
class Crab:
|
35 |
nsmirnov |
1.3 |
def __init__(self, opts):
|
36 |
fanzago |
1.76 |
## test_tag
|
37 |
nsmirnov |
1.1 |
# The order of main_actions is important !
|
38 |
fanzago |
1.111 |
self.main_actions = [ '-create', '-submit' ]
|
39 |
slacapra |
1.70 |
self.aux_actions = [ '-list', '-kill', '-status', '-getoutput','-get',
|
40 |
slacapra |
1.163 |
'-resubmit' , '-cancelAndResubmit', '-testJdl',
|
41 |
|
|
'-listMatch', '-match', '-postMortem', '-clean',
|
42 |
fanzago |
1.111 |
'-printId', '-publish' ]
|
43 |
nsmirnov |
1.1 |
|
44 |
|
|
# Dictionary of actions, e.g. '-create' -> object of class Creator
|
45 |
|
|
self.actions = {}
|
46 |
fanzago |
1.76 |
|
47 |
nsmirnov |
1.1 |
# Configuration file
|
48 |
|
|
self.cfg_fname = None
|
49 |
|
|
# Dictionary with configuration parameters
|
50 |
|
|
self.cfg_params = {}
|
51 |
|
|
|
52 |
|
|
# Current working directory
|
53 |
|
|
self.cwd = os.getcwd()+'/'
|
54 |
|
|
# Current time in format 'yymmdd_hhmmss'
|
55 |
|
|
self.current_time = time.strftime('%y%m%d_%H%M%S',
|
56 |
|
|
time.localtime(time.time()))
|
57 |
|
|
|
58 |
nsmirnov |
1.3 |
# Session name (?) Do we need this ?
|
59 |
nsmirnov |
1.1 |
self.name = '0'
|
60 |
|
|
|
61 |
|
|
# Job type
|
62 |
|
|
self.job_type_name = None
|
63 |
|
|
|
64 |
|
|
# Continuation flag
|
65 |
|
|
self.flag_continue = 0
|
66 |
|
|
|
67 |
|
|
# quiet mode, i.e. no output on screen
|
68 |
|
|
self.flag_quiet = 0
|
69 |
|
|
# produce more output
|
70 |
|
|
self.debug_level = 0
|
71 |
|
|
|
72 |
|
|
|
73 |
nsmirnov |
1.3 |
self.initialize_(opts)
|
74 |
nsmirnov |
1.1 |
|
75 |
|
|
return
|
76 |
|
|
|
77 |
nsmirnov |
1.7 |
def version():
|
78 |
nsmirnov |
1.1 |
return common.prog_version_str
|
79 |
|
|
|
80 |
nsmirnov |
1.7 |
version = staticmethod(version)
|
81 |
|
|
|
82 |
nsmirnov |
1.3 |
def initialize_(self, opts):
|
83 |
nsmirnov |
1.1 |
|
84 |
|
|
# Process the '-continue' option first because
|
85 |
|
|
# in the case of continuation the CRAB configuration
|
86 |
|
|
# parameters are loaded from already existing Working Space.
|
87 |
nsmirnov |
1.3 |
self.processContinueOption_(opts)
|
88 |
nsmirnov |
1.1 |
|
89 |
|
|
# Process ini-file first, then command line options
|
90 |
|
|
# because they override ini-file settings.
|
91 |
|
|
|
92 |
nsmirnov |
1.3 |
self.processIniFile_(opts)
|
93 |
nsmirnov |
1.1 |
|
94 |
nsmirnov |
1.3 |
if self.flag_continue: opts = self.loadConfiguration_(opts)
|
95 |
nsmirnov |
1.1 |
|
96 |
nsmirnov |
1.3 |
self.processOptions_(opts)
|
97 |
nsmirnov |
1.1 |
|
98 |
slacapra |
1.77 |
|
99 |
farinafa |
1.154 |
# self.UseServer=int(self.cfg_params.get('CRAB.server_mode',0))
|
100 |
|
|
#
|
101 |
|
|
srvName = opts.get('-server_name', None)
|
102 |
|
|
if srvName == 'None':
|
103 |
|
|
srvName = None
|
104 |
|
|
self.UseServer = int( srvName is not None ) # cast bool to int
|
105 |
|
|
|
106 |
spiga |
1.152 |
common._db = DBinterface(self.cfg_params) #BL--DS
|
107 |
slacapra |
1.101 |
|
108 |
nsmirnov |
1.1 |
if not self.flag_continue:
|
109 |
nsmirnov |
1.3 |
self.createWorkingSpace_()
|
110 |
spiga |
1.152 |
common._db.configureDB()
|
111 |
slacapra |
1.9 |
optsToBeSaved={}
|
112 |
spiga |
1.151 |
optsToBeSavedDB={}
|
113 |
slacapra |
1.9 |
for it in opts.keys():
|
114 |
|
|
if (it in self.main_actions) or (it in self.aux_actions) or (it == '-debug'):
|
115 |
|
|
pass
|
116 |
|
|
else:
|
117 |
spiga |
1.151 |
optsToBeSavedDB[it[1:]]=opts[it]
|
118 |
slacapra |
1.9 |
optsToBeSaved[it]=opts[it]
|
119 |
spiga |
1.158 |
if self.UseServer==0: optsToBeSavedDB['server_name']= srvName
|
120 |
slacapra |
1.101 |
# store in taskDB the opts
|
121 |
farinafa |
1.154 |
|
122 |
|
|
|
123 |
spiga |
1.151 |
common._db.createTask_(optsToBeSavedDB) #BL--DS
|
124 |
slacapra |
1.9 |
common.work_space.saveConfiguration(optsToBeSaved, self.cfg_fname)
|
125 |
spiga |
1.152 |
else:
|
126 |
|
|
common._db.loadDB()
|
127 |
nsmirnov |
1.1 |
|
128 |
|
|
# At this point all configuration options have been read.
|
129 |
|
|
args = string.join(sys.argv,' ')
|
130 |
slacapra |
1.11 |
|
131 |
nsmirnov |
1.3 |
self.updateHistory_(args)
|
132 |
slacapra |
1.11 |
|
133 |
nsmirnov |
1.3 |
self.createLogger_(args)
|
134 |
corvo |
1.51 |
|
135 |
slacapra |
1.144 |
common.apmon = ApmonIf()
|
136 |
slacapra |
1.11 |
|
137 |
nsmirnov |
1.3 |
self.createScheduler_()
|
138 |
slacapra |
1.11 |
|
139 |
slacapra |
1.106 |
common.logger.debug(6, 'Used properties:')
|
140 |
|
|
if (common.logger.debugLevel()<6 ):
|
141 |
|
|
common.logger.write('Used properties:')
|
142 |
|
|
keys = self.cfg_params.keys()
|
143 |
|
|
keys.sort()
|
144 |
|
|
for k in keys:
|
145 |
|
|
if self.cfg_params[k]:
|
146 |
|
|
common.logger.debug(6, ' '+k+' : '+str(self.cfg_params[k]))
|
147 |
|
|
if (common.logger.debugLevel()<6 ):
|
148 |
|
|
common.logger.write(' '+k+' : '+str(self.cfg_params[k]))
|
149 |
|
|
pass
|
150 |
|
|
else:
|
151 |
|
|
common.logger.debug(6, ' '+k+' : ')
|
152 |
|
|
if (common.logger.debugLevel()<6 ):
|
153 |
|
|
common.logger.write(' '+k+' : ')
|
154 |
nsmirnov |
1.3 |
pass
|
155 |
|
|
pass
|
156 |
slacapra |
1.106 |
common.logger.debug(6, 'End of used properties.\n')
|
157 |
|
|
if (common.logger.debugLevel()<6 ):
|
158 |
|
|
common.logger.write('End of used properties.\n')
|
159 |
|
|
|
160 |
nsmirnov |
1.3 |
self.initializeActions_(opts)
|
161 |
nsmirnov |
1.1 |
return
|
162 |
|
|
|
163 |
nsmirnov |
1.3 |
def processContinueOption_(self,opts):
|
164 |
nsmirnov |
1.1 |
|
165 |
|
|
continue_dir = None
|
166 |
nsmirnov |
1.4 |
|
167 |
|
|
# Look for the '-continue' option.
|
168 |
|
|
|
169 |
nsmirnov |
1.1 |
for opt in opts.keys():
|
170 |
|
|
if ( opt in ('-continue','-c') ):
|
171 |
|
|
self.flag_continue = 1
|
172 |
|
|
val = opts[opt]
|
173 |
|
|
if val:
|
174 |
|
|
if val[0] == '/': continue_dir = val # abs path
|
175 |
|
|
else: continue_dir = self.cwd + val # rel path
|
176 |
|
|
pass
|
177 |
nsmirnov |
1.4 |
break
|
178 |
|
|
pass
|
179 |
|
|
|
180 |
|
|
# Look for actions which has sense only with '-continue'
|
181 |
|
|
|
182 |
slacapra |
1.144 |
if "-create" not in opts.keys() :
|
183 |
|
|
self.flag_continue = 1
|
184 |
nsmirnov |
1.1 |
|
185 |
|
|
if not self.flag_continue: return
|
186 |
|
|
|
187 |
|
|
if not continue_dir:
|
188 |
|
|
prefix = common.prog_name + '_' + self.name + '_'
|
189 |
|
|
continue_dir = findLastWorkDir(prefix)
|
190 |
|
|
pass
|
191 |
|
|
|
192 |
|
|
if not continue_dir:
|
193 |
|
|
raise CrabException('Cannot find last working directory.')
|
194 |
|
|
|
195 |
|
|
if not os.path.exists(continue_dir):
|
196 |
|
|
msg = 'Cannot continue because the working directory <'
|
197 |
|
|
msg += continue_dir
|
198 |
|
|
msg += '> does not exist.'
|
199 |
|
|
raise CrabException(msg)
|
200 |
|
|
|
201 |
|
|
# Instantiate WorkSpace
|
202 |
fanzago |
1.49 |
common.work_space = WorkSpace(continue_dir, self.cfg_params)
|
203 |
nsmirnov |
1.1 |
|
204 |
|
|
return
|
205 |
|
|
|
206 |
nsmirnov |
1.3 |
def processIniFile_(self, opts):
|
207 |
nsmirnov |
1.1 |
"""
|
208 |
|
|
Processes a configuration INI-file.
|
209 |
|
|
"""
|
210 |
|
|
|
211 |
|
|
# Extract cfg-file name from the cmd-line options.
|
212 |
|
|
|
213 |
|
|
for opt in opts.keys():
|
214 |
|
|
if ( opt == '-cfg' ):
|
215 |
|
|
if self.flag_continue:
|
216 |
|
|
raise CrabException('-continue and -cfg cannot coexist.')
|
217 |
|
|
if opts[opt] : self.cfg_fname = opts[opt]
|
218 |
slacapra |
1.144 |
else : processHelpOptions()
|
219 |
nsmirnov |
1.1 |
pass
|
220 |
|
|
|
221 |
|
|
elif ( opt == '-name' ):
|
222 |
|
|
self.name = opts[opt]
|
223 |
|
|
pass
|
224 |
|
|
|
225 |
|
|
pass
|
226 |
|
|
|
227 |
|
|
# Set default cfg-fname
|
228 |
|
|
|
229 |
|
|
if self.cfg_fname == None:
|
230 |
|
|
if self.flag_continue:
|
231 |
|
|
self.cfg_fname = common.work_space.cfgFileName()
|
232 |
|
|
else:
|
233 |
|
|
self.cfg_fname = common.prog_name+'.cfg'
|
234 |
|
|
pass
|
235 |
|
|
pass
|
236 |
|
|
|
237 |
|
|
# Load cfg-file
|
238 |
|
|
|
239 |
|
|
if string.lower(self.cfg_fname) != 'none':
|
240 |
|
|
if os.path.exists(self.cfg_fname):
|
241 |
|
|
self.cfg_params = loadConfig(self.cfg_fname)
|
242 |
corvo |
1.64 |
self.cfg_params['user'] = os.environ['USER']
|
243 |
nsmirnov |
1.1 |
pass
|
244 |
|
|
else:
|
245 |
|
|
msg = 'cfg-file '+self.cfg_fname+' not found.'
|
246 |
|
|
raise CrabException(msg)
|
247 |
|
|
pass
|
248 |
|
|
pass
|
249 |
|
|
|
250 |
|
|
# process the [CRAB] section
|
251 |
|
|
|
252 |
|
|
lhp = len('CRAB.')
|
253 |
|
|
for k in self.cfg_params.keys():
|
254 |
|
|
if len(k) >= lhp and k[:lhp] == 'CRAB.':
|
255 |
|
|
opt = '-'+k[lhp:]
|
256 |
|
|
if len(opt) >= 3 and opt[:3] == '-__': continue
|
257 |
|
|
if opt not in opts.keys():
|
258 |
|
|
opts[opt] = self.cfg_params[k]
|
259 |
|
|
pass
|
260 |
|
|
pass
|
261 |
|
|
pass
|
262 |
|
|
|
263 |
|
|
return
|
264 |
|
|
|
265 |
nsmirnov |
1.3 |
def processOptions_(self, opts):
|
266 |
nsmirnov |
1.1 |
"""
|
267 |
|
|
Processes the command-line options.
|
268 |
|
|
"""
|
269 |
|
|
|
270 |
|
|
for opt in opts.keys():
|
271 |
|
|
val = opts[opt]
|
272 |
|
|
|
273 |
nsmirnov |
1.3 |
# Skip actions, they are processed later in initializeActions_()
|
274 |
|
|
if opt in self.main_actions:
|
275 |
|
|
self.cfg_params['CRAB.'+opt[1:]] = val
|
276 |
|
|
continue
|
277 |
|
|
if opt in self.aux_actions:
|
278 |
|
|
self.cfg_params['CRAB.'+opt[1:]] = val
|
279 |
|
|
continue
|
280 |
nsmirnov |
1.1 |
|
281 |
spiga |
1.107 |
elif ( opt == '-server_name' ):
|
282 |
farinafa |
1.154 |
# TODO
|
283 |
spiga |
1.107 |
pass
|
284 |
nsmirnov |
1.1 |
|
285 |
|
|
elif ( opt == '-cfg' ):
|
286 |
|
|
pass
|
287 |
|
|
|
288 |
|
|
elif ( opt in ('-continue', '-c') ):
|
289 |
nsmirnov |
1.4 |
# Already processed in processContinueOption_()
|
290 |
nsmirnov |
1.1 |
pass
|
291 |
|
|
|
292 |
|
|
elif ( opt == '-jobtype' ):
|
293 |
|
|
if val : self.job_type_name = string.upper(val)
|
294 |
slacapra |
1.144 |
else : processHelpOptions()
|
295 |
nsmirnov |
1.1 |
pass
|
296 |
|
|
|
297 |
|
|
elif ( opt == '-Q' ):
|
298 |
|
|
self.flag_quiet = 1
|
299 |
|
|
pass
|
300 |
|
|
|
301 |
|
|
elif ( opt == '-debug' ):
|
302 |
slacapra |
1.6 |
if val: self.debug_level = int(val)
|
303 |
|
|
else: self.debug_level = 1
|
304 |
nsmirnov |
1.1 |
pass
|
305 |
|
|
|
306 |
|
|
elif ( opt == '-scheduler' ):
|
307 |
|
|
pass
|
308 |
slacapra |
1.22 |
|
309 |
nsmirnov |
1.3 |
elif string.find(opt,'.') == -1:
|
310 |
|
|
print common.prog_name+'. Unrecognized option '+opt
|
311 |
slacapra |
1.144 |
processHelpOptions()
|
312 |
nsmirnov |
1.3 |
pass
|
313 |
nsmirnov |
1.1 |
|
314 |
nsmirnov |
1.3 |
# Override config parameters from INI-file with cmd-line params
|
315 |
|
|
if string.find(opt,'.') == -1 :
|
316 |
|
|
self.cfg_params['CRAB.'+opt[1:]] = val
|
317 |
nsmirnov |
1.1 |
pass
|
318 |
nsmirnov |
1.3 |
else:
|
319 |
nsmirnov |
1.1 |
# Command line parameters in the form -SECTION.ENTRY=VALUE
|
320 |
|
|
self.cfg_params[opt[1:]] = val
|
321 |
|
|
pass
|
322 |
|
|
pass
|
323 |
|
|
return
|
324 |
|
|
|
325 |
slacapra |
1.8 |
def parseRange_(self, aRange):
|
326 |
nsmirnov |
1.4 |
"""
|
327 |
slacapra |
1.8 |
Takes as the input a string with a range defined in any of the following
|
328 |
|
|
way, including combination, and return a tuple with the ints defined
|
329 |
|
|
according to following table. A consistency check is done.
|
330 |
|
|
NB: the first job is "1", not "0".
|
331 |
|
|
'all' -> [1,2,..., NJobs]
|
332 |
|
|
'' -> [1,2,..., NJobs]
|
333 |
|
|
'n1' -> [n1]
|
334 |
|
|
'n1-n2' -> [n1, n1+1, n1+2, ..., n2-1, n2]
|
335 |
|
|
'n1,n2' -> [n1, n2]
|
336 |
|
|
'n1,n2-n3' -> [n1, n2, n2+1, n2+2, ..., n3-1, n3]
|
337 |
|
|
"""
|
338 |
|
|
result = []
|
339 |
farinafa |
1.128 |
|
340 |
slacapra |
1.9 |
common.logger.debug(5,"parseRange_ "+str(aRange))
|
341 |
|
|
if aRange=='all' or aRange==None or aRange=='':
|
342 |
spiga |
1.151 |
result=range(1,common._db.nJobs()+1)## new funct. BL--DS
|
343 |
slacapra |
1.8 |
return result
|
344 |
slacapra |
1.9 |
elif aRange=='0':
|
345 |
|
|
return result
|
346 |
slacapra |
1.8 |
|
347 |
farinafa |
1.128 |
subRanges = str(aRange).split(',') # DEPRECATED # Fabio #string.split(aRange, ',')
|
348 |
slacapra |
1.8 |
for subRange in subRanges:
|
349 |
|
|
result = result+self.parseSimpleRange_(subRange)
|
350 |
|
|
|
351 |
|
|
if self.checkUniqueness_(result):
|
352 |
|
|
return result
|
353 |
|
|
else:
|
354 |
mcinquil |
1.132 |
common.logger.message( "Error " +str(result) )
|
355 |
slacapra |
1.8 |
return []
|
356 |
|
|
|
357 |
|
|
def checkUniqueness_(self, list):
|
358 |
|
|
"""
|
359 |
slacapra |
1.9 |
check if a list contains only unique elements
|
360 |
slacapra |
1.8 |
"""
|
361 |
|
|
|
362 |
|
|
uniqueList = []
|
363 |
|
|
# use a list comprehension statement (takes a while to understand)
|
364 |
|
|
|
365 |
|
|
[uniqueList.append(it) for it in list if not uniqueList.count(it)]
|
366 |
|
|
|
367 |
|
|
return (len(list)==len(uniqueList))
|
368 |
|
|
|
369 |
spiga |
1.107 |
|
370 |
slacapra |
1.8 |
def parseSimpleRange_(self, aRange):
|
371 |
|
|
"""
|
372 |
|
|
Takes as the input a string with two integers separated by
|
373 |
|
|
the minus sign and returns the tuple with these numbers:
|
374 |
|
|
'n1-n2' -> [n1, n1+1, n1+2, ..., n2-1, n2]
|
375 |
|
|
'n1' -> [n1]
|
376 |
|
|
"""
|
377 |
|
|
(start, end) = (None, None)
|
378 |
|
|
|
379 |
|
|
result = []
|
380 |
farinafa |
1.128 |
minus = str(aRange).find('-') #DEPRECATED #Fabio #string.find(aRange, '-')
|
381 |
slacapra |
1.8 |
if ( minus < 0 ):
|
382 |
farinafa |
1.128 |
if int(aRange)>0:
|
383 |
corvo |
1.97 |
# FEDE
|
384 |
|
|
#result.append(int(aRange)-1)
|
385 |
|
|
###
|
386 |
slacapra |
1.62 |
result.append(int(aRange))
|
387 |
slacapra |
1.8 |
else:
|
388 |
spiga |
1.47 |
common.logger.message("parseSimpleRange_ ERROR "+aRange)
|
389 |
slacapra |
1.144 |
processHelpOptions()
|
390 |
spiga |
1.47 |
pass
|
391 |
|
|
|
392 |
nsmirnov |
1.4 |
pass
|
393 |
|
|
else:
|
394 |
farinafa |
1.128 |
(start, end) = str(aRange).split('-')
|
395 |
slacapra |
1.8 |
if isInt(start) and isInt(end) and int(start)>0 and int(start)<int(end):
|
396 |
corvo |
1.97 |
#result=range(int(start)-1, int(end))
|
397 |
|
|
result=range(int(start), int(end)+1) #Daniele
|
398 |
slacapra |
1.8 |
else:
|
399 |
slacapra |
1.33 |
common.logger.message("parseSimpleRange_ ERROR "+start+end)
|
400 |
slacapra |
1.8 |
|
401 |
|
|
return result
|
402 |
nsmirnov |
1.4 |
|
403 |
nsmirnov |
1.3 |
def initializeActions_(self, opts):
|
404 |
nsmirnov |
1.1 |
"""
|
405 |
|
|
For each user action instantiate a corresponding
|
406 |
|
|
object and put it in the action dictionary.
|
407 |
|
|
"""
|
408 |
spiga |
1.15 |
|
409 |
|
|
for opt in opts.keys():
|
410 |
|
|
|
411 |
nsmirnov |
1.1 |
val = opts[opt]
|
412 |
spiga |
1.15 |
|
413 |
|
|
|
414 |
|
|
if ( opt == '-create' ):
|
415 |
gutsche |
1.83 |
if val and val != 'all':
|
416 |
|
|
msg = 'Per default, CRAB will create all jobs as specified in the crab.cfg file, not the command line!'
|
417 |
|
|
common.logger.message(msg)
|
418 |
|
|
msg = 'Submission will still take into account the number of jobs specified on the command line!\n'
|
419 |
|
|
common.logger.message(msg)
|
420 |
slacapra |
1.82 |
ncjobs = 'all'
|
421 |
farinafa |
1.138 |
|
422 |
slacapra |
1.144 |
from Creator import Creator
|
423 |
slacapra |
1.82 |
# Instantiate Creator object
|
424 |
|
|
self.creator = Creator(self.job_type_name,
|
425 |
|
|
self.cfg_params,
|
426 |
|
|
ncjobs)
|
427 |
|
|
self.actions[opt] = self.creator
|
428 |
|
|
|
429 |
spiga |
1.139 |
# ############################
|
430 |
farinafa |
1.138 |
|
431 |
slacapra |
1.82 |
# Initialize the JobDB object if needed
|
432 |
|
|
if not self.flag_continue:
|
433 |
spiga |
1.156 |
common._db.createJobs_(self.creator.nJobsL()) ## new BL--DS
|
434 |
nsmirnov |
1.1 |
pass
|
435 |
nsmirnov |
1.3 |
|
436 |
slacapra |
1.82 |
# Create and initialize JobList
|
437 |
spiga |
1.151 |
common.job_list = JobList(common._db.nJobs(), ## new BL--DS
|
438 |
slacapra |
1.82 |
self.creator.jobType())
|
439 |
spiga |
1.151 |
|
440 |
|
|
taskinfo={} ## new BL--DS
|
441 |
|
|
taskinfo['scriptName'] = common.work_space.jobDir()+"/"+self.job_type_name+'.sh' ## new BL--DS
|
442 |
|
|
taskinfo['cfgName'] = common.work_space.jobDir()+"/"+self.creator.jobType().configFilename() ## new BL--DS
|
443 |
nsmirnov |
1.3 |
|
444 |
spiga |
1.151 |
|
445 |
|
|
|
446 |
|
|
|
447 |
slacapra |
1.82 |
common.job_list.setScriptNames(self.job_type_name+'.sh')
|
448 |
|
|
common.job_list.setCfgNames(self.creator.jobType().configFilename())
|
449 |
slacapra |
1.9 |
|
450 |
slacapra |
1.82 |
self.creator.writeJobsSpecsToDB()
|
451 |
spiga |
1.151 |
common._db.updateTask_(taskinfo) ## New BL--DS
|
452 |
nsmirnov |
1.3 |
pass
|
453 |
nsmirnov |
1.1 |
|
454 |
|
|
elif ( opt == '-submit' ):
|
455 |
slacapra |
1.150 |
## Dealt with val == int so that -submit N means submit N jobs and not job # N
|
456 |
spiga |
1.107 |
# modified to support server mode
|
457 |
|
|
if (self.UseServer== 1):
|
458 |
mcinquil |
1.119 |
from SubmitterServer import SubmitterServer
|
459 |
farinafa |
1.125 |
self.actions[opt] = SubmitterServer(self.cfg_params, self.parseRange_(val), val)
|
460 |
spiga |
1.107 |
else:
|
461 |
slacapra |
1.146 |
from Submitter import Submitter
|
462 |
|
|
# Instantiate Submitter object
|
463 |
|
|
self.actions[opt] = Submitter(self.cfg_params, self.parseRange_(val), val)
|
464 |
|
|
# Create and initialize JobList
|
465 |
|
|
if len(common.job_list) == 0 :
|
466 |
spiga |
1.151 |
common.job_list = JobList(common._db.nJobs(), ## New BL--DS
|
467 |
slacapra |
1.146 |
None)
|
468 |
spiga |
1.151 |
# common.job_list.setJDLNames(self.job_type_name+'.jdl')
|
469 |
slacapra |
1.23 |
pass
|
470 |
nsmirnov |
1.1 |
pass
|
471 |
|
|
|
472 |
nsmirnov |
1.4 |
elif ( opt == '-list' ):
|
473 |
spiga |
1.151 |
'''
|
474 |
|
|
Print the relevant infos of a range-all jobs/task
|
475 |
|
|
'''
|
476 |
slacapra |
1.8 |
jobs = self.parseRange_(val)
|
477 |
|
|
|
478 |
spiga |
1.151 |
common._db.dump(jobs) ## New BL--DS
|
479 |
nsmirnov |
1.4 |
pass
|
480 |
|
|
|
481 |
slacapra |
1.67 |
elif ( opt == '-printId' ):
|
482 |
spiga |
1.151 |
'''
|
483 |
|
|
Print the unique name of the task if crab is used as client
|
484 |
|
|
Print the SID list of all the jobs
|
485 |
|
|
'''
|
486 |
spiga |
1.115 |
# modified to support server mode
|
487 |
spiga |
1.157 |
common._db.queryID(self.UseServer) ## New BL--DS
|
488 |
slacapra |
1.67 |
|
489 |
nsmirnov |
1.4 |
elif ( opt == '-status' ):
|
490 |
spiga |
1.153 |
from Status import Status
|
491 |
spiga |
1.107 |
if (self.UseServer== 1):
|
492 |
mcinquil |
1.119 |
from StatusServer import StatusServer
|
493 |
spiga |
1.107 |
self.actions[opt] = StatusServer(self.cfg_params)
|
494 |
|
|
else:
|
495 |
|
|
jobs = self.parseRange_(val)
|
496 |
|
|
|
497 |
|
|
if len(jobs) != 0:
|
498 |
spiga |
1.153 |
self.actions[opt] = Status(self.cfg_params)
|
499 |
spiga |
1.107 |
pass
|
500 |
slacapra |
1.22 |
|
501 |
nsmirnov |
1.4 |
elif ( opt == '-kill' ):
|
502 |
slacapra |
1.8 |
|
503 |
slacapra |
1.148 |
if val:
|
504 |
|
|
if val =='all':
|
505 |
slacapra |
1.161 |
jobs = common._db.nJobs("list")
|
506 |
slacapra |
1.148 |
else:
|
507 |
|
|
jobs = self.parseRange_(val)
|
508 |
|
|
pass
|
509 |
|
|
else:
|
510 |
|
|
raise CrabException("Warning: with '-kill' you _MUST_ specify a job range or 'all'")
|
511 |
|
|
pass
|
512 |
|
|
|
513 |
corvo |
1.109 |
if (self.UseServer== 1):
|
514 |
slacapra |
1.148 |
from KillerServer import KillerServer
|
515 |
spiga |
1.162 |
self.actions[opt] = KillerServer(self.cfg_params,jobs)
|
516 |
corvo |
1.109 |
else:
|
517 |
slacapra |
1.161 |
from Killer import Killer
|
518 |
spiga |
1.162 |
self.actions[opt] = Killer(self.cfg_params,jobs)
|
519 |
nsmirnov |
1.1 |
|
520 |
farinafa |
1.120 |
|
521 |
slacapra |
1.70 |
elif ( opt == '-getoutput' or opt == '-get'):
|
522 |
spiga |
1.162 |
|
523 |
|
|
if val=='all' or val==None or val=='':
|
524 |
|
|
jobs = 'all'
|
525 |
|
|
else:
|
526 |
|
|
jobs = self.parseRange_(val)
|
527 |
|
|
|
528 |
spiga |
1.107 |
if (self.UseServer== 1):
|
529 |
mcinquil |
1.119 |
from GetOutputServer import GetOutputServer
|
530 |
spiga |
1.162 |
self.actions[opt] = GetOutputServer(self.cfg_params,jobs)
|
531 |
spiga |
1.20 |
else:
|
532 |
spiga |
1.162 |
from GetOutput import GetOutput
|
533 |
spiga |
1.159 |
self.actions[opt] = GetOutput(self.cfg_params,jobs)
|
534 |
nsmirnov |
1.4 |
|
535 |
|
|
elif ( opt == '-resubmit' ):
|
536 |
slacapra |
1.11 |
if val:
|
537 |
slacapra |
1.150 |
if val=='all':
|
538 |
|
|
jobs = common.scheduler.list()
|
539 |
|
|
else:
|
540 |
|
|
jobs = self.parseRange_(val)
|
541 |
slacapra |
1.8 |
|
542 |
slacapra |
1.150 |
# Instantiate Submitter object
|
543 |
|
|
from Resubmitter import Resubmitter
|
544 |
|
|
self.actions[opt] = Resubmitter(self.cfg_params, jobs, self.UseServer)
|
545 |
corvo |
1.93 |
|
546 |
slacapra |
1.150 |
# if len(common.job_list) == 0 :
|
547 |
|
|
# common.job_list = JobList(common.jobDB.nJobs(),None)
|
548 |
|
|
# common.job_list.setJDLNames(self.job_type_name+'.jdl')
|
549 |
|
|
# pass
|
550 |
slacapra |
1.8 |
pass
|
551 |
slacapra |
1.11 |
else:
|
552 |
|
|
common.logger.message("Warning: with '-resubmit' you _MUST_ specify a job range or 'all'")
|
553 |
spiga |
1.60 |
common.logger.message("WARNING: _all_ job specified in the range will be resubmitted!!!")
|
554 |
slacapra |
1.11 |
pass
|
555 |
slacapra |
1.8 |
pass
|
556 |
gutsche |
1.61 |
|
557 |
slacapra |
1.8 |
elif ( opt == '-cancelAndResubmit' ):
|
558 |
nsmirnov |
1.5 |
|
559 |
slacapra |
1.78 |
if val:
|
560 |
|
|
if val =='all':
|
561 |
slacapra |
1.147 |
jobs = common.scheduler.list()
|
562 |
spiga |
1.47 |
else:
|
563 |
slacapra |
1.78 |
jobs = self.parseRange_(val)
|
564 |
|
|
# kill submitted jobs
|
565 |
|
|
common.scheduler.cancel(jobs)
|
566 |
spiga |
1.47 |
else:
|
567 |
slacapra |
1.78 |
common.logger.message("Warning: with '-cancelAndResubmit' you _MUST_ specify a job range or 'all'")
|
568 |
nsmirnov |
1.5 |
|
569 |
spiga |
1.47 |
# resubmit cancelled jobs.
|
570 |
|
|
if val:
|
571 |
|
|
nj_list = []
|
572 |
|
|
for nj in jobs:
|
573 |
|
|
st = common.jobDB.status(int(nj)-1)
|
574 |
|
|
if st in ['K','A']:
|
575 |
corvo |
1.97 |
nj_list.append(int(nj)-1)
|
576 |
|
|
common.jobDB.setStatus(int(nj)-1,'C')
|
577 |
spiga |
1.47 |
elif st == 'Y':
|
578 |
spiga |
1.159 |
# common.scheduler.moveOutput(nj)
|
579 |
corvo |
1.97 |
nj_list.append(int(nj)-1)
|
580 |
|
|
st = common.jobDB.setStatus(int(nj)-1,'RC')
|
581 |
spiga |
1.47 |
elif st in ['C','X']:
|
582 |
corvo |
1.97 |
common.logger.message('Job #'+`int(nj)`+' has status '+crabJobStatusToString(st)+' not yet submitted!!!')
|
583 |
spiga |
1.47 |
pass
|
584 |
|
|
elif st == 'D':
|
585 |
corvo |
1.97 |
common.logger.message('Job #'+`int(nj)`+' has status '+crabJobStatusToString(st)+' must be retrieved before resubmission')
|
586 |
spiga |
1.47 |
else:
|
587 |
|
|
common.logger.message('Job #'+`nj`+' has status '+crabJobStatusToString(st)+' must be "killed" before resubmission')
|
588 |
|
|
pass
|
589 |
|
|
|
590 |
nsmirnov |
1.5 |
if len(common.job_list) == 0 :
|
591 |
spiga |
1.47 |
common.job_list = JobList(common.jobDB.nJobs(),None)
|
592 |
nsmirnov |
1.5 |
common.job_list.setJDLNames(self.job_type_name+'.jdl')
|
593 |
|
|
pass
|
594 |
spiga |
1.47 |
|
595 |
|
|
if len(nj_list) != 0:
|
596 |
spiga |
1.86 |
# common.scheduler.resubmit(nj_list)
|
597 |
fanzago |
1.58 |
self.actions[opt] = Submitter(self.cfg_params, nj_list)
|
598 |
spiga |
1.47 |
pass
|
599 |
|
|
pass
|
600 |
|
|
else:
|
601 |
|
|
common.logger.message("WARNING: _all_ job specified in the rage will be cancelled and resubmitted!!!")
|
602 |
nsmirnov |
1.5 |
pass
|
603 |
spiga |
1.47 |
common.jobDB.save()
|
604 |
nsmirnov |
1.4 |
pass
|
605 |
slacapra |
1.163 |
elif ( opt in ['-testJdl','-listMatch', '-match']):
|
606 |
slacapra |
1.8 |
jobs = self.parseRange_(val)
|
607 |
|
|
|
608 |
slacapra |
1.163 |
if len(jobs) != 0:
|
609 |
slacapra |
1.77 |
# Instantiate Checker object
|
610 |
slacapra |
1.144 |
from Checker import Checker
|
611 |
slacapra |
1.163 |
self.actions[opt] = Checker(self.cfg_params, jobs)
|
612 |
slacapra |
1.8 |
|
613 |
slacapra |
1.9 |
elif ( opt == '-postMortem' ):
|
614 |
corvo |
1.95 |
|
615 |
spiga |
1.162 |
if val:
|
616 |
|
|
if val =='all':
|
617 |
|
|
jobs = common._db.nJobs("list")
|
618 |
|
|
else:
|
619 |
|
|
jobs = self.parseRange_(val)
|
620 |
|
|
pass
|
621 |
|
|
else:
|
622 |
|
|
raise CrabException("Warning: please specify a job range or 'all'")
|
623 |
|
|
pass
|
624 |
|
|
|
625 |
spiga |
1.108 |
if (self.UseServer== 1):
|
626 |
mcinquil |
1.119 |
from PostMortemServer import PostMortemServer
|
627 |
spiga |
1.162 |
self.actions[opt] = PostMortemServer(self.cfg_params,jobs)
|
628 |
spiga |
1.108 |
else:
|
629 |
spiga |
1.162 |
from PostMortem import PostMortem
|
630 |
|
|
self.actions[opt] = PostMortem(self.cfg_params, jobs)
|
631 |
slacapra |
1.9 |
|
632 |
|
|
elif ( opt == '-clean' ):
|
633 |
|
|
if val != None:
|
634 |
|
|
raise CrabException("No range allowed for '-clean'")
|
635 |
mcinquil |
1.118 |
if (self.UseServer== 1):
|
636 |
mcinquil |
1.119 |
from CleanerServer import CleanerServer
|
637 |
mcinquil |
1.118 |
self.actions[opt] = CleanerServer(self.cfg_params)
|
638 |
|
|
else:
|
639 |
slacapra |
1.144 |
from Cleaner import Cleaner
|
640 |
mcinquil |
1.118 |
self.actions[opt] = Cleaner(self.cfg_params)
|
641 |
|
|
|
642 |
fanzago |
1.111 |
elif ( opt == '-publish' ):
|
643 |
slacapra |
1.141 |
from Publisher import Publisher
|
644 |
slacapra |
1.116 |
self.actions[opt] = Publisher(self.cfg_params)
|
645 |
|
|
|
646 |
nsmirnov |
1.1 |
pass
|
647 |
|
|
return
|
648 |
|
|
|
649 |
nsmirnov |
1.3 |
def createWorkingSpace_(self):
|
650 |
slacapra |
1.9 |
new_dir = ''
|
651 |
|
|
|
652 |
slacapra |
1.144 |
if self.cfg_params.has_key('USER.ui_working_dir') :
|
653 |
slacapra |
1.9 |
new_dir = self.cfg_params['USER.ui_working_dir']
|
654 |
slacapra |
1.144 |
if not new_dir[1] == '/':
|
655 |
slacapra |
1.122 |
new_dir = self.cwd + new_dir
|
656 |
slacapra |
1.9 |
pass
|
657 |
slacapra |
1.144 |
else:
|
658 |
|
|
new_dir = self.cwd + common.prog_name + '_' + self.name + '_' + self.current_time
|
659 |
|
|
pass
|
660 |
|
|
if os.path.exists(new_dir):
|
661 |
|
|
if os.listdir(new_dir):
|
662 |
|
|
msg = new_dir + ' already exists and is not empty. Please remove it before create new task'
|
663 |
|
|
raise CrabException(msg)
|
664 |
|
|
|
665 |
fanzago |
1.49 |
common.work_space = WorkSpace(new_dir, self.cfg_params)
|
666 |
nsmirnov |
1.1 |
common.work_space.create()
|
667 |
slacapra |
1.144 |
|
668 |
nsmirnov |
1.1 |
return
|
669 |
|
|
|
670 |
nsmirnov |
1.3 |
def loadConfiguration_(self, opts):
|
671 |
nsmirnov |
1.1 |
|
672 |
|
|
save_opts = common.work_space.loadSavedOptions()
|
673 |
|
|
|
674 |
|
|
# Override saved options with new command-line options
|
675 |
|
|
|
676 |
|
|
for k in opts.keys():
|
677 |
|
|
save_opts[k] = opts[k]
|
678 |
|
|
pass
|
679 |
|
|
|
680 |
|
|
# Return updated options
|
681 |
|
|
return save_opts
|
682 |
|
|
|
683 |
nsmirnov |
1.3 |
def createLogger_(self, args):
|
684 |
nsmirnov |
1.1 |
|
685 |
|
|
log = Logger()
|
686 |
|
|
log.quiet(self.flag_quiet)
|
687 |
|
|
log.setDebugLevel(self.debug_level)
|
688 |
|
|
log.write(args+'\n')
|
689 |
nsmirnov |
1.3 |
log.message(self.headerString_())
|
690 |
nsmirnov |
1.1 |
log.flush()
|
691 |
|
|
common.logger = log
|
692 |
|
|
return
|
693 |
|
|
|
694 |
nsmirnov |
1.3 |
def updateHistory_(self, args):
|
695 |
nsmirnov |
1.1 |
history_fname = common.prog_name+'.history'
|
696 |
|
|
history_file = open(history_fname, 'a')
|
697 |
|
|
history_file.write(self.current_time+': '+args+'\n')
|
698 |
|
|
history_file.close()
|
699 |
|
|
return
|
700 |
|
|
|
701 |
nsmirnov |
1.3 |
def headerString_(self):
|
702 |
nsmirnov |
1.1 |
"""
|
703 |
|
|
Creates a string describing program options either given in
|
704 |
|
|
the command line or their default values.
|
705 |
|
|
"""
|
706 |
|
|
header = common.prog_name + ' (version ' + common.prog_version_str + \
|
707 |
|
|
') running on ' + \
|
708 |
|
|
time.ctime(time.time())+'\n\n' + \
|
709 |
|
|
common.prog_name+'. Working options:\n'
|
710 |
fanzago |
1.59 |
#print self.job_type_name
|
711 |
nsmirnov |
1.1 |
header = header +\
|
712 |
slacapra |
1.85 |
' scheduler ' + self.cfg_params['CRAB.scheduler'] + '\n'+\
|
713 |
nsmirnov |
1.1 |
' job type ' + self.job_type_name + '\n'+\
|
714 |
|
|
' working directory ' + common.work_space.topDir()\
|
715 |
|
|
+ '\n'
|
716 |
|
|
return header
|
717 |
|
|
|
718 |
nsmirnov |
1.3 |
def createScheduler_(self):
|
719 |
nsmirnov |
1.1 |
"""
|
720 |
|
|
Creates a scheduler object instantiated by its name.
|
721 |
|
|
"""
|
722 |
slacapra |
1.147 |
if not self.cfg_params.has_key("CRAB.scheduler"):
|
723 |
|
|
msg = 'No real scheduler selected: edg, lsf ...'
|
724 |
|
|
msg = msg + 'Please specify a scheduler type in the crab cfg file'
|
725 |
|
|
raise CrabException(msg)
|
726 |
|
|
self.scheduler_name = self.cfg_params["CRAB.scheduler"]
|
727 |
spiga |
1.160 |
### just temporary... will disappear
|
728 |
|
|
if self.scheduler_name.lower()=='glitecoll': self.scheduler_name='glite'
|
729 |
slacapra |
1.147 |
|
730 |
|
|
klass_name = 'Scheduler' + string.capitalize(self.scheduler_name)
|
731 |
nsmirnov |
1.1 |
file_name = klass_name
|
732 |
|
|
try:
|
733 |
|
|
klass = importName(file_name, klass_name)
|
734 |
|
|
except KeyError:
|
735 |
|
|
msg = 'No `class '+klass_name+'` found in file `'+file_name+'.py`'
|
736 |
|
|
raise CrabException(msg)
|
737 |
|
|
except ImportError, e:
|
738 |
slacapra |
1.101 |
msg = 'Cannot create scheduler Boss'
|
739 |
nsmirnov |
1.1 |
msg += ' (file: '+file_name+', class '+klass_name+'):\n'
|
740 |
|
|
msg += str(e)
|
741 |
|
|
raise CrabException(msg)
|
742 |
|
|
|
743 |
|
|
common.scheduler = klass()
|
744 |
|
|
common.scheduler.configure(self.cfg_params)
|
745 |
|
|
return
|
746 |
|
|
|
747 |
|
|
def run(self):
|
748 |
|
|
"""
|
749 |
|
|
For each
|
750 |
|
|
"""
|
751 |
|
|
|
752 |
|
|
for act in self.main_actions:
|
753 |
|
|
if act in self.actions.keys(): self.actions[act].run()
|
754 |
|
|
pass
|
755 |
|
|
|
756 |
|
|
for act in self.aux_actions:
|
757 |
|
|
if act in self.actions.keys(): self.actions[act].run()
|
758 |
|
|
pass
|
759 |
|
|
return
|
760 |
|
|
|
761 |
|
|
###########################################################################
|
762 |
slacapra |
1.144 |
def processHelpOptions(opts={}):
|
763 |
|
|
from crab_help import usage, help
|
764 |
nsmirnov |
1.1 |
|
765 |
slacapra |
1.11 |
if len(opts):
|
766 |
|
|
for opt in opts.keys():
|
767 |
|
|
if opt in ('-v', '-version', '--version') :
|
768 |
slacapra |
1.144 |
print 'CRAB version: ',Crab.version()
|
769 |
slacapra |
1.11 |
return 1
|
770 |
|
|
if opt in ('-h','-help','--help') :
|
771 |
|
|
if opts[opt] : help(opts[opt])
|
772 |
|
|
else: help()
|
773 |
|
|
return 1
|
774 |
|
|
else:
|
775 |
|
|
usage()
|
776 |
corvo |
1.93 |
|
777 |
nsmirnov |
1.1 |
return 0
|
778 |
|
|
|
779 |
corvo |
1.93 |
###########################################################################
|
780 |
nsmirnov |
1.1 |
if __name__ == '__main__':
|
781 |
slacapra |
1.92 |
## Get rid of some useless warning
|
782 |
slacapra |
1.94 |
try:
|
783 |
|
|
import warnings
|
784 |
|
|
warnings.simplefilter("ignore", RuntimeWarning)
|
785 |
slacapra |
1.163 |
except ImportError:
|
786 |
slacapra |
1.94 |
pass # too bad, you'll get the warning
|
787 |
spiga |
1.137 |
|
788 |
nsmirnov |
1.1 |
# Parse command-line options and create a dictionary with
|
789 |
|
|
# key-value pairs.
|
790 |
|
|
options = parseOptions(sys.argv[1:])
|
791 |
|
|
|
792 |
|
|
# Process "help" options, such as '-help', '-version'
|
793 |
slacapra |
1.11 |
if processHelpOptions(options) : sys.exit(0)
|
794 |
nsmirnov |
1.1 |
|
795 |
|
|
# Create, initialize, and run a Crab object
|
796 |
|
|
try:
|
797 |
nsmirnov |
1.3 |
crab = Crab(options)
|
798 |
nsmirnov |
1.1 |
crab.run()
|
799 |
slacapra |
1.144 |
common.apmon.free()
|
800 |
nsmirnov |
1.1 |
except CrabException, e:
|
801 |
|
|
print '\n' + common.prog_name + ': ' + str(e) + '\n'
|
802 |
|
|
if common.logger:
|
803 |
|
|
common.logger.write('ERROR: '+str(e)+'\n')
|
804 |
|
|
pass
|
805 |
|
|
pass
|
806 |
|
|
|
807 |
|
|
pass
|