ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.43
Committed: Wed Feb 11 17:02:59 2009 UTC (16 years, 2 months ago) by fanzago
Content type: text/x-python
Branch: MAIN
Changes since 1.42: +6 -2 lines
Log Message:
changed an echo

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