ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerGlite.py
Revision: 1.69
Committed: Tue Jun 9 13:12:06 2009 UTC (15 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_6_0_pre13, CRAB_2_6_0_pre12, CRAB_2_6_0_pre11, CRAB_2_6_0_pre10, CRAB_2_6_0_pre9, CRAB_2_6_0_pre8
Changes since 1.68: +3 -3 lines
Log Message:
Introduce a CrabLogger class which hanlde the std python logging

File Contents

# User Rev Content
1 ewv 1.62 """
2     CRAB interface to BossLite gLite Scheduler
3     """
4    
5 slacapra 1.69 __revision__ = "$Id: SchedulerGlite.py,v 1.68 2009/05/26 16:53:23 spiga Exp $"
6     __version__ = "$Revision: 1.68 $"
7 ewv 1.62
8 slacapra 1.31 from SchedulerGrid import SchedulerGrid
9 spiga 1.2 from crab_exceptions import *
10     from crab_util import *
11 fanzago 1.4 from GliteConfig import *
12 spiga 1.47 import EdgLoggingInfo
13 spiga 1.2 import common
14 ewv 1.65 from WMCore.SiteScreening.BlackWhiteListParser import CEBlackWhiteListParser
15 spiga 1.2
16     import os, sys, time
17    
18 slacapra 1.31 class SchedulerGlite(SchedulerGrid):
19 slacapra 1.33 def __init__(self, name="GLITE"):
20     SchedulerGrid.__init__(self,name)
21 slacapra 1.31
22 fanzago 1.54 self.OSBsize = 55000000
23 spiga 1.51
24 slacapra 1.31 def configure(self,cfg_params):
25     SchedulerGrid.configure(self, cfg_params)
26 ewv 1.61 self.environment_unique_identifier = '$GLITE_WMS_JOBID'
27 slacapra 1.3
28 spiga 1.51 def realSchedParams(self,cfg_params):
29     """
30 ewv 1.61 Return dictionary with specific parameters, to use
31     with real scheduler
32 spiga 1.51 """
33     self.rb_param_file=''
34 spiga 1.68 if (not cfg_params.has_key('GRID.rb')):
35     cfg_params['GRID.rb']='CERN'
36     self.rb_param_file=common.scheduler.rb_configure(cfg_params.get("GRID.rb"))
37     self.wms_service=cfg_params.get("GRID.wms_service",'')
38     self.skipWMSAuth=cfg_params.get("GRID.skipwmsauth",1)
39 spiga 1.51 params = { 'service' : self.wms_service, \
40 afanfani 1.55 'config' : self.rb_param_file, \
41 ewv 1.61 'skipWMSAuth' : self.skipWMSAuth
42 spiga 1.51 }
43     return params
44 ewv 1.61
45 spiga 1.51
46 fanzago 1.4 def rb_configure(self, RB):
47 slacapra 1.31 if not RB: return None
48     glite_config = None
49     rb_param_file = None
50 fanzago 1.4
51     gliteConfig = GliteConfig(RB)
52 slacapra 1.31 glite_config = gliteConfig.config()
53 fanzago 1.4
54 slacapra 1.31 if (glite_config ):
55 spiga 1.40 rb_param_file = glite_config
56 slacapra 1.31 return rb_param_file
57 fanzago 1.4
58 spiga 1.36 def ce_list(self):
59 spiga 1.2 """
60 ewv 1.42 Returns string with requirement CE related
61 spiga 1.2 """
62 ewv 1.65 ceParser = CEBlackWhiteListParser(self.EDG_ce_white_list,
63 slacapra 1.69 self.EDG_ce_black_list, common.logger())
64 ewv 1.42 req = ''
65 ewv 1.65 ce_white_list = []
66     ce_black_list = []
67 spiga 1.2 if self.EDG_ce_white_list:
68 ewv 1.65 ce_white_list = ceParser.whiteList()
69 slacapra 1.13 tmpCe=[]
70     concString = '&&'
71     for ce in ce_white_list:
72     tmpCe.append('RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId)')
73 mcinquil 1.20 if len(tmpCe) == 1:
74     req += " && (" + concString.join(tmpCe) + ") "
75     elif len(tmpCe) > 1:
76     firstCE = 0
77     for reqTemp in tmpCe:
78     if firstCE == 0:
79     req += " && ( (" + reqTemp + ") "
80     firstCE = 1
81     elif firstCE > 0:
82     req += " || (" + reqTemp + ") "
83     if firstCE > 0:
84     req += ") "
85 ewv 1.28
86 spiga 1.2 if self.EDG_ce_black_list:
87 ewv 1.65 ce_black_list = ceParser.blackList()
88 slacapra 1.13 tmpCe=[]
89     concString = '&&'
90 spiga 1.2 for ce in ce_black_list:
91 slacapra 1.13 tmpCe.append('(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))')
92 spiga 1.36 if len(tmpCe): req += " && (" + concString.join(tmpCe) + ") "
93    
94     # requirement added to skip gliteCE
95     req += '&& (!RegExp("blah", other.GlueCEUniqueId))'
96 ewv 1.66 retWL = ','.join(ce_white_list)
97     retBL = ','.join(ce_black_list)
98     if not retWL:
99     retWL = None
100     if not retBL:
101     retBL = None
102 spiga 1.36
103 ewv 1.66 return req, retWL, retBL
104 spiga 1.36
105 slacapra 1.60 def se_list(self, dest):
106 spiga 1.36 """
107 ewv 1.42 Returns string with requirement SE related
108     """
109 slacapra 1.60 hostList=self.findSites_(dest)
110 spiga 1.36 req=''
111     reqtmp=[]
112     concString = '||'
113    
114     for arg in hostList:
115     reqtmp.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
116    
117     if len(reqtmp): req += " && (" + concString.join(reqtmp) + ") "
118 spiga 1.11
119 spiga 1.36 return req
120    
121     def jdlParam(self):
122     """
123 ewv 1.42 Returns
124     """
125 spiga 1.36 req=''
126     if self.EDG_addJdlParam:
127 ewv 1.42 if self.EDG_addJdlParam[-1] == '': self.EDG_addJdlParam= self.EDG_addJdlParam[:-1]
128 spiga 1.36 for p in self.EDG_addJdlParam:
129 ewv 1.61 req+=string.strip(p)+';\n'
130 spiga 1.36 return req
131    
132     def specific_req(self):
133     """
134     Returns string with specific requirements
135 ewv 1.42 """
136 spiga 1.36 req=''
137 spiga 1.2 if self.EDG_clock_time:
138 slacapra 1.13 if (not req == ' '): req = req + ' && '
139     req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
140 spiga 1.2
141     if self.EDG_cpu_time:
142 slacapra 1.13 if (not req == ' '): req = req + ' && '
143     req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
144 ewv 1.42
145 spiga 1.36 return req
146 ewv 1.28
147 spiga 1.39 def sched_parameter(self,i,task):
148     """
149     Returns string with requirements and scheduler-specific parameters
150     """
151 ewv 1.61 dest= task.jobs[i-1]['dlsDestination']
152 spiga 1.39
153     req=''
154     req +=task['jobType']
155    
156     sched_param=''
157 slacapra 1.60 sched_param+='Requirements = ' + req +self.specific_req() + self.se_list(dest) +\
158 ewv 1.61 self.ce_list()[0] +';\n'
159     if self.EDG_addJdlParam: sched_param+=self.jdlParam()
160 spiga 1.39 sched_param+='MyProxyServer = "' + self.proxyServer + '";\n'
161     sched_param+='VirtualOrganisation = "' + self.VO + '";\n'
162     sched_param+='RetryCount = '+str(self.EDG_retry_count)+';\n'
163     sched_param+='ShallowRetryCount = '+str(self.EDG_shallow_retry_count)+';\n'
164    
165     return sched_param
166 ewv 1.42
167 spiga 1.47 def decodeLogInfo(self, file):
168     """
169     Parse logging info file and return main info
170     """
171     loggingInfo = EdgLoggingInfo.EdgLoggingInfo()
172     reason = loggingInfo.decodeReason(file)
173     return reason
174    
175 slacapra 1.60 def findSites_(self, sites):
176 spiga 1.39 itr4 =[]
177     if len(sites)>0 and sites[0]=="":
178     return itr4
179     if sites != [""]:
180 slacapra 1.60 replicas = self.blackWhiteListParser.checkBlackList(sites)
181 spiga 1.39 if len(replicas)!=0:
182 slacapra 1.60 replicas = self.blackWhiteListParser.checkWhiteList(replicas)
183 ewv 1.42
184 spiga 1.39 itr4 = replicas
185     return itr4
186    
187 ewv 1.61
188 spiga 1.51 def wsExitFunc(self):
189     """
190     """
191     txt = '\n'
192    
193     txt += '#\n'
194     txt += '# EXECUTE THIS FUNCTION BEFORE EXIT \n'
195     txt += '#\n\n'
196    
197     txt += 'func_exit() { \n'
198     txt += self.wsExitFunc_common()
199     ### specific Glite check for OSB
200     txt += ' tar zcvf ${out_files}.tgz ${final_list}\n'
201     txt += ' tmp_size=`ls -gGrta ${out_files}.tgz | awk \'{ print $3 }\'`\n'
202 ewv 1.61 txt += ' rm ${out_files}.tgz\n'
203 spiga 1.51 txt += ' size=`expr $tmp_size`\n'
204     txt += ' echo "Total Output dimension: $size"\n'
205 ewv 1.61 txt += ' limit='+str(self.OSBsize) +' \n'
206 spiga 1.51 txt += ' echo "WARNING: output files size limit is set to: $limit"\n'
207 spiga 1.53 txt += ' if [ "$limit" -lt "$size" ]; then\n'
208 spiga 1.51 txt += ' exceed=1\n'
209     txt += ' job_exit_code=70000\n'
210     txt += ' echo "Output Sanbox too big. Produced output is lost "\n'
211     txt += ' else\n'
212     txt += ' exceed=0\n'
213 spiga 1.53 txt += ' echo "Total Output dimension $size is fine."\n'
214 spiga 1.51 txt += ' fi\n'
215    
216     txt += ' echo "JOB_EXIT_STATUS = $job_exit_code"\n'
217     txt += ' echo "JobExitCode=$job_exit_code" >> $RUNTIME_AREA/$repo\n'
218     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
219     txt += ' if [ $exceed -ne 1 ]; then\n'
220     txt += ' tar zcvf ${out_files}.tgz ${final_list}\n'
221     txt += ' else\n'
222     txt += ' tar zcvf ${out_files}.tgz CMSSW_${NJob}.stdout CMSSW_${NJob}.stderr\n'
223     txt += ' fi\n'
224     txt += ' exit $job_exit_code\n'
225    
226     txt += '}\n'
227     return txt