ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.58
Committed: Fri Jan 22 20:24:14 2010 UTC (15 years, 3 months ago) by ewv
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_7_3_beta, CRAB_2_7_2_p1, CRAB_2_7_1_branch_firstMERGE, CRAB_2_7_2, CRAB_2_7_2_pre4, CRAB_2_7_2_pre3, CRAB_2_7_2_pre2, CRAB_2_7_2_pre1, CRAB_2_7_1, fede_170310, CRAB_2_7_1_pre12, CRAB_2_7_1_pre11, CRAB_2_7_1_pre10, CRAB_2_7_1_pre9, CRAB_LumiMask, CRAB_2_7_lumi, from_LimiMask, CRAB_2_7_1_pre8, CRAB_2_7_1_pre6, CRAB_2_7_1_pre5, CRAB_2_7_1_wmbs_pre4
Branch point for: CRAB_multiout, CRAB_2_7_1_branch
Changes since 1.57: +11 -2 lines
Log Message:
Add final_list to local scheduler

File Contents

# Content
1 from Scheduler import Scheduler
2 from crab_exceptions import *
3 from crab_util import getLocalDomain
4 import common
5 from PhEDExDatasvcInfo import PhEDExDatasvcInfo
6
7 import os,string
8
9 # Base class for all local scheduler
10
11 class SchedulerLocal(Scheduler) :
12
13 def configure(self, cfg_params):
14 self.environment_unique_identifier = None
15 self.cfg_params = cfg_params
16 Scheduler.configure(self,cfg_params)
17 self.jobtypeName = cfg_params['CRAB.jobtype']
18
19 name=string.upper(self.name())
20 self.queue = cfg_params.get(name+'.queue',None)
21
22 self.res = cfg_params.get(name+'.resource',None)
23
24 # minimal padding time for jobs. For local schedulers is disabled.
25 # Added for alignment purpose only (and for test) with Grid schedulers
26 self.minimal_job_duration = 0
27
28 if (cfg_params.has_key(self.name()+'.env_id')): self.environment_unique_identifier = cfg_params[self.name()+'.env_id']
29 ## is this ok?
30 localDomainName = getLocalDomain(self)
31 if not cfg_params.has_key('GRID.se_white_list'):
32 cfg_params['GRID.se_white_list']=localDomainName
33 common.logger.info("Your domain name is "+str(localDomainName)+": only local dataset will be considered")
34 else:
35 common.logger.info("Your se_white_list is set to "+str(cfg_params['GRID.se_white_list'])+": only local dataset will be considered")
36 return
37
38 def userName(self):
39 """ return the user name """
40 import pwd,getpass
41 tmp=pwd.getpwnam(getpass.getuser())[4]
42 return "/CN="+tmp.strip()
43
44 def envUniqueID(self):
45 return
46
47 def wsSetupEnvironment(self):
48 """
49 Returns part of a job script which does scheduler-specific work.
50 """
51 taskId = common._db.queryTask('name')
52 if not self.environment_unique_identifier:
53 try :
54 self.environment_unique_identifier = self.envUniqueID()
55 except :
56 raise CrabException('environment_unique_identifier not set')
57 index = int(common._db.nJobs())
58 job = common.job_list[index-1]
59 jbt = job.type()
60 # start with wrapper timing
61 txt = 'export TIME_WRAP_INI=`date +%s` \n'
62 txt += 'export TIME_STAGEOUT=-2 \n\n'
63
64 txt += '# '+self.name()+' specific stuff\n'
65 txt += '# strip arguments\n'
66 txt += 'echo "strip arguments"\n'
67 txt += 'args=("$@")\n'
68 txt += 'nargs=$#\n'
69 txt += 'shift $nargs\n'
70 txt += "# job number (first parameter for job wrapper)\n"
71 txt += "NJob=${args[0]}; export NJob\n"
72 txt += "NResub=${args[1]}; export NResub\n"
73 txt += 'OutUniqueID=_$NResub\n'
74 txt += 'OutUniqueID=$NJob$OutUniqueID; export OutUniqueID\n'
75
76 txt += "out_files=out_files_${NJob}; export out_files\n"
77 txt += "echo $out_files\n"
78 txt += jbt.outList()
79
80 txt += 'SyncGridJobId=`echo '+self.environment_unique_identifier+'`\n'
81 txt += 'MonitorJobID=`echo ${NJob}_${SyncGridJobId}`\n'
82 txt += 'MonitorID=`echo ' + taskId + '`\n'
83
84 txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
85 txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
86 txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
87 txt += 'echo "SyncCE='+self.name()+'.`hostname -d`" | tee -a $RUNTIME_AREA/$repo \n'
88
89 txt += 'middleware='+self.name().upper()+' \n'
90
91 txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
92
93 txt += 'InputSandBox=${args[3]}\n'
94
95 txt += '\n\n'
96
97 return txt
98
99 def wsCopyOutput_comm(self, pool=None):
100 """
101 Write a CopyResults part of a job script, e.g.
102 to copy produced output into a storage element.
103 """
104 index = int(common._db.nJobs())
105 job = common.job_list[index-1]
106 jbt = job.type()
107 txt = '\n'
108 if int(self.copy_data) == 1:
109
110 stageout = PhEDExDatasvcInfo(self.cfg_params)
111 endpoint, lfn, SE, SE_PATH, user = stageout.getEndpoint()
112 if self.check_RemoteDir == 1 :
113 self.checkRemoteDir(endpoint,jbt.outList('list') )
114
115 txt += '#\n'
116 txt += '# COPY OUTPUT FILE TO '+SE_PATH+ '\n'
117 txt += '#\n\n'
118
119 txt += 'export SE='+SE+'\n'
120 txt += 'echo "SE = $SE"\n'
121 txt += 'export SE_PATH='+SE_PATH+'\n'
122 txt += 'echo "SE_PATH = $SE_PATH"\n'
123 txt += 'export LFNBaseName='+lfn+'\n'
124 txt += 'echo "LFNBaseName = $LFNBaseName"\n'
125 txt += 'export USER='+user+'\n'
126 txt += 'echo "USER = $USER"\n'
127 txt += 'export endpoint='+endpoint+'\n'
128 txt += 'echo "endpoint = $endpoint"\n'
129 ### Needed i.e. for caf
130 if (pool) and (pool != 'None'):
131 txt += 'export STAGE_SVCCLASS='+str(pool)+'\n'
132
133 txt += 'echo ">>> Copy output files from WN = `hostname` to $SE_PATH :"\n'
134 txt += 'export TIME_STAGEOUT_INI=`date +%s` \n'
135 txt += 'copy_exit_status=0\n'
136 cmscp_args = ' --destination $endpoint --inputFileList $file_list'
137 cmscp_args +=' --middleware $middleware --lfn $LFNBaseName %s %s '%(self.loc_stage_out,self.debugWrap)
138 txt += 'echo "python cmscp.py %s "\n'%cmscp_args
139 txt += 'python cmscp.py %s \n'%cmscp_args
140 if self.debug_wrapper==1:
141 txt += 'if [ -f .SEinteraction.log ] ;then\n'
142 txt += '########### details of SE interaction\n'
143 txt += ' cat .SEinteraction.log\n'
144 txt += 'else\n'
145 txt += ' echo ".SEinteraction.log file not found"\n'
146 txt += 'fi\n'
147 txt += '##################################### \n'
148 txt += 'if [ -f cmscpReport.sh ] ;then\n'
149 txt += ' cat cmscpReport.sh\n'
150 txt += ' source cmscpReport.sh\n'
151 txt += 'else\n'
152 txt += ' echo "cmscpReport.sh file not found"\n'
153 txt += ' StageOutExitStatus=60307\n'
154 txt += 'fi\n'
155 txt += 'if [ $StageOutExitStatus -ne 0 ]; then\n'
156 txt += ' echo "Problem copying file to $SE $SE_PATH"\n'
157 txt += ' copy_exit_status=$StageOutExitStatus \n'
158 if not self.debug_wrapper==1:
159 txt += ' ########### details of SE interaction\n'
160 txt += ' if [ -f .SEinteraction.log ] ;then\n'
161 txt += ' cat .SEinteraction.log\n'
162 txt += ' else\n'
163 txt += ' echo ".SEinteraction.log file not found"\n'
164 txt += ' fi\n'
165 txt += ' ##################################### \n'
166 txt += ' job_exit_code=$StageOutExitStatus\n'
167 txt += 'fi\n'
168 txt += 'export TIME_STAGEOUT_END=`date +%s` \n'
169 txt += 'let "TIME_STAGEOUT = TIME_STAGEOUT_END - TIME_STAGEOUT_INI" \n'
170 else:
171 txt += 'export TIME_STAGEOUT=-1 \n'
172 return txt
173
174 def wsExitFunc_common(self):
175 """
176 """
177 txt = ''
178 txt += ' if [ $PYTHONPATH ]; then \n'
179 txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
180 txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
181 txt += ' else \n'
182 txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --errorcode $job_exit_code $executable_exit_status \n'
183 txt += ' fi\n'
184 txt += ' fi\n'
185 txt += ' cd $RUNTIME_AREA \n'
186 txt += ' for file in $filesToCheck ; do\n'
187 txt += ' if [ -e $file ]; then\n'
188 txt += ' echo "tarring file $file in $out_files"\n'
189 txt += ' else\n'
190 txt += ' echo "WARNING: output file $file not found!"\n'
191 txt += ' fi\n'
192 txt += ' done\n'
193 txt += ' if [ $middleware == OSG ]; then\n'
194 txt += ' final_list=$filesToCheck\n'
195 txt += ' if [ $WORKING_DIR ]; then\n'
196 txt += ' remove_working_dir\n'
197 txt += ' fi\n'
198 txt += ' symlinks -d .\n'
199 txt += ' else\n'
200 txt += ' final_list=$filesToCheck" .BrokerInfo"\n'
201 txt += ' fi\n'
202 txt += ' export TIME_WRAP_END=`date +%s`\n'
203 txt += ' let "TIME_WRAP = TIME_WRAP_END - TIME_WRAP_END_INI" \n\n'
204 # padding for minimal job duration
205 txt += ' let "MIN_JOB_DURATION = 60*%d" \n'%self.minimal_job_duration
206 txt += ' let "PADDING_DURATION = MIN_JOB_DURATION - TIME_WRAP" \n'
207 txt += ' if [ $PADDING_DURATION -gt 0 ]; then \n'
208 txt += ' echo ">>> padding time: Sleeping the wrapper for $PADDING_DURATION seconds"\n'
209 txt += ' sleep $PADDING_DURATION\n'
210 txt += ' TIME_WRAP_END=`date +%s`\n'
211 txt += ' let "TIME_WRAP = TIME_WRAP_END - TIME_WRAP_INI" \n'
212 txt += ' else \n'
213 txt += ' echo ">>> padding time: Wrapper lasting more than $MIN_JOB_DURATION seconds. No sleep required."\n'
214 txt += ' fi\n\n'
215 # call timing FJR filling
216 txt += ' if [ $PYTHONPATH ]; then \n'
217 txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
218 txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
219 txt += ' else \n'
220 txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --timing $TIME_WRAP $TIME_EXE $TIME_STAGEOUT \n'
221 txt += ' echo "CrabWrapperTime=$TIME_WRAP" >> $RUNTIME_AREA/$repo \n'
222 txt += ' if [ $TIME_STAGEOUT -lt 0 ]; then \n'
223 txt += ' export TIME_STAGEOUT=NULL \n'
224 txt += ' fi\n'
225 txt += ' echo "CrabStageoutTime=$TIME_STAGEOUT" >> $RUNTIME_AREA/$repo \n'
226 txt += ' fi\n'
227 txt += ' fi\n'
228 txt += ' dumpStatus $RUNTIME_AREA/$repo \n\n'
229 txt += ' echo "JOB_EXIT_STATUS = $job_exit_code"\n'
230 txt += ' echo "JobExitCode=$job_exit_code" >> $RUNTIME_AREA/$repo\n'
231 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
232
233 return txt
234