ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/JdlWriter.py
Revision: 1.3
Committed: Thu Jan 8 15:12:30 2009 UTC (16 years, 4 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.2: +12 -0 lines
Log Message:
use blackWhiteListParser before creating Jdl

File Contents

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