ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerEdg.py
Revision: 1.86
Committed: Wed Oct 4 16:31:13 2006 UTC (18 years, 6 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.85: +3 -4 lines
Log Message:
next fix for removal of analisys_common_info. analisys_common_info previously hold a flag for copy_input_data probably needed by famos to stage in input files to deactvate stage-in for cmssw. As ORCA support is dropped in >= CRAB_1_3_0, we can safely set this to 0 in SchedulerEdg.py

File Contents

# Content
1 from Scheduler import Scheduler
2 from crab_logger import Logger
3 from crab_exceptions import *
4 from crab_util import *
5 from EdgConfig import *
6 import common
7
8 import os, sys, time
9
10 class SchedulerEdg(Scheduler):
11 def __init__(self):
12 Scheduler.__init__(self,"EDG")
13 self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
14 "children_hist","children_num","children_states","condorId","condor_jdl", \
15 "cpuTime","destination", "done_code","exit_code","expectFrom", \
16 "expectUpdate","globusId","jdl","jobId","jobtype", \
17 "lastUpdateTime","localId","location", "matched_jdl","network_server", \
18 "owner","parent_job", "reason","resubmitted","rsl","seed",\
19 "stateEnterTime","stateEnterTimes","subjob_failed", \
20 "user tags" , "status" , "status_code","hierarchy"]
21 return
22
23 def configure(self, cfg_params):
24
25 try:
26 RB = cfg_params["EDG.rb"]
27 edgConfig = EdgConfig(RB)
28 self.edg_config = edgConfig.config()
29 self.edg_config_vo = edgConfig.configVO()
30 except KeyError:
31 self.edg_config = ''
32 self.edg_config_vo = ''
33
34 try:
35 self.proxyServer = cfg_params["EDG.proxy_server"]
36 except KeyError:
37 self.proxyServer = 'myproxy.cern.ch'
38 common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
39
40 try:
41 self.role = cfg_params["EDG.role"]
42 except KeyError:
43 self.role = None
44
45 try: self.LCG_version = cfg_params["EDG.lcg_version"]
46 except KeyError: self.LCG_version = '2'
47
48 try: self.EDG_requirements = cfg_params['EDG.requirements']
49 except KeyError: self.EDG_requirements = ''
50
51 try: self.EDG_retry_count = cfg_params['EDG.retry_count']
52 except KeyError: self.EDG_retry_count = ''
53
54 try:
55 self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
56 #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
57 except KeyError:
58 self.EDG_ce_black_list = ''
59
60 try:
61 self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
62 #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
63 except KeyError: self.EDG_ce_white_list = ''
64
65 try: self.VO = cfg_params['EDG.virtual_organization']
66 except KeyError: self.VO = 'cms'
67
68 try: self.return_data = cfg_params['USER.return_data']
69 except KeyError: self.return_data = 1
70
71 # was set t o zero in cms_cmssw.py to deactivate only for cmssw
72 # after CRAB_1_3_0, support for ORCA was dropped, so setting it here to zero and avoiding usage of non-existant analisys_common_info
73 self.copy_input_data = 0
74
75 try:
76 self.copy_data = cfg_params["USER.copy_data"]
77 if int(self.copy_data) == 1:
78 try:
79 self.SE = cfg_params['USER.storage_element']
80 self.SE_PATH = cfg_params['USER.storage_path']
81 except KeyError:
82 msg = "Error. The [USER] section does not have 'storage_element'"
83 msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
84 common.logger.message(msg)
85 raise CrabException(msg)
86 except KeyError: self.copy_data = 0
87
88 if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
89 msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
90 msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
91 raise CrabException(msg)
92
93 try:
94 self.lfc_host = cfg_params['EDG.lfc_host']
95 except KeyError:
96 msg = "Error. The [EDG] section does not have 'lfc_host' value"
97 msg = msg + " it's necessary to know the LFC host name"
98 common.logger.message(msg)
99 raise CrabException(msg)
100 try:
101 self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
102 except KeyError:
103 msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
104 msg = msg + " it's necessary to know the catalog type"
105 common.logger.message(msg)
106 raise CrabException(msg)
107 try:
108 self.lfc_home = cfg_params['EDG.lfc_home']
109 except KeyError:
110 msg = "Error. The [EDG] section does not have 'lfc_home' value"
111 msg = msg + " it's necessary to know the home catalog dir"
112 common.logger.message(msg)
113 raise CrabException(msg)
114
115 try:
116 self.register_data = cfg_params["USER.register_data"]
117 if int(self.register_data) == 1:
118 try:
119 self.LFN = cfg_params['USER.lfn_dir']
120 except KeyError:
121 msg = "Error. The [USER] section does not have 'lfn_dir' value"
122 msg = msg + " it's necessary for LCF registration"
123 common.logger.message(msg)
124 raise CrabException(msg)
125 except KeyError: self.register_data = 0
126
127 if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
128 msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
129 msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
130 common.logger.message(msg)
131 raise CrabException(msg)
132
133 try: self.EDG_requirements = cfg_params['EDG.requirements']
134 except KeyError: self.EDG_requirements = ''
135
136 try: self.EDG_retry_count = cfg_params['EDG.retry_count']
137 except KeyError: self.EDG_retry_count = ''
138
139 try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
140 except KeyError: self.EDG_clock_time= ''
141
142 try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
143 except KeyError: self.EDG_cpu_time = ''
144
145 # Add EDG_WL_LOCATION to the python path
146
147 try:
148 path = os.environ['EDG_WL_LOCATION']
149 except:
150 msg = "Error: the EDG_WL_LOCATION variable is not set."
151 raise CrabException(msg)
152
153 libPath=os.path.join(path, "lib")
154 sys.path.append(libPath)
155 libPath=os.path.join(path, "lib", "python")
156 sys.path.append(libPath)
157
158 self.proxyValid=0
159
160 try:
161 self._taskId = cfg_params['taskId']
162 except:
163 self._taskId = ''
164
165 try: self.jobtypeName = cfg_params['CRAB.jobtype']
166 except KeyError: self.jobtypeName = ''
167
168 try: self.schedulerName = cfg_params['CRAB.scheduler']
169 except KeyError: self.scheduler = ''
170
171 return
172
173
174 def sched_parameter(self):
175 """
176 Returns file with scheduler-specific parameters
177 """
178
179 if (self.edg_config and self.edg_config_vo != ''):
180 self.param='sched_param.clad'
181 param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
182 param_file.write('RBconfig = "'+self.edg_config+'";\n')
183 param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
184 param_file.close()
185 return 1
186 else:
187 return 0
188
189 def wsSetupEnvironment(self):
190 """
191 Returns part of a job script which does scheduler-specific work.
192 """
193 txt = ''
194 txt += '# strip arguments\n'
195 txt += 'echo "strip arguments"\n'
196 txt += 'args=("$@")\n'
197 txt += 'nargs=$#\n'
198 txt += 'shift $nargs\n'
199 txt += "# job number (first parameter for job wrapper)\n"
200 #txt += "NJob=$1\n"
201 txt += "NJob=${args[0]}\n"
202
203 txt += '# job identification to DashBoard \n'
204 txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
205 txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
206 txt += 'MonitorID=`echo ' + self._taskId + '`\n'
207 txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
208 txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
209 txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
210
211 txt += 'echo "middleware discovery " \n'
212 txt += 'if [ $GRID3_APP_DIR ]; then\n'
213 txt += ' middleware=OSG \n'
214 txt += ' echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
215 txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
216 txt += ' echo "middleware =$middleware" \n'
217 txt += 'elif [ $OSG_APP ]; then \n'
218 txt += ' middleware=OSG \n'
219 txt += ' echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
220 txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
221 txt += ' echo "middleware =$middleware" \n'
222 txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
223 txt += ' middleware=LCG \n'
224 txt += ' echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
225 txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
226 txt += ' echo "middleware =$middleware" \n'
227 txt += 'else \n'
228 txt += ' echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
229 txt += ' echo "JOB_EXIT_STATUS = 10030" \n'
230 txt += ' echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
231 txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
232 txt += ' rm -f $RUNTIME_AREA/$repo \n'
233 txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
234 txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
235 txt += ' exit 1 \n'
236 txt += 'fi \n'
237
238 txt += '# report first time to DashBoard \n'
239 txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
240 txt += 'rm -f $RUNTIME_AREA/$repo \n'
241 txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
242 txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
243
244 txt += '\n\n'
245
246 if int(self.copy_data) == 1:
247 if self.SE:
248 txt += 'export SE='+self.SE+'\n'
249 txt += 'echo "SE = $SE"\n'
250 if self.SE_PATH:
251 if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
252 txt += 'export SE_PATH='+self.SE_PATH+'\n'
253 txt += 'echo "SE_PATH = $SE_PATH"\n'
254
255 txt += 'export VO='+self.VO+'\n'
256 ### FEDE: add some line for LFC catalog setting
257 txt += 'if [ $middleware == LCG ]; then \n'
258 txt += ' if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
259 txt += ' export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
260 txt += ' fi\n'
261 txt += ' if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
262 txt += ' export LFC_HOST='+self.lfc_host+'\n'
263 txt += ' fi\n'
264 txt += ' if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
265 txt += ' export LFC_HOME='+self.lfc_home+'\n'
266 txt += ' fi\n'
267 txt += 'elif [ $middleware == OSG ]; then\n'
268 txt += ' echo "LFC catalog setting to be implemented for OSG"\n'
269 txt += 'fi\n'
270 #####
271 if int(self.register_data) == 1:
272 txt += 'if [ $middleware == LCG ]; then \n'
273 txt += ' export LFN='+self.LFN+'\n'
274 txt += ' lfc-ls $LFN\n'
275 txt += ' result=$?\n'
276 txt += ' echo $result\n'
277 ### creation of LFN dir in LFC catalog, under /grid/cms dir
278 txt += ' if [ $result != 0 ]; then\n'
279 txt += ' lfc-mkdir $LFN\n'
280 txt += ' result=$?\n'
281 txt += ' echo $result\n'
282 txt += ' fi\n'
283 txt += 'elif [ $middleware == OSG ]; then\n'
284 txt += ' echo " Files registration to be implemented for OSG"\n'
285 txt += 'fi\n'
286 txt += '\n'
287
288 if self.VO:
289 txt += 'export VO='+self.VO+'\n'
290 if self.LFN:
291 txt += 'if [ $middleware == LCG ]; then \n'
292 txt += ' export LFN='+self.LFN+'\n'
293 txt += 'fi\n'
294 txt += '\n'
295
296 txt += 'if [ $middleware == LCG ]; then\n'
297 txt += ' CloseCEs=`edg-brokerinfo getCE`\n'
298 txt += ' echo "CloseCEs = $CloseCEs"\n'
299 txt += ' CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
300 txt += ' echo "CE = $CE"\n'
301 txt += 'elif [ $middleware == OSG ]; then \n'
302 txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
303 txt += ' CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
304 txt += ' else \n'
305 txt += ' echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
306 txt += ' echo "JOB_EXIT_STATUS = 10099" \n'
307 txt += ' echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
308 txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
309 txt += ' rm -f $RUNTIME_AREA/$repo \n'
310 txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
311 txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
312 txt += ' exit 1 \n'
313 txt += ' fi \n'
314 txt += 'fi \n'
315
316 return txt
317
318 def wsCopyInput(self):
319 """
320 Copy input data from SE to WN
321 """
322 txt = ''
323 try:
324 self.copy_input_data = common.analisys_common_info['copy_input_data']
325 except KeyError: self.copy_input_data = 0
326 if int(self.copy_input_data) == 1:
327 ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
328 txt += 'if [ $middleware == OSG ]; then\n'
329 txt += ' #\n'
330 txt += ' # Copy Input Data from SE to this WN deactivated in OSG mode\n'
331 txt += ' #\n'
332 txt += ' echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
333 txt += 'elif [ $middleware == LCG ]; then \n'
334 txt += ' #\n'
335 txt += ' # Copy Input Data from SE to this WN\n'
336 txt += ' #\n'
337 ### changed by georgia (put a loop copying more than one input files per jobs)
338 txt += ' for input_file in $cur_file_list \n'
339 txt += ' do \n'
340 txt += ' lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
341 txt += ' copy_input_exit_status=$?\n'
342 txt += ' echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
343 txt += ' if [ $copy_input_exit_status -ne 0 ]; then \n'
344 txt += ' echo "Problems with copying to WN" \n'
345 txt += ' else \n'
346 txt += ' echo "input copied into WN" \n'
347 txt += ' fi \n'
348 txt += ' done \n'
349 ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
350 txt += ' for file in $cur_pu_list \n'
351 txt += ' do \n'
352 txt += ' lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
353 txt += ' copy_input_pu_exit_status=$?\n'
354 txt += ' echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
355 txt += ' if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
356 txt += ' echo "Problems with copying pu to WN" \n'
357 txt += ' else \n'
358 txt += ' echo "input pu files copied into WN" \n'
359 txt += ' fi \n'
360 txt += ' done \n'
361 txt += ' \n'
362 txt += ' ### Check SCRATCH space available on WN : \n'
363 txt += ' df -h \n'
364 txt += 'fi \n'
365
366 return txt
367
368 def wsCopyOutput(self):
369 """
370 Write a CopyResults part of a job script, e.g.
371 to copy produced output into a storage element.
372 """
373 txt = ''
374 if int(self.copy_data) == 1:
375 txt += '#\n'
376 txt += '# Copy output to SE = $SE\n'
377 txt += '#\n'
378 txt += ' if [ $middleware == OSG ]; then\n'
379 txt += ' echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
380 txt += ' echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
381 txt += ' source $OSG_APP/glite/setup_glite_ui.sh\n'
382 txt += ' export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
383 txt += ' echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
384 txt += ' fi \n'
385 txt += ' for out_file in $file_list ; do\n'
386 txt += ' echo "Trying to copy output file to $SE using lcg-cp"\n'
387 if common.logger.debugLevel() >= 5:
388 txt += ' echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
389 txt += ' exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
390 else:
391 txt += ' echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
392 txt += ' exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
393 txt += ' copy_exit_status=$?\n'
394 txt += ' echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
395 txt += ' echo "STAGE_OUT = $copy_exit_status"\n'
396 txt += ' if [ $copy_exit_status -ne 0 ]; then\n'
397 txt += ' echo "Possible problem with SE = $SE"\n'
398 txt += ' echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
399 txt += ' echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
400 txt += ' echo "lcg-cp failed. For verbose lcg-cp output, use command line option -debug 5."\n'
401 txt += ' echo "lcg-cp failed, attempting srmcp"\n'
402 txt += ' echo "mkdir -p $HOME/.srmconfig"\n'
403 txt += ' mkdir -p $HOME/.srmconfig\n'
404 txt += ' if [ $middleware == LCG ]; then\n'
405 txt += ' echo "srmcp -retry_num 5 -retry_timeout 480000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
406 txt += ' exitstring=`srmcp -retry_num 5 -retry_timeout 480000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
407 txt += ' elif [ $middleware == OSG ]; then\n'
408 txt += ' echo "srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
409 txt += ' exitstring=`srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
410 txt += ' fi \n'
411 txt += ' copy_exit_status=$?\n'
412 txt += ' echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
413 txt += ' echo "STAGE_OUT = $copy_exit_status"\n'
414 txt += ' if [ $copy_exit_status -ne 0 ]; then\n'
415 txt += ' echo "Problems with SE = $SE"\n'
416 txt += ' echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
417 txt += ' echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
418 txt += ' echo "lcg-cp and srm failed"\n'
419 txt += ' echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
420 txt += ' else\n'
421 txt += ' echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
422 txt += ' echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
423 txt += ' echo "output copied into $SE/$SE_PATH directory"\n'
424 txt += ' echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
425 txt += ' echo "srmcp succeeded"\n'
426 txt += ' fi\n'
427 txt += ' else\n'
428 txt += ' echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
429 txt += ' echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
430 txt += ' echo "output copied into $SE/$SE_PATH directory"\n'
431 txt += ' echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
432 txt += ' echo "lcg-cp succeeded"\n'
433 txt += ' fi\n'
434 txt += ' done\n'
435 return txt
436
437 def wsRegisterOutput(self):
438 """
439 Returns part of a job script which does scheduler-specific work.
440 """
441
442 txt = ''
443 if int(self.register_data) == 1:
444 ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
445 txt += 'if [ $middleware == OSG ]; then\n'
446 txt += ' #\n'
447 txt += ' # Register output to LFC deactivated in OSG mode\n'
448 txt += ' #\n'
449 txt += ' echo "Register output to LFC deactivated in OSG mode"\n'
450 txt += 'elif [ $middleware == LCG ]; then \n'
451 txt += '#\n'
452 txt += '# Register output to LFC\n'
453 txt += '#\n'
454 txt += ' if [ $copy_exit_status -eq 0 ]; then\n'
455 txt += ' for out_file in $file_list ; do\n'
456 txt += ' echo "Trying to register the output file into LFC"\n'
457 txt += ' echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
458 txt += ' lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
459 txt += ' register_exit_status=$?\n'
460 txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
461 txt += ' echo "STAGE_OUT = $register_exit_status"\n'
462 txt += ' if [ $register_exit_status -ne 0 ]; then \n'
463 txt += ' echo "Problems with the registration to LFC" \n'
464 txt += ' echo "Try with srm protocol" \n'
465 txt += ' echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
466 txt += ' lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
467 txt += ' register_exit_status=$?\n'
468 txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
469 txt += ' echo "STAGE_OUT = $register_exit_status"\n'
470 txt += ' if [ $register_exit_status -ne 0 ]; then \n'
471 txt += ' echo "Problems with the registration into LFC" \n'
472 txt += ' fi \n'
473 txt += ' else \n'
474 txt += ' echo "output registered to LFC"\n'
475 txt += ' fi \n'
476 txt += ' echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
477 txt += ' done\n'
478 txt += ' else \n'
479 txt += ' echo "Trying to copy output file to CloseSE"\n'
480 txt += ' CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
481 txt += ' for out_file in $file_list ; do\n'
482 txt += ' echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1" \n'
483 txt += ' lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1 \n'
484 txt += ' register_exit_status=$?\n'
485 txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
486 txt += ' echo "STAGE_OUT = $register_exit_status"\n'
487 txt += ' if [ $register_exit_status -ne 0 ]; then \n'
488 txt += ' echo "Problems with CloseSE or Catalog" \n'
489 txt += ' else \n'
490 txt += ' echo "The program was successfully executed"\n'
491 txt += ' echo "SE = $CLOSE_SE"\n'
492 txt += ' echo "LFN for the file is LFN=${LFN}/$out_file"\n'
493 txt += ' fi \n'
494 txt += ' echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
495 txt += ' done\n'
496 txt += ' fi \n'
497 txt += ' exit_status=$register_exit_status\n'
498 txt += 'fi \n'
499 return txt
500
501 def loggingInfo(self, id):
502 """
503 retrieve the logging info from logging and bookkeeping and return it
504 """
505 self.checkProxy()
506 cmd = 'edg-job-get-logging-info -v 2 ' + id
507 #cmd_out = os.popen(cmd)
508 cmd_out = runCommand(cmd)
509 return cmd_out
510
511 def getExitStatus(self, id):
512 return self.getStatusAttribute_(id, 'exit_code')
513
514 def queryStatus(self, id):
515 return self.getStatusAttribute_(id, 'status')
516
517 def queryDest(self, id):
518 return self.getStatusAttribute_(id, 'destination')
519
520
521 def getStatusAttribute_(self, id, attr):
522 """ Query a status of the job with id """
523
524 self.checkProxy()
525 hstates = {}
526 Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
527 # Bypass edg-job-status interfacing directly to C++ API
528 # Job attribute vector to retrieve status without edg-job-status
529 level = 0
530 # Instance of the Status class provided by LB API
531 jobStat = Status()
532 st = 0
533 jobStat.getStatus(id, level)
534 err, apiMsg = jobStat.get_error()
535 if err:
536 common.logger.debug(5,'Error caught' + apiMsg)
537 return None
538 else:
539 for i in range(len(self.states)):
540 # Fill an hash table with all information retrieved from LB API
541 hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
542 result = jobStat.loadStatus(st)[self.states.index(attr)]
543 return result
544
545 def queryDetailedStatus(self, id):
546 """ Query a detailed status of the job with id """
547 cmd = 'edg-job-status '+id
548 cmd_out = runCommand(cmd)
549 return cmd_out
550
551 ##### FEDE ######
552 def findSites_(self, n_tot_job):
553 itr4 = []
554 # print "n_tot_job = ", n_tot_job
555 for n in range(n_tot_job):
556 sites = common.jobDB.destination(n)
557 if len(sites)>0 and sites[0]=="Any": continue
558
559 #job = common.job_list[n]
560 #jbt = job.type()
561 # print "common.jobDB.destination(n) = ", common.jobDB.destination(n)
562 # print "sites = ", sites
563 itr = ''
564 if sites != [""]:#CarlosDaniele
565 for site in sites:
566 #itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
567 itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
568 pass
569 # remove last ||
570 itr = itr[0:-4]
571 itr4.append( itr )
572 # remove last ,
573 # print "itr4 = ", itr4
574 return itr4
575
576 def createXMLSchScript(self, nj, argsList):
577 # def createXMLSchScript(self, nj):
578 """
579 Create a XML-file for BOSS4.
580 """
581 # job = common.job_list[nj]
582 """
583 INDY
584 [begin] da rivedere:
585 in particolare passerei il jobType ed eliminerei le dipendenze da job
586 """
587 index = nj - 1
588 job = common.job_list[index]
589 jbt = job.type()
590
591 inp_sandbox = jbt.inputSandbox(index)
592 out_sandbox = jbt.outputSandbox(index)
593 """
594 [end] da rivedere
595 """
596
597
598 title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
599 jt_string = ''
600
601 xml_fname = str(self.jobtypeName)+'.xml'
602 xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
603
604 #TaskName
605 dir = string.split(common.work_space.topDir(), '/')
606 taskName = dir[len(dir)-2]
607
608 to_writeReq = ''
609 to_write = ''
610
611 req=' '
612 req = req + jbt.getRequirements()
613
614
615 #sites = common.jobDB.destination(nj)
616 #if len(sites)>0 and sites[0]!="Any":
617 # req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
618 #req = req
619
620 if self.EDG_requirements:
621 if (req == ' '):
622 req = req + self.EDG_requirements
623 else:
624 req = req + ' && ' + self.EDG_requirements
625 if self.EDG_ce_white_list:
626 ce_white_list = string.split(self.EDG_ce_white_list,',')
627 for i in range(len(ce_white_list)):
628 if i == 0:
629 if (req == ' '):
630 req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
631 else:
632 req = req + ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
633 pass
634 else:
635 req = req + ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
636 req = req + ')'
637
638 if self.EDG_ce_black_list:
639 ce_black_list = string.split(self.EDG_ce_black_list,',')
640 for ce in ce_black_list:
641 if (req == ' '):
642 req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
643 else:
644 req = req + ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
645 pass
646 if self.EDG_clock_time:
647 if (req == ' '):
648 req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
649 else:
650 req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
651
652 if self.EDG_cpu_time:
653 if (req == ' '):
654 req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
655 else:
656 req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
657
658 if ( self.EDG_retry_count ):
659 to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
660 pass
661
662 to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
663 to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
664
665
666 #TaskName
667 dir = string.split(common.work_space.topDir(), '/')
668 taskName = dir[len(dir)-2]
669
670 xml.write(str(title))
671 xml.write('<task name="' +str(taskName)+'">\n')
672 xml.write(jt_string)
673
674 xml.write('<iterator>\n')
675 xml.write('\t<iteratorRule name="ITR1">\n')
676 xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
677 xml.write('\t</iteratorRule>\n')
678 xml.write('\t<iteratorRule name="ITR2">\n')
679 for arg in argsList:
680 xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
681 pass
682 xml.write('\t</iteratorRule>\n')
683 #print jobList
684 xml.write('\t<iteratorRule name="ITR3">\n')
685 xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
686 xml.write('\t</iteratorRule>\n')
687
688 '''
689 indy: qui sotto ci sta itr4
690 '''
691
692 itr4=self.findSites_(nj)
693 #print "--->>> itr4 = ", itr4
694 if (itr4 != []):
695 xml.write('\t<iteratorRule name="ITR4">\n')
696 #print argsList
697 for arg in itr4:
698 xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
699 pass
700 xml.write('\t</iteratorRule>\n')
701 req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
702 pass
703 # print "--->>> req= ", req
704
705 if (to_write != ''):
706 xml.write('<extraTags\n')
707 xml.write(to_write)
708 xml.write('/>\n')
709 pass
710
711 xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
712 xml.write(jt_string)
713
714 if (req != ' '):
715 req = req + '\n'
716 xml.write('<extraTags>\n')
717 xml.write('<Requirements>\n')
718 xml.write('<![CDATA[\n')
719 xml.write(req)
720 xml.write(']]>\n')
721 xml.write('</Requirements>\n')
722 xml.write('</extraTags>\n')
723 pass
724
725 #executable
726
727 """
728 INDY
729 script dipende dal jobType: dovrebbe essere semplice tirarlo fuori in altro modo
730 """
731 script = job.scriptFilename()
732 xml.write('<program>\n')
733 xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
734 xml.write(jt_string)
735
736
737 ### only one .sh JDL has arguments:
738 ### Fabio
739 # xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
740 xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
741 xml.write('<program_types> crabjob </program_types>\n')
742 inp_box = script + ','
743
744 if inp_sandbox != None:
745 for fl in inp_sandbox:
746 inp_box = inp_box + '' + fl + ','
747 pass
748 pass
749
750 inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
751 os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
752 os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
753 os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
754 os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
755
756 if (not jbt.additional_inbox_files == []):
757 inp_box = inp_box + ','
758 for addFile in jbt.additional_inbox_files:
759 addFile = os.path.abspath(addFile)
760 inp_box = inp_box+''+addFile+','
761 pass
762
763 if inp_box[-1] == ',' : inp_box = inp_box[:-1]
764 inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
765 xml.write(inp_box)
766
767 base = jbt.name()
768 stdout = base + '__ITR3_.stdout'
769 stderr = base + '__ITR3_.stderr'
770
771 xml.write('<stderr> ' + stderr + '</stderr>\n')
772 xml.write('<stdout> ' + stdout + '</stdout>\n')
773
774
775 out_box = stdout + ',' + \
776 stderr + ',.BrokerInfo,'
777
778 """
779 if int(self.return_data) == 1:
780 if out_sandbox != None:
781 for fl in out_sandbox:
782 out_box = out_box + '' + fl + ','
783 pass
784 pass
785 pass
786 """
787
788 """
789 INDY
790 qualcosa del genere andrebbe fatta per gli infiles
791 """
792 if int(self.return_data) == 1:
793 for fl in jbt.output_file:
794 out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
795 pass
796 pass
797
798 if out_box[-1] == ',' : out_box = out_box[:-1]
799 out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
800 xml.write(out_box)
801
802 xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
803
804 xml.write('</program>\n')
805 xml.write('</chain>\n')
806
807 xml.write('</iterator>\n')
808 xml.write('</task>\n')
809
810 xml.close()
811 return
812
813 def checkProxy(self):
814 """
815 Function to check the Globus proxy.
816 """
817 if (self.proxyValid): return
818 timeleft = -999
819 minTimeLeft=10*3600 # in seconds
820
821 minTimeLeftServer = 100 # in hours
822
823 mustRenew = 0
824 timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
825 timeLeftServer = -999
826 if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
827 mustRenew = 1
828 else:
829 timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
830 if not timeLeftServer or not isInt(timeLeftServer):
831 mustRenew = 1
832 elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
833 mustRenew = 1
834 pass
835 pass
836
837 if mustRenew:
838 common.logger.message( "No valid proxy found or remaining time of validity of already existing proxy shorter than 10 hours!\n Creating a user proxy with default length of 96h\n")
839 cmd = 'voms-proxy-init -voms '+self.VO+' -valid 96:00'
840 if self.role:
841 cmd = 'voms-proxy-init -voms '+self.VO+':/'+self.VO+'/role='+self.role+' -valid 96:00'
842 try:
843 # SL as above: damn it!
844 out = os.system(cmd)
845 if (out>0): raise CrabException("Unable to create a valid proxy!\n")
846 except:
847 msg = "Unable to create a valid proxy!\n"
848 raise CrabException(msg)
849 pass
850
851 ## now I do have a voms proxy valid, and I check the myproxy server
852 renewProxy = 0
853 cmd = 'myproxy-info -d -s '+self.proxyServer
854 cmd_out = runCommand(cmd,0,20)
855 if not cmd_out:
856 common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
857 renewProxy = 1
858 else:
859 # if myproxy exist but not long enough, renew
860 reTime = re.compile( r'timeleft: (\d+)' )
861 #print "<"+str(reTime.search( cmd_out ).group(1))+">"
862 if reTime.match( cmd_out ):
863 time = reTime.search( line ).group(1)
864 if time < minTimeLeftServer:
865 renewProxy = 1
866 common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
867 pass
868 pass
869
870 # if not, create one.
871 if renewProxy:
872 cmd = 'myproxy-init -d -n -s '+self.proxyServer
873 out = os.system(cmd)
874 if (out>0):
875 raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
876 pass
877
878 # cache proxy validity
879 self.proxyValid=1
880 return
881
882 def configOpt_(self):
883 edg_ui_cfg_opt = ' '
884 if self.edg_config:
885 edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
886 if self.edg_config_vo:
887 edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
888 return edg_ui_cfg_opt