ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerEdg.py
(Generate patch)

Comparing COMP/CRAB/python/SchedulerEdg.py (file contents):
Revision 1.23 by spiga, Tue Nov 8 13:27:11 2005 UTC vs.
Revision 1.64 by gutsche, Tue Jun 27 02:31:31 2006 UTC

# Line 2 | Line 2 | 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
# Line 21 | Line 22 | class SchedulerEdg(Scheduler):
22  
23      def configure(self, cfg_params):
24  
25 <        try: self.edg_config = cfg_params["EDG.config"]
26 <        except KeyError: self.edg_config = ''
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: self.edg_config_vo = cfg_params["EDG.config_vo"]
35 <        except KeyError: self.edg_config_vo = ''
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: self.LCG_version = cfg_params["EDG.lcg_version"]
41          except KeyError: self.LCG_version = '2'
# Line 36 | Line 46 | class SchedulerEdg(Scheduler):
46          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
47          except KeyError: self.EDG_retry_count = ''
48  
49 +        try:
50 +            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
51 +            #print "self.EDG_ce_black_list = ", self.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 +            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
58 +        except KeyError: self.EDG_ce_white_list = ''
59 +
60          try: self.VO = cfg_params['EDG.virtual_organization']
61          except KeyError: self.VO = 'cms'
62  
63          try: self.return_data = cfg_params['USER.return_data']
64 <        except KeyError: self.return_data = ''
64 >        except KeyError: self.return_data = 1
65 >
66 >        try:
67 >             self.copy_input_data = common.analisys_common_info['copy_input_data']
68 >             #print "self.copy_input_data = ", self.copy_input_data
69 >        except KeyError: self.copy_input_data = 0
70  
71          try:
72              self.copy_data = cfg_params["USER.copy_data"]
73 <            try:
74 <                self.SE = cfg_params['USER.storage_element']
75 <                self.SE_PATH = cfg_params['USER.storage_path']
76 <            except KeyError:
77 <                msg = "Error. The [USER] section does not have 'storage_element'"
78 <                msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
79 <                common.logger.message(msg)
80 <                raise CrabException(msg)
81 <        except KeyError: self.copy_data = ''
73 >            if int(self.copy_data) == 1:
74 >                try:
75 >                    self.SE = cfg_params['USER.storage_element']
76 >                    self.SE_PATH = cfg_params['USER.storage_path']
77 >                except KeyError:
78 >                    msg = "Error. The [USER] section does not have 'storage_element'"
79 >                    msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
80 >                    common.logger.message(msg)
81 >                    raise CrabException(msg)
82 >        except KeyError: self.copy_data = 0
83 >
84 >        if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
85 >           msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
86 >           msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
87 >           raise CrabException(msg)
88  
89 +        try:
90 +            self.lfc_host = cfg_params['EDG.lfc_host']
91 +        except KeyError:
92 +            msg = "Error. The [EDG] section does not have 'lfc_host' value"
93 +            msg = msg + " it's necessary to know the LFC host name"
94 +            common.logger.message(msg)
95 +            raise CrabException(msg)
96 +        try:
97 +            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
98 +        except KeyError:
99 +            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
100 +            msg = msg + " it's necessary to know the catalog type"
101 +            common.logger.message(msg)
102 +            raise CrabException(msg)
103 +        try:
104 +            self.lfc_home = cfg_params['EDG.lfc_home']
105 +        except KeyError:
106 +            msg = "Error. The [EDG] section does not have 'lfc_home' value"
107 +            msg = msg + " it's necessary to know the home catalog dir"
108 +            common.logger.message(msg)
109 +            raise CrabException(msg)
110 +      
111          try:
112              self.register_data = cfg_params["USER.register_data"]
113 <            try:
114 <                 self.LFN = cfg_params['USER.lfn_dir']
115 <            except KeyError:
116 <                msg = "Error. The [USER] section does not have 'lfn_dir' value"
117 <                msg = msg + " it's necessary for RLS registration"
118 <                common.logger.message(msg)
119 <                raise CrabException(msg)
120 <        except KeyError: self.register_data= ''
113 >            if int(self.register_data) == 1:
114 >                try:
115 >                    self.LFN = cfg_params['USER.lfn_dir']
116 >                except KeyError:
117 >                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
118 >                    msg = msg + " it's necessary for LCF registration"
119 >                    common.logger.message(msg)
120 >                    raise CrabException(msg)
121 >        except KeyError: self.register_data = 0
122 >
123 >        if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
124 >           msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
125 >           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
126 >           common.logger.message(msg)
127 >           raise CrabException(msg)
128  
129          try: self.EDG_requirements = cfg_params['EDG.requirements']
130          except KeyError: self.EDG_requirements = ''
# Line 91 | Line 152 | class SchedulerEdg(Scheduler):
152          sys.path.append(libPath)
153  
154          self.proxyValid=0
155 +
156 +        try:
157 +            self._taskId = cfg_params['taskId']
158 +        except:
159 +            self._taskId = ''
160 +
161          return
162      
163  
# Line 113 | Line 180 | class SchedulerEdg(Scheduler):
180          """
181          Returns part of a job script which does scheduler-specific work.
182          """
116
183          txt = ''
184 <        if self.copy_data:
184 >        txt += "# job number (first parameter for job wrapper)\n"
185 >        txt += "NJob=$1\n"
186 >
187 >        txt += '# job identification to DashBoard \n'
188 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
189 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
190 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
191 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
192 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
193 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
194 >
195 >        txt += 'echo "middleware discovery " \n'
196 >        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
197 >        txt += '    middleware=LCG \n'
198 >        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
199 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
200 >        txt += '    echo "middleware =$middleware" \n'
201 >        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
202 >        txt += '    middleware=OSG \n'
203 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
204 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
205 >        txt += '    echo "middleware =$middleware" \n'
206 >        txt += 'elif [ $OSG_APP ]; then \n'
207 >        txt += '    middleware=OSG \n'
208 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
209 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
210 >        txt += '    echo "middleware =$middleware" \n'
211 >        txt += 'else \n'
212 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
213 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
214 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
215 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
216 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
217 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
218 >        txt += '    echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
219 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
220 >        txt += '    exit 1 \n'
221 >        txt += 'fi \n'
222 >
223 >        txt += '# report first time to DashBoard \n'
224 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
225 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
226 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
227 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
228 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
229 >        
230 >        txt += '\n\n'
231 >
232 >        if int(self.copy_data) == 1:
233             if self.SE:
234                txt += 'export SE='+self.SE+'\n'
235                txt += 'echo "SE = $SE"\n'
# Line 123 | Line 237 | class SchedulerEdg(Scheduler):
237                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
238                txt += 'export SE_PATH='+self.SE_PATH+'\n'
239                txt += 'echo "SE_PATH = $SE_PATH"\n'
240 <                                                                                                                                                            
241 <        if self.register_data:
240 >
241 >        txt += 'export VO='+self.VO+'\n'
242 >        ### FEDE: add some line for LFC catalog setting
243 >        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 >        txt += 'fi\n'
256 >        #####
257 >        if int(self.register_data) == 1:
258 >           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 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
264 >           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 >           txt += 'fi\n'
272 >           txt += '\n'
273 >
274             if self.VO:
275                txt += 'export VO='+self.VO+'\n'
276             if self.LFN:
277 <              txt += 'export LFN='+self.LFN+'\n'
277 >              txt += 'if [ $middleware == LCG ]; then \n'
278 >              txt += '    export LFN='+self.LFN+'\n'
279 >              txt += 'fi\n'
280                txt += '\n'
281 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
282 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
283 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
284 <        txt += 'echo "CE = $CE"\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 >        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 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
296 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
297 >        txt += '        echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
298 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
299 >        txt += '        exit 1 \n'
300 >        txt += '    fi \n'
301 >        txt += 'fi \n'
302 >
303 >        return txt
304 >
305 >    def wsCopyInput(self):
306 >        """
307 >        Copy input data from SE to WN    
308 >        """
309 >        txt = ''
310 >        try:
311 >            self.copy_input_data = common.analisys_common_info['copy_input_data']
312 >            #print "self.copy_input_data = ", self.copy_input_data
313 >        except KeyError: self.copy_input_data = 0
314 >        if int(self.copy_input_data) == 1:
315 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
316 >           txt += 'if [ $middleware == OSG ]; then\n'
317 >           txt += '   #\n'
318 >           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
319 >           txt += '   #\n'
320 >           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
321 >           txt += 'elif [ $middleware == LCG ]; then \n'
322 >           txt += '   #\n'
323 >           txt += '   #   Copy Input Data from SE to this WN\n'
324 >           txt += '   #\n'
325 > ### changed by georgia (put a loop copying more than one input files per jobs)          
326 >           txt += '   for input_file in $cur_file_list \n'
327 >           txt += '   do \n'
328 >           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
329 >           txt += '    copy_input_exit_status=$?\n'
330 >           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
331 >           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
332 >           txt += '       echo "Problems with copying to WN" \n'
333 >           txt += '    else \n'
334 >           txt += '       echo "input copied into WN" \n'
335 >           txt += '    fi \n'
336 >           txt += '   done \n'
337 > ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
338 >           txt += '   for file in $cur_pu_list \n'
339 >           txt += '   do \n'
340 >           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
341 >           txt += '    copy_input_exit_status=$?\n'
342 >           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
343 >           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
344 >           txt += '       echo "Problems with copying pu to WN" \n'
345 >           txt += '    else \n'
346 >           txt += '       echo "input pu files copied into WN" \n'
347 >           txt += '    fi \n'
348 >           txt += '   done \n'
349 >           txt += '   \n'
350 >           txt += '   ### Check SCRATCH space available on WN : \n'
351 >           txt += '   df -h \n'
352 >           txt += 'fi \n'
353 >          
354          return txt
355  
356      def wsCopyOutput(self):
# Line 142 | Line 359 | class SchedulerEdg(Scheduler):
359          to copy produced output into a storage element.
360          """
361          txt = ''
362 <        if self.copy_data:
146 <           copy = 'globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file'
362 >        if int(self.copy_data) == 1:
363             txt += '#\n'
364             txt += '#   Copy output to SE = $SE\n'
365             txt += '#\n'
150           #### per orca l'exit_status non e' affidabile.....
151           #txt += 'if [ $executable_exit_status -eq 0 ]; then\n'
366             txt += 'if [ $exe_result -eq 0 ]; then\n'
367 <           txt += '  for out_file in $file_list ; do\n'
368 <           txt += '    echo "Trying to copy output file to $SE "\n'
369 <           txt += '    echo "'+copy+'"\n'
370 <           txt += '    '+copy+' 2>&1\n'
371 <           txt += '    copy_exit_status=$?\n'
372 <           txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
373 <           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
374 <           txt += '    if [ $copy_exit_status -ne 0 ]; then \n'
375 <           txt += '       echo "Problems with SE= $SE" \n'
376 <           txt += '    else \n'
377 <           txt += '       echo "output copied into $SE/$SE_PATH directory"\n'
378 <           txt += '    fi \n'
379 <           txt += '  done\n'
380 <           txt += 'fi \n'
367 >           txt += '    for out_file in $file_list ; do\n'
368 >           txt += '        echo "Trying to copy output file to $SE "\n'
369 >           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
370 >           txt += '        if [ $middleware == OSG ]; then\n'
371 >           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
372 >           txt += '           globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1 \n'
373 >           txt += '           copy_exit_status=$? \n'
374 >           txt += '        elif [ $middleware == LCG ]; then \n'
375 >           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
376 >           txt += '           lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1\n'
377 >           txt += '           copy_exit_status=$? \n'
378 >           txt += '        fi \n'
379 >           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
380 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
381 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
382 >           txt += '            echo "Problems with SE = $SE"\n'
383 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
384 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
385 >           txt += '        else\n'
386 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
387 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
388 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
389 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
390 >           txt += '         fi\n'
391 >           txt += '     done\n'
392 >           txt += 'fi\n'
393          return txt
394  
395      def wsRegisterOutput(self):
# Line 172 | Line 398 | class SchedulerEdg(Scheduler):
398          """
399  
400          txt = ''
401 <        if self.register_data:
401 >        if int(self.register_data) == 1:
402 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
403 >           txt += 'if [ $middleware == OSG ]; then\n'
404 >           txt += '   #\n'
405 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
406 >           txt += '   #\n'
407 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
408 >           txt += 'elif [ $middleware == LCG ]; then \n'
409             txt += '#\n'
410 <           txt += '#  Register output to RLS\n'
410 >           txt += '#  Register output to LFC\n'
411             txt += '#\n'
412 <           ### analogo
413 <           #txt += 'if [[ $executable_exit_status -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
414 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
415 <           txt += '   for out_file in $file_list ; do\n'
416 <           txt += '      echo "Trying to register the output file into RLS"\n'
417 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
418 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
419 <           txt += '      register_exit_status=$?\n'
420 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
421 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
422 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
423 <           txt += '         echo "Problems with the registration to RLS" \n'
424 <           txt += '         echo "Try with srm protocol" \n'
425 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
426 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
412 >           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
413 >           txt += '      for out_file in $file_list ; do\n'
414 >           txt += '         echo "Trying to register the output file into LFC"\n'
415 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
416 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
417 >           txt += '         register_exit_status=$?\n'
418 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
419 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
420 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
421 >           txt += '            echo "Problems with the registration to LFC" \n'
422 >           txt += '            echo "Try with srm protocol" \n'
423 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
424 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
425 >           txt += '            register_exit_status=$?\n'
426 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
427 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
428 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
429 >           txt += '               echo "Problems with the registration into LFC" \n'
430 >           txt += '            fi \n'
431 >           txt += '         else \n'
432 >           txt += '            echo "output registered to LFC"\n'
433 >           txt += '         fi \n'
434 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
435 >           txt += '      done\n'
436 >           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
437 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
438 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
439 >           txt += '      for out_file in $file_list ; do\n'
440 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
441 >           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'
442             txt += '         register_exit_status=$?\n'
443             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
444             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
445             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
446 <           txt += '            echo "Problems with the registration into RLS" \n'
446 >           txt += '            echo "Problems with CloseSE" \n'
447 >           txt += '         else \n'
448 >           txt += '            echo "The program was successfully executed"\n'
449 >           txt += '            echo "SE = $CLOSE_SE"\n'
450 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
451             txt += '         fi \n'
452 <           txt += '      else \n'
453 <           txt += '         echo "output registered to RLS"\n'
454 <           txt += '      fi \n'
455 <           txt += '   done\n'
456 <           txt += 'elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
205 <           txt += '   echo "Trying to copy output file to CloseSE"\n'
206 <           txt += '   CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
207 <           txt += '   for out_file in $file_list ; do\n'
208 <           txt += '      echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
209 <           txt += '      lcg-cr -v -l lfn:${LFN}/$out_file -d $SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
210 <           txt += '      register_exit_status=$?\n'
211 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
212 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
213 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
214 <           txt += '         echo "Problems with CloseSE" \n'
215 <           txt += '      else \n'
216 <           txt += '         echo "The program was successfully executed"\n'
217 <           txt += '         echo "SE = $CLOSE_SE"\n'
218 <           txt += '         echo "LFN for the file is LFN=${LFN}/$out_file"\n'
219 <           txt += '      fi \n'
220 <           txt += '   done\n'
221 <           txt += 'else\n'
222 <           txt += '   echo "Problem with the executable"\n'
452 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
453 >           txt += '      done\n'
454 >           txt += '   else\n'
455 >           txt += '      echo "Problem with the executable"\n'
456 >           txt += '   fi \n'
457             txt += 'fi \n'
458          return txt
225        #####################
459  
460      def loggingInfo(self, id):
461          """
462          retrieve the logging info from logging and bookkeeping and return it
463          """
464          self.checkProxy()
465 <      #  id = common.jobDB.jobId(nj)
466 <        cmd = 'edg-job-get-logging-info -v 2 ' + self.configOpt_() + id
465 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
466 >        #cmd_out = os.popen(cmd)
467          cmd_out = runCommand(cmd)
468          return cmd_out
469  
# Line 241 | Line 474 | class SchedulerEdg(Scheduler):
474          self.checkProxy()
475          jdl = common.job_list[nj].jdlFilename()
476          cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
477 <        cmd_out = runCommand(cmd)
477 >        cmd_out = runCommand(cmd,0,10)
478 >        if not cmd_out:
479 >            raise CrabException("ERROR: "+cmd+" failed!")
480 >
481          return self.parseListMatch_(cmd_out, jdl)
482  
483      def parseListMatch_(self, out, jdl):
484 +        """
485 +        Parse the f* output of edg-list-match and produce something sensible
486 +        """
487          reComment = re.compile( r'^\**$' )
488          reEmptyLine = re.compile( r'^$' )
489          reVO = re.compile( r'Selected Virtual Organisation name.*' )
490 <        reCE = re.compile( r'CEId.*\n((.*:.*)\n)*' )
490 >        reLine = re.compile( r'.*')
491 >        reCE = re.compile( r'(.*:.*)')
492 >        reCEId = re.compile( r'CEId.*')
493          reNO = re.compile( r'No Computing Element matching' )
494          reRB = re.compile( r'Connecting to host' )
495          next = 0
496          CEs=[]
497          Match=0
498  
499 <        if reNO.match( out ):
500 <            common.logger.debug(5,out)
260 <            self.noMatchFound_(jdl)
261 <            Match=0
262 <            pass
263 <        if reVO.match( out ):
264 <            VO =reVO.match( out ).group()
265 <            common.logger.debug(5, 'VO           :'+VO)
266 <            pass
499 >        #print out
500 >        lines = reLine.findall(out)
501  
502 <        if reRB.match( out ):
503 <            RB =reRB.match(out).group()
504 <            common.logger.debug(5, 'Using RB     :'+RB)
502 >        i=0
503 >        CEs=[]
504 >        for line in lines:
505 >            string.strip(line)
506 >            #print line
507 >            if reNO.match( line ):
508 >                common.logger.debug(5,line)
509 >                return 0
510 >                pass
511 >            if reVO.match( line ):
512 >                VO =reVO.match( line ).group()
513 >                common.logger.debug(5,"VO "+VO)
514 >                pass
515 >
516 >            if reRB.match( line ):
517 >                RB = reRB.match(line).group()
518 >                common.logger.debug(5,"RB "+RB)
519 >                pass
520 >
521 >            if reCEId.search( line ):
522 >                for lineCE in lines[i:-1]:
523 >                    if reCE.match( lineCE ):
524 >                        CE = string.strip(reCE.search(lineCE).group(1))
525 >                        CEs.append(CE.split(':')[0])
526 >                        pass
527 >                    pass
528 >                pass
529 >            i=i+1
530              pass
531  
532 <        if reCE.search( out ):
274 <            groups=reCE.search(out).groups()
275 <            for CE in groups:
276 <                tmp = string.strip(CE)
277 <                CEs.append(tmp)
278 <                common.logger.debug(5, 'Matched CE   :'+tmp)
279 <                Match=Match+1
280 <            pass
532 >        common.logger.debug(5,"All CE :"+str(CEs))
533  
534 <        return Match
534 >        sites = []
535 >        [sites.append(it) for it in CEs if not sites.count(it)]
536 >
537 >        common.logger.debug(5,"All Sites :"+str(sites))
538 >        common.logger.message("Matched Sites :"+str(sites))
539 >        return len(sites)
540  
541      def noMatchFound_(self, jdl):
542          reReq = re.compile( r'Requirements' )
# Line 317 | Line 574 | class SchedulerEdg(Scheduler):
574              pass
575          return jid
576  
577 +    def resubmit(self, nj_list):
578 +        """
579 +        Prepare jobs to be submit
580 +        """
581 +        return
582 +
583      def getExitStatus(self, id):
584          return self.getStatusAttribute_(id, 'exit_code')
585  
# Line 342 | Line 605 | class SchedulerEdg(Scheduler):
605          jobStat.getStatus(id, level)
606          err, apiMsg = jobStat.get_error()
607          if err:
608 <            print 'Error caught', apiMsg
346 <            common.log.message(apiMsg)
608 >            common.logger.debug(5,'Error caught' + apiMsg)
609              return None
610          else:
611              for i in range(len(self.states)):
# Line 370 | Line 632 | class SchedulerEdg(Scheduler):
632  
633          # Determine the output directory name
634          dir = common.work_space.resDir()
635 <        dir += os.getlogin()
635 >        dir += os.environ['USER']
636          dir += '_' + os.path.basename(id)
637          return dir
638  
# Line 410 | Line 672 | class SchedulerEdg(Scheduler):
672          jdl.write(jt_string)
673  
674          ### only one .sh  JDL has arguments:
413        firstEvent = common.jobDB.firstEvent(nj)
414        maxEvents = common.jobDB.maxEvents(nj)
415        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
675  
676 +        ### Fabio
677 +        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
678          inp_box = 'InputSandbox = { '
679          inp_box = inp_box + '"' + script + '",'
680  
# Line 426 | Line 687 | class SchedulerEdg(Scheduler):
687          #if common.use_jam:
688          #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
689  
690 <        for addFile in jbt.additional_inbox_files:
691 <            addFile = os.path.abspath(addFile)
692 <            inp_box = inp_box+' "'+addFile+'",'
693 <            pass
690 >        # Marco (VERY TEMPORARY ML STUFF)
691 >        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
692 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
693 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
694 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
695 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
696 >        # End Marco
697 >
698 >        if (not jbt.additional_inbox_files == []):
699 >            inp_box = inp_box + ', '
700 >            for addFile in jbt.additional_inbox_files:
701 >                addFile = os.path.abspath(addFile)
702 >                inp_box = inp_box+' "'+addFile+'",'
703 >                pass
704  
705          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
706          inp_box = inp_box + ' };\n'
# Line 447 | Line 718 | class SchedulerEdg(Scheduler):
718                      job.stdout() + '", "' + \
719                      job.stderr() + '", ".BrokerInfo",'
720  
721 <        if self.return_data :
721 >        if int(self.return_data) == 1:
722              if out_sandbox != None:
723                  for fl in out_sandbox:
724                      out_box = out_box + ' "' + fl + '",'
# Line 459 | Line 730 | class SchedulerEdg(Scheduler):
730          out_box = out_box + ' };'
731          jdl.write(out_box+'\n')
732  
733 <        ### if at least a CE exists ...
734 <        if common.analisys_common_info['sites']:
735 <            if common.analisys_common_info['sw_version']:
736 <                req='Requirements = '
737 <                req=req + 'Member("VO-cms-' + \
738 <                     common.analisys_common_info['sw_version'] + \
739 <                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
740 <            if len(common.analisys_common_info['sites'])>0:
741 <                req = req + ' && ('
742 <                for i in range(len(common.analisys_common_info['sites'])):
743 <                    req = req + 'other.GlueCEInfoHostName == "' \
744 <                         + common.analisys_common_info['sites'][i] + '"'
745 <                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
746 <                        req = req + ' || '
733 >
734 >        req='Requirements = '
735 >        noreq=req
736 >        req = req + jbt.getRequirements()
737 >        #### and USER REQUIREMENT
738 >        if self.EDG_requirements:
739 >            if (req != noreq):
740 >                req = req +  ' && '
741 >            req = req + self.EDG_requirements
742 >        #### FEDE #####
743 >        if self.EDG_ce_white_list:
744 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
745 >            #print "req = ", req
746 >            for i in range(len(ce_white_list)):
747 >                if i == 0:
748 >                    if (req != noreq):
749 >                        req = req +  ' && '
750 >                    req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
751 >                    pass
752 >                else:
753 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
754              req = req + ')'
755 +        
756 +        if self.EDG_ce_black_list:
757 +            ce_black_list = string.split(self.EDG_ce_black_list,',')
758 +            for ce in ce_black_list:
759 +                if (req != noreq):
760 +                    req = req +  ' && '
761 +                req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
762 +                pass
763  
764 <            #### and USER REQUIREMENT
765 <            if self.EDG_requirements:
766 <                req = req +  ' && ' + self.EDG_requirements
767 <            if self.EDG_clock_time:
768 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
769 <            if self.EDG_cpu_time:
770 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
764 >        ###############
765 >        clockTime=480
766 >        if self.EDG_clock_time:
767 >            clockTime= self.EDG_clock_time
768 >        if (req != noreq):
769 >            req = req + ' && '
770 >        req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
771 >
772 >        cpuTime=1000
773 >        if self.EDG_cpu_time:
774 >            cpuTime=self.EDG_cpu_time
775 >        if (req != noreq):
776 >            req = req + ' && '
777 >        req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+str(cpuTime)+'))'
778 >
779 >        if (req != noreq):
780              req = req + ';\n'
781              jdl.write(req)
782                                                                                                                                                              
# Line 491 | Line 786 | class SchedulerEdg(Scheduler):
786              jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
787              pass
788  
789 +        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
790 +
791          jdl.close()
792          return
793  
# Line 500 | Line 797 | class SchedulerEdg(Scheduler):
797          """
798          if (self.proxyValid): return
799          timeleft = -999
800 <        minTimeLeft=10 # in hours
801 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
802 <        try: cmd_out = runCommand(cmd,0)
803 <        except: print cmd_out
804 <        if (cmd_out == None or cmd_out=='1'):
805 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
806 <            cmd = 'grid-proxy-init -valid 100:00'
800 >        minTimeLeft=10*3600 # in seconds
801 >
802 >        minTimeLeftServer = 100 # in hours
803 >
804 >        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
805 >        #cmd = 'voms-proxy-info -timeleft'
806 >        mustRenew = 0
807 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
808 >        timeLeftServer = -999
809 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
810 >            mustRenew = 1
811 >        else:
812 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
813 >            if not timeLeftServer or not isInt(timeLeftServer):
814 >                mustRenew = 1
815 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
816 >                mustRenew = 1
817 >            pass
818 >        pass
819 >
820 >        if mustRenew:
821 >            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")
822 >            cmd = 'voms-proxy-init -voms cms -valid 96:00'
823              try:
824 +                # SL as above: damn it!
825                  out = os.system(cmd)
826                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
827              except:
828                  msg = "Unable to create a valid proxy!\n"
829                  raise CrabException(msg)
830 <            cmd = 'grid-proxy-info -timeleft'
831 <            cmd_out = runCommand(cmd,0)
832 <            #print cmd_out, time.time()
833 <            #time.time(cms_out)
830 >            # cmd = 'grid-proxy-info -timeleft'
831 >            # cmd_out = runCommand(cmd,0,20)
832 >            pass
833 >
834 >        ## now I do have a voms proxy valid, and I check the myproxy server
835 >        renewProxy = 0
836 >        cmd = 'myproxy-info -d -s '+self.proxyServer
837 >        cmd_out = runCommand(cmd,0,20)
838 >        if not cmd_out:
839 >            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
840 >            renewProxy = 1
841 >        else:
842 >            # if myproxy exist but not long enough, renew
843 >            reTime = re.compile( r'timeleft: (\d+)' )
844 >            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
845 >            if reTime.match( cmd_out ):
846 >                time = reTime.search( line ).group(1)
847 >                if time < minTimeLeftServer:
848 >                    renewProxy = 1
849 >                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
850 >                pass
851              pass
852 +        
853 +        # if not, create one.
854 +        if renewProxy:
855 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
856 +            out = os.system(cmd)
857 +            if (out>0):
858 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
859 +            pass
860 +
861 +        # cache proxy validity
862          self.proxyValid=1
863          return
864 <    
864 >
865      def configOpt_(self):
866          edg_ui_cfg_opt = ' '
867          if self.edg_config:
868 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
868 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
869          if self.edg_config_vo:
870 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
870 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
871          return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines