ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.45
Committed: Thu Mar 5 16:55:54 2009 UTC (16 years, 2 months ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.44: +2 -5 lines
Log Message:
removed not useful print out

File Contents

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