ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerGlite.py
Revision: 1.38
Committed: Tue Mar 4 11:38:15 2008 UTC (17 years, 1 month ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.37: +5 -9 lines
Log Message:
sched_param must be cleaned for each job

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     rb_param_file = 'WMSconfig = '+glite_config+';\n'
28     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     return req
66    
67     def se_list(self, id):
68     """
69     Returns string with requirement SE related
70     """
71     hostList=self.findSites_(id)
72     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.36 def sched_parameter(self):
111     """
112     Returns string with requirements and scheduler-specific parameters
113     """
114     index = int(common._db.nJobs()) - 1
115     job = common.job_list[index]
116     jbt = job.type()
117    
118     ### To Be Removed BL--DS
119     # lastDest=''
120     # first = []
121     # last = []
122     # for n in range(common.jobDB.nJobs()):
123     # currDest=common.jobDB.destination(n)
124     # if (currDest!=lastDest):
125     # lastDest = currDest
126     # first.append(n)
127     # if n != 0:last.append(n-1)
128     # if len(first)>len(last) :last.append(common.jobDB.nJobs())
129 spiga 1.2
130 spiga 1.36 req = ''
131     req = req + jbt.getRequirements()
132 slacapra 1.13
133 spiga 1.36 if self.EDG_requirements:
134     if (not req == ' '): req = req + ' && '
135     req = req + self.EDG_requirements
136     for i in range(index):
137 spiga 1.38 sched_param=''
138     sched_param+='Requirements = ' + req +self.specific_req() + self.se_list(i) +\
139     self.ce_list() +';\n' ## BL--DS
140     if self.EDG_addJdlParam: sched_param+=self.jdlParam() ## BL--DS
141     if (self.rb_param_file): sched_param+=self.rb_param_file ## BL--DS
142 spiga 1.36 run_jobReq={'schedulerAttributes':sched_param}## DS--BL
143     common._db.updateRunJob_(i,run_jobReq)
144 spiga 1.2
145     def wsSetupEnvironment(self):
146     """
147     Returns part of a job script which does scheduler-specific work.
148     """
149     txt = ''
150     txt += '# strip arguments\n'
151     txt += 'echo "strip arguments"\n'
152     txt += 'args=("$@")\n'
153     txt += 'nargs=$#\n'
154     txt += 'shift $nargs\n'
155     txt += "# job number (first parameter for job wrapper)\n"
156 ewv 1.34 txt += "NJob=${args[0]}; export NJob\n"
157 spiga 1.2
158     txt += '# job identification to DashBoard \n'
159 fanzago 1.37 #txt += 'MonitorJobID=`echo ${NJob}_$GLITE_WMS_JOBID`\n'
160     #txt += 'SyncGridJobId=`echo $GLITE_WMS_JOBID`\n'
161     #txt += 'MonitorID=`echo ' + self._taskId + '`\n'
162     txt += 'MonitorJobID=${NJob}_$GLITE_WMS_JOBID \n'
163     txt += 'SyncGridJobId=$GLITE_WMS_JOBID \n'
164     txt += 'MonitorID='+self._taskId+' \n'
165     txt += 'echo "MonitorJobID=$MonitorJobID" > $RUNTIME_AREA/$repo \n'
166     txt += 'echo "SyncGridJobId=$SyncGridJobId" >> $RUNTIME_AREA/$repo \n'
167     txt += 'echo "MonitorID=$MonitorID" >> $RUNTIME_AREA/$repo\n'
168     #txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
169     #txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
170     #txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
171 spiga 1.2
172 fanzago 1.37 #txt += 'echo "middleware discovery: " \n'
173     txt += 'echo ">>> GridFlavour discovery: " \n'
174 spiga 1.2 txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
175 fanzago 1.37 txt += ' middleware=LCG\n'
176     #txt += ' echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
177     txt += ' echo "SyncCE=`glite-brokerinfo getCE`" >> $RUNTIME_AREA/$repo \n'
178     #txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
179     txt += ' echo "GridFlavour=$middleware" | tee -a $RUNTIME_AREA/$repo \n'
180     #txt += ' echo ">>> middleware =$middleware" \n'
181 spiga 1.2 txt += 'elif [ $OSG_APP ]; then \n'
182     txt += ' middleware=OSG \n'
183 mcinquil 1.25 txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
184     txt += ' SyncCE="$OSG_JOB_CONTACT"; \n'
185 fanzago 1.37 #txt += ' echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
186     txt += ' echo "SyncCE=$SyncCE" >> $RUNTIME_AREA/$repo ;\n'
187 mcinquil 1.22 txt += ' else\n'
188     txt += ' echo "not reporting SyncCE";\n'
189     txt += ' fi\n';
190 fanzago 1.37 txt += ' echo "GridFlavour=$middleware" | tee -a $RUNTIME_AREA/$repo \n'
191     #txt += ' echo ">>> middleware =$middleware" \n'
192 spiga 1.2 txt += 'else \n'
193 fanzago 1.37 txt += ' echo "ERROR ==> GridFlavour not identified" \n'
194     txt += ' job_exit_code=10030\n'
195     txt += ' func_exit \n'
196     #txt += ' echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
197     #txt += ' echo "JOB_EXIT_STATUS = 10030" \n'
198     #txt += ' echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
199     #txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
200     #txt += ' exit 1 \n'
201 spiga 1.2 txt += 'fi \n'
202    
203     txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
204 ewv 1.28
205 spiga 1.2 txt += '\n\n'
206    
207     txt += 'export VO='+self.VO+'\n'
208 ewv 1.28 txt += 'if [ $middleware == LCG ]; then\n'
209 spiga 1.2 txt += ' CloseCEs=`glite-brokerinfo getCE`\n'
210     txt += ' echo "CloseCEs = $CloseCEs"\n'
211     txt += ' CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
212     txt += ' echo "CE = $CE"\n'
213     txt += 'elif [ $middleware == OSG ]; then \n'
214     txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
215     txt += ' CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
216     txt += ' else \n'
217 fanzago 1.35 txt += ' echo "ERROR ==> OSG mode in setting CE name from OSG_JOB_CONTACT" \n'
218     txt += ' job_exit_code=10099\n'
219     txt += ' func_exit \n'
220     #txt += ' echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
221     #txt += ' echo "JOB_EXIT_STATUS = 10099" \n'
222     #txt += ' echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
223     #txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
224     #txt += ' exit 1 \n'
225 spiga 1.2 txt += ' fi \n'
226 ewv 1.28 txt += 'fi \n'
227 spiga 1.2
228     return txt
229 ewv 1.28
230 spiga 1.2 def loggingInfo(self, id):
231     """
232     retrieve the logging info from logging and bookkeeping and return it
233     """
234     self.checkProxy()
235 slacapra 1.8 cmd = 'glite-job-logging-info -v 3 ' + id
236 spiga 1.2 cmd_out = runCommand(cmd)
237     return cmd_out
238    
239     def queryDetailedStatus(self, id):
240     """ Query a detailed status of the job with id """
241     cmd = 'glite-job-status '+id
242     cmd_out = runCommand(cmd)
243     return cmd_out
244    
245 spiga 1.14
246 mcinquil 1.27 def tOut(self, list):
247 mcinquil 1.18 return 180