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 |
spiga |
1.10 |
import Statistic
|
6 |
nsmirnov |
1.1 |
|
7 |
|
|
class Submitter(Actor):
|
8 |
nsmirnov |
1.4 |
def __init__(self, cfg_params, nj_list):
|
9 |
nsmirnov |
1.1 |
self.cfg_params = cfg_params
|
10 |
nsmirnov |
1.4 |
self.nj_list = nj_list
|
11 |
slacapra |
1.25 |
try:
|
12 |
|
|
self.ML = int(cfg_params['USER.activate_monalisa'])
|
13 |
|
|
except KeyError:
|
14 |
|
|
self.ML = 0
|
15 |
|
|
pass
|
16 |
|
|
|
17 |
|
|
if (self.ML==1): self.mon = ApmonIf()
|
18 |
spiga |
1.10 |
|
19 |
nsmirnov |
1.1 |
return
|
20 |
|
|
|
21 |
|
|
def run(self):
|
22 |
nsmirnov |
1.2 |
"""
|
23 |
|
|
The main method of the class.
|
24 |
|
|
"""
|
25 |
|
|
common.logger.debug(5, "Submitter::run() called")
|
26 |
slacapra |
1.24 |
|
27 |
|
|
totalCreatedJobs= 0
|
28 |
|
|
for nj in range(common.jobDB.nJobs()):
|
29 |
|
|
if (common.jobDB.status(nj)=='C'): totalCreatedJobs +=1
|
30 |
|
|
pass
|
31 |
|
|
|
32 |
|
|
if (totalCreatedJobs==0):
|
33 |
|
|
common.logger.message("No jobs to be submitted: first create them")
|
34 |
|
|
|
35 |
slacapra |
1.7 |
firstJob=self.nj_list[0]
|
36 |
|
|
match = common.scheduler.listMatch(firstJob)
|
37 |
slacapra |
1.8 |
if match:
|
38 |
|
|
common.logger.message("Found compatible resources "+str(match))
|
39 |
|
|
else:
|
40 |
|
|
raise CrabException("No compatible resources found!")
|
41 |
fanzago |
1.16 |
#########
|
42 |
nsmirnov |
1.2 |
# Loop over jobs
|
43 |
nsmirnov |
1.6 |
njs = 0
|
44 |
corvo |
1.15 |
try:
|
45 |
corvo |
1.17 |
for nj in self.nj_list:
|
46 |
|
|
st = common.jobDB.status(nj)
|
47 |
corvo |
1.21 |
# print "nj = ", nj
|
48 |
|
|
# print "st = ", st
|
49 |
corvo |
1.17 |
if st != 'C' and st != 'K' and st != 'A' and st != 'RC':
|
50 |
|
|
long_st = crabJobStatusToString(st)
|
51 |
slacapra |
1.19 |
msg = "Job # %d not submitted: status %s"%(nj+1, long_st)
|
52 |
slacapra |
1.18 |
common.logger.message(msg)
|
53 |
corvo |
1.17 |
continue
|
54 |
|
|
|
55 |
|
|
common.logger.message("Submitting job # "+`(nj+1)`)
|
56 |
|
|
jid = common.scheduler.submit(nj)
|
57 |
|
|
|
58 |
|
|
common.jobDB.setStatus(nj, 'S')
|
59 |
|
|
common.jobDB.setJobId(nj, jid)
|
60 |
|
|
njs += 1
|
61 |
|
|
|
62 |
|
|
############################################
|
63 |
|
|
|
64 |
|
|
if st == 'C':
|
65 |
|
|
resFlag = 0
|
66 |
|
|
elif st == 'RC':
|
67 |
|
|
resFlag = 2
|
68 |
|
|
else:
|
69 |
|
|
resFlag = 0
|
70 |
|
|
pass
|
71 |
spiga |
1.26 |
|
72 |
|
|
#try:
|
73 |
|
|
# print 'submitter prima '
|
74 |
|
|
|
75 |
|
|
Statistic.Monitor('submit',resFlag,jid,'-----')
|
76 |
|
|
# print 'submitter Dopo '
|
77 |
|
|
|
78 |
corvo |
1.17 |
|
79 |
spiga |
1.26 |
#except:
|
80 |
|
|
# pass
|
81 |
corvo |
1.17 |
|
82 |
slacapra |
1.25 |
if (self.ML==1):
|
83 |
slacapra |
1.22 |
try:
|
84 |
slacapra |
1.25 |
# SL this is crap! Should not be here!!!!
|
85 |
spiga |
1.26 |
#List of parameters to be sent to ML monitor system
|
86 |
slacapra |
1.25 |
user = os.getlogin()
|
87 |
|
|
taskId = os.getlogin()+'_'+string.split(common.work_space.topDir(),'/')[-2]
|
88 |
|
|
jobId = str(nj)
|
89 |
|
|
sid = jid
|
90 |
|
|
try:
|
91 |
|
|
application = os.path.basename(os.environ['SCRAMRT_LOCALRT'])
|
92 |
|
|
except KeyError:
|
93 |
|
|
application = os.path.basename(os.environ['LOCALRT'])
|
94 |
|
|
|
95 |
|
|
nevtJob = common.jobDB.maxEvents(nj)
|
96 |
|
|
exe = self.cfg_params['USER.executable']
|
97 |
|
|
tool = common.prog_name
|
98 |
|
|
scheduler = self.cfg_params['CRAB.scheduler']
|
99 |
|
|
taskType = 'analysis'
|
100 |
|
|
vo = 'cms'
|
101 |
|
|
rb = sid.split(':')[1]
|
102 |
|
|
rb = rb.replace('//', '')
|
103 |
|
|
params = {'taskId': taskId, 'jobId': jobId, 'sid': sid, 'application': application, \
|
104 |
|
|
'exe': exe, 'nevtJob': nevtJob, 'tool': tool, 'scheduler': scheduler, \
|
105 |
|
|
'user': user, 'taskType': taskType, 'vo': vo, 'dataset': self.dataset, 'owner': self.owner, 'broker': rb}
|
106 |
|
|
self.mon.fillDict(params)
|
107 |
|
|
self.mon.sendToML()
|
108 |
|
|
except:
|
109 |
|
|
pass
|
110 |
|
|
pass # use ML
|
111 |
corvo |
1.17 |
except:
|
112 |
slacapra |
1.22 |
common.logger.message("Submitter::run Exception raised")
|
113 |
corvo |
1.17 |
common.jobDB.save()
|
114 |
slacapra |
1.18 |
|
115 |
corvo |
1.17 |
common.jobDB.save()
|
116 |
corvo |
1.15 |
|
117 |
nsmirnov |
1.6 |
msg = '\nTotal of %d jobs submitted'%njs
|
118 |
|
|
if njs != len(self.nj_list) :
|
119 |
|
|
msg += ' (from %d requested).'%(len(self.nj_list))
|
120 |
|
|
pass
|
121 |
|
|
else:
|
122 |
|
|
msg += '.'
|
123 |
|
|
pass
|
124 |
nsmirnov |
1.2 |
common.logger.message(msg)
|
125 |
nsmirnov |
1.1 |
return
|
126 |
|
|
|
127 |
spiga |
1.26 |
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|