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.64 by gutsche, Tue Jun 27 02:31:31 2006 UTC vs.
Revision 1.85 by gutsche, Wed Sep 27 16:17:07 2006 UTC

# Line 37 | Line 37 | class SchedulerEdg(Scheduler):
37              self.proxyServer = 'myproxy.cern.ch'
38          common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
39  
40 +        try:
41 +            self.role = cfg_params["EDG.role"]
42 +        except KeyError:
43 +            self.role = None
44 +            
45          try: self.LCG_version = cfg_params["EDG.lcg_version"]
46          except KeyError: self.LCG_version = '2'
47  
# Line 158 | Line 163 | class SchedulerEdg(Scheduler):
163          except:
164              self._taskId = ''
165  
166 +        try: self.jobtypeName = cfg_params['CRAB.jobtype']
167 +        except KeyError: self.jobtypeName = ''
168 +
169 +        try: self.schedulerName = cfg_params['CRAB.scheduler']
170 +        except KeyError: self.scheduler = ''
171 +
172          return
173      
174  
# Line 181 | Line 192 | class SchedulerEdg(Scheduler):
192          Returns part of a job script which does scheduler-specific work.
193          """
194          txt = ''
195 +        txt += '# strip arguments\n'
196 +        txt += 'echo "strip arguments"\n'
197 +        txt += 'args=("$@")\n'
198 +        txt += 'nargs=$#\n'
199 +        txt += 'shift $nargs\n'
200          txt += "# job number (first parameter for job wrapper)\n"
201 <        txt += "NJob=$1\n"
201 >        #txt += "NJob=$1\n"
202 >        txt += "NJob=${args[0]}\n"
203  
204          txt += '# job identification to DashBoard \n'
205          txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
# Line 193 | Line 210 | class SchedulerEdg(Scheduler):
210          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
211  
212          txt += 'echo "middleware discovery " \n'
213 <        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'
213 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
214          txt += '    middleware=OSG \n'
215          txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
216          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
# Line 208 | Line 220 | class SchedulerEdg(Scheduler):
220          txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
221          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
222          txt += '    echo "middleware =$middleware" \n'
223 +        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
224 +        txt += '    middleware=LCG \n'
225 +        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
226 +        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
227 +        txt += '    echo "middleware =$middleware" \n'
228          txt += 'else \n'
229          txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
230          txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
# Line 215 | Line 232 | class SchedulerEdg(Scheduler):
232          txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
233          txt += '    rm -f $RUNTIME_AREA/$repo \n'
234          txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
218        txt += '    echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
235          txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
236          txt += '    exit 1 \n'
237          txt += 'fi \n'
# Line 224 | Line 240 | class SchedulerEdg(Scheduler):
240          txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
241          txt += 'rm -f $RUNTIME_AREA/$repo \n'
242          txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
227        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
243          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
244          
245          txt += '\n\n'
# Line 294 | Line 309 | class SchedulerEdg(Scheduler):
309          txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
310          txt += '        rm -f $RUNTIME_AREA/$repo \n'
311          txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
297        txt += '        echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
312          txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
313          txt += '        exit 1 \n'
314          txt += '    fi \n'
# Line 309 | Line 323 | class SchedulerEdg(Scheduler):
323          txt = ''
324          try:
325              self.copy_input_data = common.analisys_common_info['copy_input_data']
312            #print "self.copy_input_data = ", self.copy_input_data
326          except KeyError: self.copy_input_data = 0
327          if int(self.copy_input_data) == 1:
328          ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
# Line 322 | Line 335 | class SchedulerEdg(Scheduler):
335             txt += '   #\n'
336             txt += '   #   Copy Input Data from SE to this WN\n'
337             txt += '   #\n'
338 < ### changed by georgia (put a loop copying more than one input files per jobs)          
338 >           ### changed by georgia (put a loop copying more than one input files per jobs)          
339             txt += '   for input_file in $cur_file_list \n'
340             txt += '   do \n'
341 <           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
342 <           txt += '    copy_input_exit_status=$?\n'
343 <           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
344 <           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
345 <           txt += '       echo "Problems with copying to WN" \n'
346 <           txt += '    else \n'
347 <           txt += '       echo "input copied into WN" \n'
348 <           txt += '    fi \n'
341 >           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
342 >           txt += '      copy_input_exit_status=$?\n'
343 >           txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
344 >           txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
345 >           txt += '         echo "Problems with copying to WN" \n'
346 >           txt += '      else \n'
347 >           txt += '         echo "input copied into WN" \n'
348 >           txt += '      fi \n'
349             txt += '   done \n'
350 < ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
350 >           ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
351             txt += '   for file in $cur_pu_list \n'
352             txt += '   do \n'
353 <           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
354 <           txt += '    copy_input_exit_status=$?\n'
355 <           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
356 <           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
357 <           txt += '       echo "Problems with copying pu to WN" \n'
358 <           txt += '    else \n'
359 <           txt += '       echo "input pu files copied into WN" \n'
360 <           txt += '    fi \n'
353 >           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
354 >           txt += '      copy_input_pu_exit_status=$?\n'
355 >           txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
356 >           txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
357 >           txt += '         echo "Problems with copying pu to WN" \n'
358 >           txt += '      else \n'
359 >           txt += '         echo "input pu files copied into WN" \n'
360 >           txt += '      fi \n'
361             txt += '   done \n'
362             txt += '   \n'
363             txt += '   ### Check SCRATCH space available on WN : \n'
# Line 363 | Line 376 | class SchedulerEdg(Scheduler):
376             txt += '#\n'
377             txt += '#   Copy output to SE = $SE\n'
378             txt += '#\n'
379 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
379 >           txt += '    if [ $middleware == OSG ]; then\n'
380 >           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
381 >           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
382 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
383 >           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
384 >           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
385 >           txt += '    fi \n'
386             txt += '    for out_file in $file_list ; do\n'
387 <           txt += '        echo "Trying to copy output file to $SE "\n'
388 <           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
389 <           txt += '        if [ $middleware == OSG ]; then\n'
390 <           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
391 <           txt += '           globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1 \n'
392 <           txt += '           copy_exit_status=$? \n'
393 <           txt += '        elif [ $middleware == LCG ]; then \n'
394 <           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
395 <           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'
387 >           txt += '        echo "Trying to copy output file to $SE using lcg-cp"\n'
388 >           if common.logger.debugLevel() >= 5:
389 >               txt += '        echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
390 >               txt += '        exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
391 >           else:
392 >               txt += '        echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
393 >               txt += '        exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
394 >           txt += '        copy_exit_status=$?\n'
395 >           txt += '        echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
396             txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
397             txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
398 <           txt += '            echo "Problems with SE = $SE"\n'
398 >           txt += '            echo "Possible problem with SE = $SE"\n'
399             txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
400             txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
401 +           txt += '            echo "lcg-cp failed.  For verbose lcg-cp output, use command line option -debug 5."\n'
402 +           txt += '            echo "lcg-cp failed, attempting srmcp"\n'
403 +           txt += '            echo "mkdir -p $HOME/.srmconfig"\n'
404 +           txt += '            mkdir -p $HOME/.srmconfig\n'
405 +           txt += '            if [ $middleware == LCG ]; then\n'
406 +           txt += '               echo "srmcp -retry_num 5 -retry_timeout 480000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
407 +           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 480000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
408 +           txt += '            elif [ $middleware == OSG ]; then\n'
409 +           txt += '               echo "srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
410 +           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
411 +           txt += '            fi \n'
412 +           txt += '            copy_exit_status=$?\n'
413 +           txt += '            echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
414 +           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
415 +           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
416 +           txt += '               echo "Problems with SE = $SE"\n'
417 +           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
418 +           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
419 +           txt += '               echo "lcg-cp and srm failed"\n'
420 +           txt += '               echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
421 +           txt += '            else\n'
422 +           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
423 +           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
424 +           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
425 +           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
426 +           txt += '               echo "srmcp succeeded"\n'
427 +           txt += '            fi\n'
428             txt += '        else\n'
429             txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
430             txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
431             txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
432             txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
433 +           txt += '            echo "lcg-cp succeeded"\n'
434             txt += '         fi\n'
435             txt += '     done\n'
392           txt += 'fi\n'
436          return txt
437  
438      def wsRegisterOutput(self):
# Line 409 | Line 452 | class SchedulerEdg(Scheduler):
452             txt += '#\n'
453             txt += '#  Register output to LFC\n'
454             txt += '#\n'
455 <           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
455 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
456             txt += '      for out_file in $file_list ; do\n'
457             txt += '         echo "Trying to register the output file into LFC"\n'
458 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
459 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
458 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
459 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
460             txt += '         register_exit_status=$?\n'
461             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
462             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
463             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
464             txt += '            echo "Problems with the registration to LFC" \n'
465             txt += '            echo "Try with srm protocol" \n'
466 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
467 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
466 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
467 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
468             txt += '            register_exit_status=$?\n'
469             txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
470             txt += '            echo "STAGE_OUT = $register_exit_status"\n'
# Line 433 | Line 476 | class SchedulerEdg(Scheduler):
476             txt += '         fi \n'
477             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
478             txt += '      done\n'
479 <           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
479 >           txt += '   else \n'
480             txt += '      echo "Trying to copy output file to CloseSE"\n'
481             txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
482             txt += '      for out_file in $file_list ; do\n'
483 <           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
484 <           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'
483 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1" \n'
484 >           txt += '         lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1 \n'
485             txt += '         register_exit_status=$?\n'
486             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
487             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
488             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
489 <           txt += '            echo "Problems with CloseSE" \n'
489 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
490             txt += '         else \n'
491             txt += '            echo "The program was successfully executed"\n'
492             txt += '            echo "SE = $CLOSE_SE"\n'
# Line 451 | Line 494 | class SchedulerEdg(Scheduler):
494             txt += '         fi \n'
495             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
496             txt += '      done\n'
454           txt += '   else\n'
455           txt += '      echo "Problem with the executable"\n'
497             txt += '   fi \n'
498 +           txt += '   exit_status=$register_exit_status\n'
499             txt += 'fi \n'
500          return txt
501  
# Line 467 | Line 509 | class SchedulerEdg(Scheduler):
509          cmd_out = runCommand(cmd)
510          return cmd_out
511  
470    def listMatch(self, nj):
471        """
472        Check the compatibility of available resources
473        """
474        self.checkProxy()
475        jdl = common.job_list[nj].jdlFilename()
476        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
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        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        #print out
500        lines = reLine.findall(out)
501
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        common.logger.debug(5,"All CE :"+str(CEs))
533
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' )
543        reString = re.compile( r'"\S*"' )
544        f = file(jdl,'r')
545        for line in f.readlines():
546            line= line.strip()
547            if reReq.match(line):
548                for req in reString.findall(line):
549                    if re.search("VO",req):
550                        common.logger.message( "SW required: "+req)
551                        continue
552                    if re.search('"\d+',req):
553                        common.logger.message("Other req  : "+req)
554                        continue
555                    common.logger.message( "CE required: "+req)
556                break
557            pass
558        raise CrabException("No compatible resources found!")
559
560    def submit(self, nj):
561        """
562        Submit one EDG job.
563        """
564
565        self.checkProxy()
566        jid = None
567        jdl = common.job_list[nj].jdlFilename()
568
569        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
570        cmd_out = runCommand(cmd)
571        if cmd_out != None:
572            reSid = re.compile( r'https.+' )
573            jid = reSid.search(cmd_out).group()
574            pass
575        return jid
576
577    def resubmit(self, nj_list):
578        """
579        Prepare jobs to be submit
580        """
581        return
582
512      def getExitStatus(self, id):
513          return self.getStatusAttribute_(id, 'exit_code')
514  
# Line 611 | Line 540 | class SchedulerEdg(Scheduler):
540              for i in range(len(self.states)):
541                  # Fill an hash table with all information retrieved from LB API
542                  hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
543 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
543 >            result = jobStat.loadStatus(st)[self.states.index(attr)]
544              return result
545  
546      def queryDetailedStatus(self, id):
# Line 620 | Line 549 | class SchedulerEdg(Scheduler):
549          cmd_out = runCommand(cmd)
550          return cmd_out
551  
552 <    def getOutput(self, id):
552 >    ##### FEDE ######        
553 >    def findSites_(self, n_tot_job):
554 >        itr4 = []
555 >       # print "n_tot_job = ", n_tot_job
556 >        for n in range(n_tot_job):
557 >            sites = common.jobDB.destination(n)
558 >            if len(sites)>0 and sites[0]=="Any": continue
559 >
560 >            #job = common.job_list[n]
561 >            #jbt = job.type()
562 >           # print "common.jobDB.destination(n) = ", common.jobDB.destination(n)
563 >           # print "sites = ", sites
564 >            itr = ''
565 >            if sites != [""]:#CarlosDaniele
566 >                for site in sites:
567 >                    #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
568 >                    itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
569 >                    pass
570 >                # remove last ||
571 >                itr = itr[0:-4]
572 >                itr4.append( itr )
573 >        # remove last ,
574 >       # print "itr4 = ", itr4
575 >        return itr4
576 >
577 >    def createXMLSchScript(self, nj, argsList):
578 >   # def createXMLSchScript(self, nj):
579 >        """
580 >        Create a XML-file for BOSS4.
581 >        """
582 >  #      job = common.job_list[nj]
583 >        """
584 >        INDY
585 >        [begin] da rivedere:
586 >        in particolare passerei il jobType ed eliminerei le dipendenze da job
587 >        """
588 >        index = nj - 1
589 >        job = common.job_list[index]
590 >        jbt = job.type()
591 >        
592 >        inp_sandbox = jbt.inputSandbox(index)
593 >        out_sandbox = jbt.outputSandbox(index)
594          """
595 <        Get output for a finished job with id.
626 <        Returns the name of directory with results.
595 >        [end] da rivedere
596          """
597  
598 <        self.checkProxy()
599 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
600 <        cmd_out = runCommand(cmd)
598 >        
599 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
600 >        jt_string = ''
601 >        
602 >        xml_fname = str(self.jobtypeName)+'.xml'
603 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
604  
605 <        # Determine the output directory name
606 <        dir = common.work_space.resDir()
607 <        dir += os.environ['USER']
608 <        dir += '_' + os.path.basename(id)
609 <        return dir
605 >        #TaskName  
606 >        dir = string.split(common.work_space.topDir(), '/')
607 >        taskName = dir[len(dir)-2]
608 >  
609 >        to_writeReq = ''
610 >        to_write = ''
611  
612 <    def cancel(self, id):
613 <        """ Cancel the EDG job with id """
641 <        self.checkProxy()
642 <        cmd = 'edg-job-cancel --noint ' + id
643 <        cmd_out = runCommand(cmd)
644 <        return cmd_out
612 >        req=' '
613 >        req = req + jbt.getRequirements()
614  
646    def createSchScript(self, nj):
647        """
648        Create a JDL-file for EDG.
649        """
615  
616 <        job = common.job_list[nj]
617 <        jbt = job.type()
618 <        inp_sandbox = jbt.inputSandbox(nj)
619 <        out_sandbox = jbt.outputSandbox(nj)
620 <        inp_storage_subdir = ''
616 >        #sites = common.jobDB.destination(nj)
617 >        #if len(sites)>0 and sites[0]!="Any":
618 >        #    req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
619 >        #req = req    
620 >    
621 >        if self.EDG_requirements:
622 >            if (req == ' '):
623 >                req = req + self.EDG_requirements
624 >            else:
625 >                req = req +  ' && ' + self.EDG_requirements
626 >        if self.EDG_ce_white_list:
627 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
628 >            for i in range(len(ce_white_list)):
629 >                if i == 0:
630 >                    if (req == ' '):
631 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
632 >                    else:
633 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
634 >                    pass
635 >                else:
636 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
637 >            req = req + ')'
638          
639 <        title = '# This JDL was generated by '+\
640 <                common.prog_name+' (version '+common.prog_version_str+')\n'
641 <        jt_string = ''
639 >        if self.EDG_ce_black_list:
640 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
641 >            for ce in ce_black_list:
642 >                if (req == ' '):
643 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
644 >                else:
645 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
646 >                pass
647 >        if self.EDG_clock_time:
648 >            if (req == ' '):
649 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
650 >            else:
651 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
652 >
653 >        if self.EDG_cpu_time:
654 >            if (req == ' '):
655 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
656 >            else:
657 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
658 >                                                                                          
659 >        if ( self.EDG_retry_count ):              
660 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
661 >            pass
662  
663 +        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
664 +        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
665  
666 +
667 +        #TaskName  
668 +        dir = string.split(common.work_space.topDir(), '/')
669 +        taskName = dir[len(dir)-2]
670 +
671 +        xml.write(str(title))
672 +        xml.write('<task name="' +str(taskName)+'">\n')
673 +        xml.write(jt_string)
674 +
675 +        xml.write('<iterator>\n')
676 +        xml.write('\t<iteratorRule name="ITR1">\n')
677 +        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
678 +        xml.write('\t</iteratorRule>\n')
679 +        xml.write('\t<iteratorRule name="ITR2">\n')
680 +        for arg in argsList:
681 +            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
682 +            pass
683 +        xml.write('\t</iteratorRule>\n')
684 +        #print jobList
685 +        xml.write('\t<iteratorRule name="ITR3">\n')
686 +        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
687 +        xml.write('\t</iteratorRule>\n')
688 +
689 +        '''
690 +        indy: qui sotto ci sta itr4
691 +        '''
692 +        
693 +        itr4=self.findSites_(nj)
694 +        #print "--->>> itr4 = ", itr4
695 +        if (itr4 != []):
696 +            xml.write('\t<iteratorRule name="ITR4">\n')
697 +        #print argsList
698 +            for arg in itr4:
699 +                xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
700 +                pass
701 +            xml.write('\t</iteratorRule>\n')
702 +            req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
703 +            pass
704 +        #    print "--->>> req= ", req        
705          
706 <        SPL = inp_storage_subdir
707 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
706 >        if (to_write != ''):
707 >            xml.write('<extraTags\n')
708 >            xml.write(to_write)
709 >            xml.write('/>\n')
710 >            pass
711  
712 <        jdl_fname = job.jdlFilename()
713 <        jdl = open(jdl_fname, 'w')
668 <        jdl.write(title)
712 >        xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
713 >        xml.write(jt_string)
714  
715 <        script = job.scriptFilename()
716 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
717 <        jdl.write(jt_string)
715 >        if (req != ' '):
716 >            req = req + '\n'
717 >            xml.write('<extraTags>\n')
718 >            xml.write('<Requirements>\n')
719 >            xml.write('<![CDATA[\n')
720 >            xml.write(req)
721 >            xml.write(']]>\n')
722 >            xml.write('</Requirements>\n')
723 >            xml.write('</extraTags>\n')
724 >            pass
725  
726 <        ### only one .sh  JDL has arguments:
726 >        #executable
727  
728 +        """
729 +        INDY
730 +        script dipende dal jobType: dovrebbe essere semplice tirarlo fuori in altro modo
731 +        """        
732 +        script = job.scriptFilename()
733 +        xml.write('<program>\n')
734 +        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
735 +        xml.write(jt_string)
736 +    
737 +          
738 +        ### only one .sh  JDL has arguments:
739          ### Fabio
740 <        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
741 <        inp_box = 'InputSandbox = { '
742 <        inp_box = inp_box + '"' + script + '",'
740 > #        xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
741 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
742 >        xml.write('<program_types> crabjob </program_types>\n')
743 >        inp_box = script + ','
744  
745          if inp_sandbox != None:
746              for fl in inp_sandbox:
747 <                inp_box = inp_box + ' "' + fl + '",'
747 >                inp_box = inp_box + '' + fl + ','
748                  pass
749              pass
750  
751 <        #if common.use_jam:
752 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
753 <
754 <        # Marco (VERY TEMPORARY ML STUFF)
755 <        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
751 >        inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
752 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
753 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
754 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
755 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
756  
757          if (not jbt.additional_inbox_files == []):
758 <            inp_box = inp_box + ', '
758 >            inp_box = inp_box + ','
759              for addFile in jbt.additional_inbox_files:
760                  addFile = os.path.abspath(addFile)
761 <                inp_box = inp_box+' "'+addFile+'",'
761 >                inp_box = inp_box+''+addFile+','
762                  pass
763  
764          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
765 <        inp_box = inp_box + ' };\n'
766 <        jdl.write(inp_box)
708 <
709 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
710 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
765 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
766 >        xml.write(inp_box)
767          
768 +        base = jbt.name()
769 +        stdout = base + '__ITR3_.stdout'
770 +        stderr = base + '__ITR3_.stderr'
771 +        
772 +        xml.write('<stderr> ' + stderr + '</stderr>\n')
773 +        xml.write('<stdout> ' + stdout + '</stdout>\n')
774          
713        if job.stdout() == job.stderr():
714          out_box = 'OutputSandbox = { "' + \
715                    job.stdout() + '", ".BrokerInfo",'
716        else:
717          out_box = 'OutputSandbox = { "' + \
718                    job.stdout() + '", "' + \
719                    job.stderr() + '", ".BrokerInfo",'
775  
776 +        out_box = stdout + ',' + \
777 +                  stderr + ',.BrokerInfo,'
778 +
779 +        """
780          if int(self.return_data) == 1:
781              if out_sandbox != None:
782                  for fl in out_sandbox:
783 <                    out_box = out_box + ' "' + fl + '",'
783 >                    out_box = out_box + '' + fl + ','
784                      pass
785                  pass
786              pass
787 <                                                                                                                                                            
729 <        if out_box[-1] == ',' : out_box = out_box[:-1]
730 <        out_box = out_box + ' };'
731 <        jdl.write(out_box+'\n')
732 <
787 >        """
788  
789 <        req='Requirements = '
790 <        noreq=req
791 <        req = req + jbt.getRequirements()
792 <        #### and USER REQUIREMENT
793 <        if self.EDG_requirements:
794 <            if (req != noreq):
795 <                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))'
789 >        """
790 >        INDY
791 >        qualcosa del genere andrebbe fatta per gli infiles
792 >        """        
793 >        if int(self.return_data) == 1:
794 >            for fl in jbt.output_file:
795 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
796                  pass
797 +            pass
798  
799 <        ###############
800 <        clockTime=480
801 <        if self.EDG_clock_time:
802 <            clockTime= self.EDG_clock_time
803 <        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 <                                                                                                                                                            
783 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
799 >        if out_box[-1] == ',' : out_box = out_box[:-1]
800 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
801 >        xml.write(out_box)
802 >
803 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
804  
805 <        if ( self.EDG_retry_count ):              
806 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
787 <            pass
805 >        xml.write('</program>\n')
806 >        xml.write('</chain>\n')
807  
808 <        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
808 >        xml.write('</iterator>\n')
809 >        xml.write('</task>\n')
810  
811 <        jdl.close()
811 >        xml.close()
812          return
813  
814      def checkProxy(self):
# Line 801 | Line 821 | class SchedulerEdg(Scheduler):
821  
822          minTimeLeftServer = 100 # in hours
823  
804        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
805        #cmd = 'voms-proxy-info -timeleft'
824          mustRenew = 0
825 <        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
825 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
826          timeLeftServer = -999
827          if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
828              mustRenew = 1
829          else:
830 <            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
830 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
831              if not timeLeftServer or not isInt(timeLeftServer):
832                  mustRenew = 1
833              elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
# Line 819 | Line 837 | class SchedulerEdg(Scheduler):
837  
838          if mustRenew:
839              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")
840 <            cmd = 'voms-proxy-init -voms cms -valid 96:00'
840 >            cmd = 'voms-proxy-init -voms '+self.VO+' -valid 96:00'
841 >            if self.role:
842 >                cmd = 'voms-proxy-init -voms '+self.VO+':/'+self.VO+'/role='+self.role+' -valid 96:00'
843              try:
844                  # SL as above: damn it!
845                  out = os.system(cmd)
# Line 827 | Line 847 | class SchedulerEdg(Scheduler):
847              except:
848                  msg = "Unable to create a valid proxy!\n"
849                  raise CrabException(msg)
830            # cmd = 'grid-proxy-info -timeleft'
831            # cmd_out = runCommand(cmd,0,20)
850              pass
851  
852          ## now I do have a voms proxy valid, and I check the myproxy server

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines