ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.30
Committed: Fri Sep 26 11:00:06 2008 UTC (16 years, 7 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_0_pre4, CRAB_2_4_0_pre3
Changes since 1.29: +1 -1 lines
Log Message:
adjustements for stage 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.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    
55 slacapra 1.13 Scheduler.configure(self,cfg_params)
56 slacapra 1.1 return
57    
58     def userName(self):
59     """ return the user name """
60 slacapra 1.5 import pwd,getpass
61     tmp=pwd.getpwnam(getpass.getuser())[4]
62     return "/CN="+tmp.strip()
63 slacapra 1.1
64     def wsSetupEnvironment(self):
65     """
66     Returns part of a job script which does scheduler-specific work.
67     """
68     if not self.environment_unique_identifier:
69     raise CrabException('environment_unique_identifier not set')
70    
71 slacapra 1.12 index = int(common._db.nJobs())
72     job = common.job_list[index-1]
73     jbt = job.type()
74 ewv 1.20 # start with wrapper timing
75 spiga 1.18 txt = 'export TIME_WRAP_INI=`date +%s` \n'
76 farinafa 1.22 txt += 'export TIME_STAGEOUT=-2 \n\n'
77 spiga 1.17
78 spiga 1.19 txt += '# '+self.name()+' specific stuff\n'
79 slacapra 1.1 txt += '# strip arguments\n'
80     txt += 'echo "strip arguments"\n'
81     txt += 'args=("$@")\n'
82     txt += 'nargs=$#\n'
83     txt += 'shift $nargs\n'
84     txt += "# job number (first parameter for job wrapper)\n"
85 ewv 1.9 txt += "NJob=${args[0]}; export NJob\n"
86 slacapra 1.1
87 slacapra 1.12 txt += "out_files=out_files_${NJob}; export out_files\n"
88     txt += "echo $out_files\n"
89     txt += jbt.outList()
90    
91 slacapra 1.6 txt += 'SyncGridJobId=`echo '+self.environment_unique_identifier+'`\n'
92     txt += 'MonitorJobID=`echo ${NJob}_${SyncGridJobId}`\n'
93 slacapra 1.1 txt += 'MonitorID=`echo ' + self._taskId + '`\n'
94    
95     txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
96     txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
97     txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
98 slacapra 1.7 txt += 'echo "SyncCE='+self.name()+'.`hostname -d`" | tee -a $RUNTIME_AREA/$repo \n'
99 spiga 1.27
100 fanzago 1.23 txt += 'middleware='+self.name().upper()+' \n'
101 slacapra 1.1
102     txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
103    
104 slacapra 1.12 txt += 'InputSandBox=${args[3]}\n'
105    
106 slacapra 1.1 txt += '\n\n'
107    
108     return txt
109    
110 spiga 1.27 def wsCopyOutput_comm(self, pool=None):
111 slacapra 1.3 """
112     Write a CopyResults part of a job script, e.g.
113     to copy produced output into a storage element.
114     """
115 slacapra 1.8 txt = '\n'
116 spiga 1.27 if int(self.copy_data) == 1:
117 slacapra 1.3
118 spiga 1.27 stageout = PhEDExDatasvcInfo(self.cfg_params)
119     endpoint, lfn, SE, SE_PATH, user = stageout.getEndpoint()
120 slacapra 1.3
121 spiga 1.27 txt += '#\n'
122     txt += '# COPY OUTPUT FILE TO '+SE_PATH+ '\n'
123     txt += '#\n\n'
124    
125     txt += 'export SE'+SE+'\n'
126     txt += 'echo "SE = $SE"\n'
127     txt += 'export SE_PATH='+SE_PATH+'\n'
128     txt += 'echo "SE_PATH = $SE_PATH"\n'
129     txt += 'export LFNBaseName='+lfn+'\n'
130     txt += 'echo LFNBaseName = $LFNBaseName\n'
131     txt += 'export USER='+user+'\n'
132     txt += 'echo "USER = $USER\n'
133     txt += 'export endpoint='+endpoint+'\n'
134     txt += 'echo "endpoint = $endpoint\n'
135     ### Needed i.e. for caf
136     if (pool):
137     txt += 'export STAGE_SVCCLASS='+str(pool)+'\n'
138    
139     txt += 'echo ">>> Copy output files from WN = `hostname` to $SE_PATH :"\n'
140     txt += 'export TIME_STAGEOUT_INI=`date +%s` \n'
141     txt += 'copy_exit_status=0\n'
142 spiga 1.29 txt += 'python cmscp.py --destination $endpoint --inputFileList $file_list --middleware $middleware '+self.debugWrap+'\n'
143 spiga 1.27 if self.debug_wrapper:
144     txt += '########### details of SE interaction\n'
145     txt += 'cat .SEinteraction.log\n'
146     txt += '########### \n'
147 spiga 1.30 txt += 'source cmscpReport.sh'
148 spiga 1.27 txt += 'if [ $StageOutExitStatus -ne 0 ]; then\n'
149     txt += ' echo "Problem copying file to $SE $SE_PATH"\n'
150     txt += ' copy_exit_status=$StageOutExitStatus \n'
151     # txt += ' SE=""\n'
152     # txt += ' SE_PATH=""\n'
153     txt += ' job_exit_code=$StageOutExitStatus\n'
154     txt += 'fi\n'
155     txt += 'export TIME_STAGEOUT_END=`date +%s` \n'
156     txt += 'let "TIME_STAGEOUT = TIME_STAGEOUT_END - TIME_STAGEOUT_INI" \n'
157     else:
158     txt += 'export TIME_STAGEOUT=-1 \n'
159 slacapra 1.3 return txt
160 spiga 1.21
161     def wsExitFunc_comm(self):
162     """
163     """
164     txt = ''
165     txt += ' if [ $PYTHONPATH ]; then \n'
166     txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
167     txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
168     txt += ' else \n'
169     txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --errorcode $job_exit_code $executable_exit_status \n'
170     txt += ' fi\n'
171     txt += ' fi\n'
172     txt += ' cd $RUNTIME_AREA \n'
173     txt += ' for file in $filesToCheck ; do\n'
174     txt += ' if [ -e $file ]; then\n'
175     txt += ' echo "tarring file $file in $out_files"\n'
176     txt += ' else\n'
177     txt += ' echo "WARNING: output file $file not found!"\n'
178     txt += ' fi\n'
179     txt += ' done\n'
180     txt += ' export TIME_WRAP_END=`date +%s`\n'
181     txt += ' let "TIME_WRAP = TIME_WRAP_END - TIME_WRAP_END_INI" \n'
182     txt += ' if [ $PYTHONPATH ]; then \n'
183     txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
184     txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
185     txt += ' else \n'
186     # call timing FJR filling
187     txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --timing $TIME_WRAP $TIME_EXE $TIME_STAGEOUT \n'
188     txt += ' echo "CrabWrapperTime=$TIME_WRAP" >> $RUNTIME_AREA/$repo \n'
189     txt += ' if [ $TIME_STAGEOUT -lt 0 ]; then \n'
190     txt += ' export TIME_STAGEOUT=NULL \n'
191     txt += ' fi\n'
192     txt += ' echo "CrabStageoutTime=$TIME_STAGEOUT" >> $RUNTIME_AREA/$repo \n'
193     txt += ' fi\n'
194     txt += ' fi\n'
195     txt += ' dumpStatus $RUNTIME_AREA/$repo \n\n'
196     txt += ' echo "JOB_EXIT_STATUS = $job_exit_code"\n'
197     txt += ' echo "JobExitCode=$job_exit_code" >> $RUNTIME_AREA/$repo\n'
198     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
199    
200     return txt
201