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.29 by fanzago, Fri Nov 18 15:50:23 2005 UTC vs.
Revision 1.58 by gutsche, Sun Jun 4 17:42:28 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 113 | Line 174 | class SchedulerEdg(Scheduler):
174          """
175          Returns part of a job script which does scheduler-specific work.
176          """
116
177          txt = ''
178 <        if self.copy_data:
178 >        txt += 'echo "middleware discovery " \n'
179 >        txt += 'if [ $VO_CMS_SW_DIR ]; then\n'
180 >        txt += '    middleware=LCG \n'
181 >        txt += '    echo "middleware =$middleware" \n'
182 >        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
183 >        txt += '    middleware=OSG \n'
184 >        txt += '    echo "middleware =$middleware" \n'
185 >        txt += 'elif [ $OSG_APP ]; then \n'
186 >        txt += '    middleware=OSG \n'
187 >        txt += '    echo "middleware =$middleware" \n'
188 >        txt += 'else \n'
189 >        txt += '    echo "SET_CMS_ENV 1 ==> middleware not identified" \n'
190 >        txt += '    echo "JOB_EXIT_STATUS = 1"\n'
191 >        txt += '    exit 1\n'
192 >        txt += 'fi\n'
193 >
194 >        txt += '\n\n'
195 >
196 >        ### OLI: removed to move DashBoard reporting header to front of wrapper script
197 >        # txt += 'if [ $middleware == LCG ]; then \n'
198 >        # txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
199 >        # txt += 'fi\n'
200 >
201 >        if int(self.copy_data) == 1:
202             if self.SE:
203                txt += 'export SE='+self.SE+'\n'
204                txt += 'echo "SE = $SE"\n'
# Line 123 | Line 206 | class SchedulerEdg(Scheduler):
206                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
207                txt += 'export SE_PATH='+self.SE_PATH+'\n'
208                txt += 'echo "SE_PATH = $SE_PATH"\n'
209 <                                                                                                                                                            
210 <        if self.register_data:
209 >
210 >        txt += 'export VO='+self.VO+'\n'
211 >        ### FEDE: add some line for LFC catalog setting
212 >        txt += 'if [ $middleware == LCG ]; then \n'
213 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
214 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
215 >        txt += '    fi\n'
216 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
217 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
218 >        txt += '    fi\n'
219 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
220 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
221 >        txt += '    fi\n'
222 >        txt += 'elif [ $middleware == OSG ]; then\n'
223 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
224 >        txt += 'fi\n'
225 >        #####
226 >        if int(self.register_data) == 1:
227 >           txt += 'if [ $middleware == LCG ]; then \n'
228 >           txt += '    export LFN='+self.LFN+'\n'
229 >           txt += '    lfc-ls $LFN\n'
230 >           txt += '    result=$?\n'
231 >           txt += '    echo $result\n'
232 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
233 >           txt += '    if [ $result != 0 ]; then\n'
234 >           txt += '       lfc-mkdir $LFN\n'
235 >           txt += '       result=$?\n'
236 >           txt += '       echo $result\n'
237 >           txt += '    fi\n'
238 >           txt += 'elif [ $middleware == OSG ]; then\n'
239 >           txt += '    echo " Files registration to be implemented for OSG"\n'
240 >           txt += 'fi\n'
241 >           txt += '\n'
242 >
243             if self.VO:
244                txt += 'export VO='+self.VO+'\n'
245             if self.LFN:
246 <              txt += 'export LFN='+self.LFN+'\n'
246 >              txt += 'if [ $middleware == LCG ]; then \n'
247 >              txt += '    export LFN='+self.LFN+'\n'
248 >              txt += 'fi\n'
249                txt += '\n'
250 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
251 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
252 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
253 <        txt += 'echo "CE = $CE"\n'
250 >
251 >        txt += 'if [ $middleware == LCG ]; then\n'
252 >        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
253 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
254 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
255 >        txt += '    echo "CE = $CE"\n'
256 >        txt += 'elif [ $middleware == OSG ]; then \n'
257 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
258 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
259 >        txt += '    else \n'
260 >        txt += '        echo "SET_ENV 1 ==> ERROR in setting CE name - OSG mode -" \n'
261 >        txt += '        exit 1 \n'
262 >        txt += '    fi \n'
263 >        txt += 'fi \n'
264 >
265 >        return txt
266 >
267 >    def wsCopyInput(self):
268 >        """
269 >        Copy input data from SE to WN    
270 >        """
271 >        txt = ''
272 >        try:
273 >            self.copy_input_data = common.analisys_common_info['copy_input_data']
274 >            #print "self.copy_input_data = ", self.copy_input_data
275 >        except KeyError: self.copy_input_data = 0
276 >        if int(self.copy_input_data) == 1:
277 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
278 >           txt += 'if [ $middleware == OSG ]; then\n'
279 >           txt += '   #\n'
280 >           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
281 >           txt += '   #\n'
282 >           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
283 >           txt += 'elif [ $middleware == LCG ]; then \n'
284 >           txt += '   #\n'
285 >           txt += '   #   Copy Input Data from SE to this WN\n'
286 >           txt += '   #\n'
287 > ### changed by georgia (put a loop copying more than one input files per jobs)          
288 >           txt += '   for input_file in $cur_file_list \n'
289 >           txt += '   do \n'
290 >           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
291 >           txt += '    copy_input_exit_status=$?\n'
292 >           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
293 >           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
294 >           txt += '       echo "Problems with copying to WN" \n'
295 >           txt += '    else \n'
296 >           txt += '       echo "input copied into WN" \n'
297 >           txt += '    fi \n'
298 >           txt += '   done \n'
299 > ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
300 >           txt += '   for file in $cur_pu_list \n'
301 >           txt += '   do \n'
302 >           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
303 >           txt += '    copy_input_exit_status=$?\n'
304 >           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
305 >           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
306 >           txt += '       echo "Problems with copying pu to WN" \n'
307 >           txt += '    else \n'
308 >           txt += '       echo "input pu files copied into WN" \n'
309 >           txt += '    fi \n'
310 >           txt += '   done \n'
311 >           txt += '   \n'
312 >           txt += '   ### Check SCRATCH space available on WN : \n'
313 >           txt += '   df -h \n'
314 >           txt += 'fi \n'
315 >          
316          return txt
317  
318      def wsCopyOutput(self):
# Line 142 | Line 321 | class SchedulerEdg(Scheduler):
321          to copy produced output into a storage element.
322          """
323          txt = ''
324 <        if self.copy_data:
146 <           copy = 'globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file'
324 >        if int(self.copy_data) == 1:
325             txt += '#\n'
326             txt += '#   Copy output to SE = $SE\n'
327             txt += '#\n'
328             txt += 'if [ $exe_result -eq 0 ]; then\n'
329 <           txt += '  for out_file in $file_list ; do\n'
330 <           txt += '    echo "Trying to copy output file to $SE "\n'
331 <           txt += '    echo "'+copy+'"\n'
332 <           txt += '    '+copy+' 2>&1\n'
333 <           txt += '    copy_exit_status=$?\n'
334 <           txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
335 <           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
336 <           txt += '    if [ $copy_exit_status -ne 0 ]; then \n'
337 <           txt += '       echo "Problems with SE= $SE" \n'
338 <           txt += '    else \n'
339 <           txt += '       echo "output copied into $SE/$SE_PATH directory"\n'
340 <           txt += '    fi \n'
341 <           txt += '  done\n'
342 <           txt += 'fi \n'
329 >           txt += '    for out_file in $file_list ; do\n'
330 >           txt += '        echo "Trying to copy output file to $SE "\n'
331 >           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
332 >           txt += '        if [ $middleware == OSG ]; then\n'
333 >           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
334 >           txt += '           copy_exit_status=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
335 >           #txt += '           exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
336 >           txt += '        elif [ $middleware == LCG ]; then \n'
337 >           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
338 >           txt += '           copy_exit_status=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
339 >           #txt += '           exitstring=`lcg-cp --vo cms -t 30 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
340 >           txt += '        fi \n'
341 >           #txt += '        copy_exit_status=$?\n'
342 >           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
343 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
344 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
345 >           txt += '            echo "Problems with SE = $SE"\n'
346 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
347 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
348 >           txt += '        else\n'
349 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
350 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
351 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
352 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
353 >           txt += '         fi\n'
354 >           txt += '     done\n'
355 >           txt += 'fi\n'
356          return txt
357  
358      def wsRegisterOutput(self):
# Line 170 | Line 361 | class SchedulerEdg(Scheduler):
361          """
362  
363          txt = ''
364 <        if self.register_data:
364 >        if int(self.register_data) == 1:
365 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
366 >           txt += 'if [ $middleware == OSG ]; then\n'
367 >           txt += '   #\n'
368 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
369 >           txt += '   #\n'
370 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
371 >           txt += 'elif [ $middleware == LCG ]; then \n'
372             txt += '#\n'
373 <           txt += '#  Register output to RLS\n'
373 >           txt += '#  Register output to LFC\n'
374             txt += '#\n'
375 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
376 <           txt += '   for out_file in $file_list ; do\n'
377 <           txt += '      echo "Trying to register the output file into RLS"\n'
378 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
379 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
182 <           txt += '      register_exit_status=$?\n'
183 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
184 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
185 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
186 <           txt += '         echo "Problems with the registration to RLS" \n'
187 <           txt += '         echo "Try with srm protocol" \n'
188 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
189 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
375 >           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
376 >           txt += '      for out_file in $file_list ; do\n'
377 >           txt += '         echo "Trying to register the output file into LFC"\n'
378 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
379 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
380             txt += '         register_exit_status=$?\n'
381             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
382             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
383             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
384 <           txt += '            echo "Problems with the registration into RLS" \n'
384 >           txt += '            echo "Problems with the registration to LFC" \n'
385 >           txt += '            echo "Try with srm protocol" \n'
386 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
387 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
388 >           txt += '            register_exit_status=$?\n'
389 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
390 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
391 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
392 >           txt += '               echo "Problems with the registration into LFC" \n'
393 >           txt += '            fi \n'
394 >           txt += '         else \n'
395 >           txt += '            echo "output registered to LFC"\n'
396             txt += '         fi \n'
397 <           txt += '      else \n'
398 <           txt += '         echo "output registered to RLS"\n'
399 <           txt += '      fi \n'
400 <           txt += '   done\n'
401 <           txt += 'elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
402 <           txt += '   echo "Trying to copy output file to CloseSE"\n'
403 <           txt += '   CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
404 <           txt += '   for out_file in $file_list ; do\n'
405 <           txt += '      echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
406 <           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'
407 <           txt += '      register_exit_status=$?\n'
408 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
409 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
410 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
411 <           txt += '         echo "Problems with CloseSE" \n'
412 <           txt += '      else \n'
413 <           txt += '         echo "The program was successfully executed"\n'
414 <           txt += '         echo "SE = $CLOSE_SE"\n'
415 <           txt += '         echo "LFN for the file is LFN=${LFN}/$out_file"\n'
416 <           txt += '      fi \n'
417 <           txt += '   done\n'
418 <           txt += 'else\n'
419 <           txt += '   echo "Problem with the executable"\n'
397 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
398 >           txt += '      done\n'
399 >           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
400 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
401 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
402 >           txt += '      for out_file in $file_list ; do\n'
403 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
404 >           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'
405 >           txt += '         register_exit_status=$?\n'
406 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
407 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
408 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
409 >           txt += '            echo "Problems with CloseSE" \n'
410 >           txt += '         else \n'
411 >           txt += '            echo "The program was successfully executed"\n'
412 >           txt += '            echo "SE = $CLOSE_SE"\n'
413 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
414 >           txt += '         fi \n'
415 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
416 >           txt += '      done\n'
417 >           txt += '   else\n'
418 >           txt += '      echo "Problem with the executable"\n'
419 >           txt += '   fi \n'
420             txt += 'fi \n'
421          return txt
422  
# Line 224 | Line 425 | class SchedulerEdg(Scheduler):
425          retrieve the logging info from logging and bookkeeping and return it
426          """
427          self.checkProxy()
227      #  id = common.jobDB.jobId(nj)
428          cmd = 'edg-job-get-logging-info -v 2 ' + id
429 <        cmd_out = os.popen(cmd)
430 <      #  cmd_out = runCommand(cmd)
429 >        #cmd_out = os.popen(cmd)
430 >        cmd_out = runCommand(cmd)
431          return cmd_out
432  
433      def listMatch(self, nj):
# Line 237 | Line 437 | class SchedulerEdg(Scheduler):
437          self.checkProxy()
438          jdl = common.job_list[nj].jdlFilename()
439          cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
440 <        myCmd = os.popen(cmd)
441 <        cmd_out = myCmd.readlines()
442 <        myCmd.close()
440 >        cmd_out = runCommand(cmd,0,10)
441 >        if not cmd_out:
442 >            raise CrabException("ERROR: "+cmd+" failed!")
443 >
444          return self.parseListMatch_(cmd_out, jdl)
445  
446      def parseListMatch_(self, out, jdl):
447 <
447 >        """
448 >        Parse the f* output of edg-list-match and produce something sensible
449 >        """
450          reComment = re.compile( r'^\**$' )
451          reEmptyLine = re.compile( r'^$' )
452          reVO = re.compile( r'Selected Virtual Organisation name.*' )
453 <        reCE = re.compile( r'CEId' )
453 >        reLine = re.compile( r'.*')
454 >        reCE = re.compile( r'(.*:.*)')
455 >        reCEId = re.compile( r'CEId.*')
456          reNO = re.compile( r'No Computing Element matching' )
457          reRB = re.compile( r'Connecting to host' )
458          next = 0
459          CEs=[]
460          Match=0
461  
462 <        for line in out:
463 <            line = line.strip()
464 <            if reComment.match( line ):
465 <                next = 0
466 <                continue
467 <            if reEmptyLine.match(line):
468 <                continue
462 >        #print out
463 >        lines = reLine.findall(out)
464 >
465 >        i=0
466 >        CEs=[]
467 >        for line in lines:
468 >            string.strip(line)
469 >            #print line
470 >            if reNO.match( line ):
471 >                common.logger.debug(5,line)
472 >                return 0
473 >                pass
474              if reVO.match( line ):
475 <                VO =line.split()[-1]
476 <                common.logger.debug(5, 'VO           :'+VO)
475 >                VO =reVO.match( line ).group()
476 >                common.logger.debug(5,"VO "+VO)
477                  pass
478 +
479              if reRB.match( line ):
480 <                RB =line.split()[3]
481 <                common.logger.debug(5, 'Using RB     :'+RB)
480 >                RB = reRB.match(line).group()
481 >                common.logger.debug(5,"RB "+RB)
482                  pass
483 <            if reCE.search( line ):
484 <                next = 1
485 <                continue
486 <            if next:
487 <                CE=line.split(':')[0]
488 <                if (CEs.count(CE) > 0):
489 <                   pass
490 <                else:
280 <                   CEs.append(CE)  
281 <                   Match=Match+1
282 <                common.logger.debug(5, 'Matched CE   :'+CE)
283 <                pass
284 <            if reNO.match( line ):
285 <                common.logger.debug(5,line)
286 <                self.noMatchFound_(jdl)
287 <                Match=0
483 >
484 >            if reCEId.search( line ):
485 >                for lineCE in lines[i:-1]:
486 >                    if reCE.match( lineCE ):
487 >                        CE = string.strip(reCE.search(lineCE).group(1))
488 >                        CEs.append(CE.split(':')[0])
489 >                        pass
490 >                    pass
491                  pass
492 <        return Match
492 >            i=i+1
493 >            pass
494 >
495 >        common.logger.debug(5,"All CE :"+str(CEs))
496 >
497 >        sites = []
498 >        [sites.append(it) for it in CEs if not sites.count(it)]
499 >
500 >        common.logger.debug(5,"All Sites :"+str(sites))
501 >        common.logger.message("Matched Sites :"+str(sites))
502 >        return len(sites)
503  
504      def noMatchFound_(self, jdl):
505          reReq = re.compile( r'Requirements' )
# Line 324 | Line 537 | class SchedulerEdg(Scheduler):
537              pass
538          return jid
539  
540 +    def resubmit(self, nj_list):
541 +        """
542 +        Prepare jobs to be submit
543 +        """
544 +        return
545 +
546      def getExitStatus(self, id):
547          return self.getStatusAttribute_(id, 'exit_code')
548  
# Line 349 | Line 568 | class SchedulerEdg(Scheduler):
568          jobStat.getStatus(id, level)
569          err, apiMsg = jobStat.get_error()
570          if err:
352            #print 'Error caught', apiMsg
353            #common.log.message(apiMsg)
571              common.logger.debug(5,'Error caught' + apiMsg)
572              return None
573          else:
# Line 378 | Line 595 | class SchedulerEdg(Scheduler):
595  
596          # Determine the output directory name
597          dir = common.work_space.resDir()
598 <        dir += os.getlogin()
598 >        dir += os.environ['USER']
599          dir += '_' + os.path.basename(id)
600          return dir
601  
# Line 418 | Line 635 | class SchedulerEdg(Scheduler):
635          jdl.write(jt_string)
636  
637          ### only one .sh  JDL has arguments:
421        firstEvent = common.jobDB.firstEvent(nj)
422        maxEvents = common.jobDB.maxEvents(nj)
423        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
638  
639 +        ### Fabio
640 +        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
641          inp_box = 'InputSandbox = { '
642          inp_box = inp_box + '"' + script + '",'
643  
# Line 434 | Line 650 | class SchedulerEdg(Scheduler):
650          #if common.use_jam:
651          #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
652  
653 <        for addFile in jbt.additional_inbox_files:
654 <            addFile = os.path.abspath(addFile)
655 <            inp_box = inp_box+' "'+addFile+'",'
656 <            pass
653 >        # Marco (VERY TEMPORARY ML STUFF)
654 >        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
655 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
656 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
657 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
658 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
659 >        # End Marco
660 >
661 >        if (not jbt.additional_inbox_files == []):
662 >            inp_box = inp_box + ', '
663 >            for addFile in jbt.additional_inbox_files:
664 >                addFile = os.path.abspath(addFile)
665 >                inp_box = inp_box+' "'+addFile+'",'
666 >                pass
667  
668          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
669          inp_box = inp_box + ' };\n'
# Line 455 | Line 681 | class SchedulerEdg(Scheduler):
681                      job.stdout() + '", "' + \
682                      job.stderr() + '", ".BrokerInfo",'
683  
684 <        if self.return_data :
684 >        if int(self.return_data) == 1:
685              if out_sandbox != None:
686                  for fl in out_sandbox:
687                      out_box = out_box + ' "' + fl + '",'
# Line 467 | Line 693 | class SchedulerEdg(Scheduler):
693          out_box = out_box + ' };'
694          jdl.write(out_box+'\n')
695  
470        ### if at least a CE exists ...
471        if common.analisys_common_info['sites']:
472            if common.analisys_common_info['sw_version']:
473                req='Requirements = '
474                req=req + 'Member("VO-cms-' + \
475                     common.analisys_common_info['sw_version'] + \
476                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
477            if len(common.analisys_common_info['sites'])>0:
478                req = req + ' && ('
479                for i in range(len(common.analisys_common_info['sites'])):
480                    req = req + 'other.GlueCEInfoHostName == "' \
481                         + common.analisys_common_info['sites'][i] + '"'
482                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
483                        req = req + ' || '
484            req = req + ')'
696  
697 <            #### and USER REQUIREMENT
698 <            if self.EDG_requirements:
697 >        req='Requirements = '
698 >        req = req + jbt.getRequirements()
699 > #        ### if at least a CE exists ...
700 > #        if common.analisys_common_info['sites']:
701 > #           if common.analisys_common_info['sw_version']:
702 > #                req='Requirements = '
703 > #                req=req + 'Member("VO-cms-' + \
704 > #                     common.analisys_common_info['sw_version'] + \
705 > #                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
706 > #            if len(common.analisys_common_info['sites'])>0:
707 > #                req = req + ' && ('
708 > #                for i in range(len(common.analisys_common_info['sites'])):
709 > #                    req = req + 'other.GlueCEInfoHostName == "' \
710 > #                         + common.analisys_common_info['sites'][i] + '"'
711 > #                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
712 > #                        req = req + ' || '
713 > #            req = req + ')'
714 >        #### and USER REQUIREMENT
715 >        if self.EDG_requirements:
716 >            if (req == 'Requirement = '):
717 >                req = req + self.EDG_requirements
718 >            else:
719                  req = req +  ' && ' + self.EDG_requirements
720 <            if self.EDG_clock_time:
720 >        #### FEDE #####
721 >        if self.EDG_ce_white_list:
722 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
723 >            #print "req = ", req
724 >            for i in range(len(ce_white_list)):
725 >                if i == 0:
726 >                    if (req == 'Requirement = '):
727 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
728 >                    else:
729 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
730 >                    pass
731 >                else:
732 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
733 >            req = req + ')'
734 >        
735 >        if self.EDG_ce_black_list:
736 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
737 >            for ce in ce_black_list:
738 >                if (req == 'Requirement = '):
739 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
740 >                else:
741 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
742 >                pass
743 >        ###############
744 >        if self.EDG_clock_time:
745 >            if (req == 'Requirement = '):
746 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
747 >            else:
748                  req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
749 <            if self.EDG_cpu_time:
749 >
750 >        if self.EDG_cpu_time:
751 >            if (req == 'Requirement = '):
752 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
753 >            else:
754                  req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
755 +        if (req != 'Requirement = '):
756              req = req + ';\n'
757              jdl.write(req)
758                                                                                                                                                              
# Line 499 | Line 762 | class SchedulerEdg(Scheduler):
762              jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
763              pass
764  
765 +        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
766 +
767          jdl.close()
768          return
769  
# Line 508 | Line 773 | class SchedulerEdg(Scheduler):
773          """
774          if (self.proxyValid): return
775          timeleft = -999
776 <        minTimeLeft=10 # in hours
777 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
778 <        try: cmd_out = runCommand(cmd,0)
779 <        except: print cmd_out
780 <        if (cmd_out == None or cmd_out=='1'):
781 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
782 <            cmd = 'grid-proxy-init -valid 100:00'
776 >        minTimeLeft=10*3600 # in seconds
777 >
778 >        minTimeLeftServer = 100 # in hours
779 >
780 >        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
781 >        #cmd = 'voms-proxy-info -timeleft'
782 >        mustRenew = 0
783 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
784 >        timeLeftServer = -999
785 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
786 >            mustRenew = 1
787 >        else:
788 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
789 >            if not timeLeftServer or not isInt(timeLeftServer):
790 >                mustRenew = 1
791 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
792 >                mustRenew = 1
793 >            pass
794 >        pass
795 >
796 >        if mustRenew:
797 >            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")
798 >            cmd = 'voms-proxy-init -voms cms -valid 96:00'
799              try:
800 +                # SL as above: damn it!
801                  out = os.system(cmd)
802                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
803              except:
804                  msg = "Unable to create a valid proxy!\n"
805                  raise CrabException(msg)
806 <            cmd = 'grid-proxy-info -timeleft'
807 <            cmd_out = runCommand(cmd,0)
808 <            #print cmd_out, time.time()
809 <            #time.time(cms_out)
806 >            # cmd = 'grid-proxy-info -timeleft'
807 >            # cmd_out = runCommand(cmd,0,20)
808 >            pass
809 >
810 >        ## now I do have a voms proxy valid, and I check the myproxy server
811 >        renewProxy = 0
812 >        cmd = 'myproxy-info -d -s '+self.proxyServer
813 >        cmd_out = runCommand(cmd,0,20)
814 >        if not cmd_out:
815 >            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
816 >            renewProxy = 1
817 >        else:
818 >            # if myproxy exist but not long enough, renew
819 >            reTime = re.compile( r'timeleft: (\d+)' )
820 >            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
821 >            if reTime.match( cmd_out ):
822 >                time = reTime.search( line ).group(1)
823 >                if time < minTimeLeftServer:
824 >                    renewProxy = 1
825 >                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
826 >                pass
827              pass
828 +        
829 +        # if not, create one.
830 +        if renewProxy:
831 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
832 +            out = os.system(cmd)
833 +            if (out>0):
834 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
835 +            pass
836 +
837 +        # cache proxy validity
838          self.proxyValid=1
839          return
840 <    
840 >
841      def configOpt_(self):
842          edg_ui_cfg_opt = ' '
843          if self.edg_config:
844 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
844 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
845          if self.edg_config_vo:
846 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
846 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
847          return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines