ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerEdg.py
Revision: 1.50
Committed: Thu Apr 13 15:59:08 2006 UTC (19 years ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.49: +19 -7 lines
Log Message:
include EdgConfig and update checkProxy to voms

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     def __init__(self):
12     Scheduler.__init__(self,"EDG")
13 slacapra 1.8 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 nsmirnov 1.1 return
22    
23     def configure(self, cfg_params):
24 spiga 1.49
25 slacapra 1.46 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 nsmirnov 1.1
34 spiga 1.49
35 nsmirnov 1.1 try: self.LCG_version = cfg_params["EDG.lcg_version"]
36     except KeyError: self.LCG_version = '2'
37    
38     try: self.EDG_requirements = cfg_params['EDG.requirements']
39     except KeyError: self.EDG_requirements = ''
40    
41 spiga 1.49 try: self.EDG_retry_count = cfg_params['EDG.retry_count']
42 nsmirnov 1.1 except KeyError: self.EDG_retry_count = ''
43    
44 fanzago 1.48 try:
45     self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
46     #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
47     except KeyError:
48     self.EDG_ce_black_list = ''
49    
50     try:
51     self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
52     #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
53     except KeyError: self.EDG_ce_white_list = ''
54    
55 fanzago 1.14 try: self.VO = cfg_params['EDG.virtual_organization']
56     except KeyError: self.VO = 'cms'
57    
58 spiga 1.49 try: self.return_data = cfg_params['USER.return_data']
59     except KeyError: self.return_data = 1
60    
61 fanzago 1.39 try:
62     self.copy_input_data = common.analisys_common_info['copy_input_data']
63 fanzago 1.41 #print "self.copy_input_data = ", self.copy_input_data
64 fanzago 1.39 except KeyError: self.copy_input_data = 0
65    
66 fanzago 1.14 try:
67     self.copy_data = cfg_params["USER.copy_data"]
68 fanzago 1.30 if int(self.copy_data) == 1:
69     try:
70     self.SE = cfg_params['USER.storage_element']
71     self.SE_PATH = cfg_params['USER.storage_path']
72     except KeyError:
73     msg = "Error. The [USER] section does not have 'storage_element'"
74     msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
75     common.logger.message(msg)
76     raise CrabException(msg)
77     except KeyError: self.copy_data = 0
78    
79     if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
80     msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
81     msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
82     raise CrabException(msg)
83 fanzago 1.38
84     try:
85     self.lfc_host = cfg_params['EDG.lfc_host']
86     except KeyError:
87     msg = "Error. The [EDG] section does not have 'lfc_host' value"
88     msg = msg + " it's necessary to know the LFC host name"
89     common.logger.message(msg)
90     raise CrabException(msg)
91     try:
92     self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
93     except KeyError:
94     msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
95     msg = msg + " it's necessary to know the catalog type"
96     common.logger.message(msg)
97     raise CrabException(msg)
98     try:
99     self.lfc_home = cfg_params['EDG.lfc_home']
100     except KeyError:
101     msg = "Error. The [EDG] section does not have 'lfc_home' value"
102     msg = msg + " it's necessary to know the home catalog dir"
103     common.logger.message(msg)
104     raise CrabException(msg)
105 fanzago 1.30
106 fanzago 1.14 try:
107     self.register_data = cfg_params["USER.register_data"]
108 fanzago 1.30 if int(self.register_data) == 1:
109     try:
110     self.LFN = cfg_params['USER.lfn_dir']
111     except KeyError:
112     msg = "Error. The [USER] section does not have 'lfn_dir' value"
113 fanzago 1.36 msg = msg + " it's necessary for LCF registration"
114 fanzago 1.30 common.logger.message(msg)
115     raise CrabException(msg)
116     except KeyError: self.register_data = 0
117    
118     if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
119     msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
120     msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
121     common.logger.message(msg)
122     raise CrabException(msg)
123 fanzago 1.14
124     try: self.EDG_requirements = cfg_params['EDG.requirements']
125     except KeyError: self.EDG_requirements = ''
126    
127     try: self.EDG_retry_count = cfg_params['EDG.retry_count']
128     except KeyError: self.EDG_retry_count = ''
129    
130     try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
131     except KeyError: self.EDG_clock_time= ''
132    
133     try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
134     except KeyError: self.EDG_cpu_time = ''
135    
136 fanzago 1.16 # Add EDG_WL_LOCATION to the python path
137    
138     try:
139     path = os.environ['EDG_WL_LOCATION']
140     except:
141     msg = "Error: the EDG_WL_LOCATION variable is not set."
142     raise CrabException(msg)
143    
144     libPath=os.path.join(path, "lib")
145     sys.path.append(libPath)
146     libPath=os.path.join(path, "lib", "python")
147     sys.path.append(libPath)
148 nsmirnov 1.1
149 slacapra 1.18 self.proxyValid=0
150 nsmirnov 1.1 return
151    
152 fanzago 1.10
153     def sched_parameter(self):
154     """
155     Returns file with scheduler-specific parameters
156     """
157    
158     if (self.edg_config and self.edg_config_vo != ''):
159     self.param='sched_param.clad'
160     param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
161     param_file.write('RBconfig = "'+self.edg_config+'";\n')
162     param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
163     param_file.close()
164     return 1
165     else:
166     return 0
167 fanzago 1.13
168 nsmirnov 1.2 def wsSetupEnvironment(self):
169     """
170     Returns part of a job script which does scheduler-specific work.
171     """
172 spiga 1.49 txt = ''
173     txt += 'echo "middleware discovery " \n'
174     txt += 'if [ $VO_CMS_SW_DIR ]; then\n'
175     txt += ' middleware=LCG \n'
176     txt += ' echo "middleware =$middleware" \n'
177     txt += 'elif [ $GRID3_APP_DIR ]; then\n'
178     txt += ' middleware=OSG \n'
179     txt += ' echo "middleware =$middleware" \n'
180     txt += 'elif [ $OSG_APP ]; then \n'
181     txt += ' middleware=OSG \n'
182     txt += ' echo "middleware =$middleware" \n'
183     txt += 'else \n'
184     txt += ' echo "SET_CMS_ENV 1 ==> middleware not identified" \n'
185     txt += ' echo "JOB_EXIT_STATUS = 1"\n'
186     txt += ' exit 1\n'
187     txt += 'fi\n'
188    
189     txt += '\n\n'
190    
191     txt += 'if [ $middleware == LCG ]; then \n'
192     txt += ' echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
193     txt += 'fi\n'
194 fanzago 1.14
195 fanzago 1.30 if int(self.copy_data) == 1:
196 fanzago 1.14 if self.SE:
197     txt += 'export SE='+self.SE+'\n'
198 fanzago 1.15 txt += 'echo "SE = $SE"\n'
199 fanzago 1.14 if self.SE_PATH:
200     if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
201     txt += 'export SE_PATH='+self.SE_PATH+'\n'
202 fanzago 1.15 txt += 'echo "SE_PATH = $SE_PATH"\n'
203 spiga 1.49
204 fanzago 1.38 txt += 'export VO='+self.VO+'\n'
205     ### FEDE: add some line for LFC catalog setting
206 spiga 1.49 txt += 'if [ $middleware == LCG ]; then \n'
207     txt += ' if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
208     txt += ' export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
209     txt += ' fi\n'
210     txt += ' if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
211     txt += ' export LFC_HOST='+self.lfc_host+'\n'
212     txt += ' fi\n'
213     txt += ' if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
214     txt += ' export LFC_HOME='+self.lfc_home+'\n'
215     txt += ' fi\n'
216     txt += 'elif [ $middleware == OSG ]; then\n'
217     txt += ' echo "LFC catalog setting to be implemented for OSG"\n'
218 fanzago 1.38 txt += 'fi\n'
219     #####
220 fanzago 1.30 if int(self.register_data) == 1:
221 spiga 1.49 txt += 'if [ $middleware == LCG ]; then \n'
222     txt += ' export LFN='+self.LFN+'\n'
223     txt += ' lfc-ls $LFN\n'
224     txt += ' result=$?\n'
225     txt += ' echo $result\n'
226 fanzago 1.36 ### creation of LFN dir in LFC catalog, under /grid/cms dir
227 spiga 1.49 txt += ' if [ $result != 0 ]; then\n'
228     txt += ' lfc-mkdir $LFN\n'
229     txt += ' result=$?\n'
230     txt += ' echo $result\n'
231     txt += ' fi\n'
232     txt += 'elif [ $middleware == OSG ]; then\n'
233     txt += ' echo " Files registration to be implemented for OSG"\n'
234 fanzago 1.36 txt += 'fi\n'
235     txt += '\n'
236 spiga 1.49
237     if self.VO:
238     txt += 'export VO='+self.VO+'\n'
239     if self.LFN:
240     txt += 'if [ $middleware == LCG ]; then \n'
241     txt += ' export LFN='+self.LFN+'\n'
242     txt += 'fi\n'
243     txt += '\n'
244    
245     txt += 'if [ $middleware == LCG ]; then\n'
246     txt += ' CloseCEs=`edg-brokerinfo getCE`\n'
247     txt += ' echo "CloseCEs = $CloseCEs"\n'
248     txt += ' CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
249     txt += ' echo "CE = $CE"\n'
250     txt += 'elif [ $middleware == OSG ]; then \n'
251     txt += ' if [ $OSG_JOB_CONTACT ]; then \n'
252     txt += ' CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
253     txt += ' else \n'
254     txt += ' echo "SET_ENV 1 ==> ERROR in setting CE name - OSG mode -" \n'
255     txt += ' exit 1 \n'
256     txt += ' fi \n'
257     txt += 'fi \n'
258    
259 nsmirnov 1.2 return txt
260 fanzago 1.15
261 fanzago 1.39 def wsCopyInput(self):
262     """
263     Copy input data from SE to WN
264     """
265     txt = ''
266     try:
267     self.copy_input_data = common.analisys_common_info['copy_input_data']
268     #print "self.copy_input_data = ", self.copy_input_data
269     except KeyError: self.copy_input_data = 0
270     if int(self.copy_input_data) == 1:
271 spiga 1.49 ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
272     txt += 'if [ $middleware == OSG ]; then\n'
273     txt += ' #\n'
274     txt += ' # Copy Input Data from SE to this WN deactivated in OSG mode\n'
275     txt += ' #\n'
276     txt += ' echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
277     txt += 'elif [ $middleware == LCG ]; then \n'
278     txt += ' #\n'
279     txt += ' # Copy Input Data from SE to this WN\n'
280     txt += ' #\n'
281 spiga 1.42 ### changed by georgia (put a loop copying more than one input files per jobs)
282 spiga 1.49 txt += ' for input_file in $cur_file_list \n'
283     txt += ' do \n'
284     txt += ' lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
285     txt += ' copy_input_exit_status=$?\n'
286     txt += ' echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
287     txt += ' if [ $copy_input_exit_status -ne 0 ]; then \n'
288     txt += ' echo "Problems with copying to WN" \n'
289     txt += ' else \n'
290     txt += ' echo "input copied into WN" \n'
291     txt += ' fi \n'
292     txt += ' done \n'
293 spiga 1.43 ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
294 spiga 1.49 txt += ' for file in $cur_pu_list \n'
295     txt += ' do \n'
296     txt += ' lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
297     txt += ' copy_input_exit_status=$?\n'
298     txt += ' echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
299     txt += ' if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
300     txt += ' echo "Problems with copying pu to WN" \n'
301     txt += ' else \n'
302     txt += ' echo "input pu files copied into WN" \n'
303     txt += ' fi \n'
304     txt += ' done \n'
305     txt += ' \n'
306     txt += ' ### Check SCRATCH space available on WN : \n'
307     txt += ' df -h \n'
308     txt += 'fi \n'
309    
310 fanzago 1.39 return txt
311    
312 fanzago 1.14 def wsCopyOutput(self):
313     """
314     Write a CopyResults part of a job script, e.g.
315     to copy produced output into a storage element.
316     """
317     txt = ''
318 fanzago 1.30 if int(self.copy_data) == 1:
319 fanzago 1.14 txt += '#\n'
320 fanzago 1.15 txt += '# Copy output to SE = $SE\n'
321 fanzago 1.14 txt += '#\n'
322 fanzago 1.17 txt += 'if [ $exe_result -eq 0 ]; then\n'
323 corvo 1.34 txt += ' for out_file in $file_list ; do\n'
324     txt += ' echo "Trying to copy output file to $SE "\n'
325 spiga 1.49 ## OLI_Daniele globus-* for OSG, lcg-* for LCG
326     txt += ' if [ $middleware == OSG ]; then\n'
327     txt += ' echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
328     txt += ' copy_exit_status=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
329     #txt += ' exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
330     txt += ' elif [ $middleware == LCG ]; then \n'
331     txt += ' echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
332     txt += ' copy_exit_status=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
333     #txt += ' exitstring=`lcg-cp --vo cms -t 30 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
334     txt += ' fi \n'
335     #txt += ' copy_exit_status=$?\n'
336 corvo 1.34 txt += ' echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
337     txt += ' echo "STAGE_OUT = $copy_exit_status"\n'
338     txt += ' if [ $copy_exit_status -ne 0 ]; then\n'
339     txt += ' echo "Problems with SE = $SE"\n'
340     txt += ' echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
341     txt += ' echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
342     txt += ' else\n'
343     txt += ' echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
344     txt += ' echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
345     txt += ' echo "output copied into $SE/$SE_PATH directory"\n'
346     txt += ' echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
347     txt += ' fi\n'
348     txt += ' done\n'
349     txt += 'fi\n'
350 fanzago 1.14 return txt
351    
352     def wsRegisterOutput(self):
353     """
354     Returns part of a job script which does scheduler-specific work.
355     """
356    
357     txt = ''
358 fanzago 1.30 if int(self.register_data) == 1:
359 spiga 1.49 ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
360     txt += 'if [ $middleware == OSG ]; then\n'
361     txt += ' #\n'
362     txt += ' # Register output to LFC deactivated in OSG mode\n'
363     txt += ' #\n'
364     txt += ' echo "Register output to LFC deactivated in OSG mode"\n'
365     txt += 'elif [ $middleware == LCG ]; then \n'
366 fanzago 1.14 txt += '#\n'
367 fanzago 1.36 txt += '# Register output to LFC\n'
368 fanzago 1.14 txt += '#\n'
369 spiga 1.49 txt += ' if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
370     txt += ' for out_file in $file_list ; do\n'
371     txt += ' echo "Trying to register the output file into LFC"\n'
372     txt += ' echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
373     txt += ' lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
374 fanzago 1.14 txt += ' register_exit_status=$?\n'
375 fanzago 1.15 txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
376     txt += ' echo "STAGE_OUT = $register_exit_status"\n'
377 fanzago 1.14 txt += ' if [ $register_exit_status -ne 0 ]; then \n'
378 spiga 1.49 txt += ' echo "Problems with the registration to LFC" \n'
379     txt += ' echo "Try with srm protocol" \n'
380     txt += ' echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
381     txt += ' lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
382     txt += ' register_exit_status=$?\n'
383     txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
384     txt += ' echo "STAGE_OUT = $register_exit_status"\n'
385     txt += ' if [ $register_exit_status -ne 0 ]; then \n'
386     txt += ' echo "Problems with the registration into LFC" \n'
387     txt += ' fi \n'
388     txt += ' else \n'
389     txt += ' echo "output registered to LFC"\n'
390 fanzago 1.14 txt += ' fi \n'
391 spiga 1.49 txt += ' echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
392     txt += ' done\n'
393     txt += ' elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
394     txt += ' echo "Trying to copy output file to CloseSE"\n'
395     txt += ' CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
396     txt += ' for out_file in $file_list ; do\n'
397     txt += ' echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
398     txt += ' lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
399     txt += ' register_exit_status=$?\n'
400     txt += ' echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
401     txt += ' echo "STAGE_OUT = $register_exit_status"\n'
402     txt += ' if [ $register_exit_status -ne 0 ]; then \n'
403     txt += ' echo "Problems with CloseSE" \n'
404     txt += ' else \n'
405     txt += ' echo "The program was successfully executed"\n'
406     txt += ' echo "SE = $CLOSE_SE"\n'
407     txt += ' echo "LFN for the file is LFN=${LFN}/$out_file"\n'
408     txt += ' fi \n'
409     txt += ' echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
410     txt += ' done\n'
411     txt += ' else\n'
412     txt += ' echo "Problem with the executable"\n'
413     txt += ' fi \n'
414 fanzago 1.14 txt += 'fi \n'
415     return txt
416 nsmirnov 1.1
417 spiga 1.23 def loggingInfo(self, id):
418 slacapra 1.7 """
419     retrieve the logging info from logging and bookkeeping and return it
420     """
421 slacapra 1.18 self.checkProxy()
422 fanzago 1.24 cmd = 'edg-job-get-logging-info -v 2 ' + id
423 slacapra 1.32 #cmd_out = os.popen(cmd)
424     cmd_out = runCommand(cmd)
425 slacapra 1.7 return cmd_out
426    
427 slacapra 1.6 def listMatch(self, nj):
428     """
429     Check the compatibility of available resources
430     """
431 slacapra 1.18 self.checkProxy()
432 slacapra 1.6 jdl = common.job_list[nj].jdlFilename()
433 slacapra 1.18 cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
434 slacapra 1.32 cmd_out = runCommand(cmd,0,10)
435 slacapra 1.44 if not cmd_out:
436     raise CrabException("ERROR: "+cmd+" failed!")
437    
438 slacapra 1.6 return self.parseListMatch_(cmd_out, jdl)
439    
440     def parseListMatch_(self, out, jdl):
441 slacapra 1.31 """
442     Parse the f* output of edg-list-match and produce something sensible
443     """
444 slacapra 1.6 reComment = re.compile( r'^\**$' )
445     reEmptyLine = re.compile( r'^$' )
446     reVO = re.compile( r'Selected Virtual Organisation name.*' )
447 slacapra 1.31 reLine = re.compile( r'.*')
448     reCE = re.compile( r'(.*:.*)')
449     reCEId = re.compile( r'CEId.*')
450 slacapra 1.6 reNO = re.compile( r'No Computing Element matching' )
451     reRB = re.compile( r'Connecting to host' )
452     next = 0
453     CEs=[]
454     Match=0
455 slacapra 1.22
456 slacapra 1.31 #print out
457     lines = reLine.findall(out)
458    
459     i=0
460     CEs=[]
461     for line in lines:
462     string.strip(line)
463     #print line
464     if reNO.match( line ):
465     common.logger.debug(5,line)
466     return 0
467     pass
468 fanzago 1.28 if reVO.match( line ):
469 slacapra 1.31 VO =reVO.match( line ).group()
470     common.logger.debug(5,"VO "+VO)
471 fanzago 1.28 pass
472 slacapra 1.31
473 fanzago 1.28 if reRB.match( line ):
474 slacapra 1.31 RB = reRB.match(line).group()
475     common.logger.debug(5,"RB "+RB)
476 fanzago 1.28 pass
477 slacapra 1.31
478     if reCEId.search( line ):
479     for lineCE in lines[i:-1]:
480     if reCE.match( lineCE ):
481     CE = string.strip(reCE.search(lineCE).group(1))
482     CEs.append(CE.split(':')[0])
483     pass
484     pass
485 fanzago 1.28 pass
486 slacapra 1.31 i=i+1
487     pass
488    
489     common.logger.debug(5,"All CE :"+str(CEs))
490    
491     sites = []
492     [sites.append(it) for it in CEs if not sites.count(it)]
493    
494     common.logger.debug(5,"All Sites :"+str(sites))
495     return len(sites)
496 slacapra 1.6
497     def noMatchFound_(self, jdl):
498     reReq = re.compile( r'Requirements' )
499     reString = re.compile( r'"\S*"' )
500     f = file(jdl,'r')
501     for line in f.readlines():
502     line= line.strip()
503     if reReq.match(line):
504     for req in reString.findall(line):
505     if re.search("VO",req):
506     common.logger.message( "SW required: "+req)
507     continue
508     if re.search('"\d+',req):
509     common.logger.message("Other req : "+req)
510     continue
511     common.logger.message( "CE required: "+req)
512     break
513     pass
514     raise CrabException("No compatible resources found!")
515    
516 nsmirnov 1.1 def submit(self, nj):
517 nsmirnov 1.3 """
518     Submit one EDG job.
519     """
520 nsmirnov 1.1
521 slacapra 1.18 self.checkProxy()
522 nsmirnov 1.1 jid = None
523     jdl = common.job_list[nj].jdlFilename()
524 slacapra 1.18
525     cmd = 'edg-job-submit ' + self.configOpt_() + jdl
526 nsmirnov 1.1 cmd_out = runCommand(cmd)
527     if cmd_out != None:
528 slacapra 1.18 reSid = re.compile( r'https.+' )
529 slacapra 1.20 jid = reSid.search(cmd_out).group()
530 nsmirnov 1.3 pass
531 nsmirnov 1.1 return jid
532    
533 fanzago 1.33 def resubmit(self, nj_list):
534     """
535     Prepare jobs to be submit
536     """
537     return
538    
539 slacapra 1.8 def getExitStatus(self, id):
540     return self.getStatusAttribute_(id, 'exit_code')
541 fanzago 1.10
542 nsmirnov 1.1 def queryStatus(self, id):
543 slacapra 1.8 return self.getStatusAttribute_(id, 'status')
544 fanzago 1.10
545 spiga 1.9 def queryDest(self, id):
546     return self.getStatusAttribute_(id, 'destination')
547    
548 slacapra 1.8
549     def getStatusAttribute_(self, id, attr):
550 nsmirnov 1.1 """ Query a status of the job with id """
551 slacapra 1.8
552 slacapra 1.18 self.checkProxy()
553 slacapra 1.8 hstates = {}
554 fanzago 1.12 Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
555 slacapra 1.8 # Bypass edg-job-status interfacing directly to C++ API
556     # Job attribute vector to retrieve status without edg-job-status
557     level = 0
558     # Instance of the Status class provided by LB API
559     jobStat = Status()
560     st = 0
561     jobStat.getStatus(id, level)
562     err, apiMsg = jobStat.get_error()
563     if err:
564 fanzago 1.26 common.logger.debug(5,'Error caught' + apiMsg)
565 nsmirnov 1.1 return None
566 slacapra 1.8 else:
567     for i in range(len(self.states)):
568     # Fill an hash table with all information retrieved from LB API
569     hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
570     result = jobStat.loadStatus(st)[ self.states.index(attr) ]
571     return result
572 nsmirnov 1.1
573     def queryDetailedStatus(self, id):
574     """ Query a detailed status of the job with id """
575     cmd = 'edg-job-status '+id
576     cmd_out = runCommand(cmd)
577     return cmd_out
578    
579     def getOutput(self, id):
580 nsmirnov 1.5 """
581     Get output for a finished job with id.
582     Returns the name of directory with results.
583     """
584 slacapra 1.6
585 slacapra 1.18 self.checkProxy()
586 slacapra 1.6 cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
587 nsmirnov 1.1 cmd_out = runCommand(cmd)
588 nsmirnov 1.5
589     # Determine the output directory name
590     dir = common.work_space.resDir()
591     dir += os.getlogin()
592     dir += '_' + os.path.basename(id)
593     return dir
594 nsmirnov 1.1
595     def cancel(self, id):
596     """ Cancel the EDG job with id """
597 slacapra 1.18 self.checkProxy()
598 nsmirnov 1.1 cmd = 'edg-job-cancel --noint ' + id
599     cmd_out = runCommand(cmd)
600     return cmd_out
601    
602 fanzago 1.10 def createSchScript(self, nj):
603 nsmirnov 1.1 """
604     Create a JDL-file for EDG.
605     """
606    
607     job = common.job_list[nj]
608     jbt = job.type()
609     inp_sandbox = jbt.inputSandbox(nj)
610     out_sandbox = jbt.outputSandbox(nj)
611 fanzago 1.10 inp_storage_subdir = ''
612 nsmirnov 1.1
613     title = '# This JDL was generated by '+\
614     common.prog_name+' (version '+common.prog_version_str+')\n'
615     jt_string = ''
616 fanzago 1.14
617    
618 nsmirnov 1.1
619     SPL = inp_storage_subdir
620     if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
621    
622     jdl_fname = job.jdlFilename()
623     jdl = open(jdl_fname, 'w')
624     jdl.write(title)
625    
626     script = job.scriptFilename()
627     jdl.write('Executable = "' + os.path.basename(script) +'";\n')
628     jdl.write(jt_string)
629    
630 fanzago 1.14 ### only one .sh JDL has arguments:
631 slacapra 1.8 firstEvent = common.jobDB.firstEvent(nj)
632     maxEvents = common.jobDB.maxEvents(nj)
633     jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
634    
635 nsmirnov 1.1 inp_box = 'InputSandbox = { '
636     inp_box = inp_box + '"' + script + '",'
637    
638     if inp_sandbox != None:
639     for fl in inp_sandbox:
640     inp_box = inp_box + ' "' + fl + '",'
641     pass
642     pass
643    
644     #if common.use_jam:
645     # inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
646 fanzago 1.40
647 corvo 1.34 # Marco (VERY TEMPORARY ML STUFF)
648     inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
649 gutsche 1.47 os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
650 corvo 1.34 os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
651     os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
652     os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
653     # End Marco
654 nsmirnov 1.1
655 fanzago 1.40 if (not jbt.additional_inbox_files == []):
656     inp_box = inp_box + ', '
657     for addFile in jbt.additional_inbox_files:
658     addFile = os.path.abspath(addFile)
659     inp_box = inp_box+' "'+addFile+'",'
660     pass
661 nsmirnov 1.1
662     if inp_box[-1] == ',' : inp_box = inp_box[:-1]
663     inp_box = inp_box + ' };\n'
664     jdl.write(inp_box)
665    
666     jdl.write('StdOutput = "' + job.stdout() + '";\n')
667     jdl.write('StdError = "' + job.stderr() + '";\n')
668 fanzago 1.14
669    
670     if job.stdout() == job.stderr():
671     out_box = 'OutputSandbox = { "' + \
672     job.stdout() + '", ".BrokerInfo",'
673     else:
674     out_box = 'OutputSandbox = { "' + \
675     job.stdout() + '", "' + \
676     job.stderr() + '", ".BrokerInfo",'
677    
678 fanzago 1.30 if int(self.return_data) == 1:
679 fanzago 1.14 if out_sandbox != None:
680     for fl in out_sandbox:
681     out_box = out_box + ' "' + fl + '",'
682     pass
683 nsmirnov 1.1 pass
684     pass
685 fanzago 1.14
686 nsmirnov 1.1 if out_box[-1] == ',' : out_box = out_box[:-1]
687     out_box = out_box + ' };'
688     jdl.write(out_box+'\n')
689    
690 fanzago 1.14
691 fanzago 1.38 req='Requirements = '
692     req = req + jbt.getRequirements()
693 spiga 1.49 # ### if at least a CE exists ...
694     # if common.analisys_common_info['sites']:
695     # if common.analisys_common_info['sw_version']:
696     # req='Requirements = '
697     # req=req + 'Member("VO-cms-' + \
698     # common.analisys_common_info['sw_version'] + \
699     # '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
700     # if len(common.analisys_common_info['sites'])>0:
701     # req = req + ' && ('
702     # for i in range(len(common.analisys_common_info['sites'])):
703     # req = req + 'other.GlueCEInfoHostName == "' \
704     # + common.analisys_common_info['sites'][i] + '"'
705     # if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
706     # req = req + ' || '
707     # req = req + ')'
708     #### and USER REQUIREMENT
709 fanzago 1.38 if self.EDG_requirements:
710     if (req == 'Requirement = '):
711     req = req + self.EDG_requirements
712     else:
713 fanzago 1.14 req = req + ' && ' + self.EDG_requirements
714 fanzago 1.48 #### FEDE #####
715     if self.EDG_ce_white_list:
716     ce_white_list = string.split(self.EDG_ce_white_list,',')
717     #print "req = ", req
718     for i in range(len(ce_white_list)):
719     if i == 0:
720     if (req == 'Requirement = '):
721     req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
722     else:
723     req = req + ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
724     pass
725     else:
726     req = req + ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
727     req = req + ')'
728    
729     if self.EDG_ce_black_list:
730     ce_black_list = string.split(self.EDG_ce_black_list,',')
731     for ce in ce_black_list:
732     if (req == 'Requirement = '):
733     req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
734     else:
735     req = req + ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
736     pass
737     ###############
738 fanzago 1.38 if self.EDG_clock_time:
739     if (req == 'Requirement = '):
740     req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
741     else:
742 fanzago 1.14 req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
743 fanzago 1.48
744 fanzago 1.38 if self.EDG_cpu_time:
745     if (req == 'Requirement = '):
746 spiga 1.43 req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
747     else:
748 fanzago 1.14 req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
749 fanzago 1.38 if (req != 'Requirement = '):
750 fanzago 1.14 req = req + ';\n'
751     jdl.write(req)
752    
753 nsmirnov 1.1 jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
754    
755     if ( self.EDG_retry_count ):
756     jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
757     pass
758    
759     jdl.close()
760     return
761 slacapra 1.18
762     def checkProxy(self):
763     """
764     Function to check the Globus proxy.
765     """
766     if (self.proxyValid): return
767     timeleft = -999
768 slacapra 1.50 minTimeLeft=10*3600 # in seconds
769     #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
770     #cmd = 'voms-proxy-info -timeleft'
771     mustRenew = 0
772     timeLeftLocal = runCommand('voms-proxy-info -timeleft')
773     timeLeftServer = -999
774     if not timeLeftLocal or not isInt(timeLeftLocal):
775     mustRenew = 1
776     else:
777     timeLeftServer = runCommand('voms-proxy-info -actimeleft')
778     if not timeLeftServer or not isInt(timeLeftServer):
779     mustRenew = 1
780     elif timeLeftServer<minTimeLeft or timeLeftServer<minTimeLeft:
781     mustRenew = 1
782     pass
783     pass
784    
785     if (mustRenew):
786 spiga 1.49 common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 24h\n")
787     cmd = 'voms-proxy-init -voms cms -valid 100:00'
788 slacapra 1.18 try:
789 slacapra 1.32 # SL as above: damn it!
790 slacapra 1.19 out = os.system(cmd)
791     if (out>0): raise CrabException("Unable to create a valid proxy!\n")
792 slacapra 1.18 except:
793     msg = "Unable to create a valid proxy!\n"
794     raise CrabException(msg)
795     pass
796     self.proxyValid=1
797     return
798 spiga 1.49
799 slacapra 1.18 def configOpt_(self):
800     edg_ui_cfg_opt = ' '
801     if self.edg_config:
802     edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
803     if self.edg_config_vo:
804     edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
805     return edg_ui_cfg_opt