ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerLocal.py
Revision: 1.24
Committed: Tue Jul 1 15:01:17 2008 UTC (16 years, 10 months ago) by fanzago
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_0_test
Changes since 1.23: +23 -58 lines
Log Message:
reimplemented CP_CMD and added change for publication on user data

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     import common
5    
6     import os,string
7    
8 slacapra 1.2 # Base class for all local scheduler
9 slacapra 1.1
10     class SchedulerLocal(Scheduler) :
11    
12     def configure(self, cfg_params):
13    
14     self.jobtypeName = cfg_params['CRAB.jobtype']
15    
16     name=string.upper(self.name())
17     self.queue = cfg_params.get(name+'.queue',None)
18    
19     self.res = cfg_params.get(name+'.resource',None)
20    
21     if (cfg_params.has_key(self.name()+'.env_id')): self.environment_unique_identifier = cfg_params[self.name()+'.env_id']
22    
23 spiga 1.14 self._taskId=str("_".join(common._db.queryTask('name').split('_')[:-1]))
24 slacapra 1.1
25 slacapra 1.3 self.return_data = int(cfg_params.get('USER.return_data',0))
26    
27 fanzago 1.23 ## FEDE publication options
28     self.publish_data = cfg_params.get("USER.publish_data",0)
29     if int(self.publish_data) == 1 :
30     self.publish_data_name = cfg_params.get('USER.publish_data_name',None)
31     if not self.publish_data_name and int(self.publish_data) == 1:
32     msg = "Error. The [USER] section does not have 'publish_data_name'"
33     raise CrabException(msg)
34     self.SE = cfg_params.get("USER.storage_element", None)
35     if not self.SE:
36     msg = "Error. The [USER] section does not have 'storage_element'.\n"
37     msg = msg + "Please fill this field if you want to publish your data"
38     raise CrabException(msg)
39 slacapra 1.3 self.copy_data = int(cfg_params.get("USER.copy_data",0))
40     if self.copy_data == 1:
41 fanzago 1.24 self._copyCommand = cfg_params.get('USER.copycommand','rfcp')
42     common.logger.debug(3, "copyCommand set to "+ self._copyCommand)
43 slacapra 1.3 self.SE_path= cfg_params.get('USER.storage_path',None)
44     if not self.SE_path:
45 fanzago 1.23 # do not allow CASTOR_HOME if publish_data is enabled
46     if int(self.publish_data) == 0 and os.environ.has_key('CASTOR_HOME'):
47 slacapra 1.3 self.SE_path=os.environ['CASTOR_HOME']
48     else:
49     msg='No USER.storage_path has been provided: cannot copy_output'
50     raise CrabException(msg)
51     pass
52     pass
53 fanzago 1.23 ### FEDE to improve the final / control
54 slacapra 1.10 self.SE_path+='/'
55 slacapra 1.3
56     if ( self.return_data == 0 and self.copy_data == 0 ):
57     msg = 'Error: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
58     msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
59     raise CrabException(msg)
60    
61     if ( self.return_data == 1 and self.copy_data == 1 ):
62     msg = 'Error: return_data and copy_data cannot be set both to 1\n'
63     msg = msg + 'Please modify return_data or copy_data value in your crab.cfg file\n'
64     raise CrabException(msg)
65 slacapra 1.1
66     ## Get local domain name
67     import socket
68     tmp=socket.gethostname()
69     dot=string.find(tmp,'.')
70     if (dot==-1):
71     msg='Unkown domain name. Cannot use local scheduler'
72     raise CrabException(msg)
73     localDomainName = string.split(tmp,'.',1)[-1]
74 slacapra 1.11 #common.taskDB.setDict('localSite',localDomainName)
75 slacapra 1.1 ## is this ok?
76 slacapra 1.16 if not cfg_params.has_key('EDG.se_white_list'):
77     cfg_params['EDG.se_white_list']=localDomainName
78     common.logger.message("Your domain name is "+str(localDomainName)+": only local dataset will be considered")
79     else:
80     common.logger.message("Your se_white_list is set to "+str(cfg_params['EDG.se_white_list'])+": only local dataset will be considered")
81    
82 ewv 1.20
83    
84 slacapra 1.1
85 slacapra 1.13 Scheduler.configure(self,cfg_params)
86 slacapra 1.1 return
87    
88     def userName(self):
89     """ return the user name """
90 slacapra 1.5 import pwd,getpass
91     tmp=pwd.getpwnam(getpass.getuser())[4]
92     return "/CN="+tmp.strip()
93 slacapra 1.1
94     def wsSetupEnvironment(self):
95     """
96     Returns part of a job script which does scheduler-specific work.
97     """
98     if not self.environment_unique_identifier:
99     raise CrabException('environment_unique_identifier not set')
100    
101 slacapra 1.12 index = int(common._db.nJobs())
102     job = common.job_list[index-1]
103     jbt = job.type()
104 ewv 1.20 # start with wrapper timing
105 spiga 1.18 txt = 'export TIME_WRAP_INI=`date +%s` \n'
106 farinafa 1.22 txt += 'export TIME_STAGEOUT=-2 \n\n'
107 spiga 1.17
108 spiga 1.19 txt += '# '+self.name()+' specific stuff\n'
109 slacapra 1.1 txt += '# strip arguments\n'
110     txt += 'echo "strip arguments"\n'
111     txt += 'args=("$@")\n'
112     txt += 'nargs=$#\n'
113     txt += 'shift $nargs\n'
114     txt += "# job number (first parameter for job wrapper)\n"
115 ewv 1.9 txt += "NJob=${args[0]}; export NJob\n"
116 slacapra 1.1
117 slacapra 1.12 txt += "out_files=out_files_${NJob}; export out_files\n"
118     txt += "echo $out_files\n"
119     txt += jbt.outList()
120    
121 slacapra 1.6 txt += 'SyncGridJobId=`echo '+self.environment_unique_identifier+'`\n'
122     txt += 'MonitorJobID=`echo ${NJob}_${SyncGridJobId}`\n'
123 slacapra 1.1 txt += 'MonitorID=`echo ' + self._taskId + '`\n'
124    
125     txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
126     txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
127     txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
128 slacapra 1.7 txt += 'echo "SyncCE='+self.name()+'.`hostname -d`" | tee -a $RUNTIME_AREA/$repo \n'
129 fanzago 1.23 ###### FEDE
130     txt += 'middleware='+self.name().upper()+' \n'
131 slacapra 1.1
132     txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
133    
134 slacapra 1.12 txt += 'InputSandBox=${args[3]}\n'
135    
136 slacapra 1.1 txt += '\n\n'
137    
138     return txt
139    
140 slacapra 1.3 def wsCopyOutput(self):
141     """
142     Write a CopyResults part of a job script, e.g.
143     to copy produced output into a storage element.
144     """
145 slacapra 1.8 txt = '\n'
146     if not self.copy_data: return txt
147 slacapra 1.3
148    
149     txt += '#\n'
150 fanzago 1.23 txt += '# COPY OUTPUT FILE TO '+self.SE_path+ '\n'
151 slacapra 1.3 txt += '#\n\n'
152    
153     txt += 'export SE_PATH='+self.SE_path+'\n'
154    
155 fanzago 1.24 txt += 'export CP_CMD='+self._copyCommand+'\n'
156     common.logger.debug(3, "Wrapper script CP_CMD set to "+ self._copyCommand)
157 slacapra 1.3
158 fanzago 1.24 txt += 'echo ">>> Copy output files from WN = `hostname` to PATH = $SE_PATH using $CP_CMD :"\n'
159 slacapra 1.3
160 fanzago 1.24 txt += 'if [ $job_exit_code -eq 60302 ]; then\n'
161     txt += ' echo "--> No output file to copy to $SE"\n'
162     txt += ' copy_exit_status=$job_exit_code\n'
163     txt += ' echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
164     txt += 'else\n'
165     txt += ' for out_file in $file_list ; do\n'
166 slacapra 1.3 txt += ' echo "Trying to copy output file to $SE_PATH"\n'
167 fanzago 1.24 txt += ' $CP_CMD $SOFTWARE_DIR/$out_file ${SE_PATH}/$out_file\n'
168     txt += ' copy_exit_status=$?\n'
169     txt += ' echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
170     txt += ' echo "STAGE_OUT = $copy_exit_status"\n'
171     txt += ' if [ $copy_exit_status -ne 0 ]; then\n'
172     txt += ' echo "Problem copying $out_file to $SE $SE_PATH"\n'
173     txt += ' echo "StageOutExitStatus = $copy_exit_status " | tee -a $RUNTIME_AREA/$repo\n'
174 slacapra 1.3 txt += ' else\n'
175 fanzago 1.24 txt += ' echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
176     txt += ' echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
177 slacapra 1.3 txt += ' echo "output copied into $SE/$SE_PATH directory"\n'
178 fanzago 1.24 txt += ' echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
179 slacapra 1.3 txt += ' fi\n'
180 fanzago 1.24 txt += ' done\n'
181 slacapra 1.3 txt += 'fi\n'
182 fanzago 1.24 txt += 'exit_status=$copy_exit_status\n'
183 fanzago 1.23 txt += 'export TIME_STAGEOUT_END=`date +%s` \n'
184     txt += 'let "TIME_STAGEOUT = TIME_STAGEOUT_END - TIME_STAGEOUT_INI" \n'
185 slacapra 1.3
186     return txt
187 spiga 1.21
188    
189     def wsExitFunc_comm(self):
190     """
191     """
192     txt = ''
193     txt += ' if [ $PYTHONPATH ]; then \n'
194     txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
195     txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
196     txt += ' else \n'
197     txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --errorcode $job_exit_code $executable_exit_status \n'
198     txt += ' fi\n'
199     txt += ' fi\n'
200     txt += ' cd $RUNTIME_AREA \n'
201     txt += ' for file in $filesToCheck ; do\n'
202     txt += ' if [ -e $file ]; then\n'
203     txt += ' echo "tarring file $file in $out_files"\n'
204     txt += ' else\n'
205     txt += ' echo "WARNING: output file $file not found!"\n'
206     txt += ' fi\n'
207     txt += ' done\n'
208     txt += ' export TIME_WRAP_END=`date +%s`\n'
209     txt += ' let "TIME_WRAP = TIME_WRAP_END - TIME_WRAP_END_INI" \n'
210     txt += ' if [ $PYTHONPATH ]; then \n'
211     txt += ' if [ ! -s $RUNTIME_AREA/fillCrabFjr.py ]; then \n'
212     txt += ' echo "WARNING: it is not possible to create crab_fjr.xml to final report" \n'
213     txt += ' else \n'
214     # call timing FJR filling
215     txt += ' python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --timing $TIME_WRAP $TIME_EXE $TIME_STAGEOUT \n'
216     txt += ' echo "CrabWrapperTime=$TIME_WRAP" >> $RUNTIME_AREA/$repo \n'
217     txt += ' if [ $TIME_STAGEOUT -lt 0 ]; then \n'
218     txt += ' export TIME_STAGEOUT=NULL \n'
219     txt += ' fi\n'
220     txt += ' echo "CrabStageoutTime=$TIME_STAGEOUT" >> $RUNTIME_AREA/$repo \n'
221     txt += ' fi\n'
222     txt += ' fi\n'
223     txt += ' dumpStatus $RUNTIME_AREA/$repo \n\n'
224     txt += ' echo "JOB_EXIT_STATUS = $job_exit_code"\n'
225     txt += ' echo "JobExitCode=$job_exit_code" >> $RUNTIME_AREA/$repo\n'
226     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
227    
228     return txt
229