1 |
spiga |
1.1 |
from Actor import *
|
2 |
|
|
from crab_util import *
|
3 |
|
|
import common
|
4 |
|
|
from ApmonIf import ApmonIf
|
5 |
|
|
|
6 |
|
|
import os, errno, time, sys, re
|
7 |
|
|
import commands
|
8 |
|
|
|
9 |
|
|
class JdlWriter( Actor ):
|
10 |
|
|
def __init__(self, cfg_params, jobs):
|
11 |
|
|
self.cfg_params = cfg_params
|
12 |
|
|
self.nj_list = jobs
|
13 |
|
|
return
|
14 |
|
|
|
15 |
|
|
def run(self):
|
16 |
|
|
"""
|
17 |
|
|
The main method of the class: write JDL for jobs in range self.nj_list
|
18 |
|
|
"""
|
19 |
|
|
common.logger.debug(5, "JdlWriter::run() called")
|
20 |
|
|
|
21 |
|
|
start = time.time()
|
22 |
|
|
|
23 |
|
|
jobs_L = self.listOfjobs()
|
24 |
|
|
|
25 |
|
|
self.writer(jobs_L)
|
26 |
|
|
|
27 |
|
|
stop = time.time()
|
28 |
|
|
|
29 |
|
|
common.logger.write("JDL writing time :"+str(stop - start))
|
30 |
|
|
|
31 |
|
|
return
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
def listOfjobs(self):
|
35 |
|
|
|
36 |
|
|
### define here the list of distinct destinations sites list
|
37 |
|
|
distinct_dests = common._db.queryDistJob_Attr('dlsDestination', 'jobId' ,self.nj_list)
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
### define here the list of jobs Id for each distinct list of sites
|
41 |
|
|
self.sub_jobs =[] # list of jobs Id list to submit
|
42 |
|
|
jobs_to_match =[] # list of jobs Id to match
|
43 |
|
|
all_jobs=[]
|
44 |
|
|
count=0
|
45 |
|
|
for distDest in distinct_dests:
|
46 |
|
|
all_jobs.append(common._db.queryAttrJob({'dlsDestination':distDest},'jobId'))
|
47 |
|
|
sub_jobs_temp=[]
|
48 |
|
|
for i in self.nj_list:
|
49 |
|
|
if i in all_jobs[count]: sub_jobs_temp.append(i)
|
50 |
|
|
if len(sub_jobs_temp)>0:
|
51 |
|
|
self.sub_jobs.append(sub_jobs_temp)
|
52 |
|
|
count +=1
|
53 |
|
|
return self.sub_jobs
|
54 |
|
|
|
55 |
|
|
def writer(self,list):
|
56 |
|
|
"""
|
57 |
|
|
Materialize JDL into file
|
58 |
|
|
"""
|
59 |
|
|
task = common._db.getTask()
|
60 |
|
|
c1 = 1
|
61 |
|
|
c2 = 1
|
62 |
|
|
for sub_list in list:
|
63 |
|
|
jdl = common.scheduler.writeJDL(sub_list, task)
|
64 |
|
|
|
65 |
|
|
for stri in jdl:
|
66 |
|
|
#self.jdlFile='File-'+str(c1)+'_'+str(c2)+'.jdl'
|
67 |
|
|
self.jdlFile='File-'+str(c1)+'_'+str(c2)+'.jdl'
|
68 |
|
|
j_file = open(common.work_space.shareDir()+'/'+self.jdlFile, 'w')
|
69 |
|
|
j_file.write( stri )
|
70 |
|
|
j_file.close()
|
71 |
|
|
c2 += 1
|
72 |
|
|
c1 += 1
|
73 |
|
|
|
74 |
|
|
common.logger.message('JDL files are written to '+str(common.work_space.shareDir())+'File-*.jdl \n' )
|
75 |
|
|
|
76 |
|
|
return
|
77 |
|
|
|
78 |
|
|
|