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.73.2.2 by fanzago, Wed Jul 19 10:53:40 2006 UTC vs.
Revision 1.93 by mkirn, Fri Oct 6 22:24:17 2006 UTC

# Line 21 | Line 21 | class SchedulerEdg(Scheduler):
21          return
22  
23      def configure(self, cfg_params):
24 <        # test branch 2
24 >
25          try:
26              RB = cfg_params["EDG.rb"]
27              edgConfig = EdgConfig(RB)
# 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.group = cfg_params["EDG.group"]
42 +        except KeyError:
43 +            self.group = None
44 +            
45 +        try:
46 +            self.role = cfg_params["EDG.role"]
47 +        except KeyError:
48 +            self.role = None
49 +            
50          try: self.LCG_version = cfg_params["EDG.lcg_version"]
51          except KeyError: self.LCG_version = '2'
52  
# Line 61 | Line 71 | class SchedulerEdg(Scheduler):
71          except KeyError: self.VO = 'cms'
72  
73          try: self.return_data = cfg_params['USER.return_data']
74 <        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
74 >        except KeyError: self.return_data = 0
75  
76          try:
77              self.copy_data = cfg_params["USER.copy_data"]
# 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  
175      def sched_parameter(self):
176          """
177 <        Returns file with scheduler-specific parameters
177 >        Returns file with requirements and scheduler-specific parameters
178          """
179 <      
180 <        if (self.edg_config and self.edg_config_vo != ''):
181 <            self.param='sched_param.clad'
179 >        index = int(common.jobDB.nJobs()) - 1
180 >        job = common.job_list[index]
181 >        jbt = job.type()
182 >        
183 >        lastDest=''
184 >        first = []
185 >        last  = []
186 >        for n in range(common.jobDB.nJobs()):
187 >            currDest=common.jobDB.destination(n)
188 >            if (currDest!=lastDest):
189 >                lastDest = currDest
190 >                first.append(n)
191 >                if n != 0:last.append(n-1)
192 >        if len(first)>len(last) :last.append(common.jobDB.nJobs())
193 >  
194 >        req = ''
195 >        req = req + jbt.getRequirements()
196 >    
197 >        if self.EDG_requirements:
198 >            if (req == ' '):
199 >                req = req + self.EDG_requirements
200 >            else:
201 >                req = req +  ' && ' + self.EDG_requirements
202 >        if self.EDG_ce_white_list:
203 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
204 >            for i in range(len(ce_white_list)):
205 >                if i == 0:
206 >                    if (req == ' '):
207 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
208 >                    else:
209 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
210 >                    pass
211 >                else:
212 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
213 >            req = req + ')'
214 >        
215 >        if self.EDG_ce_black_list:
216 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
217 >            for ce in ce_black_list:
218 >                if (req == ' '):
219 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
220 >                else:
221 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
222 >                pass
223 >        if self.EDG_clock_time:
224 >            if (req == ' '):
225 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
226 >            else:
227 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
228 >
229 >        if self.EDG_cpu_time:
230 >            if (req == ' '):
231 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
232 >            else:
233 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
234 >                
235 >        for i in range(len(first)): # Add loop DS
236 >            self.param='sched_param_'+str(i)+'.clad'
237              param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
238 <            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
239 <            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
238 >
239 >            itr4=self.findSites_(first[i])
240 >            if (itr4 != []):
241 >                req1=''  
242 >                for arg in itr4:
243 >                    req1 = req + ' && anyMatch(other.storage.CloseSEs, ('+str(arg)+'))'
244 >            param_file.write('Requirements = '+req1 +';\n')  
245 >  
246 >            if (self.edg_config and self.edg_config_vo != ''):
247 >                param_file.write('RBconfig = "'+self.edg_config+'";\n')  
248 >                param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
249 >
250              param_file.close()  
251 <            return 1
176 <        else:
177 <            return 0
251 >
252  
253      def wsSetupEnvironment(self):
254          """
255          Returns part of a job script which does scheduler-specific work.
256          """
257          txt = ''
258 +        txt += '# strip arguments\n'
259 +        txt += 'echo "strip arguments"\n'
260 +        txt += 'args=("$@")\n'
261 +        txt += 'nargs=$#\n'
262 +        txt += 'shift $nargs\n'
263          txt += "# job number (first parameter for job wrapper)\n"
264 <        txt += "NJob=$1\n"
264 >        #txt += "NJob=$1\n"
265 >        txt += "NJob=${args[0]}\n"
266  
267          txt += '# job identification to DashBoard \n'
268          txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
# Line 193 | Line 273 | class SchedulerEdg(Scheduler):
273          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
274  
275          txt += 'echo "middleware discovery " \n'
276 <        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'
276 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
277          txt += '    middleware=OSG \n'
278          txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
279          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
# Line 208 | Line 283 | class SchedulerEdg(Scheduler):
283          txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
284          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
285          txt += '    echo "middleware =$middleware" \n'
286 +        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
287 +        txt += '    middleware=LCG \n'
288 +        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
289 +        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
290 +        txt += '    echo "middleware =$middleware" \n'
291          txt += 'else \n'
292          txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
293          txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
# Line 237 | Line 317 | class SchedulerEdg(Scheduler):
317                txt += 'echo "SE_PATH = $SE_PATH"\n'
318  
319          txt += 'export VO='+self.VO+'\n'
320 <        ### FEDE: add some line for LFC catalog setting
320 >        ### add some line for LFC catalog setting
321          txt += 'if [ $middleware == LCG ]; then \n'
322          txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
323          txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
# Line 304 | Line 384 | class SchedulerEdg(Scheduler):
384          Copy input data from SE to WN    
385          """
386          txt = ''
387 <        try:
308 <            self.copy_input_data = common.analisys_common_info['copy_input_data']
309 <            #print "self.copy_input_data = ", self.copy_input_data
310 <        except KeyError: self.copy_input_data = 0
311 <        if int(self.copy_input_data) == 1:
387 >
388          ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
389 <           txt += 'if [ $middleware == OSG ]; then\n'
390 <           txt += '   #\n'
391 <           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
392 <           txt += '   #\n'
393 <           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
394 <           txt += 'elif [ $middleware == LCG ]; then \n'
395 <           txt += '   #\n'
396 <           txt += '   #   Copy Input Data from SE to this WN\n'
397 <           txt += '   #\n'
398 < ### changed by georgia (put a loop copying more than one input files per jobs)          
399 <           txt += '   for input_file in $cur_file_list \n'
400 <           txt += '   do \n'
401 <           #### FEDE
402 <           #txt += '      echo "which lcg-cp" \n'
403 <           #txt += '      which lcg-cp \n'
404 <           #########
405 <           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
406 <           txt += '      copy_input_exit_status=$?\n'
407 <           txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
408 <           txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
409 <           txt += '         echo "Problems with copying to WN" \n'
410 <           txt += '      else \n'
411 <           txt += '         echo "input copied into WN" \n'
412 <           txt += '      fi \n'
413 <           txt += '   done \n'
414 < ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
415 <           txt += '   for file in $cur_pu_list \n'
416 <           txt += '   do \n'
417 <           #### FEDE
418 <           #txt += '      echo "which lcg-cp" \n'
419 <           #txt += '      which lcg-cp \n'
420 <           #########
421 <           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
422 <           txt += '      copy_input_pu_exit_status=$?\n'
423 <           txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
424 <           txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
425 <           txt += '         echo "Problems with copying pu to WN" \n'
350 <           txt += '      else \n'
351 <           txt += '         echo "input pu files copied into WN" \n'
352 <           txt += '      fi \n'
353 <           txt += '   done \n'
354 <           txt += '   \n'
355 <           txt += '   ### Check SCRATCH space available on WN : \n'
356 <           txt += '   df -h \n'
357 <           txt += 'fi \n'
389 >        txt += 'if [ $middleware == OSG ]; then\n'
390 >        txt += '   #\n'
391 >        txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
392 >        txt += '   #\n'
393 >        txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
394 >        txt += 'elif [ $middleware == LCG ]; then \n'
395 >        txt += '   #\n'
396 >        txt += '   #   Copy Input Data from SE to this WN\n'
397 >        txt += '   #\n'
398 >        ### changed by georgia (put a loop copying more than one input files per jobs)          
399 >        txt += '   for input_file in $cur_file_list \n'
400 >        txt += '   do \n'
401 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
402 >        txt += '      copy_input_exit_status=$?\n'
403 >        txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
404 >        txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
405 >        txt += '         echo "Problems with copying to WN" \n'
406 >        txt += '      else \n'
407 >        txt += '         echo "input copied into WN" \n'
408 >        txt += '      fi \n'
409 >        txt += '   done \n'
410 >        ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
411 >        txt += '   for file in $cur_pu_list \n'
412 >        txt += '   do \n'
413 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
414 >        txt += '      copy_input_pu_exit_status=$?\n'
415 >        txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
416 >        txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
417 >        txt += '         echo "Problems with copying pu to WN" \n'
418 >        txt += '      else \n'
419 >        txt += '         echo "input pu files copied into WN" \n'
420 >        txt += '      fi \n'
421 >        txt += '   done \n'
422 >        txt += '   \n'
423 >        txt += '   ### Check SCRATCH space available on WN : \n'
424 >        txt += '   df -h \n'
425 >        txt += 'fi \n'
426            
427          return txt
428  
# Line 368 | Line 436 | class SchedulerEdg(Scheduler):
436             txt += '#\n'
437             txt += '#   Copy output to SE = $SE\n'
438             txt += '#\n'
371           #txt += 'if [ $exe_result -eq 0 ]; then\n'
439             txt += '    if [ $middleware == OSG ]; then\n'
440             txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
441             txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
# Line 376 | Line 443 | class SchedulerEdg(Scheduler):
443             txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
444             txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
445             txt += '    fi \n'
446 +
447             txt += '    for out_file in $file_list ; do\n'
448 <           txt += '        echo "Trying to copy output file to $SE using lcg-cp"\n'
449 <           txt += '        echo "lcg-cp --vo $VO -t 1200 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
450 <           txt += '        exitstring=`lcg-cp --vo $VO -t 1200 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
448 >           txt += '        echo "Trying to copy output file to $SE using srmcp"\n'
449 >           txt += '        echo "mkdir -p $HOME/.srmconfig"\n'
450 >           txt += '        mkdir -p $HOME/.srmconfig\n'
451 >           txt += '        if [ $middleware == LCG ]; then\n'
452 >           txt += '           echo "srmcp -retry_num 3 -retry_timeout 480000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
453 >           txt += '           exitstring=`srmcp -retry_num 3 -retry_timeout 480000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
454 >           txt += '        elif [ $middleware == OSG ]; then\n'
455 >           txt += '           echo "srmcp -retry_num 3 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
456 >           txt += '           exitstring=`srmcp -retry_num 3 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
457 >           txt += '        fi \n'
458             txt += '        copy_exit_status=$?\n'
459 <           txt += '        echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
459 >           txt += '        echo "COPY_EXIT_STATUS for srmcp = $copy_exit_status"\n'
460             txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
461 +
462             txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
463             txt += '            echo "Possible problem with SE = $SE"\n'
464             txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
465             txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
466 <           txt += '            echo "lcg-cp failed, attempting srmcp"\n'
467 <           txt += '            echo "mkdir -p $HOME/.srmconfig"\n'
468 <           txt += '            mkdir -p $HOME/.srmconfig\n'
469 <           txt += '            if [ $middleware == LCG ]; then\n'
470 <           txt += '               echo "srmcp -retry_num 5 -retry_timeout 240000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
471 <           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 240000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
472 <           txt += '            elif [ $middleware == OSG ]; then\n'
397 <           txt += '               echo "srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
398 <           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
399 <           txt += '            fi \n'
466 >           txt += '            echo "srmcp failed, attempting lcg-cp."\n'
467 >           if common.logger.debugLevel() >= 5:
468 >               txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
469 >               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
470 >           else:              
471 >               txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
472 >               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
473             txt += '            copy_exit_status=$?\n'
474 <           txt += '            echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
474 >           txt += '            echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
475             txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
476 +
477             txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
478             txt += '               echo "Problems with SE = $SE"\n'
479             txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
480             txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
481 <           txt += '               echo "lcg-cp and srm failed"\n'
408 <           txt += '               echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
481 >           txt += '               echo "srmcp and lcg-cp and failed!"\n'
482             txt += '            else\n'
483             txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
484             txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
485             txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
486             txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
487 <           txt += '               echo "srmcp succeeded"\n'
487 >           txt += '               echo "lcg-cp succeeded"\n'
488             txt += '            fi\n'
489             txt += '        else\n'
490             txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
491             txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
492             txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
493             txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
494 <           txt += '            echo "lcg-cp succeeded"\n'
494 >           txt += '            echo "srmcp succeeded"\n'
495             txt += '         fi\n'
496             txt += '     done\n'
424           #txt += 'fi\n'
497          return txt
498  
499      def wsRegisterOutput(self):
# Line 441 | Line 513 | class SchedulerEdg(Scheduler):
513             txt += '#\n'
514             txt += '#  Register output to LFC\n'
515             txt += '#\n'
444           #txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
516             txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
517             txt += '      for out_file in $file_list ; do\n'
518             txt += '         echo "Trying to register the output file into LFC"\n'
448           #### FEDE
449           #txt += '         echo "which lcg-rf" \n'
450           #txt += '         which lcg-rf \n'
451           #########
519             txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
520             txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
521             txt += '         register_exit_status=$?\n'
# Line 457 | Line 524 | class SchedulerEdg(Scheduler):
524             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
525             txt += '            echo "Problems with the registration to LFC" \n'
526             txt += '            echo "Try with srm protocol" \n'
460           #### FEDE
461           #txt += '            echo "which lcg-rf" \n'
462           #txt += '            which lcg-rf \n'
463           #########
527             txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
528             txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
529             txt += '            register_exit_status=$?\n'
# Line 474 | Line 537 | class SchedulerEdg(Scheduler):
537             txt += '         fi \n'
538             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
539             txt += '      done\n'
477           #txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
540             txt += '   else \n'
541             txt += '      echo "Trying to copy output file to CloseSE"\n'
542             txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
543             txt += '      for out_file in $file_list ; do\n'
482           #### FEDE
483           #txt += '         echo "which lcg-cr" \n'
484           #txt += '         which lcg-cr \n'
485           #########
544             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'
545             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'
546             txt += '         register_exit_status=$?\n'
# Line 497 | Line 555 | class SchedulerEdg(Scheduler):
555             txt += '         fi \n'
556             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
557             txt += '      done\n'
500           #txt += '   else\n'
501           #txt += '      echo "Problem with the executable"\n'
558             txt += '   fi \n'
559             txt += '   exit_status=$register_exit_status\n'
560             txt += 'fi \n'
# Line 514 | Line 570 | class SchedulerEdg(Scheduler):
570          cmd_out = runCommand(cmd)
571          return cmd_out
572  
517    def listMatch(self, nj):
518        """
519        Check the compatibility of available resources
520        """
521        self.checkProxy()
522        jdl = common.job_list[nj].jdlFilename()
523        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
524        cmd_out = runCommand(cmd,0,10)
525        if not cmd_out:
526            raise CrabException("ERROR: "+cmd+" failed!")
527
528        return self.parseListMatch_(cmd_out, jdl)
529
530    def parseListMatch_(self, out, jdl):
531        """
532        Parse the f* output of edg-list-match and produce something sensible
533        """
534        reComment = re.compile( r'^\**$' )
535        reEmptyLine = re.compile( r'^$' )
536        reVO = re.compile( r'Selected Virtual Organisation name.*' )
537        reLine = re.compile( r'.*')
538        reCE = re.compile( r'(.*:.*)')
539        reCEId = re.compile( r'CEId.*')
540        reNO = re.compile( r'No Computing Element matching' )
541        reRB = re.compile( r'Connecting to host' )
542        next = 0
543        CEs=[]
544        Match=0
545
546        #print out
547        lines = reLine.findall(out)
548
549        i=0
550        CEs=[]
551        for line in lines:
552            string.strip(line)
553            #print line
554            if reNO.match( line ):
555                common.logger.debug(5,line)
556                return 0
557                pass
558            if reVO.match( line ):
559                VO =reVO.match( line ).group()
560                common.logger.debug(5,"VO "+VO)
561                pass
562
563            if reRB.match( line ):
564                RB = reRB.match(line).group()
565                common.logger.debug(5,"RB "+RB)
566                pass
567
568            if reCEId.search( line ):
569                for lineCE in lines[i:-1]:
570                    if reCE.match( lineCE ):
571                        CE = string.strip(reCE.search(lineCE).group(1))
572                        CEs.append(CE.split(':')[0])
573                        pass
574                    pass
575                pass
576            i=i+1
577            pass
578
579        common.logger.debug(5,"All CE :"+str(CEs))
580
581        sites = []
582        [sites.append(it) for it in CEs if not sites.count(it)]
583
584        common.logger.debug(5,"All Sites :"+str(sites))
585        common.logger.message("Matched Sites :"+str(sites))
586        return len(sites)
587
588    def noMatchFound_(self, jdl):
589        reReq = re.compile( r'Requirements' )
590        reString = re.compile( r'"\S*"' )
591        f = file(jdl,'r')
592        for line in f.readlines():
593            line= line.strip()
594            if reReq.match(line):
595                for req in reString.findall(line):
596                    if re.search("VO",req):
597                        common.logger.message( "SW required: "+req)
598                        continue
599                    if re.search('"\d+',req):
600                        common.logger.message("Other req  : "+req)
601                        continue
602                    common.logger.message( "CE required: "+req)
603                break
604            pass
605        raise CrabException("No compatible resources found!")
606
607    def submit(self, nj):
608        """
609        Submit one EDG job.
610        """
611
612        self.checkProxy()
613        jid = None
614        jdl = common.job_list[nj].jdlFilename()
615
616        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
617        cmd_out = runCommand(cmd)
618        if cmd_out != None:
619            reSid = re.compile( r'https.+' )
620            jid = reSid.search(cmd_out).group()
621            pass
622        return jid
623
624    def resubmit(self, nj_list):
625        """
626        Prepare jobs to be submit
627        """
628        return
629
573      def getExitStatus(self, id):
574          return self.getStatusAttribute_(id, 'exit_code')
575  
# Line 658 | Line 601 | class SchedulerEdg(Scheduler):
601              for i in range(len(self.states)):
602                  # Fill an hash table with all information retrieved from LB API
603                  hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
604 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
604 >            result = jobStat.loadStatus(st)[self.states.index(attr)]
605              return result
606  
607      def queryDetailedStatus(self, id):
# Line 667 | Line 610 | class SchedulerEdg(Scheduler):
610          cmd_out = runCommand(cmd)
611          return cmd_out
612  
613 <    def getOutput(self, id):
613 >    ##### FEDE ######        
614 >    def findSites_(self, n):
615 >        itr4 =[]
616 >        sites = common.jobDB.destination(n)
617 >        if len(sites)>0 and sites[0]=="Any":
618 >            return itr4
619 >        itr = ''
620 >        if sites != [""]:#CarlosDaniele
621 >            for site in sites:
622 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
623 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
624 >            itr = itr[0:-4]
625 >            itr4.append( itr )
626 >        return itr4
627 >
628 >    def createXMLSchScript(self, nj, argsList):
629 >   # def createXMLSchScript(self, nj):
630 >      
631 >        """
632 >        Create a XML-file for BOSS4.
633 >        """
634 >  #      job = common.job_list[nj]
635          """
636 <        Get output for a finished job with id.
637 <        Returns the name of directory with results.
636 >        INDY
637 >        [begin] FIX-ME:
638 >        I would pass jobType instead of job
639 >        """
640 >        index = nj - 1
641 >        job = common.job_list[index]
642 >        jbt = job.type()
643 >        
644 >        inp_sandbox = jbt.inputSandbox(index)
645 >        out_sandbox = jbt.outputSandbox(index)
646 >        """
647 >        [end] FIX-ME
648          """
649  
650 <        self.checkProxy()
651 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
652 <        cmd_out = runCommand(cmd)
650 >        
651 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
652 >        jt_string = ''
653 >        
654 >        xml_fname = str(self.jobtypeName)+'.xml'
655 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
656  
657 <        # Determine the output directory name
658 <        dir = common.work_space.resDir()
659 <        dir += os.environ['USER']
660 <        dir += '_' + os.path.basename(id)
661 <        return dir
657 >        #TaskName  
658 >        dir = string.split(common.work_space.topDir(), '/')
659 >        taskName = dir[len(dir)-2]
660 >  
661 >        to_writeReq = ''
662 >        to_write = ''
663  
664 <    def cancel(self, id):
665 <        """ Cancel the EDG job with id """
688 <        self.checkProxy()
689 <        cmd = 'edg-job-cancel --noint ' + id
690 <        cmd_out = runCommand(cmd)
691 <        return cmd_out
664 >        req=' '
665 >        req = req + jbt.getRequirements()
666  
693    def createSchScript(self, nj):
694        """
695        Create a JDL-file for EDG.
696        """
667  
668 <        job = common.job_list[nj]
669 <        jbt = job.type()
670 <        inp_sandbox = jbt.inputSandbox(nj)
671 <        out_sandbox = jbt.outputSandbox(nj)
672 <        inp_storage_subdir = ''
668 >        #sites = common.jobDB.destination(nj)
669 >        #if len(sites)>0 and sites[0]!="Any":
670 >        #    req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
671 >        #req = req    
672 >    
673 >        if self.EDG_requirements:
674 >            if (req == ' '):
675 >                req = req + self.EDG_requirements
676 >            else:
677 >                req = req +  ' && ' + self.EDG_requirements
678 >        if self.EDG_ce_white_list:
679 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
680 >            for i in range(len(ce_white_list)):
681 >                if i == 0:
682 >                    if (req == ' '):
683 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
684 >                    else:
685 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
686 >                    pass
687 >                else:
688 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
689 >            req = req + ')'
690          
691 <        title = '# This JDL was generated by '+\
692 <                common.prog_name+' (version '+common.prog_version_str+')\n'
693 <        jt_string = ''
691 >        if self.EDG_ce_black_list:
692 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
693 >            for ce in ce_black_list:
694 >                if (req == ' '):
695 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
696 >                else:
697 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
698 >                pass
699 >        if self.EDG_clock_time:
700 >            if (req == ' '):
701 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
702 >            else:
703 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
704 >
705 >        if self.EDG_cpu_time:
706 >            if (req == ' '):
707 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
708 >            else:
709 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
710 >                                                                                          
711 >        if ( self.EDG_retry_count ):              
712 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
713 >            pass
714  
715 +        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
716 +        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
717  
718 +                #TaskName  
719 +        dir = string.split(common.work_space.topDir(), '/')
720 +        taskName = dir[len(dir)-2]
721 +
722 +        xml.write(str(title))
723 +        xml.write('<task name="' +str(taskName)+'">\n')
724 +        xml.write(jt_string)
725          
726 <        SPL = inp_storage_subdir
727 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
726 >        if (to_write != ''):
727 >            xml.write('<extraTags\n')
728 >            xml.write(to_write)
729 >            xml.write('/>\n')
730 >            pass
731  
732 <        jdl_fname = job.jdlFilename()
733 <        jdl = open(jdl_fname, 'w')
734 <        jdl.write(title)
732 >        xml.write('<iterator>\n')
733 >        xml.write('\t<iteratorRule name="ITR1">\n')
734 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
735 >        xml.write('\t</iteratorRule>\n')
736 >        xml.write('\t<iteratorRule name="ITR2">\n')
737 >        for arg in argsList:
738 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
739 >            pass
740 >        xml.write('\t</iteratorRule>\n')
741 >        #print jobList
742 >        xml.write('\t<iteratorRule name="ITR3">\n')
743 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
744 >        xml.write('\t</iteratorRule>\n')
745 >
746 >        '''
747 >        indy: here itr4
748 >        '''
749 >        
750  
751 <        script = job.scriptFilename()
752 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
719 <        jdl.write(jt_string)
751 >        xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
752 >        xml.write(jt_string)
753  
754 <        ### only one .sh  JDL has arguments:
754 >        #executable
755  
756 +        """
757 +        INDY
758 +        script depends on jobType: it should be probably get in a different way
759 +        """        
760 +        script = job.scriptFilename()
761 +        xml.write('<program>\n')
762 +        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
763 +        xml.write(jt_string)
764 +    
765 +          
766 +        ### only one .sh  JDL has arguments:
767          ### Fabio
768 <        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
769 <        inp_box = 'InputSandbox = { '
770 <        inp_box = inp_box + '"' + script + '",'
768 > #        xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
769 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
770 >        xml.write('<program_types> crabjob </program_types>\n')
771 >        inp_box = script + ','
772  
773          if inp_sandbox != None:
774              for fl in inp_sandbox:
775 <                inp_box = inp_box + ' "' + fl + '",'
775 >                inp_box = inp_box + '' + fl + ','
776                  pass
777              pass
778  
779 <        #if common.use_jam:
780 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
781 <
782 <        # Marco (VERY TEMPORARY ML STUFF)
783 <        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
739 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
740 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
741 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
742 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
743 <        # End Marco
779 >        inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
780 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
781 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
782 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
783 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
784  
785          if (not jbt.additional_inbox_files == []):
786 <            inp_box = inp_box + ', '
786 >            inp_box = inp_box + ','
787              for addFile in jbt.additional_inbox_files:
788                  addFile = os.path.abspath(addFile)
789 <                inp_box = inp_box+' "'+addFile+'",'
789 >                inp_box = inp_box+''+addFile+','
790                  pass
791  
792          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
793 <        inp_box = inp_box + ' };\n'
794 <        jdl.write(inp_box)
755 <
756 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
757 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
793 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
794 >        xml.write(inp_box)
795          
796 +        base = jbt.name()
797 +        stdout = base + '__ITR3_.stdout'
798 +        stderr = base + '__ITR3_.stderr'
799 +        
800 +        xml.write('<stderr> ' + stderr + '</stderr>\n')
801 +        xml.write('<stdout> ' + stdout + '</stdout>\n')
802          
760        if job.stdout() == job.stderr():
761          out_box = 'OutputSandbox = { "' + \
762                    job.stdout() + '", ".BrokerInfo",'
763        else:
764          out_box = 'OutputSandbox = { "' + \
765                    job.stdout() + '", "' + \
766                    job.stderr() + '", ".BrokerInfo",'
803  
804 +        out_box = stdout + ',' + \
805 +                  stderr + ',.BrokerInfo,'
806 +
807 +        """
808          if int(self.return_data) == 1:
809              if out_sandbox != None:
810                  for fl in out_sandbox:
811 <                    out_box = out_box + ' "' + fl + '",'
811 >                    out_box = out_box + '' + fl + ','
812                      pass
813                  pass
814              pass
815 <                                                                                                                                                            
776 <        if out_box[-1] == ',' : out_box = out_box[:-1]
777 <        out_box = out_box + ' };'
778 <        jdl.write(out_box+'\n')
779 <
815 >        """
816  
817 <        req='Requirements = '
818 <        noreq=req
819 <        req = req + jbt.getRequirements()
820 <        #### and USER REQUIREMENT
821 <        if self.EDG_requirements:
822 <            if (req != noreq):
823 <                req = req +  ' && '
788 <            req = req + self.EDG_requirements
789 <        #### FEDE #####
790 <        if self.EDG_ce_white_list:
791 <            ce_white_list = string.split(self.EDG_ce_white_list,',')
792 <            #print "req = ", req
793 <            for i in range(len(ce_white_list)):
794 <                if i == 0:
795 <                    if (req != noreq):
796 <                        req = req +  ' && '
797 <                    req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
798 <                    pass
799 <                else:
800 <                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
801 <            req = req + ')'
802 <        
803 <        if self.EDG_ce_black_list:
804 <            ce_black_list = string.split(self.EDG_ce_black_list,',')
805 <            for ce in ce_black_list:
806 <                if (req != noreq):
807 <                    req = req +  ' && '
808 <                req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
817 >        """
818 >        INDY
819 >        something similar should be also done for infiles (if it makes sense!)
820 >        """
821 >        if int(self.return_data) == 1:
822 >            for fl in jbt.output_file:
823 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
824                  pass
825 +            pass
826  
827 <        ###############
828 <        clockTime=480
829 <        if self.EDG_clock_time:
830 <            clockTime= self.EDG_clock_time
831 <        if (req != noreq):
816 <            req = req + ' && '
817 <        req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
827 >        if out_box[-1] == ',' : out_box = out_box[:-1]
828 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
829 >        xml.write(out_box)
830 >
831 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
832  
833 <        cpuTime=1000
834 <        if self.EDG_cpu_time:
821 <            cpuTime=self.EDG_cpu_time
822 <        if (req != noreq):
823 <            req = req + ' && '
824 <        req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+str(cpuTime)+'))'
825 <
826 <        if (req != noreq):
827 <            req = req + ';\n'
828 <            jdl.write(req)
829 <                                                                                                                                                            
830 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
833 >        xml.write('</program>\n')
834 >        xml.write('</chain>\n')
835  
836 <        if ( self.EDG_retry_count ):              
837 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
834 <            pass
836 >        xml.write('</iterator>\n')
837 >        xml.write('</task>\n')
838  
839 <        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
839 >        xml.close()
840 >      
841  
838        jdl.close()
842          return
843  
844      def checkProxy(self):
# Line 848 | Line 851 | class SchedulerEdg(Scheduler):
851  
852          minTimeLeftServer = 100 # in hours
853  
851        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
852        #cmd = 'voms-proxy-info -timeleft'
854          mustRenew = 0
855          timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
856          timeLeftServer = -999
# Line 866 | Line 867 | class SchedulerEdg(Scheduler):
867  
868          if mustRenew:
869              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")
870 <            cmd = 'voms-proxy-init -voms cms -valid 96:00'
870 >            cmd = 'voms-proxy-init -voms '+self.VO
871 >            if self.group:
872 >                cmd += ':/'+self.VO+'/'+self.group
873 >            if self.role:
874 >                cmd += '/role='+self.role
875 >            cmd += ' -valid 96:00'
876              try:
877                  # SL as above: damn it!
878 +                common.logger.debug(10,cmd)
879                  out = os.system(cmd)
880                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
881              except:
882                  msg = "Unable to create a valid proxy!\n"
883                  raise CrabException(msg)
877            # cmd = 'grid-proxy-info -timeleft'
878            # cmd_out = runCommand(cmd,0,20)
884              pass
885  
886          ## now I do have a voms proxy valid, and I check the myproxy server

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines