ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.32
Committed: Fri Oct 3 11:18:23 2008 UTC (16 years, 7 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_0_pre6
Changes since 1.31: +5 -0 lines
Log Message:
report the full output of the underlying stageout command in case of stage out failure

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.25 from crab_util import getLocalDomain
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 spiga 1.14 self._taskId=str("_".join(common._db.queryTask('name').split('_')[:-1]))
27 slacapra 1.1
28 slacapra 1.3 self.return_data = int(cfg_params.get('USER.return_data',0))
29 spiga 1.27 self.copy_data = int(cfg_params.get('USER.copy_data',0))
30 slacapra 1.3
31    
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    
47 slacapra 1.1 ## is this ok?
48 spiga 1.25 localDomainName = getLocalDomain(self)
49 slacapra 1.16 if not cfg_params.has_key('EDG.se_white_list'):
50     cfg_params['EDG.se_white_list']=localDomainName
51     common.logger.message("Your domain name is "+str(localDomainName)+": only local dataset will be considered")
52     else:
53     common.logger.message("Your se_white_list is set to "+str(cfg_params['EDG.se_white_list'])+": only local dataset will be considered")
54 spiga 1.31 self.debug_wrapper = cfg_params.get('USER.debug_wrapper',False)
55     self.debugWrap=''
56     if self.debug_wrapper: self.debugWrap='--debug'
57 slacapra 1.16
58 slacapra 1.13 Scheduler.configure(self,cfg_params)
59 slacapra 1.1 return
60    
61     def userName(self):
62     """ return the user name """
63 slacapra 1.5 import pwd,getpass
64     tmp=pwd.getpwnam(getpass.getuser())[4]
65     return "/CN="+tmp.strip()
66 slacapra 1.1
67     def wsSetupEnvironment(self):
68     """
69     Returns part of a job script which does scheduler-specific work.
70     """
71     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 slacapra 1.1 txt += 'MonitorID=`echo ' + self._taskId + '`\n'
97    
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 slacapra 1.8 txt = '\n'
119 spiga 1.27 if int(self.copy_data) == 1:
120 slacapra 1.3
121 spiga 1.27 stageout = PhEDExDatasvcInfo(self.cfg_params)
122     endpoint, lfn, SE, SE_PATH, user = stageout.getEndpoint()
123 slacapra 1.3
124 spiga 1.27 txt += '#\n'
125     txt += '# COPY OUTPUT FILE TO '+SE_PATH+ '\n'
126     txt += '#\n\n'
127    
128     txt += 'export SE'+SE+'\n'
129     txt += 'echo "SE = $SE"\n'
130     txt += 'export SE_PATH='+SE_PATH+'\n'
131     txt += 'echo "SE_PATH = $SE_PATH"\n'
132     txt += 'export LFNBaseName='+lfn+'\n'
133     txt += 'echo LFNBaseName = $LFNBaseName\n'
134     txt += 'export USER='+user+'\n'
135     txt += 'echo "USER = $USER\n'
136     txt += 'export endpoint='+endpoint+'\n'
137     txt += 'echo "endpoint = $endpoint\n'
138     ### Needed i.e. for caf
139     if (pool):
140     txt += 'export STAGE_SVCCLASS='+str(pool)+'\n'
141    
142     txt += 'echo ">>> Copy output files from WN = `hostname` to $SE_PATH :"\n'
143     txt += 'export TIME_STAGEOUT_INI=`date +%s` \n'
144     txt += 'copy_exit_status=0\n'
145 spiga 1.29 txt += 'python cmscp.py --destination $endpoint --inputFileList $file_list --middleware $middleware '+self.debugWrap+'\n'
146 spiga 1.27 if self.debug_wrapper:
147     txt += '########### details of SE interaction\n'
148     txt += 'cat .SEinteraction.log\n'
149     txt += '########### \n'
150 spiga 1.30 txt += 'source cmscpReport.sh'
151 spiga 1.27 txt += 'if [ $StageOutExitStatus -ne 0 ]; then\n'
152     txt += ' echo "Problem copying file to $SE $SE_PATH"\n'
153     txt += ' copy_exit_status=$StageOutExitStatus \n'
154 spiga 1.32 txt += ' copy_exit_status=$StageOutExitStatus \n'
155     if not self.debug_wrapper:
156     txt += ' ########### details of SE interaction\n'
157     txt += ' cat .SEinteraction.log\n'
158     txt += ' ########### \n'
159 spiga 1.27 # txt += ' SE=""\n'
160     # txt += ' SE_PATH=""\n'
161     txt += ' job_exit_code=$StageOutExitStatus\n'
162     txt += 'fi\n'
163     txt += 'export TIME_STAGEOUT_END=`date +%s` \n'
164     txt += 'let "TIME_STAGEOUT = TIME_STAGEOUT_END - TIME_STAGEOUT_INI" \n'
165     else:
166     txt += 'export TIME_STAGEOUT=-1 \n'
167 slacapra 1.3 return txt
168 spiga 1.21
169     def wsExitFunc_comm(self):
170     """
171     """
172     txt = ''
173     txt += ' if [ $PYTHONPATH ]; then \n'
174     txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
175     txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
176     txt += ' else \n'
177     txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --errorcode $job_exit_code $executable_exit_status \n'
178     txt += ' fi\n'
179     txt += ' fi\n'
180     txt += ' cd $RUNTIME_AREA \n'
181     txt += ' for file in $filesToCheck ; do\n'
182     txt += ' if [ -e $file ]; then\n'
183     txt += ' echo "tarring file $file in $out_files"\n'
184     txt += ' else\n'
185     txt += ' echo "WARNING: output file $file not found!"\n'
186     txt += ' fi\n'
187     txt += ' done\n'
188     txt += ' export TIME_WRAP_END=`date +%s`\n'
189     txt += ' let "TIME_WRAP = TIME_WRAP_END - TIME_WRAP_END_INI" \n'
190     txt += ' if [ $PYTHONPATH ]; then \n'
191     txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
192     txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
193     txt += ' else \n'
194     # call timing FJR filling
195     txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --timing $TIME_WRAP $TIME_EXE $TIME_STAGEOUT \n'
196     txt += ' echo "CrabWrapperTime=$TIME_WRAP" >> $RUNTIME_AREA/$repo \n'
197     txt += ' if [ $TIME_STAGEOUT -lt 0 ]; then \n'
198     txt += ' export TIME_STAGEOUT=NULL \n'
199     txt += ' fi\n'
200     txt += ' echo "CrabStageoutTime=$TIME_STAGEOUT" >> $RUNTIME_AREA/$repo \n'
201     txt += ' fi\n'
202     txt += ' fi\n'
203     txt += ' dumpStatus $RUNTIME_AREA/$repo \n\n'
204     txt += ' echo "JOB_EXIT_STATUS = $job_exit_code"\n'
205     txt += ' echo "JobExitCode=$job_exit_code" >> $RUNTIME_AREA/$repo\n'
206     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
207    
208     return txt
209