ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.54
Committed: Fri Nov 20 18:09:28 2009 UTC (15 years, 5 months ago) by farinafa
Content type: text/x-python
Branch: MAIN
Changes since 1.53: +5 -0 lines
Log Message:
Added a check on maximal allowed padding time for the job duration

File Contents

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