ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerEdg.py
Revision: 1.73.2.5.2.1
Committed: Mon Aug 21 15:06:46 2006 UTC (18 years, 8 months ago) by fanzago
Content type: text/x-python
Branch: CRAB_BOSS4_v1
Changes since 1.73.2.5: +1 -0 lines
Log Message:
test branch

File Contents

# User Rev Content
1 nsmirnov 1.1 from Scheduler import Scheduler
2     from crab_logger import Logger
3     from crab_exceptions import *
4     from crab_util import *
5 slacapra 1.50 from EdgConfig import *
6 nsmirnov 1.1 import common
7    
8 slacapra 1.18 import os, sys, time
9 nsmirnov 1.1
10     class SchedulerEdg(Scheduler):
11 fanzago 1.73.2.5.2.1 #"test crab_boss4_v1"
12 nsmirnov 1.1 def __init__(self):
13     Scheduler.__init__(self,"EDG")
14 slacapra 1.8 self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
15     "children_hist","children_num","children_states","condorId","condor_jdl", \
16     "cpuTime","destination", "done_code","exit_code","expectFrom", \
17     "expectUpdate","globusId","jdl","jobId","jobtype", \
18     "lastUpdateTime","localId","location", "matched_jdl","network_server", \
19     "owner","parent_job", "reason","resubmitted","rsl","seed",\
20     "stateEnterTime","stateEnterTimes","subjob_failed", \
21     "user tags" , "status" , "status_code","hierarchy"]
22 nsmirnov 1.1 return
23    
24     def configure(self, cfg_params):
25 spiga 1.73.2.3
26 slacapra 1.46 try:
27     RB = cfg_params["EDG.rb"]
28     edgConfig = EdgConfig(RB)
29     self.edg_config = edgConfig.config()
30     self.edg_config_vo = edgConfig.configVO()
31     except KeyError:
32     self.edg_config = ''
33     self.edg_config_vo = ''
34 nsmirnov 1.1
35 slacapra 1.51 try:
36     self.proxyServer = cfg_params["EDG.proxy_server"]
37     except KeyError:
38     self.proxyServer = 'myproxy.cern.ch'
39     common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
40 spiga 1.49
41 nsmirnov 1.1 try: self.LCG_version = cfg_params["EDG.lcg_version"]
42     except KeyError: self.LCG_version = '2'
43    
44     try: self.EDG_requirements = cfg_params['EDG.requirements']
45     except KeyError: self.EDG_requirements = ''
46    
47 spiga 1.49 try: self.EDG_retry_count = cfg_params['EDG.retry_count']
48 nsmirnov 1.1 except KeyError: self.EDG_retry_count = ''
49    
50 fanzago 1.48 try:
51     self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
52     except KeyError:
53     self.EDG_ce_black_list = ''
54    
55     try:
56     self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
57     except KeyError: self.EDG_ce_white_list = ''
58    
59 fanzago 1.14 try: self.VO = cfg_params['EDG.virtual_organization']
60     except KeyError: self.VO = 'cms'
61    
62 spiga 1.49 try: self.return_data = cfg_params['USER.return_data']
63     except KeyError: self.return_data = 1
64    
65 fanzago 1.39 try:
66     self.copy_input_data = common.analisys_common_info['copy_input_data']
67     except KeyError: self.copy_input_data = 0
68    
69 fanzago 1.14 try:
70     self.copy_data = cfg_params["USER.copy_data"]
71 fanzago 1.30 if int(self.copy_data) == 1:
72     try:
73     self.SE = cfg_params['USER.storage_element']
74     self.SE_PATH = cfg_params['USER.storage_path']
75     except KeyError:
76     msg = "Error. The [USER] section does not have 'storage_element'"
77     msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
78     common.logger.message(msg)
79     raise CrabException(msg)
80     except KeyError: self.copy_data = 0
81    
82     if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
83     msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
84     msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
85     raise CrabException(msg)
86 fanzago 1.38
87     try:
88     self.lfc_host = cfg_params['EDG.lfc_host']
89     except KeyError:
90     msg = "Error. The [EDG] section does not have 'lfc_host' value"
91     msg = msg + " it's necessary to know the LFC host name"
92     common.logger.message(msg)
93     raise CrabException(msg)
94     try:
95     self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
96     except KeyError:
97     msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
98     msg = msg + " it's necessary to know the catalog type"
99     common.logger.message(msg)
100     raise CrabException(msg)
101     try:
102     self.lfc_home = cfg_params['EDG.lfc_home']
103     except KeyError:
104     msg = "Error. The [EDG] section does not have 'lfc_home' value"
105     msg = msg + " it's necessary to know the home catalog dir"
106     common.logger.message(msg)
107     raise CrabException(msg)
108 fanzago 1.30
109 fanzago 1.14 try:
110     self.register_data = cfg_params["USER.register_data"]
111 fanzago 1.30 if int(self.register_data) == 1:
112     try:
113     self.LFN = cfg_params['USER.lfn_dir']
114     except KeyError:
115     msg = "Error. The [USER] section does not have 'lfn_dir' value"
116 fanzago 1.36 msg = msg + " it's necessary for LCF registration"
117 fanzago 1.30 common.logger.message(msg)
118     raise CrabException(msg)
119     except KeyError: self.register_data = 0
120    
121     if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
122     msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
123     msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
124     common.logger.message(msg)
125     raise CrabException(msg)
126 fanzago 1.14
127     try: self.EDG_requirements = cfg_params['EDG.requirements']
128     except KeyError: self.EDG_requirements = ''
129    
130     try: self.EDG_retry_count = cfg_params['EDG.retry_count']
131     except KeyError: self.EDG_retry_count = ''
132    
133     try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
134     except KeyError: self.EDG_clock_time= ''
135    
136     try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
137     except KeyError: self.EDG_cpu_time = ''
138    
139 fanzago 1.16 # Add EDG_WL_LOCATION to the python path
140     try:
141     path = os.environ['EDG_WL_LOCATION']
142     except:
143     msg = "Error: the EDG_WL_LOCATION variable is not set."
144     raise CrabException(msg)
145    
146     libPath=os.path.join(path, "lib")
147     sys.path.append(libPath)
148     libPath=os.path.join(path, "lib", "python")
149     sys.path.append(libPath)
150 nsmirnov 1.1
151 slacapra 1.18 self.proxyValid=0
152 gutsche 1.60
153 slacapra 1.61 try:
154     self._taskId = cfg_params['taskId']
155     except:
156     self._taskId = ''
157 gutsche 1.60
158 spiga 1.73.2.4 try: self.jobtypeName = cfg_params['CRAB.jobtype']
159     except KeyError: self.jobtypeName = ''
160    
161     try: self.schedulerName = cfg_params['CRAB.scheduler']
162     except KeyError: self.scheduler = ''
163    
164 nsmirnov 1.1 return
165    
166 fanzago 1.10
167     def sched_parameter(self):
168     """
169     Returns file with scheduler-specific parameters
170     """
171     if (self.edg_config and self.edg_config_vo != ''):
172     self.param='sched_param.clad'
173     param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
174     param_file.write('RBconfig = "'+self.edg_config+'";\n')
175     param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
176     param_file.close()
177     return 1
178     else:
179     return 0
180 fanzago 1.13
181 nsmirnov 1.2 def wsSetupEnvironment(self):
182     """
183     Returns part of a job script which does scheduler-specific work.
184     """
185 spiga 1.49 txt = ''
186 gutsche 1.60 txt += "# job number (first parameter for job wrapper)\n"
187     txt += "NJob=$1\n"
188    
189     txt += '# job identification to DashBoard \n'
190 gutsche 1.64 txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
191     txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
192     txt += 'MonitorID=`echo ' + self._taskId + '`\n'
193     txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
194     txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
195     txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
196 gutsche 1.60
197 spiga 1.49 txt += 'echo "middleware discovery " \n'
198 gutsche 1.60 txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
199 spiga 1.49 txt += ' middleware=LCG \n'
200 gutsche 1.60 txt += ' echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
201     txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
202 spiga 1.49 txt += ' echo "middleware =$middleware" \n'
203     txt += 'elif [ $GRID3_APP_DIR ]; then\n'
204     txt += ' middleware=OSG \n'
205 gutsche 1.60 txt += ' echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
206     txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
207 spiga 1.49 txt += ' echo "middleware =$middleware" \n'
208     txt += 'elif [ $OSG_APP ]; then \n'
209     txt += ' middleware=OSG \n'
210 gutsche 1.60 txt += ' echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
211     txt += ' echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
212 spiga 1.49 txt += ' echo "middleware =$middleware" \n'
213     txt += 'else \n'
214 gutsche 1.60 txt += ' echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
215     txt += ' echo "JOB_EXIT_STATUS = 10030" \n'
216     txt += ' echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
217     txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
218 gutsche 1.64 txt += ' rm -f $RUNTIME_AREA/$repo \n'
219     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
220     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
221 gutsche 1.60 txt += ' exit 1 \n'
222     txt += 'fi \n'
223    
224     txt += '# report first time to DashBoard \n'
225     txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
226 gutsche 1.64 txt += 'rm -f $RUNTIME_AREA/$repo \n'
227     txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
228     txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
229    
230 spiga 1.49 txt += '\n\n'
231    
232 fanzago 1.30 if int(self.copy_data) == 1:
233 fanzago 1.14 if self.SE:
234     txt += 'export SE='+self.SE+'\n'
235 fanzago 1.15 txt += 'echo "SE = $SE"\n'
236 fanzago 1.14 if self.SE_PATH:
237     if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
238     txt += 'export SE_PATH='+self.SE_PATH+'\n'
239 fanzago 1.15 txt += 'echo "SE_PATH = $SE_PATH"\n'
240 spiga 1.49
241 fanzago 1.38 txt += 'export VO='+self.VO+'\n'
242     ### FEDE: add some line for LFC catalog setting
243 spiga 1.49 txt += 'if [ $middleware == LCG ]; then \n'
244     txt += ' if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
245     txt += ' export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
246     txt += ' fi\n'
247     txt += ' if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
248     txt += ' export LFC_HOST='+self.lfc_host+'\n'
249     txt += ' fi\n'
250     txt += ' if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
251     txt += ' export LFC_HOME='+self.lfc_home+'\n'
252     txt += ' fi\n'
253     txt += 'elif [ $middleware == OSG ]; then\n'
254     txt += ' echo "LFC catalog setting to be implemented for OSG"\n'
255 fanzago 1.38 txt += 'fi\n'
256     #####
257 fanzago 1.30 if int(self.register_data) == 1:
258 spiga 1.49 txt += 'if [ $middleware == LCG ]; then \n'
259     txt += ' export LFN='+self.LFN+'\n'
260     txt += ' lfc-ls $LFN\n'
261     txt += ' result=$?\n'
262     txt += ' echo $result\n'
263 fanzago 1.36 ### creation of LFN dir in LFC catalog, under /grid/cms dir
264 spiga 1.49 txt += ' if [ $result != 0 ]; then\n'
265     txt += ' lfc-mkdir $LFN\n'
266     txt += ' result=$?\n'
267     txt += ' echo $result\n'
268     txt += ' fi\n'
269     txt += 'elif [ $middleware == OSG ]; then\n'
270     txt += ' echo " Files registration to be implemented for OSG"\n'
271 fanzago 1.36 txt += 'fi\n'
272     txt += '\n'
273 spiga 1.49
274     if self.VO:
275     txt += 'export VO='+self.VO+'\n'
276     if self.LFN:
277     txt += 'if [ $middleware == LCG ]; then \n'
278     txt += ' export LFN='+self.LFN+'\n'
279     txt += 'fi\n'
280     txt += '\n'
281    
282     txt += 'if [ $middleware == LCG ]; then\n'
283     txt += ' CloseCEs=`edg-brokerinfo getCE`\n'
284     txt += ' echo "CloseCEs = $CloseCEs"\n'
285     txt += ' CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
286     txt += ' echo "CE = $CE"\n'
287     txt += 'elif [ $middleware == OSG ]; then \n'
288     txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
289     txt += ' CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
290     txt += ' else \n'
291 gutsche 1.60 txt += ' echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
292     txt += ' echo "JOB_EXIT_STATUS = 10099" \n'
293     txt += ' echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
294     txt += ' dumpStatus $RUNTIME_AREA/$repo \n'
295 gutsche 1.64 txt += ' rm -f $RUNTIME_AREA/$repo \n'
296     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
297     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
298 spiga 1.49 txt += ' exit 1 \n'
299     txt += ' fi \n'
300     txt += 'fi \n'
301    
302 nsmirnov 1.2 return txt
303 fanzago 1.15
304 fanzago 1.39 def wsCopyInput(self):
305     """
306     Copy input data from SE to WN
307     """
308     txt = ''
309     try:
310     self.copy_input_data = common.analisys_common_info['copy_input_data']
311     #print "self.copy_input_data = ", self.copy_input_data
312     except KeyError: self.copy_input_data = 0
313     if int(self.copy_input_data) == 1:
314 spiga 1.49 ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
315     txt += 'if [ $middleware == OSG ]; then\n'
316     txt += ' #\n'
317     txt += ' # Copy Input Data from SE to this WN deactivated in OSG mode\n'
318     txt += ' #\n'
319     txt += ' echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
320     txt += 'elif [ $middleware == LCG ]; then \n'
321     txt += ' #\n'
322     txt += ' # Copy Input Data from SE to this WN\n'
323     txt += ' #\n'
324 spiga 1.42 ### changed by georgia (put a loop copying more than one input files per jobs)
325 spiga 1.49 txt += ' for input_file in $cur_file_list \n'
326     txt += ' do \n'
327 fanzago 1.68 #### FEDE
328     #txt += ' echo "which lcg-cp" \n'
329     #txt += ' which lcg-cp \n'
330     #########
331 fanzago 1.70 txt += ' lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
332 fanzago 1.68 txt += ' copy_input_exit_status=$?\n'
333     txt += ' echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
334     txt += ' if [ $copy_input_exit_status -ne 0 ]; then \n'
335     txt += ' echo "Problems with copying to WN" \n'
336     txt += ' else \n'
337     txt += ' echo "input copied into WN" \n'
338     txt += ' fi \n'
339 spiga 1.49 txt += ' done \n'
340 spiga 1.43 ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
341 spiga 1.49 txt += ' for file in $cur_pu_list \n'
342     txt += ' do \n'
343 fanzago 1.68 #### FEDE
344     #txt += ' echo "which lcg-cp" \n'
345     #txt += ' which lcg-cp \n'
346     #########
347 fanzago 1.70 txt += ' lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
348 fanzago 1.72 txt += ' copy_input_pu_exit_status=$?\n'
349 fanzago 1.68 txt += ' echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
350     txt += ' if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
351     txt += ' echo "Problems with copying pu to WN" \n'
352     txt += ' else \n'
353     txt += ' echo "input pu files copied into WN" \n'
354     txt += ' fi \n'
355 spiga 1.49 txt += ' done \n'
356     txt += ' \n'
357     txt += ' ### Check SCRATCH space available on WN : \n'
358     txt += ' df -h \n'
359     txt += 'fi \n'
360    
361 fanzago 1.39 return txt
362    
363 fanzago 1.14 def wsCopyOutput(self):
364     """
365     Write a CopyResults part of a job script, e.g.
366     to copy produced output into a storage element.
367     """
368     txt = ''
369 fanzago 1.30 if int(self.copy_data) == 1:
370 fanzago 1.14 txt += '#\n'
371 fanzago 1.15 txt += '# Copy output to SE = $SE\n'
372 fanzago 1.14 txt += '#\n'
373 fanzago 1.66 #txt += 'if [ $exe_result -eq 0 ]; then\n'
374 gutsche 1.73 txt += ' if [ $middleware == OSG ]; then\n'
375     txt += ' echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
376     txt += ' echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
377     txt += ' source $OSG_APP/glite/setup_glite_ui.sh\n'
378     txt += ' export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
379     txt += ' echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
380     txt += ' fi \n'
381 corvo 1.34 txt += ' for out_file in $file_list ; do\n'
382 gutsche 1.73 txt += ' echo "Trying to copy output file to $SE using lcg-cp"\n'
383     txt += ' echo "lcg-cp --vo $VO -t 1200 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
384     txt += ' exitstring=`lcg-cp --vo $VO -t 1200 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
385     txt += ' copy_exit_status=$?\n'
386     txt += ' echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
387 corvo 1.34 txt += ' echo "STAGE_OUT = $copy_exit_status"\n'
388     txt += ' if [ $copy_exit_status -ne 0 ]; then\n'
389 gutsche 1.73 txt += ' echo "Possible problem with SE = $SE"\n'
390 corvo 1.34 txt += ' echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
391     txt += ' echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
392 gutsche 1.73 txt += ' echo "lcg-cp failed, attempting srmcp"\n'
393     txt += ' echo "mkdir -p $HOME/.srmconfig"\n'
394     txt += ' mkdir -p $HOME/.srmconfig\n'
395     txt += ' if [ $middleware == LCG ]; then\n'
396     txt += ' echo "srmcp -retry_num 5 -retry_timeout 240000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
397     txt += ' exitstring=`srmcp -retry_num 5 -retry_timeout 240000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
398     txt += ' elif [ $middleware == OSG ]; then\n'
399     txt += ' echo "srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
400     txt += ' exitstring=`srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
401     txt += ' fi \n'
402     txt += ' copy_exit_status=$?\n'
403     txt += ' echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
404     txt += ' echo "STAGE_OUT = $copy_exit_status"\n'
405     txt += ' if [ $copy_exit_status -ne 0 ]; then\n'
406     txt += ' echo "Problems with SE = $SE"\n'
407     txt += ' echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
408     txt += ' echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
409     txt += ' echo "lcg-cp and srm failed"\n'
410     txt += ' echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
411     txt += ' else\n'
412     txt += ' echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
413     txt += ' echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
414     txt += ' echo "output copied into $SE/$SE_PATH directory"\n'
415     txt += ' echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
416     txt += ' echo "srmcp succeeded"\n'
417     txt += ' fi\n'
418 corvo 1.34 txt += ' else\n'
419     txt += ' echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
420     txt += ' echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
421     txt += ' echo "output copied into $SE/$SE_PATH directory"\n'
422     txt += ' echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
423 gutsche 1.73 txt += ' echo "lcg-cp succeeded"\n'
424 corvo 1.34 txt += ' fi\n'
425     txt += ' done\n'
426 fanzago 1.66 #txt += 'fi\n'
427 fanzago 1.14 return txt
428    
429     def wsRegisterOutput(self):
430     """
431     Returns part of a job script which does scheduler-specific work.
432     """
433    
434     txt = ''
435 fanzago 1.30 if int(self.register_data) == 1:
436 spiga 1.49 ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
437     txt += 'if [ $middleware == OSG ]; then\n'
438     txt += ' #\n'
439     txt += ' # Register output to LFC deactivated in OSG mode\n'
440     txt += ' #\n'
441     txt += ' echo "Register output to LFC deactivated in OSG mode"\n'
442     txt += 'elif [ $middleware == LCG ]; then \n'
443 fanzago 1.14 txt += '#\n'
444 fanzago 1.36 txt += '# Register output to LFC\n'
445 fanzago 1.14 txt += '#\n'
446 fanzago 1.66 #txt += ' if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
447     txt += ' if [ $copy_exit_status -eq 0 ]; then\n'
448 spiga 1.49 txt += ' for out_file in $file_list ; do\n'
449     txt += ' echo "Trying to register the output file into LFC"\n'
450 fanzago 1.68 #### FEDE
451     #txt += ' echo "which lcg-rf" \n'
452     #txt += ' which lcg-rf \n'
453     #########
454 fanzago 1.71 txt += ' echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
455 fanzago 1.70 txt += ' lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
456 fanzago 1.14 txt += ' register_exit_status=$?\n'
457 fanzago 1.15 txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
458     txt += ' echo "STAGE_OUT = $register_exit_status"\n'
459 fanzago 1.14 txt += ' if [ $register_exit_status -ne 0 ]; then \n'
460 spiga 1.49 txt += ' echo "Problems with the registration to LFC" \n'
461     txt += ' echo "Try with srm protocol" \n'
462 fanzago 1.68 #### FEDE
463     #txt += ' echo "which lcg-rf" \n'
464     #txt += ' which lcg-rf \n'
465     #########
466 fanzago 1.71 txt += ' echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
467 fanzago 1.70 txt += ' lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
468 spiga 1.49 txt += ' register_exit_status=$?\n'
469     txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
470     txt += ' echo "STAGE_OUT = $register_exit_status"\n'
471     txt += ' if [ $register_exit_status -ne 0 ]; then \n'
472     txt += ' echo "Problems with the registration into LFC" \n'
473     txt += ' fi \n'
474     txt += ' else \n'
475     txt += ' echo "output registered to LFC"\n'
476 fanzago 1.14 txt += ' fi \n'
477 spiga 1.49 txt += ' echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
478     txt += ' done\n'
479 fanzago 1.66 #txt += ' elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
480     txt += ' else \n'
481 spiga 1.49 txt += ' echo "Trying to copy output file to CloseSE"\n'
482     txt += ' CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
483     txt += ' for out_file in $file_list ; do\n'
484 fanzago 1.68 #### FEDE
485     #txt += ' echo "which lcg-cr" \n'
486     #txt += ' which lcg-cr \n'
487     #########
488 fanzago 1.71 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'
489 fanzago 1.70 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'
490 spiga 1.49 txt += ' register_exit_status=$?\n'
491     txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
492     txt += ' echo "STAGE_OUT = $register_exit_status"\n'
493     txt += ' if [ $register_exit_status -ne 0 ]; then \n'
494 fanzago 1.66 txt += ' echo "Problems with CloseSE or Catalog" \n'
495 spiga 1.49 txt += ' else \n'
496     txt += ' echo "The program was successfully executed"\n'
497     txt += ' echo "SE = $CLOSE_SE"\n'
498     txt += ' echo "LFN for the file is LFN=${LFN}/$out_file"\n'
499     txt += ' fi \n'
500     txt += ' echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
501     txt += ' done\n'
502 fanzago 1.66 #txt += ' else\n'
503     #txt += ' echo "Problem with the executable"\n'
504 spiga 1.49 txt += ' fi \n'
505 fanzago 1.68 txt += ' exit_status=$register_exit_status\n'
506 fanzago 1.14 txt += 'fi \n'
507     return txt
508 nsmirnov 1.1
509 spiga 1.23 def loggingInfo(self, id):
510 slacapra 1.7 """
511     retrieve the logging info from logging and bookkeeping and return it
512     """
513 slacapra 1.18 self.checkProxy()
514 fanzago 1.24 cmd = 'edg-job-get-logging-info -v 2 ' + id
515 slacapra 1.32 #cmd_out = os.popen(cmd)
516     cmd_out = runCommand(cmd)
517 slacapra 1.7 return cmd_out
518    
519 slacapra 1.6 def listMatch(self, nj):
520     """
521     Check the compatibility of available resources
522     """
523 slacapra 1.18 self.checkProxy()
524 spiga 1.73.2.4 jdl = common.work_space.shareDir()+"fake.jdl"
525     cmd = 'edg-job-list-match ' + self.configOpt_() + str(jdl)
526 slacapra 1.32 cmd_out = runCommand(cmd,0,10)
527 slacapra 1.44 if not cmd_out:
528     raise CrabException("ERROR: "+cmd+" failed!")
529    
530 slacapra 1.6 return self.parseListMatch_(cmd_out, jdl)
531    
532     def parseListMatch_(self, out, jdl):
533 slacapra 1.31 """
534     Parse the f* output of edg-list-match and produce something sensible
535     """
536 slacapra 1.6 reComment = re.compile( r'^\**$' )
537     reEmptyLine = re.compile( r'^$' )
538     reVO = re.compile( r'Selected Virtual Organisation name.*' )
539 slacapra 1.31 reLine = re.compile( r'.*')
540     reCE = re.compile( r'(.*:.*)')
541     reCEId = re.compile( r'CEId.*')
542 slacapra 1.6 reNO = re.compile( r'No Computing Element matching' )
543     reRB = re.compile( r'Connecting to host' )
544     next = 0
545     CEs=[]
546     Match=0
547 slacapra 1.22
548 slacapra 1.31 #print out
549     lines = reLine.findall(out)
550    
551     i=0
552     CEs=[]
553     for line in lines:
554     string.strip(line)
555     #print line
556     if reNO.match( line ):
557     common.logger.debug(5,line)
558     return 0
559     pass
560 fanzago 1.28 if reVO.match( line ):
561 slacapra 1.31 VO =reVO.match( line ).group()
562     common.logger.debug(5,"VO "+VO)
563 fanzago 1.28 pass
564 slacapra 1.31
565 fanzago 1.28 if reRB.match( line ):
566 slacapra 1.31 RB = reRB.match(line).group()
567     common.logger.debug(5,"RB "+RB)
568 fanzago 1.28 pass
569 slacapra 1.31
570     if reCEId.search( line ):
571     for lineCE in lines[i:-1]:
572     if reCE.match( lineCE ):
573     CE = string.strip(reCE.search(lineCE).group(1))
574     CEs.append(CE.split(':')[0])
575     pass
576     pass
577 fanzago 1.28 pass
578 slacapra 1.31 i=i+1
579     pass
580    
581     common.logger.debug(5,"All CE :"+str(CEs))
582    
583     sites = []
584     [sites.append(it) for it in CEs if not sites.count(it)]
585    
586     common.logger.debug(5,"All Sites :"+str(sites))
587 gutsche 1.56 common.logger.message("Matched Sites :"+str(sites))
588 slacapra 1.31 return len(sites)
589 slacapra 1.6
590     def noMatchFound_(self, jdl):
591     reReq = re.compile( r'Requirements' )
592     reString = re.compile( r'"\S*"' )
593     f = file(jdl,'r')
594     for line in f.readlines():
595     line= line.strip()
596     if reReq.match(line):
597     for req in reString.findall(line):
598     if re.search("VO",req):
599     common.logger.message( "SW required: "+req)
600     continue
601     if re.search('"\d+',req):
602     common.logger.message("Other req : "+req)
603     continue
604     common.logger.message( "CE required: "+req)
605     break
606     pass
607     raise CrabException("No compatible resources found!")
608    
609 nsmirnov 1.1 def submit(self, nj):
610 nsmirnov 1.3 """
611     Submit one EDG job.
612     """
613 nsmirnov 1.1
614 slacapra 1.18 self.checkProxy()
615 nsmirnov 1.1 jid = None
616     jdl = common.job_list[nj].jdlFilename()
617 slacapra 1.18
618     cmd = 'edg-job-submit ' + self.configOpt_() + jdl
619 nsmirnov 1.1 cmd_out = runCommand(cmd)
620     if cmd_out != None:
621 slacapra 1.18 reSid = re.compile( r'https.+' )
622 slacapra 1.20 jid = reSid.search(cmd_out).group()
623 nsmirnov 1.3 pass
624 nsmirnov 1.1 return jid
625    
626 fanzago 1.33 def resubmit(self, nj_list):
627     """
628     Prepare jobs to be submit
629     """
630     return
631    
632 slacapra 1.8 def getExitStatus(self, id):
633     return self.getStatusAttribute_(id, 'exit_code')
634 fanzago 1.10
635 nsmirnov 1.1 def queryStatus(self, id):
636 slacapra 1.8 return self.getStatusAttribute_(id, 'status')
637 fanzago 1.10
638 spiga 1.9 def queryDest(self, id):
639     return self.getStatusAttribute_(id, 'destination')
640    
641 slacapra 1.8
642     def getStatusAttribute_(self, id, attr):
643 nsmirnov 1.1 """ Query a status of the job with id """
644 slacapra 1.8
645 slacapra 1.18 self.checkProxy()
646 slacapra 1.8 hstates = {}
647 fanzago 1.12 Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
648 slacapra 1.8 # Bypass edg-job-status interfacing directly to C++ API
649     # Job attribute vector to retrieve status without edg-job-status
650     level = 0
651     # Instance of the Status class provided by LB API
652     jobStat = Status()
653     st = 0
654     jobStat.getStatus(id, level)
655     err, apiMsg = jobStat.get_error()
656     if err:
657 fanzago 1.26 common.logger.debug(5,'Error caught' + apiMsg)
658 nsmirnov 1.1 return None
659 slacapra 1.8 else:
660     for i in range(len(self.states)):
661     # Fill an hash table with all information retrieved from LB API
662     hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
663     result = jobStat.loadStatus(st)[ self.states.index(attr) ]
664     return result
665 nsmirnov 1.1
666     def queryDetailedStatus(self, id):
667     """ Query a detailed status of the job with id """
668     cmd = 'edg-job-status '+id
669     cmd_out = runCommand(cmd)
670     return cmd_out
671    
672     def getOutput(self, id):
673 nsmirnov 1.5 """
674     Get output for a finished job with id.
675     Returns the name of directory with results.
676     """
677 slacapra 1.6
678 slacapra 1.18 self.checkProxy()
679 slacapra 1.6 cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
680 nsmirnov 1.1 cmd_out = runCommand(cmd)
681 nsmirnov 1.5
682     # Determine the output directory name
683     dir = common.work_space.resDir()
684 corvo 1.55 dir += os.environ['USER']
685 nsmirnov 1.5 dir += '_' + os.path.basename(id)
686     return dir
687 nsmirnov 1.1
688     def cancel(self, id):
689     """ Cancel the EDG job with id """
690 slacapra 1.18 self.checkProxy()
691 nsmirnov 1.1 cmd = 'edg-job-cancel --noint ' + id
692     cmd_out = runCommand(cmd)
693     return cmd_out
694 spiga 1.73.2.4
695     def createFakeJdl(self,nj): # TMP Just waiting listmatch functionalitly
696     # implementation into BOSS4 Daniele
697     """
698     Create a fake jdl considering
699     only requirements
700     """
701     job = common.job_list[nj]
702     jbt = job.type()
703     inp_storage_subdir = ''
704    
705    
706     SPL = inp_storage_subdir
707     if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
708 nsmirnov 1.1
709 spiga 1.73.2.4 jdl = open(common.work_space.shareDir()+"fake.jdl","w")
710    
711     script = job.scriptFilename()
712     jdl.write('Executable = "' + os.path.basename(script) +'";\n')
713    
714     req='Requirements = '
715     noreq=req
716     req = req + jbt.getRequirements()
717     #### and USER REQUIREMENT
718     if self.EDG_requirements:
719     if (req != noreq):
720     req = req + ' && '
721     req = req + self.EDG_requirements
722     #### FEDE #####
723     if self.EDG_ce_white_list:
724     ce_white_list = string.split(self.EDG_ce_white_list,',')
725     #print "req = ", req
726     for i in range(len(ce_white_list)):
727     if i == 0:
728     if (req != noreq):
729     req = req + ' && '
730     req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
731     pass
732     else:
733     req = req + ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
734     req = req + ')'
735    
736     if self.EDG_ce_black_list:
737     ce_black_list = string.split(self.EDG_ce_black_list,',')
738     for ce in ce_black_list:
739     if (req != noreq):
740     req = req + ' && '
741     req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
742     pass
743    
744     ###############
745     clockTime=480
746     if self.EDG_clock_time:
747     clockTime= self.EDG_clock_time
748     if (req != noreq):
749     req = req + ' && '
750     req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
751    
752     cpuTime=1000
753     if self.EDG_cpu_time:
754     cpuTime=self.EDG_cpu_time
755     if (req != noreq):
756     req = req + ' && '
757     req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+str(cpuTime)+'))'
758    
759     if (req != noreq):
760     req = req + ';\n'
761     jdl.write(req)
762    
763     jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
764    
765     if ( self.EDG_retry_count ):
766     jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
767     pass
768    
769     jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
770    
771     jdl.close()
772     return
773    
774 spiga 1.73.2.3
775     def createXMLSchScript(self, nj):
776 nsmirnov 1.1 """
777 spiga 1.73.2.3 Create a XML-file for BOSS4.
778 nsmirnov 1.1 """
779     job = common.job_list[nj]
780     jbt = job.type()
781 spiga 1.73.2.4
782 nsmirnov 1.1 inp_sandbox = jbt.inputSandbox(nj)
783     out_sandbox = jbt.outputSandbox(nj)
784 spiga 1.73.2.4
785 spiga 1.73.2.3 title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
786 nsmirnov 1.1 jt_string = ''
787 spiga 1.73.2.3
788 spiga 1.73.2.4 xml_fname = str(self.jobtypeName)+'.xml'
789 spiga 1.73.2.3 xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
790 fanzago 1.14
791 spiga 1.73.2.3 #TaskName
792     dir = string.split(common.work_space.topDir(), '/')
793     taskName = dir[len(dir)-2]
794    
795     to_writeReq = ''
796     to_write = ''
797     req=' '
798     req = req + jbt.getRequirements()
799     if self.EDG_requirements:
800     if (req == ' '):
801     req = req + self.EDG_requirements
802     else:
803     req = req + ' && ' + self.EDG_requirements
804     if self.EDG_ce_white_list:
805     ce_white_list = string.split(self.EDG_ce_white_list,',')
806     for i in range(len(ce_white_list)):
807     if i == 0:
808     if (req == ' '):
809     req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
810     else:
811     req = req + ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
812     pass
813     else:
814     req = req + ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
815     req = req + ')'
816 nsmirnov 1.1
817 spiga 1.73.2.3 if self.EDG_ce_black_list:
818     ce_black_list = string.split(self.EDG_ce_black_list,',')
819     for ce in ce_black_list:
820     if (req == ' '):
821     req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
822     else:
823     req = req + ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
824     pass
825     if self.EDG_clock_time:
826     if (req == ' '):
827     req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
828     else:
829     req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
830    
831     if self.EDG_cpu_time:
832     if (req == ' '):
833     req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
834     else:
835     req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
836     if (req != ' '):
837     req = req + '\n'
838     to_writeReq = req
839    
840    
841     if ( self.EDG_retry_count ):
842     to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
843     pass
844 nsmirnov 1.1
845 spiga 1.73.2.3 to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
846     to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
847 nsmirnov 1.1
848    
849 spiga 1.73.2.3 #TaskName
850     dir = string.split(common.work_space.topDir(), '/')
851     taskName = dir[len(dir)-2]
852    
853     if nj == 0:
854     xml.write(str(title))
855     xml.write('<task name="' +str(taskName)+'">\n')
856     xml.write(jt_string)
857     #Here it must pass the extra Tags.. (into Task & out of chain)
858     if (to_writeReq != ''):
859     xml.write('<extraTags>\n')
860     xml.write('<Requirements>\n')
861     xml.write('<![CDATA[\n')
862     xml.write(to_writeReq)
863     xml.write(']]>\n')
864     xml.write('</Requirements>\n')
865     xml.write('</extraTags>\n')
866     pass
867 slacapra 1.8
868 spiga 1.73.2.3 if (to_write != ''):
869     xml.write('<extraTags\n')
870     xml.write(to_write)
871     xml.write('/>\n')
872     pass
873     pass
874    
875 spiga 1.73.2.4 xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
876 spiga 1.73.2.3 xml.write(jt_string)
877    
878     #executable
879     script = job.scriptFilename()
880     xml.write('<program exec="' + os.path.basename(script) +'"\n')
881     xml.write(jt_string)
882    
883    
884     ### only one .sh JDL has arguments:
885 gutsche 1.56 ### Fabio
886 spiga 1.73.2.3 xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
887     xml.write('program_types="crabjob"\n')
888     inp_box = 'infiles="'
889     inp_box = inp_box + '' + script + ','
890 nsmirnov 1.1
891     if inp_sandbox != None:
892     for fl in inp_sandbox:
893 spiga 1.73.2.3 inp_box = inp_box + '' + fl + ','
894 nsmirnov 1.1 pass
895     pass
896    
897 corvo 1.34 # Marco (VERY TEMPORARY ML STUFF)
898 spiga 1.73.2.3 inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
899     os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
900     os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
901     os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
902     os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
903 corvo 1.34 # End Marco
904 nsmirnov 1.1
905 fanzago 1.40 if (not jbt.additional_inbox_files == []):
906     inp_box = inp_box + ', '
907     for addFile in jbt.additional_inbox_files:
908     addFile = os.path.abspath(addFile)
909 spiga 1.73.2.3 inp_box = inp_box+''+addFile+','
910 fanzago 1.40 pass
911 nsmirnov 1.1
912     if inp_box[-1] == ',' : inp_box = inp_box[:-1]
913 spiga 1.73.2.3 inp_box = inp_box + ' "\n'
914     xml.write(inp_box)
915 nsmirnov 1.1
916 fanzago 1.73.2.5 xml.write('stderr="' + job.stderr() + '"\n')
917     xml.write('stdout="' + job.stdout() + '"\n')
918 fanzago 1.14
919    
920     if job.stdout() == job.stderr():
921 spiga 1.73.2.3 out_box = 'outfiles="' + \
922     job.stdout() + ',.BrokerInfo,'
923 fanzago 1.14 else:
924 spiga 1.73.2.3 out_box = 'outfiles="' + \
925     job.stdout() + ',' + \
926     job.stderr() + ',.BrokerInfo,'
927 fanzago 1.14
928 fanzago 1.30 if int(self.return_data) == 1:
929 fanzago 1.14 if out_sandbox != None:
930     for fl in out_sandbox:
931 spiga 1.73.2.3 out_box = out_box + '' + fl + ','
932 fanzago 1.14 pass
933 nsmirnov 1.1 pass
934     pass
935 fanzago 1.14
936 nsmirnov 1.1 if out_box[-1] == ',' : out_box = out_box[:-1]
937 spiga 1.73.2.3 out_box = out_box + '"'
938     xml.write(out_box+'\n')
939    
940     xml.write('group="'+taskName+'"\n')
941     xml.write('BossAttr="[crabjob.INTERNAL_ID=' + str(nj+1) +']"\n')
942 nsmirnov 1.1
943 fanzago 1.48
944 spiga 1.73.2.3
945     xml.write('/>\n')
946     xml.write('</chain>\n')
947 fanzago 1.48
948 spiga 1.73.2.3 if int(nj) == int(common.jobDB.nJobs()-1): xml.write('</task>\n')
949 nsmirnov 1.1
950    
951 spiga 1.73.2.3 xml.close()
952 slacapra 1.51
953 nsmirnov 1.1 return
954 slacapra 1.18
955 spiga 1.73.2.3
956    
957 slacapra 1.18 def checkProxy(self):
958     """
959     Function to check the Globus proxy.
960     """
961     if (self.proxyValid): return
962     timeleft = -999
963 slacapra 1.50 minTimeLeft=10*3600 # in seconds
964 slacapra 1.51
965     minTimeLeftServer = 100 # in hours
966    
967 slacapra 1.50 #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
968     #cmd = 'voms-proxy-info -timeleft'
969     mustRenew = 0
970 fanzago 1.69 timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
971 slacapra 1.50 timeLeftServer = -999
972 fanzago 1.53 if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
973 slacapra 1.50 mustRenew = 1
974     else:
975 fanzago 1.69 timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
976 slacapra 1.50 if not timeLeftServer or not isInt(timeLeftServer):
977     mustRenew = 1
978 slacapra 1.54 elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
979 slacapra 1.50 mustRenew = 1
980     pass
981     pass
982    
983 slacapra 1.51 if mustRenew:
984 gutsche 1.58 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")
985     cmd = 'voms-proxy-init -voms cms -valid 96:00'
986 slacapra 1.18 try:
987 slacapra 1.32 # SL as above: damn it!
988 slacapra 1.19 out = os.system(cmd)
989     if (out>0): raise CrabException("Unable to create a valid proxy!\n")
990 slacapra 1.18 except:
991     msg = "Unable to create a valid proxy!\n"
992     raise CrabException(msg)
993 slacapra 1.51 # cmd = 'grid-proxy-info -timeleft'
994     # cmd_out = runCommand(cmd,0,20)
995 slacapra 1.18 pass
996 slacapra 1.51
997     ## now I do have a voms proxy valid, and I check the myproxy server
998     renewProxy = 0
999     cmd = 'myproxy-info -d -s '+self.proxyServer
1000     cmd_out = runCommand(cmd,0,20)
1001     if not cmd_out:
1002     common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
1003     renewProxy = 1
1004     else:
1005     # if myproxy exist but not long enough, renew
1006     reTime = re.compile( r'timeleft: (\d+)' )
1007     #print "<"+str(reTime.search( cmd_out ).group(1))+">"
1008     if reTime.match( cmd_out ):
1009     time = reTime.search( line ).group(1)
1010     if time < minTimeLeftServer:
1011     renewProxy = 1
1012     common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
1013     pass
1014     pass
1015    
1016     # if not, create one.
1017     if renewProxy:
1018     cmd = 'myproxy-init -d -n -s '+self.proxyServer
1019     out = os.system(cmd)
1020     if (out>0):
1021 fanzago 1.53 raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
1022 slacapra 1.51 pass
1023    
1024     # cache proxy validity
1025 slacapra 1.18 self.proxyValid=1
1026     return
1027 spiga 1.49
1028 slacapra 1.18 def configOpt_(self):
1029     edg_ui_cfg_opt = ' '
1030     if self.edg_config:
1031 slacapra 1.51 edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
1032 slacapra 1.18 if self.edg_config_vo:
1033 slacapra 1.51 edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
1034 slacapra 1.18 return edg_ui_cfg_opt