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.49 by spiga, Fri Apr 7 12:58:38 2006 UTC vs.
Revision 1.92 by slacapra, Fri Oct 6 16:02:29 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 30 | Line 31 | class SchedulerEdg(Scheduler):
31              self.edg_config = ''
32              self.edg_config_vo = ''
33  
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:
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 55 | 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
59 <
60 <        try:
61 <             self.copy_input_data = common.analisys_common_info['copy_input_data']
62 <             #print "self.copy_input_data = ", self.copy_input_data
63 <        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 146 | Line 157 | class SchedulerEdg(Scheduler):
157          sys.path.append(libPath)
158  
159          self.proxyValid=0
160 +
161 +        try:
162 +            self._taskId = cfg_params['taskId']
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
164 <        else:
165 <            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"
265 +        txt += "NJob=${args[0]}\n"
266 +
267 +        txt += '# job identification to DashBoard \n'
268 +        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
269 +        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
270 +        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
271 +        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
272 +        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
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'
174 <        txt += '    middleware=LCG \n'
175 <        txt += '    echo "middleware =$middleware" \n'
176 <        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'
280          txt += '    echo "middleware =$middleware" \n'
281          txt += 'elif [ $OSG_APP ]; then \n'
282          txt += '    middleware=OSG \n'
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 1 ==> middleware not identified" \n'
293 <        txt += '    echo "JOB_EXIT_STATUS = 1"\n'
294 <        txt += '    exit 1\n'
295 <        txt += 'fi\n'
296 <
292 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
293 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
294 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
295 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
296 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
297 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
298 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
299 >        txt += '    exit 1 \n'
300 >        txt += 'fi \n'
301 >
302 >        txt += '# report first time to DashBoard \n'
303 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
304 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
305 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
306 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
307 >        
308          txt += '\n\n'
309  
190        txt += 'if [ $middleware == LCG ]; then \n'
191        txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
192        txt += 'fi\n'
193
310          if int(self.copy_data) == 1:
311             if self.SE:
312                txt += 'export SE='+self.SE+'\n'
# Line 201 | 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 250 | Line 366 | class SchedulerEdg(Scheduler):
366          txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
367          txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
368          txt += '    else \n'
369 <        txt += '        echo "SET_ENV 1 ==> ERROR in setting CE name - OSG mode -" \n'
369 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
370 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
371 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
372 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
373 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
374 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
375 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
376          txt += '        exit 1 \n'
377          txt += '    fi \n'
378          txt += 'fi \n'
# Line 262 | Line 384 | class SchedulerEdg(Scheduler):
384          Copy input data from SE to WN    
385          """
386          txt = ''
387 <        try:
266 <            self.copy_input_data = common.analisys_common_info['copy_input_data']
267 <            #print "self.copy_input_data = ", self.copy_input_data
268 <        except KeyError: self.copy_input_data = 0
269 <        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 <           txt += '    lcg-cp --vo $VO 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 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
414 <           txt += '    copy_input_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'
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 318 | Line 436 | class SchedulerEdg(Scheduler):
436             txt += '#\n'
437             txt += '#   Copy output to SE = $SE\n'
438             txt += '#\n'
439 <           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'
442 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
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 "\n'
449 <           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
450 <           txt += '        if [ $middleware == OSG ]; then\n'
451 <           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
452 <           txt += '           copy_exit_status=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
453 <           #txt += '           exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
454 <           txt += '        elif [ $middleware == LCG ]; then \n'
455 <           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
456 <           txt += '           copy_exit_status=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
457 <           #txt += '           exitstring=`lcg-cp --vo cms -t 30 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
458 <           txt += '        fi \n'
459 <           #txt += '        copy_exit_status=$?\n'
335 <           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\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 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 "Problems with SE = $SE"\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 "srm failed."\n'
467 +           txt += '            echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
468 +           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
469 +           txt += '            echo "Trying to copy output file to $SE using lcg-cp"\n'
470 +           txt += '            echo "srmcp failed, attempting lcgcp"\n'
471 +           if common.logger.debugLevel() >= 5:
472 +               txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
473 +               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
474 +           else:              
475 +               txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
476 +               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
477 +           txt += '            copy_exit_status=$?\n'
478 +           txt += '            echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
479 +           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
480 +
481 +           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
482 +           txt += '               echo "Problems with SE = $SE"\n'
483 +           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
484 +           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
485 +           txt += '               echo "lcg-cp and srm failed"\n'
486 +           txt += '               echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
487 +           txt += '            else\n'
488 +           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
489 +           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
490 +           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
491 +           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
492 +           txt += '               echo "lcg-cp succeeded"\n'
493 +           txt += '            fi\n'
494             txt += '        else\n'
495             txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
496             txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
497             txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
498             txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
499 +           txt += '            echo "srmcp succeeded"\n'
500             txt += '         fi\n'
501             txt += '     done\n'
348           txt += 'fi\n'
502          return txt
503  
504      def wsRegisterOutput(self):
# Line 365 | Line 518 | class SchedulerEdg(Scheduler):
518             txt += '#\n'
519             txt += '#  Register output to LFC\n'
520             txt += '#\n'
521 <           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
521 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
522             txt += '      for out_file in $file_list ; do\n'
523             txt += '         echo "Trying to register the output file into LFC"\n'
524 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
525 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
524 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
525 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
526             txt += '         register_exit_status=$?\n'
527             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
528             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
529             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
530             txt += '            echo "Problems with the registration to LFC" \n'
531             txt += '            echo "Try with srm protocol" \n'
532 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
533 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
532 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
533 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
534             txt += '            register_exit_status=$?\n'
535             txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
536             txt += '            echo "STAGE_OUT = $register_exit_status"\n'
# Line 389 | Line 542 | class SchedulerEdg(Scheduler):
542             txt += '         fi \n'
543             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
544             txt += '      done\n'
545 <           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
545 >           txt += '   else \n'
546             txt += '      echo "Trying to copy output file to CloseSE"\n'
547             txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
548             txt += '      for out_file in $file_list ; do\n'
549 <           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
550 <           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'
549 >           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'
550 >           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'
551             txt += '         register_exit_status=$?\n'
552             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
553             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
554             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
555 <           txt += '            echo "Problems with CloseSE" \n'
555 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
556             txt += '         else \n'
557             txt += '            echo "The program was successfully executed"\n'
558             txt += '            echo "SE = $CLOSE_SE"\n'
# Line 407 | Line 560 | class SchedulerEdg(Scheduler):
560             txt += '         fi \n'
561             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
562             txt += '      done\n'
410           txt += '   else\n'
411           txt += '      echo "Problem with the executable"\n'
563             txt += '   fi \n'
564 +           txt += '   exit_status=$register_exit_status\n'
565             txt += 'fi \n'
566          return txt
567  
# Line 423 | Line 575 | class SchedulerEdg(Scheduler):
575          cmd_out = runCommand(cmd)
576          return cmd_out
577  
426    def listMatch(self, nj):
427        """
428        Check the compatibility of available resources
429        """
430        self.checkProxy()
431        jdl = common.job_list[nj].jdlFilename()
432        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
433        cmd_out = runCommand(cmd,0,10)
434        if not cmd_out:
435            raise CrabException("ERROR: "+cmd+" failed!")
436
437        return self.parseListMatch_(cmd_out, jdl)
438
439    def parseListMatch_(self, out, jdl):
440        """
441        Parse the f* output of edg-list-match and produce something sensible
442        """
443        reComment = re.compile( r'^\**$' )
444        reEmptyLine = re.compile( r'^$' )
445        reVO = re.compile( r'Selected Virtual Organisation name.*' )
446        reLine = re.compile( r'.*')
447        reCE = re.compile( r'(.*:.*)')
448        reCEId = re.compile( r'CEId.*')
449        reNO = re.compile( r'No Computing Element matching' )
450        reRB = re.compile( r'Connecting to host' )
451        next = 0
452        CEs=[]
453        Match=0
454
455        #print out
456        lines = reLine.findall(out)
457
458        i=0
459        CEs=[]
460        for line in lines:
461            string.strip(line)
462            #print line
463            if reNO.match( line ):
464                common.logger.debug(5,line)
465                return 0
466                pass
467            if reVO.match( line ):
468                VO =reVO.match( line ).group()
469                common.logger.debug(5,"VO "+VO)
470                pass
471
472            if reRB.match( line ):
473                RB = reRB.match(line).group()
474                common.logger.debug(5,"RB "+RB)
475                pass
476
477            if reCEId.search( line ):
478                for lineCE in lines[i:-1]:
479                    if reCE.match( lineCE ):
480                        CE = string.strip(reCE.search(lineCE).group(1))
481                        CEs.append(CE.split(':')[0])
482                        pass
483                    pass
484                pass
485            i=i+1
486            pass
487
488        common.logger.debug(5,"All CE :"+str(CEs))
489
490        sites = []
491        [sites.append(it) for it in CEs if not sites.count(it)]
492
493        common.logger.debug(5,"All Sites :"+str(sites))
494        return len(sites)
495
496    def noMatchFound_(self, jdl):
497        reReq = re.compile( r'Requirements' )
498        reString = re.compile( r'"\S*"' )
499        f = file(jdl,'r')
500        for line in f.readlines():
501            line= line.strip()
502            if reReq.match(line):
503                for req in reString.findall(line):
504                    if re.search("VO",req):
505                        common.logger.message( "SW required: "+req)
506                        continue
507                    if re.search('"\d+',req):
508                        common.logger.message("Other req  : "+req)
509                        continue
510                    common.logger.message( "CE required: "+req)
511                break
512            pass
513        raise CrabException("No compatible resources found!")
514
515    def submit(self, nj):
516        """
517        Submit one EDG job.
518        """
519
520        self.checkProxy()
521        jid = None
522        jdl = common.job_list[nj].jdlFilename()
523
524        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
525        cmd_out = runCommand(cmd)
526        if cmd_out != None:
527            reSid = re.compile( r'https.+' )
528            jid = reSid.search(cmd_out).group()
529            pass
530        return jid
531
532    def resubmit(self, nj_list):
533        """
534        Prepare jobs to be submit
535        """
536        return
537
578      def getExitStatus(self, id):
579          return self.getStatusAttribute_(id, 'exit_code')
580  
# Line 566 | Line 606 | class SchedulerEdg(Scheduler):
606              for i in range(len(self.states)):
607                  # Fill an hash table with all information retrieved from LB API
608                  hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
609 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
609 >            result = jobStat.loadStatus(st)[self.states.index(attr)]
610              return result
611  
612      def queryDetailedStatus(self, id):
# Line 575 | Line 615 | class SchedulerEdg(Scheduler):
615          cmd_out = runCommand(cmd)
616          return cmd_out
617  
618 <    def getOutput(self, id):
618 >    ##### FEDE ######        
619 >    def findSites_(self, n):
620 >        itr4 =[]
621 >        sites = common.jobDB.destination(n)
622 >        if len(sites)>0 and sites[0]=="Any":
623 >            return itr4
624 >        itr = ''
625 >        if sites != [""]:#CarlosDaniele
626 >            for site in sites:
627 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
628 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
629 >            itr = itr[0:-4]
630 >            itr4.append( itr )
631 >        return itr4
632 >
633 >    def createXMLSchScript(self, nj, argsList):
634 >   # def createXMLSchScript(self, nj):
635 >      
636          """
637 <        Get output for a finished job with id.
581 <        Returns the name of directory with results.
637 >        Create a XML-file for BOSS4.
638          """
639 <
584 <        self.checkProxy()
585 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
586 <        cmd_out = runCommand(cmd)
587 <
588 <        # Determine the output directory name
589 <        dir = common.work_space.resDir()
590 <        dir += os.getlogin()
591 <        dir += '_' + os.path.basename(id)
592 <        return dir
593 <
594 <    def cancel(self, id):
595 <        """ Cancel the EDG job with id """
596 <        self.checkProxy()
597 <        cmd = 'edg-job-cancel --noint ' + id
598 <        cmd_out = runCommand(cmd)
599 <        return cmd_out
600 <
601 <    def createSchScript(self, nj):
639 >  #      job = common.job_list[nj]
640          """
641 <        Create a JDL-file for EDG.
641 >        INDY
642 >        [begin] FIX-ME:
643 >        I would pass jobType instead of job
644          """
645 <
646 <        job = common.job_list[nj]
645 >        index = nj - 1
646 >        job = common.job_list[index]
647          jbt = job.type()
608        inp_sandbox = jbt.inputSandbox(nj)
609        out_sandbox = jbt.outputSandbox(nj)
610        inp_storage_subdir = ''
648          
649 <        title = '# This JDL was generated by '+\
650 <                common.prog_name+' (version '+common.prog_version_str+')\n'
651 <        jt_string = ''
652 <
653 <
617 <        
618 <        SPL = inp_storage_subdir
619 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
620 <
621 <        jdl_fname = job.jdlFilename()
622 <        jdl = open(jdl_fname, 'w')
623 <        jdl.write(title)
624 <
625 <        script = job.scriptFilename()
626 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
627 <        jdl.write(jt_string)
628 <
629 <        ### only one .sh  JDL has arguments:
630 <        firstEvent = common.jobDB.firstEvent(nj)
631 <        maxEvents = common.jobDB.maxEvents(nj)
632 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
633 <
634 <        inp_box = 'InputSandbox = { '
635 <        inp_box = inp_box + '"' + script + '",'
636 <
637 <        if inp_sandbox != None:
638 <            for fl in inp_sandbox:
639 <                inp_box = inp_box + ' "' + fl + '",'
640 <                pass
641 <            pass
642 <
643 <        #if common.use_jam:
644 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
645 <
646 <        # Marco (VERY TEMPORARY ML STUFF)
647 <        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
648 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
649 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
650 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
651 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
652 <        # End Marco
653 <
654 <        if (not jbt.additional_inbox_files == []):
655 <            inp_box = inp_box + ', '
656 <            for addFile in jbt.additional_inbox_files:
657 <                addFile = os.path.abspath(addFile)
658 <                inp_box = inp_box+' "'+addFile+'",'
659 <                pass
660 <
661 <        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
662 <        inp_box = inp_box + ' };\n'
663 <        jdl.write(inp_box)
649 >        inp_sandbox = jbt.inputSandbox(index)
650 >        out_sandbox = jbt.outputSandbox(index)
651 >        """
652 >        [end] FIX-ME
653 >        """
654  
665        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
666        jdl.write('StdError      = "' + job.stderr() + '";\n')
655          
656 +        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
657 +        jt_string = ''
658          
659 <        if job.stdout() == job.stderr():
660 <          out_box = 'OutputSandbox = { "' + \
671 <                    job.stdout() + '", ".BrokerInfo",'
672 <        else:
673 <          out_box = 'OutputSandbox = { "' + \
674 <                    job.stdout() + '", "' + \
675 <                    job.stderr() + '", ".BrokerInfo",'
659 >        xml_fname = str(self.jobtypeName)+'.xml'
660 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
661  
662 <        if int(self.return_data) == 1:
663 <            if out_sandbox != None:
664 <                for fl in out_sandbox:
665 <                    out_box = out_box + ' "' + fl + '",'
666 <                    pass
667 <                pass
683 <            pass
684 <                                                                                                                                                            
685 <        if out_box[-1] == ',' : out_box = out_box[:-1]
686 <        out_box = out_box + ' };'
687 <        jdl.write(out_box+'\n')
662 >        #TaskName  
663 >        dir = string.split(common.work_space.topDir(), '/')
664 >        taskName = dir[len(dir)-2]
665 >  
666 >        to_writeReq = ''
667 >        to_write = ''
668  
669 <
690 <        req='Requirements = '
669 >        req=' '
670          req = req + jbt.getRequirements()
671 < #        ### if at least a CE exists ...
672 < #        if common.analisys_common_info['sites']:
673 < #           if common.analisys_common_info['sw_version']:
674 < #                req='Requirements = '
675 < #                req=req + 'Member("VO-cms-' + \
676 < #                     common.analisys_common_info['sw_version'] + \
677 < #                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
699 < #            if len(common.analisys_common_info['sites'])>0:
700 < #                req = req + ' && ('
701 < #                for i in range(len(common.analisys_common_info['sites'])):
702 < #                    req = req + 'other.GlueCEInfoHostName == "' \
703 < #                         + common.analisys_common_info['sites'][i] + '"'
704 < #                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
705 < #                        req = req + ' || '
706 < #            req = req + ')'
707 <        #### and USER REQUIREMENT
671 >
672 >
673 >        #sites = common.jobDB.destination(nj)
674 >        #if len(sites)>0 and sites[0]!="Any":
675 >        #    req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
676 >        #req = req    
677 >    
678          if self.EDG_requirements:
679 <            if (req == 'Requirement = '):
679 >            if (req == ' '):
680                  req = req + self.EDG_requirements
681              else:
682                  req = req +  ' && ' + self.EDG_requirements
713        #### FEDE #####
683          if self.EDG_ce_white_list:
684              ce_white_list = string.split(self.EDG_ce_white_list,',')
716            #print "req = ", req
685              for i in range(len(ce_white_list)):
686                  if i == 0:
687 <                    if (req == 'Requirement = '):
687 >                    if (req == ' '):
688                          req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
689                      else:
690                          req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
# Line 728 | Line 696 | class SchedulerEdg(Scheduler):
696          if self.EDG_ce_black_list:
697              ce_black_list = string.split(self.EDG_ce_black_list,',')
698              for ce in ce_black_list:
699 <                if (req == 'Requirement = '):
699 >                if (req == ' '):
700                      req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
701                  else:
702                      req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
703                  pass
736        ###############
704          if self.EDG_clock_time:
705 <            if (req == 'Requirement = '):
705 >            if (req == ' '):
706                  req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
707              else:
708                  req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
709  
710          if self.EDG_cpu_time:
711 <            if (req == 'Requirement = '):
711 >            if (req == ' '):
712                  req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
713              else:
714                  req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
715 <        if (req != 'Requirement = '):
749 <            req = req + ';\n'
750 <            jdl.write(req)
751 <                                                                                                                                                            
752 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
753 <
715 >                                                                                          
716          if ( self.EDG_retry_count ):              
717 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
717 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
718 >            pass
719 >
720 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
721 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
722 >
723 >                #TaskName  
724 >        dir = string.split(common.work_space.topDir(), '/')
725 >        taskName = dir[len(dir)-2]
726 >
727 >        xml.write(str(title))
728 >        xml.write('<task name="' +str(taskName)+'">\n')
729 >        xml.write(jt_string)
730 >        
731 >        if (to_write != ''):
732 >            xml.write('<extraTags\n')
733 >            xml.write(to_write)
734 >            xml.write('/>\n')
735              pass
736  
737 <        jdl.close()
737 >        xml.write('<iterator>\n')
738 >        xml.write('\t<iteratorRule name="ITR1">\n')
739 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
740 >        xml.write('\t</iteratorRule>\n')
741 >        xml.write('\t<iteratorRule name="ITR2">\n')
742 >        for arg in argsList:
743 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
744 >            pass
745 >        xml.write('\t</iteratorRule>\n')
746 >        #print jobList
747 >        xml.write('\t<iteratorRule name="ITR3">\n')
748 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
749 >        xml.write('\t</iteratorRule>\n')
750 >
751 >        '''
752 >        indy: here itr4
753 >        '''
754 >        
755 >
756 >        xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
757 >        xml.write(jt_string)
758 >
759 >        #executable
760 >
761 >        """
762 >        INDY
763 >        script depends on jobType: it should be probably get in a different way
764 >        """        
765 >        script = job.scriptFilename()
766 >        xml.write('<program>\n')
767 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
768 >        xml.write(jt_string)
769 >    
770 >          
771 >        ### only one .sh  JDL has arguments:
772 >        ### Fabio
773 > #        xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
774 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
775 >        xml.write('<program_types> crabjob </program_types>\n')
776 >        inp_box = script + ','
777 >
778 >        if inp_sandbox != None:
779 >            for fl in inp_sandbox:
780 >                inp_box = inp_box + '' + fl + ','
781 >                pass
782 >            pass
783 >
784 >        inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
785 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
786 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
787 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
788 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
789 >
790 >        if (not jbt.additional_inbox_files == []):
791 >            inp_box = inp_box + ','
792 >            for addFile in jbt.additional_inbox_files:
793 >                addFile = os.path.abspath(addFile)
794 >                inp_box = inp_box+''+addFile+','
795 >                pass
796 >
797 >        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
798 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
799 >        xml.write(inp_box)
800 >        
801 >        base = jbt.name()
802 >        stdout = base + '__ITR3_.stdout'
803 >        stderr = base + '__ITR3_.stderr'
804 >        
805 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
806 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
807 >        
808 >
809 >        out_box = stdout + ',' + \
810 >                  stderr + ',.BrokerInfo,'
811 >
812 >        """
813 >        if int(self.return_data) == 1:
814 >            if out_sandbox != None:
815 >                for fl in out_sandbox:
816 >                    out_box = out_box + '' + fl + ','
817 >                    pass
818 >                pass
819 >            pass
820 >        """
821 >
822 >        """
823 >        INDY
824 >        something similar should be also done for infiles (if it makes sense!)
825 >        """
826 >        if int(self.return_data) == 1:
827 >            for fl in jbt.output_file:
828 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
829 >                pass
830 >            pass
831 >
832 >        if out_box[-1] == ',' : out_box = out_box[:-1]
833 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
834 >        xml.write(out_box)
835 >
836 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
837 >
838 >        xml.write('</program>\n')
839 >        xml.write('</chain>\n')
840 >
841 >        xml.write('</iterator>\n')
842 >        xml.write('</task>\n')
843 >
844 >        xml.close()
845 >      
846 >
847          return
848  
849      def checkProxy(self):
# Line 764 | Line 852 | class SchedulerEdg(Scheduler):
852          """
853          if (self.proxyValid): return
854          timeleft = -999
855 <        minTimeLeft=10 # in hours
856 <        cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
857 <        # SL Here I have to use os.system since the stupid command exit with >0 if no valid proxy is found
858 <        cmd_out = os.system(cmd)
859 <        if (cmd_out>0):
860 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 24h\n")
861 <            cmd = 'voms-proxy-init -voms cms -valid 100:00'
855 >        minTimeLeft=10*3600 # in seconds
856 >
857 >        minTimeLeftServer = 100 # in hours
858 >
859 >        mustRenew = 0
860 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
861 >        timeLeftServer = -999
862 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
863 >            mustRenew = 1
864 >        else:
865 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
866 >            if not timeLeftServer or not isInt(timeLeftServer):
867 >                mustRenew = 1
868 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
869 >                mustRenew = 1
870 >            pass
871 >        pass
872 >
873 >        if mustRenew:
874 >            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")
875 >            cmd = 'voms-proxy-init -voms '+self.VO
876 >            if self.group:
877 >                cmd += ':/'+self.VO+'/'+self.group
878 >            if self.role:
879 >                cmd += '/role='+self.role
880 >            cmd += ' -valid 96:00'
881              try:
882                  # SL as above: damn it!
883 +                common.logger.debug(10,cmd)
884                  out = os.system(cmd)
885                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
886              except:
887                  msg = "Unable to create a valid proxy!\n"
888                  raise CrabException(msg)
781            # cmd = 'grid-proxy-info -timeleft'
782            # cmd_out = runCommand(cmd,0,20)
889              pass
890 +
891 +        ## now I do have a voms proxy valid, and I check the myproxy server
892 +        renewProxy = 0
893 +        cmd = 'myproxy-info -d -s '+self.proxyServer
894 +        cmd_out = runCommand(cmd,0,20)
895 +        if not cmd_out:
896 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
897 +            renewProxy = 1
898 +        else:
899 +            # if myproxy exist but not long enough, renew
900 +            reTime = re.compile( r'timeleft: (\d+)' )
901 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
902 +            if reTime.match( cmd_out ):
903 +                time = reTime.search( line ).group(1)
904 +                if time < minTimeLeftServer:
905 +                    renewProxy = 1
906 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
907 +                pass
908 +            pass
909 +        
910 +        # if not, create one.
911 +        if renewProxy:
912 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
913 +            out = os.system(cmd)
914 +            if (out>0):
915 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
916 +            pass
917 +
918 +        # cache proxy validity
919          self.proxyValid=1
920          return
921  
922      def configOpt_(self):
923          edg_ui_cfg_opt = ' '
924          if self.edg_config:
925 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
925 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
926          if self.edg_config_vo:
927 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
927 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
928          return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines