ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerGlite.py
Revision: 1.41
Committed: Fri Mar 21 16:30:10 2008 UTC (17 years, 1 month ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.40: +2 -2 lines
Log Message:
Implemented the listmatch support. Cleaned also the code by many old method and workarounds...

File Contents

# User Rev Content
1 slacapra 1.31 from SchedulerGrid import SchedulerGrid
2 spiga 1.2 from crab_logger import Logger
3     from crab_exceptions import *
4     from crab_util import *
5 fanzago 1.4 from GliteConfig import *
6 spiga 1.2 import common
7    
8     import os, sys, time
9    
10 slacapra 1.31 class SchedulerGlite(SchedulerGrid):
11 slacapra 1.33 def __init__(self, name="GLITE"):
12     SchedulerGrid.__init__(self,name)
13 slacapra 1.31
14     def configure(self,cfg_params):
15     SchedulerGrid.configure(self, cfg_params)
16     self.environment_unique_identifier = 'GLITE_WMS_JOBID'
17 slacapra 1.3
18 fanzago 1.4 def rb_configure(self, RB):
19 slacapra 1.31 if not RB: return None
20     glite_config = None
21     rb_param_file = None
22 fanzago 1.4
23     gliteConfig = GliteConfig(RB)
24 slacapra 1.31 glite_config = gliteConfig.config()
25 fanzago 1.4
26 slacapra 1.31 if (glite_config ):
27 spiga 1.40 rb_param_file = glite_config
28 slacapra 1.31 return rb_param_file
29 fanzago 1.4
30 spiga 1.36 def ce_list(self):
31 spiga 1.2 """
32 spiga 1.36 Returns string with requirement CE related
33 spiga 1.2 """
34 spiga 1.36 req = ''
35 spiga 1.2 if self.EDG_ce_white_list:
36 mcinquil 1.32 ce_white_list = self.EDG_ce_white_list
37 slacapra 1.13 tmpCe=[]
38     concString = '&&'
39     for ce in ce_white_list:
40     tmpCe.append('RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId)')
41 mcinquil 1.20 if len(tmpCe) == 1:
42     req += " && (" + concString.join(tmpCe) + ") "
43     elif len(tmpCe) > 1:
44     firstCE = 0
45     for reqTemp in tmpCe:
46     if firstCE == 0:
47     req += " && ( (" + reqTemp + ") "
48     firstCE = 1
49     elif firstCE > 0:
50     req += " || (" + reqTemp + ") "
51     if firstCE > 0:
52     req += ") "
53 ewv 1.28
54 spiga 1.2 if self.EDG_ce_black_list:
55 mcinquil 1.32 ce_black_list = self.EDG_ce_black_list
56 slacapra 1.13 tmpCe=[]
57     concString = '&&'
58 spiga 1.2 for ce in ce_black_list:
59 slacapra 1.13 tmpCe.append('(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))')
60 spiga 1.36 if len(tmpCe): req += " && (" + concString.join(tmpCe) + ") "
61    
62     # requirement added to skip gliteCE
63     req += '&& (!RegExp("blah", other.GlueCEUniqueId))'
64    
65 spiga 1.41 return req,self.EDG_ce_white_list,self.EDG_ce_black_list
66 spiga 1.36
67 spiga 1.39 def se_list(self, id, dest):
68 spiga 1.36 """
69     Returns string with requirement SE related
70     """
71 spiga 1.39 hostList=self.findSites_(id,dest)
72 spiga 1.36 req=''
73     reqtmp=[]
74     concString = '||'
75    
76     for arg in hostList:
77     reqtmp.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
78    
79     if len(reqtmp): req += " && (" + concString.join(reqtmp) + ") "
80 spiga 1.11
81 spiga 1.36 return req
82    
83     def jdlParam(self):
84     """
85     Returns
86     """
87     req=''
88     if self.EDG_addJdlParam:
89     if self.EDG_addJdlParam[-1] == '': self.EDG_addJdlParam= self.EDG_addJdlParam[:-1]
90     for p in self.EDG_addJdlParam:
91     # param_file.write(string.strip(p)+';\n')
92     req+=string.strip(p)+';\n' ## BL--DS
93     return req
94    
95     def specific_req(self):
96     """
97     Returns string with specific requirements
98     """
99     req=''
100 spiga 1.2 if self.EDG_clock_time:
101 slacapra 1.13 if (not req == ' '): req = req + ' && '
102     req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
103 spiga 1.2
104     if self.EDG_cpu_time:
105 slacapra 1.13 if (not req == ' '): req = req + ' && '
106     req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
107 spiga 1.36
108     return req
109 ewv 1.28
110 spiga 1.39 def sched_fix_parameter(self):
111 spiga 1.36 """
112     Returns string with requirements and scheduler-specific parameters
113     """
114 spiga 1.39 index = int(common._db.nJobs())
115     job = common.job_list[index-1]
116 spiga 1.36 jbt = job.type()
117     req = ''
118     req = req + jbt.getRequirements()
119 slacapra 1.13
120 spiga 1.36 if self.EDG_requirements:
121     if (not req == ' '): req = req + ' && '
122     req = req + self.EDG_requirements
123 spiga 1.2
124 spiga 1.39 Task_Req={'jobType':req}## DS--BL
125     common._db.updateTask_(Task_Req)
126    
127     def sched_parameter(self,i,task):
128     """
129     Returns string with requirements and scheduler-specific parameters
130     """
131     dest= eval(task.jobs[i]['dlsDestination']) ## DS--BL
132    
133     req=''
134     req +=task['jobType']
135    
136     sched_param=''
137     sched_param+='Requirements = ' + req +self.specific_req() + self.se_list(i,dest) +\
138 spiga 1.41 self.ce_list()[0] +';\n' ## BL--DS
139 spiga 1.39 if self.EDG_addJdlParam: sched_param+=self.jdlParam() ## BL--DS
140     sched_param+='MyProxyServer = "' + self.proxyServer + '";\n'
141     sched_param+='VirtualOrganisation = "' + self.VO + '";\n'
142     sched_param+='RetryCount = '+str(self.EDG_retry_count)+';\n'
143     sched_param+='ShallowRetryCount = '+str(self.EDG_shallow_retry_count)+';\n'
144    
145     return sched_param
146    
147 spiga 1.2 def wsSetupEnvironment(self):
148     """
149     Returns part of a job script which does scheduler-specific work.
150     """
151     txt = ''
152     txt += '# strip arguments\n'
153     txt += 'echo "strip arguments"\n'
154     txt += 'args=("$@")\n'
155     txt += 'nargs=$#\n'
156     txt += 'shift $nargs\n'
157     txt += "# job number (first parameter for job wrapper)\n"
158 ewv 1.34 txt += "NJob=${args[0]}; export NJob\n"
159 spiga 1.2
160     txt += '# job identification to DashBoard \n'
161 fanzago 1.37 #txt += 'MonitorJobID=`echo ${NJob}_$GLITE_WMS_JOBID`\n'
162     #txt += 'SyncGridJobId=`echo $GLITE_WMS_JOBID`\n'
163     #txt += 'MonitorID=`echo ' + self._taskId + '`\n'
164     txt += 'MonitorJobID=${NJob}_$GLITE_WMS_JOBID \n'
165     txt += 'SyncGridJobId=$GLITE_WMS_JOBID \n'
166     txt += 'MonitorID='+self._taskId+' \n'
167     txt += 'echo "MonitorJobID=$MonitorJobID" > $RUNTIME_AREA/$repo \n'
168     txt += 'echo "SyncGridJobId=$SyncGridJobId" >> $RUNTIME_AREA/$repo \n'
169     txt += 'echo "MonitorID=$MonitorID" >> $RUNTIME_AREA/$repo\n'
170     #txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
171     #txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
172     #txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
173 spiga 1.2
174 fanzago 1.37 #txt += 'echo "middleware discovery: " \n'
175     txt += 'echo ">>> GridFlavour discovery: " \n'
176 spiga 1.2 txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
177 fanzago 1.37 txt += ' middleware=LCG\n'
178     #txt += ' echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
179     txt += ' echo "SyncCE=`glite-brokerinfo getCE`" >> $RUNTIME_AREA/$repo \n'
180     #txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
181     txt += ' echo "GridFlavour=$middleware" | tee -a $RUNTIME_AREA/$repo \n'
182     #txt += ' echo ">>> middleware =$middleware" \n'
183 spiga 1.2 txt += 'elif [ $OSG_APP ]; then \n'
184     txt += ' middleware=OSG \n'
185 mcinquil 1.25 txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
186     txt += ' SyncCE="$OSG_JOB_CONTACT"; \n'
187 fanzago 1.37 #txt += ' echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
188     txt += ' echo "SyncCE=$SyncCE" >> $RUNTIME_AREA/$repo ;\n'
189 mcinquil 1.22 txt += ' else\n'
190     txt += ' echo "not reporting SyncCE";\n'
191     txt += ' fi\n';
192 fanzago 1.37 txt += ' echo "GridFlavour=$middleware" | tee -a $RUNTIME_AREA/$repo \n'
193     #txt += ' echo ">>> middleware =$middleware" \n'
194 spiga 1.2 txt += 'else \n'
195 fanzago 1.37 txt += ' echo "ERROR ==> GridFlavour not identified" \n'
196     txt += ' job_exit_code=10030\n'
197     txt += ' func_exit \n'
198     #txt += ' echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
199     #txt += ' echo "JOB_EXIT_STATUS = 10030" \n'
200     #txt += ' echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
201     #txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
202     #txt += ' exit 1 \n'
203 spiga 1.2 txt += 'fi \n'
204    
205     txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
206 ewv 1.28
207 spiga 1.2 txt += '\n\n'
208    
209     txt += 'export VO='+self.VO+'\n'
210 ewv 1.28 txt += 'if [ $middleware == LCG ]; then\n'
211 spiga 1.2 txt += ' CloseCEs=`glite-brokerinfo getCE`\n'
212     txt += ' echo "CloseCEs = $CloseCEs"\n'
213     txt += ' CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
214     txt += ' echo "CE = $CE"\n'
215     txt += 'elif [ $middleware == OSG ]; then \n'
216     txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
217     txt += ' CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
218     txt += ' else \n'
219 fanzago 1.35 txt += ' echo "ERROR ==> OSG mode in setting CE name from OSG_JOB_CONTACT" \n'
220     txt += ' job_exit_code=10099\n'
221     txt += ' func_exit \n'
222     #txt += ' echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
223     #txt += ' echo "JOB_EXIT_STATUS = 10099" \n'
224     #txt += ' echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
225     #txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
226     #txt += ' exit 1 \n'
227 spiga 1.2 txt += ' fi \n'
228 ewv 1.28 txt += 'fi \n'
229 spiga 1.2
230     return txt
231 ewv 1.28
232 spiga 1.2 def loggingInfo(self, id):
233     """
234     retrieve the logging info from logging and bookkeeping and return it
235     """
236     self.checkProxy()
237 slacapra 1.8 cmd = 'glite-job-logging-info -v 3 ' + id
238 spiga 1.2 cmd_out = runCommand(cmd)
239     return cmd_out
240    
241     def queryDetailedStatus(self, id):
242     """ Query a detailed status of the job with id """
243     cmd = 'glite-job-status '+id
244     cmd_out = runCommand(cmd)
245     return cmd_out
246    
247 spiga 1.39 def findSites_(self, n, sites):
248     itr4 =[]
249     if len(sites)>0 and sites[0]=="":
250     return itr4
251     if sites != [""]:
252     ##Addedd Daniele
253     replicas = self.blackWhiteListParser.checkBlackList(sites,n)
254     if len(replicas)!=0:
255     replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
256    
257     itr4 = replicas
258     #####
259     return itr4
260    
261    
262    
263 spiga 1.14
264 mcinquil 1.27 def tOut(self, list):
265 mcinquil 1.18 return 180