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.19 by slacapra, Tue Oct 18 14:11:12 2005 UTC vs.
Revision 1.60 by gutsche, Tue Jun 13 20:43:39 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 +        self._taskId = cfg_params['taskId']
157 +
158          return
159      
160  
# Line 113 | Line 177 | class SchedulerEdg(Scheduler):
177          """
178          Returns part of a job script which does scheduler-specific work.
179          """
116
180          txt = ''
181 <        if self.copy_data:
181 >        txt += "# job number (first parameter for job wrapper)\n"
182 >        txt += "NJob=$1\n"
183 >
184 >        txt += '# job identification to DashBoard \n'
185 >        txt += 'echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo \n'
186 >        txt += 'echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo \n'
187 >        txt += 'echo "MonitorID=`echo ' + self._taskId + '`" | tee -a $RUNTIME_AREA/$repo\n'
188 >
189 >        txt += 'echo "middleware discovery " \n'
190 >        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
191 >        txt += '    middleware=LCG \n'
192 >        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
193 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
194 >        txt += '    echo "middleware =$middleware" \n'
195 >        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
196 >        txt += '    middleware=OSG \n'
197 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
198 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
199 >        txt += '    echo "middleware =$middleware" \n'
200 >        txt += 'elif [ $OSG_APP ]; then \n'
201 >        txt += '    middleware=OSG \n'
202 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
203 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
204 >        txt += '    echo "middleware =$middleware" \n'
205 >        txt += 'else \n'
206 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
207 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
208 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
209 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
210 >        txt += '    exit 1 \n'
211 >        txt += 'fi \n'
212 >
213 >        txt += '# report first time to DashBoard \n'
214 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
215 >
216 >        txt += '\n\n'
217 >
218 >        if int(self.copy_data) == 1:
219             if self.SE:
220                txt += 'export SE='+self.SE+'\n'
221                txt += 'echo "SE = $SE"\n'
# Line 123 | Line 223 | class SchedulerEdg(Scheduler):
223                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
224                txt += 'export SE_PATH='+self.SE_PATH+'\n'
225                txt += 'echo "SE_PATH = $SE_PATH"\n'
226 <                                                                                                                                                            
227 <        if self.register_data:
226 >
227 >        txt += 'export VO='+self.VO+'\n'
228 >        ### FEDE: add some line for LFC catalog setting
229 >        txt += 'if [ $middleware == LCG ]; then \n'
230 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
231 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
232 >        txt += '    fi\n'
233 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
234 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
235 >        txt += '    fi\n'
236 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
237 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
238 >        txt += '    fi\n'
239 >        txt += 'elif [ $middleware == OSG ]; then\n'
240 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
241 >        txt += 'fi\n'
242 >        #####
243 >        if int(self.register_data) == 1:
244 >           txt += 'if [ $middleware == LCG ]; then \n'
245 >           txt += '    export LFN='+self.LFN+'\n'
246 >           txt += '    lfc-ls $LFN\n'
247 >           txt += '    result=$?\n'
248 >           txt += '    echo $result\n'
249 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
250 >           txt += '    if [ $result != 0 ]; then\n'
251 >           txt += '       lfc-mkdir $LFN\n'
252 >           txt += '       result=$?\n'
253 >           txt += '       echo $result\n'
254 >           txt += '    fi\n'
255 >           txt += 'elif [ $middleware == OSG ]; then\n'
256 >           txt += '    echo " Files registration to be implemented for OSG"\n'
257 >           txt += 'fi\n'
258 >           txt += '\n'
259 >
260             if self.VO:
261                txt += 'export VO='+self.VO+'\n'
262             if self.LFN:
263 <              txt += 'export LFN='+self.LFN+'\n'
263 >              txt += 'if [ $middleware == LCG ]; then \n'
264 >              txt += '    export LFN='+self.LFN+'\n'
265 >              txt += 'fi\n'
266                txt += '\n'
267 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
268 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
269 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
270 <        txt += 'echo "CE = $CE"\n'
267 >
268 >        txt += 'if [ $middleware == LCG ]; then\n'
269 >        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
270 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
271 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
272 >        txt += '    echo "CE = $CE"\n'
273 >        txt += 'elif [ $middleware == OSG ]; then \n'
274 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
275 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
276 >        txt += '    else \n'
277 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
278 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
279 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
280 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
281 >        txt += '        exit 1 \n'
282 >        txt += '    fi \n'
283 >        txt += 'fi \n'
284 >
285 >        return txt
286 >
287 >    def wsCopyInput(self):
288 >        """
289 >        Copy input data from SE to WN    
290 >        """
291 >        txt = ''
292 >        try:
293 >            self.copy_input_data = common.analisys_common_info['copy_input_data']
294 >            #print "self.copy_input_data = ", self.copy_input_data
295 >        except KeyError: self.copy_input_data = 0
296 >        if int(self.copy_input_data) == 1:
297 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
298 >           txt += 'if [ $middleware == OSG ]; then\n'
299 >           txt += '   #\n'
300 >           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
301 >           txt += '   #\n'
302 >           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
303 >           txt += 'elif [ $middleware == LCG ]; then \n'
304 >           txt += '   #\n'
305 >           txt += '   #   Copy Input Data from SE to this WN\n'
306 >           txt += '   #\n'
307 > ### changed by georgia (put a loop copying more than one input files per jobs)          
308 >           txt += '   for input_file in $cur_file_list \n'
309 >           txt += '   do \n'
310 >           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
311 >           txt += '    copy_input_exit_status=$?\n'
312 >           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
313 >           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
314 >           txt += '       echo "Problems with copying to WN" \n'
315 >           txt += '    else \n'
316 >           txt += '       echo "input copied into WN" \n'
317 >           txt += '    fi \n'
318 >           txt += '   done \n'
319 > ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
320 >           txt += '   for file in $cur_pu_list \n'
321 >           txt += '   do \n'
322 >           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
323 >           txt += '    copy_input_exit_status=$?\n'
324 >           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
325 >           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
326 >           txt += '       echo "Problems with copying pu to WN" \n'
327 >           txt += '    else \n'
328 >           txt += '       echo "input pu files copied into WN" \n'
329 >           txt += '    fi \n'
330 >           txt += '   done \n'
331 >           txt += '   \n'
332 >           txt += '   ### Check SCRATCH space available on WN : \n'
333 >           txt += '   df -h \n'
334 >           txt += 'fi \n'
335 >          
336          return txt
337  
338      def wsCopyOutput(self):
# Line 142 | Line 341 | class SchedulerEdg(Scheduler):
341          to copy produced output into a storage element.
342          """
343          txt = ''
344 <        if self.copy_data:
146 <           copy = 'globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file'
344 >        if int(self.copy_data) == 1:
345             txt += '#\n'
346             txt += '#   Copy output to SE = $SE\n'
347             txt += '#\n'
150           #### per orca l'exit_status non e' affidabile.....
151           #txt += 'if [ $executable_exit_status -eq 0 ]; then\n'
348             txt += 'if [ $exe_result -eq 0 ]; then\n'
349 <           txt += '  for out_file in $file_list ; do\n'
350 <           txt += '    echo "Trying to copy output file to $SE "\n'
351 <           txt += '    echo "'+copy+'"\n'
352 <           txt += '    '+copy+' 2>&1\n'
353 <           txt += '    copy_exit_status=$?\n'
354 <           txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
355 <           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
356 <           txt += '    if [ $copy_exit_status -ne 0 ]; then \n'
357 <           txt += '       echo "Problems with SE= $SE" \n'
358 <           txt += '    else \n'
359 <           txt += '       echo "output copied into $SE/$SE_PATH directory"\n'
360 <           txt += '    fi \n'
361 <           txt += '  done\n'
362 <           txt += 'fi \n'
349 >           txt += '    for out_file in $file_list ; do\n'
350 >           txt += '        echo "Trying to copy output file to $SE "\n'
351 >           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
352 >           txt += '        if [ $middleware == OSG ]; then\n'
353 >           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
354 >           txt += '           copy_exit_status=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
355 >           #txt += '           exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
356 >           txt += '        elif [ $middleware == LCG ]; then \n'
357 >           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
358 >           txt += '           copy_exit_status=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
359 >           #txt += '           exitstring=`lcg-cp --vo cms -t 30 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
360 >           txt += '        fi \n'
361 >           #txt += '        copy_exit_status=$?\n'
362 >           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
363 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
364 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
365 >           txt += '            echo "Problems with SE = $SE"\n'
366 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
367 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
368 >           txt += '        else\n'
369 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
370 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
371 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
372 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
373 >           txt += '         fi\n'
374 >           txt += '     done\n'
375 >           txt += 'fi\n'
376          return txt
377  
378      def wsRegisterOutput(self):
# Line 172 | Line 381 | class SchedulerEdg(Scheduler):
381          """
382  
383          txt = ''
384 <        if self.register_data:
384 >        if int(self.register_data) == 1:
385 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
386 >           txt += 'if [ $middleware == OSG ]; then\n'
387 >           txt += '   #\n'
388 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
389 >           txt += '   #\n'
390 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
391 >           txt += 'elif [ $middleware == LCG ]; then \n'
392             txt += '#\n'
393 <           txt += '#  Register output to RLS\n'
393 >           txt += '#  Register output to LFC\n'
394             txt += '#\n'
395 <           ### analogo
396 <           #txt += 'if [[ $executable_exit_status -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
397 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
398 <           txt += '   for out_file in $file_list ; do\n'
399 <           txt += '      echo "Trying to register the output file into RLS"\n'
400 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
401 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
402 <           txt += '      register_exit_status=$?\n'
403 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
404 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
405 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
406 <           txt += '         echo "Problems with the registration to RLS" \n'
407 <           txt += '         echo "Try with srm protocol" \n'
408 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
409 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
395 >           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
396 >           txt += '      for out_file in $file_list ; do\n'
397 >           txt += '         echo "Trying to register the output file into LFC"\n'
398 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
399 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
400 >           txt += '         register_exit_status=$?\n'
401 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
402 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
403 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
404 >           txt += '            echo "Problems with the registration to LFC" \n'
405 >           txt += '            echo "Try with srm protocol" \n'
406 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
407 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
408 >           txt += '            register_exit_status=$?\n'
409 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
410 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
411 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
412 >           txt += '               echo "Problems with the registration into LFC" \n'
413 >           txt += '            fi \n'
414 >           txt += '         else \n'
415 >           txt += '            echo "output registered to LFC"\n'
416 >           txt += '         fi \n'
417 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
418 >           txt += '      done\n'
419 >           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
420 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
421 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
422 >           txt += '      for out_file in $file_list ; do\n'
423 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
424 >           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'
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 RLS" \n'
429 >           txt += '            echo "Problems with CloseSE" \n'
430 >           txt += '         else \n'
431 >           txt += '            echo "The program was successfully executed"\n'
432 >           txt += '            echo "SE = $CLOSE_SE"\n'
433 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
434             txt += '         fi \n'
435 <           txt += '      else \n'
436 <           txt += '         echo "output registered to RLS"\n'
437 <           txt += '      fi \n'
438 <           txt += '   done\n'
439 <           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'
435 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
436 >           txt += '      done\n'
437 >           txt += '   else\n'
438 >           txt += '      echo "Problem with the executable"\n'
439 >           txt += '   fi \n'
440             txt += 'fi \n'
441          return txt
225        #####################
442  
443 <    def loggingInfo(self, nj):
443 >    def loggingInfo(self, id):
444          """
445          retrieve the logging info from logging and bookkeeping and return it
446          """
447          self.checkProxy()
448 <        id = common.jobDB.jobId(nj)
449 <        cmd = 'edg-job-get-logging-info -v 2 ' + self.configOpt_() + id
450 <        myCmd = os.popen(cmd)
235 <        cmd_out = myCmd.readlines()
236 <        myCmd.close()
448 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
449 >        #cmd_out = os.popen(cmd)
450 >        cmd_out = runCommand(cmd)
451          return cmd_out
452  
453      def listMatch(self, nj):
# Line 243 | Line 457 | class SchedulerEdg(Scheduler):
457          self.checkProxy()
458          jdl = common.job_list[nj].jdlFilename()
459          cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
460 <        myCmd = os.popen(cmd)
461 <        cmd_out = myCmd.readlines()
462 <        myCmd.close()
460 >        cmd_out = runCommand(cmd,0,10)
461 >        if not cmd_out:
462 >            raise CrabException("ERROR: "+cmd+" failed!")
463 >
464          return self.parseListMatch_(cmd_out, jdl)
465  
466      def parseListMatch_(self, out, jdl):
467 +        """
468 +        Parse the f* output of edg-list-match and produce something sensible
469 +        """
470          reComment = re.compile( r'^\**$' )
471          reEmptyLine = re.compile( r'^$' )
472          reVO = re.compile( r'Selected Virtual Organisation name.*' )
473 <        reCE = re.compile( r'CEId' )
473 >        reLine = re.compile( r'.*')
474 >        reCE = re.compile( r'(.*:.*)')
475 >        reCEId = re.compile( r'CEId.*')
476          reNO = re.compile( r'No Computing Element matching' )
477          reRB = re.compile( r'Connecting to host' )
478          next = 0
479          CEs=[]
480          Match=0
481 <        for line in out:
482 <            line = line.strip()
483 <            if reComment.match( line ):
484 <                next = 0
485 <                continue
486 <            if reEmptyLine.match(line):
487 <                continue
481 >
482 >        #print out
483 >        lines = reLine.findall(out)
484 >
485 >        i=0
486 >        CEs=[]
487 >        for line in lines:
488 >            string.strip(line)
489 >            #print line
490 >            if reNO.match( line ):
491 >                common.logger.debug(5,line)
492 >                return 0
493 >                pass
494              if reVO.match( line ):
495 <                VO =line.split()[-1]
496 <                common.logger.debug(5, 'VO           :'+VO)
495 >                VO =reVO.match( line ).group()
496 >                common.logger.debug(5,"VO "+VO)
497                  pass
498 +
499              if reRB.match( line ):
500 <                RB =line.split()[3]
501 <                common.logger.debug(5, 'Using RB     :'+RB)
500 >                RB = reRB.match(line).group()
501 >                common.logger.debug(5,"RB "+RB)
502                  pass
503 <            if reCE.search( line ):
504 <                next = 1
505 <                continue
506 <            if next:
507 <                CE=line.split(':')[0]
508 <                CEs.append(CE)
509 <                common.logger.debug(5, 'Matched CE   :'+CE)
510 <                Match=Match+1
284 <                pass
285 <            if reNO.match( line ):
286 <                common.logger.debug(5,line)
287 <                self.noMatchFound_(jdl)
288 <                Match=0
503 >
504 >            if reCEId.search( line ):
505 >                for lineCE in lines[i:-1]:
506 >                    if reCE.match( lineCE ):
507 >                        CE = string.strip(reCE.search(lineCE).group(1))
508 >                        CEs.append(CE.split(':')[0])
509 >                        pass
510 >                    pass
511                  pass
512 <        return Match
512 >            i=i+1
513 >            pass
514 >
515 >        common.logger.debug(5,"All CE :"+str(CEs))
516 >
517 >        sites = []
518 >        [sites.append(it) for it in CEs if not sites.count(it)]
519 >
520 >        common.logger.debug(5,"All Sites :"+str(sites))
521 >        common.logger.message("Matched Sites :"+str(sites))
522 >        return len(sites)
523  
524      def noMatchFound_(self, jdl):
525          reReq = re.compile( r'Requirements' )
# Line 321 | Line 553 | class SchedulerEdg(Scheduler):
553          cmd_out = runCommand(cmd)
554          if cmd_out != None:
555              reSid = re.compile( r'https.+' )
556 <            jid = reSid.search(cmd).group()
556 >            jid = reSid.search(cmd_out).group()
557              pass
558          return jid
559  
560 +    def resubmit(self, nj_list):
561 +        """
562 +        Prepare jobs to be submit
563 +        """
564 +        return
565 +
566      def getExitStatus(self, id):
567          return self.getStatusAttribute_(id, 'exit_code')
568  
# Line 350 | Line 588 | class SchedulerEdg(Scheduler):
588          jobStat.getStatus(id, level)
589          err, apiMsg = jobStat.get_error()
590          if err:
591 <            print 'Error caught', apiMsg
354 <            common.log.message(apiMsg)
591 >            common.logger.debug(5,'Error caught' + apiMsg)
592              return None
593          else:
594              for i in range(len(self.states)):
# Line 378 | Line 615 | class SchedulerEdg(Scheduler):
615  
616          # Determine the output directory name
617          dir = common.work_space.resDir()
618 <        dir += os.getlogin()
618 >        dir += os.environ['USER']
619          dir += '_' + os.path.basename(id)
620          return dir
621  
# Line 418 | Line 655 | class SchedulerEdg(Scheduler):
655          jdl.write(jt_string)
656  
657          ### 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')
658  
659 +        ### Fabio
660 +        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
661          inp_box = 'InputSandbox = { '
662          inp_box = inp_box + '"' + script + '",'
663  
# Line 434 | Line 670 | class SchedulerEdg(Scheduler):
670          #if common.use_jam:
671          #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
672  
673 <        for addFile in jbt.additional_inbox_files:
674 <            addFile = os.path.abspath(addFile)
675 <            inp_box = inp_box+' "'+addFile+'",'
676 <            pass
673 >        # Marco (VERY TEMPORARY ML STUFF)
674 >        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
675 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
676 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
677 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
678 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
679 >        # End Marco
680 >
681 >        if (not jbt.additional_inbox_files == []):
682 >            inp_box = inp_box + ', '
683 >            for addFile in jbt.additional_inbox_files:
684 >                addFile = os.path.abspath(addFile)
685 >                inp_box = inp_box+' "'+addFile+'",'
686 >                pass
687  
688          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
689          inp_box = inp_box + ' };\n'
# Line 455 | Line 701 | class SchedulerEdg(Scheduler):
701                      job.stdout() + '", "' + \
702                      job.stderr() + '", ".BrokerInfo",'
703  
704 <        if self.return_data :
704 >        if int(self.return_data) == 1:
705              if out_sandbox != None:
706                  for fl in out_sandbox:
707                      out_box = out_box + ' "' + fl + '",'
# Line 467 | Line 713 | class SchedulerEdg(Scheduler):
713          out_box = out_box + ' };'
714          jdl.write(out_box+'\n')
715  
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 + ')'
716  
717 <            #### and USER REQUIREMENT
718 <            if self.EDG_requirements:
717 >        req='Requirements = '
718 >        req = req + jbt.getRequirements()
719 > #        ### if at least a CE exists ...
720 > #        if common.analisys_common_info['sites']:
721 > #           if common.analisys_common_info['sw_version']:
722 > #                req='Requirements = '
723 > #                req=req + 'Member("VO-cms-' + \
724 > #                     common.analisys_common_info['sw_version'] + \
725 > #                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
726 > #            if len(common.analisys_common_info['sites'])>0:
727 > #                req = req + ' && ('
728 > #                for i in range(len(common.analisys_common_info['sites'])):
729 > #                    req = req + 'other.GlueCEInfoHostName == "' \
730 > #                         + common.analisys_common_info['sites'][i] + '"'
731 > #                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
732 > #                        req = req + ' || '
733 > #            req = req + ')'
734 >        #### and USER REQUIREMENT
735 >        if self.EDG_requirements:
736 >            if (req == 'Requirement = '):
737 >                req = req + self.EDG_requirements
738 >            else:
739                  req = req +  ' && ' + self.EDG_requirements
740 <            if self.EDG_clock_time:
741 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
742 <            if self.EDG_cpu_time:
743 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
740 >        #### FEDE #####
741 >        if self.EDG_ce_white_list:
742 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
743 >            #print "req = ", req
744 >            for i in range(len(ce_white_list)):
745 >                if i == 0:
746 >                    if (req == 'Requirement = '):
747 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
748 >                    else:
749 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
750 >                    pass
751 >                else:
752 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
753 >            req = req + ')'
754 >        
755 >        if self.EDG_ce_black_list:
756 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
757 >            for ce in ce_black_list:
758 >                if (req == 'Requirement = '):
759 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
760 >                else:
761 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
762 >                pass
763 >        ###############
764 >        if self.EDG_clock_time:
765 >            if (req == 'Requirement = '):
766 >                req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time+'))'
767 >            else:
768 >                req = req + ' && ((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time+'))'
769 >        else:
770 >            if (req == 'Requirement = '):
771 >                req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>=480))'
772 >            else:
773 >                req = req + ' && ((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>=480))'
774 >
775 >        if self.EDG_cpu_time:
776 >            if (req == 'Requirement = '):
777 >                req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+self.EDG_clock_time+'))'
778 >            else:
779 >                req = req + ' && ((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+self.EDG_clock_time+'))'
780 >        else:
781 >            if (req == 'Requirement = '):
782 >                req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>=1000))'
783 >            else:
784 >                req = req + ' && ((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>=1000))'
785 >
786 >        if (req != 'Requirement = '):
787              req = req + ';\n'
788              jdl.write(req)
789                                                                                                                                                              
# Line 499 | Line 793 | class SchedulerEdg(Scheduler):
793              jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
794              pass
795  
796 +        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
797 +
798          jdl.close()
799          return
800  
# Line 508 | Line 804 | class SchedulerEdg(Scheduler):
804          """
805          if (self.proxyValid): return
806          timeleft = -999
807 <        minTimeLeft=10 # in hours
808 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
809 <        try: cmd_out = runCommand(cmd,0)
810 <        except: print cmd_out
811 <        if (cmd_out == None or cmd_out=='1'):
812 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
813 <            cmd = 'grid-proxy-init -valid 100:00'
807 >        minTimeLeft=10*3600 # in seconds
808 >
809 >        minTimeLeftServer = 100 # in hours
810 >
811 >        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
812 >        #cmd = 'voms-proxy-info -timeleft'
813 >        mustRenew = 0
814 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
815 >        timeLeftServer = -999
816 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
817 >            mustRenew = 1
818 >        else:
819 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
820 >            if not timeLeftServer or not isInt(timeLeftServer):
821 >                mustRenew = 1
822 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
823 >                mustRenew = 1
824 >            pass
825 >        pass
826 >
827 >        if mustRenew:
828 >            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")
829 >            cmd = 'voms-proxy-init -voms cms -valid 96:00'
830              try:
831 +                # SL as above: damn it!
832                  out = os.system(cmd)
833                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
834              except:
835                  msg = "Unable to create a valid proxy!\n"
836                  raise CrabException(msg)
837 <            cmd = 'grid-proxy-info -timeleft'
838 <            cmd_out = runCommand(cmd,0)
839 <            print cmd_out, time.time()
840 <            #time.time(cms_out)
837 >            # cmd = 'grid-proxy-info -timeleft'
838 >            # cmd_out = runCommand(cmd,0,20)
839 >            pass
840 >
841 >        ## now I do have a voms proxy valid, and I check the myproxy server
842 >        renewProxy = 0
843 >        cmd = 'myproxy-info -d -s '+self.proxyServer
844 >        cmd_out = runCommand(cmd,0,20)
845 >        if not cmd_out:
846 >            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
847 >            renewProxy = 1
848 >        else:
849 >            # if myproxy exist but not long enough, renew
850 >            reTime = re.compile( r'timeleft: (\d+)' )
851 >            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
852 >            if reTime.match( cmd_out ):
853 >                time = reTime.search( line ).group(1)
854 >                if time < minTimeLeftServer:
855 >                    renewProxy = 1
856 >                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
857 >                pass
858 >            pass
859 >        
860 >        # if not, create one.
861 >        if renewProxy:
862 >            cmd = 'myproxy-init -d -n -s '+self.proxyServer
863 >            out = os.system(cmd)
864 >            if (out>0):
865 >                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
866              pass
867 +
868 +        # cache proxy validity
869          self.proxyValid=1
870          return
871 <    
871 >
872      def configOpt_(self):
873          edg_ui_cfg_opt = ' '
874          if self.edg_config:
875 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
875 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
876          if self.edg_config_vo:
877 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
877 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
878          return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines