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.45 by spiga, Tue Mar 28 07:38:37 2006 UTC vs.
Revision 1.129 by slacapra, Tue Jul 17 14:08:24 2007 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 20 | Line 21 | class SchedulerEdg(Scheduler):
21          return
22  
23      def configure(self, cfg_params):
24 + ##Addedd Daniele
25 + ######################################        
26 +
27 +        SEBlackList = []
28 +        try:
29 +            tmpBad = string.split(cfg_params['EDG.se_black_list'],',')
30 +            for tmp in tmpBad:
31 +                tmp=string.strip(tmp)
32 +                SEBlackList.append(tmp)
33 +        except KeyError:
34 +            pass
35 +        common.logger.debug(5,'SEBlackList: '+str(SEBlackList))
36 +        self.reSEBlackList=[]
37 +        for bad in SEBlackList:
38 +            self.reSEBlackList.append(re.compile( string.lower(bad) ))
39 +
40 +        SEWhiteList = []
41 +        try:
42 +            tmpGood = string.split(cfg_params['EDG.se_white_list'],',')
43 +            for tmp in tmpGood:
44 +                tmp=string.strip(tmp)
45 +                SEWhiteList.append(tmp)
46 +        except KeyError:
47 +            pass
48 +        common.logger.debug(5,'SEWhiteList: '+str(SEWhiteList))
49 +        self.reSEWhiteList=[]
50 +        for good in SEWhiteList:
51 +            self.reSEWhiteList.append(re.compile( string.lower(good) ))
52  
24        try: self.edg_config = cfg_params["EDG.config"]
25        except KeyError: self.edg_config = ''
53  
54 <        try: self.edg_config_vo = cfg_params["EDG.config_vo"]
55 <        except KeyError: self.edg_config_vo = ''
54 > ######################################        
55 >        try:
56 >            RB=cfg_params["EDG.rb"]
57 >            self.rb_param_file=self.rb_configure(RB)
58 >        except KeyError:
59 >            self.rb_param_file=''
60 >            pass
61 >        try:
62 >            self.proxyServer = cfg_params["EDG.proxy_server"]
63 >        except KeyError:
64 >            self.proxyServer = 'myproxy.cern.ch'
65 >        common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
66  
67 +        try:
68 +            self.group = cfg_params["EDG.group"]
69 +        except KeyError:
70 +            self.group = None
71 +            
72 +        try:
73 +            self.role = cfg_params["EDG.role"]
74 +        except KeyError:
75 +            self.role = None
76 +            
77          try: self.LCG_version = cfg_params["EDG.lcg_version"]
78          except KeyError: self.LCG_version = '2'
79  
80 <        try: self.EDG_requirements = cfg_params['EDG.requirements']
81 <        except KeyError: self.EDG_requirements = ''
80 >        try:
81 >            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
82 >        except KeyError:
83 >            self.EDG_ce_black_list  = ''
84  
85 <        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
86 <        except KeyError: self.EDG_retry_count = ''
85 >        try:
86 >            self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
87 >        except KeyError: self.EDG_ce_white_list = ''
88  
89          try: self.VO = cfg_params['EDG.virtual_organization']
90          except KeyError: self.VO = 'cms'
91  
92 <        try:
43 <             self.copy_input_data = common.analisys_common_info['copy_input_data']
44 <             #print "self.copy_input_data = ", self.copy_input_data
92 >        try: self.copy_input_data = cfg_params["USER.copy_input_data"]
93          except KeyError: self.copy_input_data = 0
94  
95          try: self.return_data = cfg_params['USER.return_data']
96 <        except KeyError: self.return_data = 1
96 >        except KeyError: self.return_data = 0
97  
98          try:
99              self.copy_data = cfg_params["USER.copy_data"]
# Line 65 | Line 113 | class SchedulerEdg(Scheduler):
113             msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
114             raise CrabException(msg)
115  
116 +        ########### FEDE FOR DBS2 ##############################
117 +        try:
118 +            self.publish_data = cfg_params["USER.publish_data"]
119 +            if int(self.publish_data) == 1:
120 +                try:
121 +                    self.publish_data_name = cfg_params['USER.publish_data_name']
122 +                except KeyError:
123 +                    msg = "Error. The [USER] section does not have 'publish_data_name'"
124 +                    raise CrabException(msg)
125 +                try:
126 +                    tmp = runCommand("voms-proxy-info -identity")
127 +                    tmp = string.split(tmp,'/')
128 +                    reCN=re.compile(r'CN=')
129 +                    for t in tmp:
130 +                        if reCN.match(t):
131 +                            self.UserGridName=string.strip((t.replace('CN=','')).replace(' ',''))
132 +                        
133 +                    #self.UserGridName = string.strip(runCommand("voms-proxy-info -identity | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'"))
134 +                except:
135 +                    msg = "Error. Problem with voms-proxy-info -identity command"
136 +                    raise CrabException(msg)
137 +        except KeyError: self.publish_data = 0
138 +
139 +        if ( int(self.copy_data) == 0 and int(self.publish_data) == 1 ):
140 +           msg = 'Warning: publish_data = 1 must be used with copy_data = 1\n'
141 +           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
142 +           common.logger.message(msg)
143 +           raise CrabException(msg)
144 +        #################################################
145 +
146          try:
147              self.lfc_host = cfg_params['EDG.lfc_host']
148          except KeyError:
# Line 107 | Line 185 | class SchedulerEdg(Scheduler):
185  
186          try: self.EDG_requirements = cfg_params['EDG.requirements']
187          except KeyError: self.EDG_requirements = ''
188 <                                                                                                                                                            
188 >
189 >        try: self.EDG_addJdlParam = string.split(cfg_params['EDG.additional_jdl_parameters'],',')
190 >        except KeyError: self.EDG_addJdlParam = []
191 >
192          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
193          except KeyError: self.EDG_retry_count = ''
194 <                                                                                                                                                            
194 >
195 >        try: self.EDG_shallow_retry_count= cfg_params['EDG.shallow_retry_count']
196 >        except KeyError: self.EDG_shallow_retry_count = ''
197 >
198          try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
199          except KeyError: self.EDG_clock_time= ''
200 <                                                                                                                                                            
200 >
201          try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
202          except KeyError: self.EDG_cpu_time = ''
203  
# Line 131 | Line 215 | class SchedulerEdg(Scheduler):
215          sys.path.append(libPath)
216  
217          self.proxyValid=0
218 +
219 +        try:
220 +            self._taskId = cfg_params['taskId']
221 +        except:
222 +            self._taskId = ''
223 +
224 +        try: self.jobtypeName = cfg_params['CRAB.jobtype']
225 +        except KeyError: self.jobtypeName = ''
226 +
227 +        try: self.schedulerName = cfg_params['CRAB.scheduler']
228 +        except KeyError: self.scheduler = ''
229 +
230 +        try: self.dontCheckProxy=int(cfg_params["EDG.dont_check_proxy"])
231 +        except KeyError: self.dontCheckProxy = 0
232 +
233          return
234      
235  
236 +    def rb_configure(self, RB):
237 +        self.edg_config = ''
238 +        self.edg_config_vo = ''
239 +        self.rb_param_file = ''
240 +
241 +        edgConfig = EdgConfig(RB)
242 +        self.edg_config = edgConfig.config()
243 +        self.edg_config_vo = edgConfig.configVO()
244 +
245 +        if (self.edg_config and self.edg_config_vo != ''):
246 +            self.rb_param_file = 'RBconfig = "'+self.edg_config+'";\nRBconfigVO = "'+self.edg_config_vo+'";\n'
247 +            #print "rb_param_file = ", self.rb_param_file
248 +        return self.rb_param_file
249 +      
250 +
251      def sched_parameter(self):
252          """
253 <        Returns file with scheduler-specific parameters
253 >        Returns file with requirements and scheduler-specific parameters
254          """
255 <      
256 <        if (self.edg_config and self.edg_config_vo != ''):
257 <            self.param='sched_param.clad'
255 >        index = int(common.jobDB.nJobs()) - 1
256 >        job = common.job_list[index]
257 >        jbt = job.type()
258 >        
259 >        lastBlock=-1
260 >        first = []
261 >        for n in range(common.jobDB.nJobs()):
262 >            currBlock=common.jobDB.block(n)
263 >            if (currBlock!=lastBlock):
264 >                lastBlock = currBlock
265 >                first.append(n)
266 >  
267 >        req = ''
268 >        req = req + jbt.getRequirements()
269 >    
270 >        if self.EDG_requirements:
271 >            if (req == ' '):
272 >                req = req + self.EDG_requirements
273 >            else:
274 >                req = req +  ' && ' + self.EDG_requirements
275 >
276 >        if self.EDG_ce_white_list:
277 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
278 >            for i in range(len(ce_white_list)):
279 >                if i == 0:
280 >                    if (req == ' '):
281 >                        req = req + '((RegExp("' + string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
282 >                    else:
283 >                        req = req +  ' && ((RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
284 >                    pass
285 >                else:
286 >                    req = req +  ' || (RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
287 >            req = req + ')'
288 >        
289 >        if self.EDG_ce_black_list:
290 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
291 >            for ce in ce_black_list:
292 >                if (req == ' '):
293 >                    req = req + '(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
294 >                else:
295 >                    req = req +  ' && (!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
296 >                pass
297 >        if self.EDG_clock_time:
298 >            if (req == ' '):
299 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
300 >            else:
301 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
302 >
303 >        if self.EDG_cpu_time:
304 >            if (req == ' '):
305 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
306 >            else:
307 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
308 >                
309 >        for i in range(len(first)): # Add loop DS
310 >            groupReq = req
311 >            self.param='sched_param_'+str(i)+'.clad'
312              param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
313 <            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
314 <            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
313 >
314 >            itr4=self.findSites_(first[i])
315 >            for arg in itr4:
316 >                groupReq = groupReq + ' && anyMatch(other.storage.CloseSEs, ('+str(arg)+'))'
317 >            param_file.write('Requirements = '+groupReq +';\n')  
318 >  
319 >            if (self.rb_param_file != ''):
320 >                param_file.write(self.rb_param_file)  
321 >
322 >            if len(self.EDG_addJdlParam):
323 >                for p in self.EDG_addJdlParam:
324 >                    param_file.write(p)
325 >
326              param_file.close()  
327 <            return 1
149 <        else:
150 <            return 0
327 >
328  
329      def wsSetupEnvironment(self):
330          """
331          Returns part of a job script which does scheduler-specific work.
332          """
156
333          txt = ''
334 <        if int(self.copy_data) == 1:
335 <           if self.SE:
336 <              txt += 'export SE='+self.SE+'\n'
337 <              txt += 'echo "SE = $SE"\n'
338 <           if self.SE_PATH:
339 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
340 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
341 <              txt += 'echo "SE_PATH = $SE_PATH"\n'
342 <                                                                                                                                                            
334 >        txt += '# strip arguments\n'
335 >        txt += 'echo "strip arguments"\n'
336 >        txt += 'args=("$@")\n'
337 >        txt += 'nargs=$#\n'
338 >        txt += 'shift $nargs\n'
339 >        txt += "# job number (first parameter for job wrapper)\n"
340 >        #txt += "NJob=$1\n"
341 >        txt += "NJob=${args[0]}\n"
342 >
343 >        txt += '# job identification to DashBoard \n'
344 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
345 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
346 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
347 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
348 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
349 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
350 >
351 >        txt += 'echo "middleware discovery " \n'
352 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
353 >        txt += '    middleware=OSG \n'
354 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
355 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
356 >        txt += '    echo "middleware =$middleware" \n'
357 >        txt += 'elif [ $OSG_APP ]; then \n'
358 >        txt += '    middleware=OSG \n'
359 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
360 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
361 >        txt += '    echo "middleware =$middleware" \n'
362 >        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
363 >        txt += '    middleware=LCG \n'
364 >   #     txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
365 >        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
366 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
367 >        txt += '    echo "middleware =$middleware" \n'
368 >        txt += 'else \n'
369 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
370 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
371 >        txt += '    echo "JobExitCode=10030" | 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 >
379 >        txt += '# report first time to DashBoard \n'
380 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
381 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
382 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
383 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
384 >        
385 >        txt += '\n\n'
386 >
387 > #        if int(self.copy_data) == 1:
388 > #           if self.SE:
389 > #              txt += 'export SE='+self.SE+'\n'
390 > #              txt += 'echo "SE = $SE"\n'
391 > #           if self.SE_PATH:
392 > #              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
393 > #              txt += 'export SE_PATH='+self.SE_PATH+'\n'
394 > #              txt += 'echo "SE_PATH = $SE_PATH"\n'
395 >
396          txt += 'export VO='+self.VO+'\n'
397 <        ### FEDE: add some line for LFC catalog setting
398 <        txt += 'if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
399 <        txt += '   export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
400 <        txt += 'fi\n'
401 <        txt += 'if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
402 <        txt += 'export LFC_HOST='+self.lfc_host+'\n'
403 <        txt += 'fi\n'
404 <        txt += 'if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
405 <        txt += 'export LFC_HOME='+self.lfc_home+'\n'
397 >        ### add some line for LFC catalog setting
398 >        txt += 'if [ $middleware == LCG ]; then \n'
399 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
400 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
401 >        txt += '    fi\n'
402 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
403 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
404 >        txt += '    fi\n'
405 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
406 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
407 >        txt += '    fi\n'
408 >        txt += 'elif [ $middleware == OSG ]; then\n'
409 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
410          txt += 'fi\n'
411          #####
412          if int(self.register_data) == 1:
413 <           txt += 'export LFN='+self.LFN+'\n'
414 <           txt += 'lfc-ls $LFN\n'
415 <           txt += 'result=$?\n'
416 <           txt += 'echo $result\n'
413 >           txt += 'if [ $middleware == LCG ]; then \n'
414 >           txt += '    export LFN='+self.LFN+'\n'
415 >           txt += '    lfc-ls $LFN\n'
416 >           txt += '    result=$?\n'
417 >           txt += '    echo $result\n'
418             ### creation of LFN dir in LFC catalog, under /grid/cms dir  
419 <           txt += 'if [ $result != 0 ]; then\n'
420 <           txt += '   lfc-mkdir $LFN\n'
421 <           txt += '   result=$?\n'
422 <           txt += '   echo $result\n'
419 >           txt += '    if [ $result != 0 ]; then\n'
420 >           txt += '       lfc-mkdir $LFN\n'
421 >           txt += '       result=$?\n'
422 >           txt += '       echo $result\n'
423 >           txt += '    fi\n'
424 >           txt += 'elif [ $middleware == OSG ]; then\n'
425 >           txt += '    echo " Files registration to be implemented for OSG"\n'
426             txt += 'fi\n'
427             txt += '\n'
428 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
429 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
430 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
431 <        txt += 'echo "CE = $CE"\n'
428 >
429 >           if self.VO:
430 >              txt += 'export VO='+self.VO+'\n'
431 >           if self.LFN:
432 >              txt += 'if [ $middleware == LCG ]; then \n'
433 >              txt += '    export LFN='+self.LFN+'\n'
434 >              txt += 'fi\n'
435 >              txt += '\n'
436 >
437 >        txt += 'if [ $middleware == LCG ]; then\n'
438 >    #    txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
439 >        txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
440 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
441 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
442 >        txt += '    echo "CE = $CE"\n'
443 >        txt += 'elif [ $middleware == OSG ]; then \n'
444 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
445 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
446 >        txt += '    else \n'
447 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
448 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
449 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
450 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
451 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
452 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
453 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
454 >        txt += '        exit 1 \n'
455 >        txt += '    fi \n'
456 >        txt += 'fi \n'
457 >
458          return txt
459  
460      def wsCopyInput(self):
# Line 199 | Line 462 | class SchedulerEdg(Scheduler):
462          Copy input data from SE to WN    
463          """
464          txt = ''
465 <        try:
466 <            self.copy_input_data = common.analisys_common_info['copy_input_data']
467 <            #print "self.copy_input_data = ", self.copy_input_data
468 <        except KeyError: self.copy_input_data = 0
469 <        if int(self.copy_input_data) == 1:
470 <           txt += '#\n'
471 <           txt += '#   Copy Input Data from SE to this WN\n'
472 <           txt += '#\n'
473 < ### changed by georgia (put a loop copying more than one input files per jobs)          
474 <           txt +='for input_file in $cur_file_list \n'
475 <           txt +='do \n'
476 <           txt +=' lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
477 <           txt +=' copy_input_exit_status=$?\n'
478 <           txt +=' echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
479 <           txt +=' if [ $copy_input_exit_status -ne 0 ]; then \n'
480 <           txt +='    echo "Problems with copying to WN" \n'
481 <           txt +=' else \n'
482 <           txt +='    echo "input copied into WN" \n'
483 <           txt +=' fi \n'
484 <           txt +='done \n'
485 < ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
486 <           txt +='for file in $cur_pu_list \n'
487 <           txt +='do \n'
488 <           txt +=' lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
489 <           txt +=' copy_input_exit_status=$?\n'
490 <           txt +=' echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
491 <           txt +=' if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
492 <           txt +='    echo "Problems with copying pu to WN" \n'
493 <           txt +=' else \n'
494 <           txt +='    echo "input pu files copied into WN" \n'
495 <           txt +=' fi \n'
496 <           txt +='done \n'
497 <           txt +='\n'
498 <           txt +='### Check SCRATCH space available on WN : \n'
499 <           txt +='df -h \n'
465 >        if not self.copy_input_data: return txt
466 >
467 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
468 >        txt += 'if [ $middleware == OSG ]; then\n'
469 >        txt += '   #\n'
470 >        txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
471 >        txt += '   #\n'
472 >        txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
473 >        txt += 'elif [ $middleware == LCG ]; then \n'
474 >        txt += '   #\n'
475 >        txt += '   #   Copy Input Data from SE to this WN\n'
476 >        txt += '   #\n'
477 >        ### changed by georgia (put a loop copying more than one input files per jobs)          
478 >        txt += '   for input_file in $cur_file_list \n'
479 >        txt += '   do \n'
480 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
481 >        txt += '      copy_input_exit_status=$?\n'
482 >        txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
483 >        txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
484 >        txt += '         echo "Problems with copying to WN" \n'
485 >        txt += '      else \n'
486 >        txt += '         echo "input copied into WN" \n'
487 >        txt += '      fi \n'
488 >        txt += '   done \n'
489 >        ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
490 >        txt += '   for file in $cur_pu_list \n'
491 >        txt += '   do \n'
492 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
493 >        txt += '      copy_input_pu_exit_status=$?\n'
494 >        txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
495 >        txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
496 >        txt += '         echo "Problems with copying pu to WN" \n'
497 >        txt += '      else \n'
498 >        txt += '         echo "input pu files copied into WN" \n'
499 >        txt += '      fi \n'
500 >        txt += '   done \n'
501 >        txt += '   \n'
502 >        txt += '   ### Check SCRATCH space available on WN : \n'
503 >        txt += '   df -h \n'
504 >        txt += 'fi \n'
505 >          
506          return txt
507  
508      def wsCopyOutput(self):
# Line 242 | Line 511 | class SchedulerEdg(Scheduler):
511          to copy produced output into a storage element.
512          """
513          txt = ''
514 +
515 +        ##### FEDE MOVED FROM SET_ENVIRONMENT ##############
516 +        
517 +        SE_PATH=''
518          if int(self.copy_data) == 1:
519 +           if self.SE:
520 +              txt += 'export SE='+self.SE+'\n'
521 +              txt += 'echo "SE = $SE"\n'
522 +           if self.SE_PATH:
523 +              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
524 +              SE_PATH=self.SE_PATH
525 +              ####### FEDE FOR DBS2
526 +              if int(self.publish_data) == 1:
527 +                  txt += '### publish_data = 1 so the SE path where to copy the output is: \n'
528 +                  #txt += 'subject=`voms-proxy-info -subject | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'` \n'
529 +                  #txt += 'echo "subject = $subject" \n'
530 +                  #path_add = '${subject}/'+ self.publish_data_name +'_${PSETHASH}/'
531 +                  path_add = self.UserGridName + '/' + self.publish_data_name +'_${PSETHASH}/'
532 +                  SE_PATH = SE_PATH + path_add
533 +
534 +              txt += 'export SE_PATH='+SE_PATH+'\n'
535 +              txt += 'echo "SE_PATH = $SE_PATH"\n'
536 +
537 +        ##########################################################  
538 +
539 +        #if int(self.copy_data) == 1:
540             txt += '#\n'
541             txt += '#   Copy output to SE = $SE\n'
542             txt += '#\n'
543 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
543 >           txt += '    if [ $middleware == OSG ]; then\n'
544 >           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
545 >           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
546 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
547 >           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
548 >           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
549 >           txt += '    fi \n'
550 >
551             txt += '    for out_file in $file_list ; do\n'
552 <           txt += '        echo "Trying to copy output file to $SE "\n'
553 <           txt += '        echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
554 < #           txt += '        echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
555 <           txt += '        exitstring=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
556 < #           txt += '        exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
552 >           txt += '        echo "Trying to copy output file to $SE using srmcp"\n'
553 >           # txt += '        echo "mkdir -p $HOME/.srmconfig"\n'
554 >           # txt += '        mkdir -p $HOME/.srmconfig\n'
555 >           txt += '        if [ $middleware == LCG ]; then\n'
556 >           txt += '           echo "srmcp -retry_num 3 -retry_timeout 480000 file:///`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
557 >           txt += '           exitstring=`srmcp -retry_num 3 -retry_timeout 480000 file:///\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
558 >           txt += '        elif [ $middleware == OSG ]; then\n'
559 >           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'
560 >           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'
561 >           txt += '        fi \n'
562             txt += '        copy_exit_status=$?\n'
563 <           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
563 >           txt += '        echo "COPY_EXIT_STATUS for srmcp = $copy_exit_status"\n'
564             txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
565 +
566             txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
567 <           txt += '            echo "Problems with SE = $SE"\n'
567 >           txt += '            echo "Possible problem with SE = $SE"\n'
568             txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
569             txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
570 +           txt += '            echo "srmcp failed, attempting lcg-cp."\n'
571 +           if common.logger.debugLevel() >= 5:
572 +               ########### FEDE CHANGES TO WRITE IN SRM LNL.INFN.IT #################
573 +               txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
574 +               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
575 +               #txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
576 +               #txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
577 +           else:              
578 +               txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
579 +               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
580 +               #txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
581 +               #txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
582 +           txt += '            copy_exit_status=$?\n'
583 +           txt += '            echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
584 +           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
585 +
586 +           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
587 +           txt += '               echo "Problems with SE = $SE"\n'
588 +           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
589 +           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
590 +           txt += '               echo "srmcp and lcg-cp and failed!"\n'
591 +           txt += '               SE=""\n'
592 +           txt += '               echo "SE = $SE"\n'
593 +           txt += '               SE_PATH=""\n'
594 +           txt += '               echo "SE_PATH = $SE_PATH"\n'
595 +           txt += '            else\n'
596 +           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
597 +           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
598 +           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
599 +           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
600 +           txt += '               echo "lcg-cp succeeded"\n'
601 +           txt += '            fi\n'
602             txt += '        else\n'
603             txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
604             txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
605             txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
606             txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
607 +           txt += '            echo "srmcp succeeded"\n'
608             txt += '         fi\n'
609             txt += '     done\n'
610 <           txt += 'fi\n'
610 >           txt += '     exit_status=$copy_exit_status\n'
611          return txt
612  
613      def wsRegisterOutput(self):
# Line 277 | Line 617 | class SchedulerEdg(Scheduler):
617  
618          txt = ''
619          if int(self.register_data) == 1:
620 +        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
621 +           txt += 'if [ $middleware == OSG ]; then\n'
622 +           txt += '   #\n'
623 +           txt += '   #   Register output to LFC deactivated in OSG mode\n'
624 +           txt += '   #\n'
625 +           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
626 +           txt += 'elif [ $middleware == LCG ]; then \n'
627             txt += '#\n'
628             txt += '#  Register output to LFC\n'
629             txt += '#\n'
630 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
631 <           txt += '   for out_file in $file_list ; do\n'
632 <           txt += '      echo "Trying to register the output file into LFC"\n'
633 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
634 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
288 <           txt += '      register_exit_status=$?\n'
289 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
290 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
291 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
292 <           txt += '         echo "Problems with the registration to LFC" \n'
293 <           txt += '         echo "Try with srm protocol" \n'
294 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
295 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
630 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
631 >           txt += '      for out_file in $file_list ; do\n'
632 >           txt += '         echo "Trying to register the output file into LFC"\n'
633 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
634 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
635             txt += '         register_exit_status=$?\n'
636             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
637             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
638             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
639 <           txt += '            echo "Problems with the registration into LFC" \n'
639 >           txt += '            echo "Problems with the registration to LFC" \n'
640 >           txt += '            echo "Try with srm protocol" \n'
641 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
642 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
643 >           txt += '            register_exit_status=$?\n'
644 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
645 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
646 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
647 >           txt += '               echo "Problems with the registration into LFC" \n'
648 >           txt += '            fi \n'
649 >           txt += '         else \n'
650 >           txt += '            echo "output registered to LFC"\n'
651             txt += '         fi \n'
652 <           txt += '      else \n'
653 <           txt += '         echo "output registered to LFC"\n'
654 <           txt += '      fi \n'
655 <           txt += '      echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
656 <           txt += '   done\n'
657 <           txt += 'elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
658 <           txt += '   echo "Trying to copy output file to CloseSE"\n'
659 <           txt += '   CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
660 <           txt += '   for out_file in $file_list ; do\n'
661 <           txt += '      echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
662 <           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'
663 <           txt += '      register_exit_status=$?\n'
664 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
665 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
666 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
667 <           txt += '         echo "Problems with CloseSE" \n'
668 <           txt += '      else \n'
669 <           txt += '         echo "The program was successfully executed"\n'
670 <           txt += '         echo "SE = $CLOSE_SE"\n'
671 <           txt += '         echo "LFN for the file is LFN=${LFN}/$out_file"\n'
672 <           txt += '      fi \n'
673 <           txt += '      echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
674 <           txt += '   done\n'
325 <           txt += 'else\n'
326 <           txt += '   echo "Problem with the executable"\n'
652 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
653 >           txt += '      done\n'
654 >           txt += '   else \n'
655 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
656 > #          txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
657 >           txt += '      CLOSE_SE=`glite-brokerinfo getCloseSEs | head -1`\n'
658 >           txt += '      for out_file in $file_list ; do\n'
659 >           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'
660 >           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'
661 >           txt += '         register_exit_status=$?\n'
662 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
663 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
664 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
665 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
666 >           txt += '         else \n'
667 >           txt += '            echo "The program was successfully executed"\n'
668 >           txt += '            echo "SE = $CLOSE_SE"\n'
669 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
670 >           txt += '         fi \n'
671 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
672 >           txt += '      done\n'
673 >           txt += '   fi \n'
674 >           txt += '   exit_status=$register_exit_status\n'
675             txt += 'fi \n'
676          return txt
677  
# Line 333 | Line 681 | class SchedulerEdg(Scheduler):
681          """
682          self.checkProxy()
683          cmd = 'edg-job-get-logging-info -v 2 ' + id
336        #cmd_out = os.popen(cmd)
684          cmd_out = runCommand(cmd)
685          return cmd_out
686  
687 <    def listMatch(self, nj):
688 <        """
689 <        Check the compatibility of available resources
690 <        """
691 <        self.checkProxy()
345 <        jdl = common.job_list[nj].jdlFilename()
346 <        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
347 <        cmd_out = runCommand(cmd,0,10)
348 <        if not cmd_out:
349 <            raise CrabException("ERROR: "+cmd+" failed!")
687 >    def queryDetailedStatus(self, id):
688 >        """ Query a detailed status of the job with id """
689 >        cmd = 'edg-job-status '+id
690 >        cmd_out = runCommand(cmd)
691 >        return cmd_out
692  
693 <        return self.parseListMatch_(cmd_out, jdl)
693 > ##Addedd Daniele
694 > # #######################################################################
695 >    def checkBlackList(self, Sites, fileblocks):
696 >        """
697 >        select sites that are not excluded by the user (via SE black list)
698 >        """
699 >        goodSites = []
700 >        for aSite in Sites:
701 >            common.logger.debug(10,'Site '+aSite)
702 >            good=1
703 >            for re in self.reSEBlackList:
704 >                if re.search(string.lower(aSite)):
705 >                    common.logger.debug(5,'SE in black list, skipping site '+aSite)
706 >                    good=0
707 >                pass
708 >            if good: goodSites.append(aSite)
709 >        if len(goodSites) == 0:
710 >            msg = "No sites hosting the block %s after BlackList" % fileblocks
711 >            common.logger.debug(5,msg)
712 >            common.logger.debug(5,"Proceeding without this block.\n")
713 >        else:
714 >            common.logger.debug(5,"Selected sites for block "+str(fileblocks)+" via BlackList are "+str(goodSites)+"\n")
715 >        return goodSites
716  
717 <    def parseListMatch_(self, out, jdl):
717 > # #######################################################################
718 >    def checkWhiteList(self, Sites, fileblocks):
719          """
720 <        Parse the f* output of edg-list-match and produce something sensible
720 >        select sites that are defined by the user (via SE white list)
721          """
722 <        reComment = re.compile( r'^\**$' )
723 <        reEmptyLine = re.compile( r'^$' )
724 <        reVO = re.compile( r'Selected Virtual Organisation name.*' )
725 <        reLine = re.compile( r'.*')
726 <        reCE = re.compile( r'(.*:.*)')
727 <        reCEId = re.compile( r'CEId.*')
728 <        reNO = re.compile( r'No Computing Element matching' )
729 <        reRB = re.compile( r'Connecting to host' )
365 <        next = 0
366 <        CEs=[]
367 <        Match=0
368 <
369 <        #print out
370 <        lines = reLine.findall(out)
371 <
372 <        i=0
373 <        CEs=[]
374 <        for line in lines:
375 <            string.strip(line)
376 <            #print line
377 <            if reNO.match( line ):
378 <                common.logger.debug(5,line)
379 <                return 0
722 >        if len(self.reSEWhiteList)==0: return Sites
723 >        goodSites = []
724 >        for aSite in Sites:
725 >            good=0
726 >            for re in self.reSEWhiteList:
727 >                if re.search(string.lower(aSite)):
728 >                    common.logger.debug(5,'SE in white list, adding site '+aSite)
729 >                    good=1
730                  pass
731 <            if reVO.match( line ):
732 <                VO =reVO.match( line ).group()
733 <                common.logger.debug(5,"VO "+VO)
734 <                pass
735 <
736 <            if reRB.match( line ):
737 <                RB = reRB.match(line).group()
738 <                common.logger.debug(5,"RB "+RB)
739 <                pass
740 <
391 <            if reCEId.search( line ):
392 <                for lineCE in lines[i:-1]:
393 <                    if reCE.match( lineCE ):
394 <                        CE = string.strip(reCE.search(lineCE).group(1))
395 <                        CEs.append(CE.split(':')[0])
396 <                        pass
397 <                    pass
398 <                pass
399 <            i=i+1
400 <            pass
401 <
402 <        common.logger.debug(5,"All CE :"+str(CEs))
403 <
404 <        sites = []
405 <        [sites.append(it) for it in CEs if not sites.count(it)]
731 >            if good: goodSites.append(aSite)
732 >        
733 >        if len(goodSites) == 0:
734 >            msg = "No sites hosting the block %s after WhiteList" % fileblocks
735 >            common.logger.debug(5,msg)
736 >            common.logger.debug(5,"Proceeding without this block.\n")
737 >        else:
738 >            common.logger.debug(5,"Selected sites for block "+str(fileblocks)+" via WhiteList are "+str(goodSites)+"\n")
739 >      
740 >        return goodSites
741  
742 <        common.logger.debug(5,"All Sites :"+str(sites))
743 <        return len(sites)
744 <
745 <    def noMatchFound_(self, jdl):
746 <        reReq = re.compile( r'Requirements' )
747 <        reString = re.compile( r'"\S*"' )
748 <        f = file(jdl,'r')
749 <        for line in f.readlines():
750 <            line= line.strip()
751 <            if reReq.match(line):
752 <                for req in reString.findall(line):
753 <                    if re.search("VO",req):
754 <                        common.logger.message( "SW required: "+req)
755 <                        continue
756 <                    if re.search('"\d+',req):
757 <                        common.logger.message("Other req  : "+req)
758 <                        continue
759 <                    common.logger.message( "CE required: "+req)
760 <                break
761 <            pass
762 <        raise CrabException("No compatible resources found!")
742 > # #######################################################################
743 >    def findSites_(self, n):
744 >        itr4 =[]
745 >
746 >        sites = common.jobDB.destination(n)
747 >
748 >        if len(sites)>0 and sites[0]=="":
749 >            return itr4
750 >
751 >        itr = ''
752 >        if sites != [""]:#CarlosDaniele
753 >            ##Addedd Daniele
754 >            replicas = self.checkBlackList(sites,n)
755 >            if len(replicas)!=0:
756 >                replicas = self.checkWhiteList(replicas,n)
757 >              
758 >            if len(replicas)==0:
759 >                msg = 'No sites remaining that host any part of the requested data! Exiting... '
760 >                raise CrabException(msg)
761 >            #####        
762 >           # for site in sites:
763 >            for site in replicas:
764 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
765 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
766 >            itr = itr[0:-4]
767 >            itr4.append( itr )
768 >        return itr4
769  
770 <    def submit(self, nj):
770 >    def createXMLSchScript(self, nj, argsList):
771 >      
772          """
773 <        Submit one EDG job.
773 >        Create a XML-file for BOSS4.
774          """
775 <
434 <        self.checkProxy()
435 <        jid = None
436 <        jdl = common.job_list[nj].jdlFilename()
437 <
438 <        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
439 <        cmd_out = runCommand(cmd)
440 <        if cmd_out != None:
441 <            reSid = re.compile( r'https.+' )
442 <            jid = reSid.search(cmd_out).group()
443 <            pass
444 <        return jid
445 <
446 <    def resubmit(self, nj_list):
775 >  #      job = common.job_list[nj]
776          """
777 <        Prepare jobs to be submit
777 >        INDY
778 >        [begin] FIX-ME:
779 >        I would pass jobType instead of job
780 >        """
781 >        index = nj - 1
782 >        job = common.job_list[index]
783 >        jbt = job.type()
784 >        
785 >        inp_sandbox = jbt.inputSandbox(index)
786 >        #out_sandbox = jbt.outputSandbox(index)
787 >        """
788 >        [end] FIX-ME
789          """
450        return
451
452    def getExitStatus(self, id):
453        return self.getStatusAttribute_(id, 'exit_code')
454
455    def queryStatus(self, id):
456        return self.getStatusAttribute_(id, 'status')
457
458    def queryDest(self, id):  
459        return self.getStatusAttribute_(id, 'destination')
460
461
462    def getStatusAttribute_(self, id, attr):
463        """ Query a status of the job with id """
790  
791 <        self.checkProxy()
792 <        hstates = {}
793 <        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
794 <        # Bypass edg-job-status interfacing directly to C++ API
795 <        # Job attribute vector to retrieve status without edg-job-status
796 <        level = 0
471 <        # Instance of the Status class provided by LB API
472 <        jobStat = Status()
473 <        st = 0
474 <        jobStat.getStatus(id, level)
475 <        err, apiMsg = jobStat.get_error()
476 <        if err:
477 <            common.logger.debug(5,'Error caught' + apiMsg)
478 <            return None
479 <        else:
480 <            for i in range(len(self.states)):
481 <                # Fill an hash table with all information retrieved from LB API
482 <                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
483 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
484 <            return result
791 >        
792 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
793 >        jt_string = ''
794 >        
795 >        xml_fname = str(self.jobtypeName)+'.xml'
796 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
797  
798 <    def queryDetailedStatus(self, id):
799 <        """ Query a detailed status of the job with id """
800 <        cmd = 'edg-job-status '+id
801 <        cmd_out = runCommand(cmd)
802 <        return cmd_out
798 >        #TaskName  
799 >        dir = string.split(common.work_space.topDir(), '/')
800 >        taskName = dir[len(dir)-2]
801 >  
802 >        to_write = ''
803  
804 <    def getOutput(self, id):
805 <        """
494 <        Get output for a finished job with id.
495 <        Returns the name of directory with results.
496 <        """
804 >        req=' '
805 >        req = req + jbt.getRequirements()
806  
807 <        self.checkProxy()
808 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
809 <        cmd_out = runCommand(cmd)
807 >        if self.EDG_requirements:
808 >            if (req == ' '):
809 >                req = req + self.EDG_requirements
810 >            else:
811 >                req = req +  ' && ' + self.EDG_requirements
812 >        if self.EDG_ce_white_list:
813 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
814 >            for i in range(len(ce_white_list)):
815 >                if i == 0:
816 >                    if (req == ' '):
817 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
818 >                    else:
819 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
820 >                    pass
821 >                else:
822 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
823 >            req = req + ')'
824 >        
825 >        if self.EDG_ce_black_list:
826 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
827 >            for ce in ce_black_list:
828 >                if (req == ' '):
829 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
830 >                else:
831 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
832 >                pass
833 >        if self.EDG_clock_time:
834 >            if (req == ' '):
835 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
836 >            else:
837 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
838  
839 <        # Determine the output directory name
840 <        dir = common.work_space.resDir()
841 <        dir += os.getlogin()
842 <        dir += '_' + os.path.basename(id)
843 <        return dir
839 >        if self.EDG_cpu_time:
840 >            if (req == ' '):
841 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
842 >            else:
843 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
844 >                                                                                          
845 >        if ( self.EDG_retry_count ):              
846 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
847 >            pass
848  
849 <    def cancel(self, id):
850 <        """ Cancel the EDG job with id """
851 <        self.checkProxy()
511 <        cmd = 'edg-job-cancel --noint ' + id
512 <        cmd_out = runCommand(cmd)
513 <        return cmd_out
849 >        if ( self.EDG_shallow_retry_count ):              
850 >            to_write = to_write + 'ShallowRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
851 >            pass
852  
853 <    def createSchScript(self, nj):
854 <        """
517 <        Create a JDL-file for EDG.
518 <        """
853 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
854 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
855  
856 <        job = common.job_list[nj]
857 <        jbt = job.type()
858 <        inp_sandbox = jbt.inputSandbox(nj)
859 <        out_sandbox = jbt.outputSandbox(nj)
860 <        inp_storage_subdir = ''
856 >        #TaskName  
857 >        dir = string.split(common.work_space.topDir(), '/')
858 >        taskName = dir[len(dir)-2]
859 >
860 >        xml.write(str(title))
861 >        #xml.write('<task name="' +str(taskName)+'" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache">\n')
862 >
863 >        #xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + '" task_info="' + os.path.expandvars('X509_USER_PROXY') + '">\n')
864 >        xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + ' task_info="' + os.environ["X509_USER_PROXY"] + '">\n')
865 >        xml.write(jt_string)
866          
867 <        title = '# This JDL was generated by '+\
868 <                common.prog_name+' (version '+common.prog_version_str+')\n'
869 <        jt_string = ''
870 <
867 >        if (to_write != ''):
868 >            xml.write('<extraTags\n')
869 >            xml.write(to_write)
870 >            xml.write('/>\n')
871 >            pass
872  
873 +        xml.write('<iterator>\n')
874 +        xml.write('\t<iteratorRule name="ITR1">\n')
875 +        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
876 +        xml.write('\t</iteratorRule>\n')
877 +        xml.write('\t<iteratorRule name="ITR2">\n')
878 +        for arg in argsList:
879 +            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
880 +            pass
881 +        xml.write('\t</iteratorRule>\n')
882 +        #print jobList
883 +        xml.write('\t<iteratorRule name="ITR3">\n')
884 +        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
885 +        xml.write('\t</iteratorRule>\n')
886 +
887 +        '''
888 +        indy: here itr4
889 +        '''
890          
891 <        SPL = inp_storage_subdir
892 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
891 >        xml.write('<chain name="' +str(taskName)+'__ITR1_" scheduler="'+str(self.schedulerName)+'">\n')
892 >       # xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
893 >        xml.write(jt_string)
894  
895 <        jdl_fname = job.jdlFilename()
536 <        jdl = open(jdl_fname, 'w')
537 <        jdl.write(title)
895 >        #executable
896  
897 +        """
898 +        INDY
899 +        script depends on jobType: it should be probably get in a different way
900 +        """        
901          script = job.scriptFilename()
902 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
903 <        jdl.write(jt_string)
904 <
905 <        ### only one .sh  JDL has arguments:
906 <        firstEvent = common.jobDB.firstEvent(nj)
907 <        maxEvents = common.jobDB.maxEvents(nj)
908 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
547 <
548 <        inp_box = 'InputSandbox = { '
549 <        inp_box = inp_box + '"' + script + '",'
902 >        xml.write('<program>\n')
903 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
904 >        xml.write(jt_string)
905 >
906 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
907 >        xml.write('<program_types> crabjob </program_types>\n')
908 >        inp_box = common.work_space.pathForTgz() + 'job/' + jbt.scriptName + ','
909  
910          if inp_sandbox != None:
911              for fl in inp_sandbox:
912 <                inp_box = inp_box + ' "' + fl + '",'
912 >                inp_box = inp_box + '' + fl + ','
913                  pass
914              pass
915  
916 <        #if common.use_jam:
917 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
918 <
919 <        # Marco (VERY TEMPORARY ML STUFF)
920 <        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
921 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
563 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
564 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
565 <        # End Marco
566 <
567 <        if (not jbt.additional_inbox_files == []):
568 <            inp_box = inp_box + ', '
569 <            for addFile in jbt.additional_inbox_files:
570 <                addFile = os.path.abspath(addFile)
571 <                inp_box = inp_box+' "'+addFile+'",'
572 <                pass
916 > #        if (not jbt.additional_inbox_files == []):
917 > #            inp_box = inp_box + ','
918 > #            for addFile in jbt.additional_inbox_files:
919 > #                #addFile = os.path.abspath(addFile)
920 > #                inp_box = inp_box+''+addFile+','
921 > #                pass
922  
923          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
924 <        inp_box = inp_box + ' };\n'
925 <        jdl.write(inp_box)
577 <
578 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
579 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
924 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
925 >        xml.write(inp_box)
926          
927 +        base = jbt.name()
928 +        stdout = base + '__ITR3_.stdout'
929 +        stderr = base + '__ITR3_.stderr'
930          
931 <        if job.stdout() == job.stderr():
932 <          out_box = 'OutputSandbox = { "' + \
933 <                    job.stdout() + '", ".BrokerInfo",'
934 <        else:
935 <          out_box = 'OutputSandbox = { "' + \
936 <                    job.stdout() + '", "' + \
588 <                    job.stderr() + '", ".BrokerInfo",'
931 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
932 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
933 >        
934 >
935 >        out_box = stdout + ',' + \
936 >                  stderr + ',.BrokerInfo,'
937  
938 +        """
939          if int(self.return_data) == 1:
940              if out_sandbox != None:
941                  for fl in out_sandbox:
942 <                    out_box = out_box + ' "' + fl + '",'
942 >                    out_box = out_box + '' + fl + ','
943                      pass
944                  pass
945              pass
946 <                                                                                                                                                            
946 >        """
947 >
948 >        """
949 >        INDY
950 >        something similar should be also done for infiles (if it makes sense!)
951 >        """
952 >        # Stuff to be returned _always_ via sandbox
953 >        for fl in jbt.output_file_sandbox:
954 >            out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
955 >            pass
956 >        pass
957 >
958 >        # via sandbox iif required return_data
959 >        if int(self.return_data) == 1:
960 >            for fl in jbt.output_file:
961 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
962 >                pass
963 >            pass
964 >
965          if out_box[-1] == ',' : out_box = out_box[:-1]
966 <        out_box = out_box + ' };'
967 <        jdl.write(out_box+'\n')
966 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
967 >        xml.write(out_box)
968 >
969 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
970  
971 +        xml.write('</program>\n')
972 +        xml.write('</chain>\n')
973  
974 <        req='Requirements = '
975 <        req = req + jbt.getRequirements()
605 < #        ### if at least a CE exists ...
606 < #        if common.analisys_common_info['sites']:
607 < #           if common.analisys_common_info['sw_version']:
608 < #                req='Requirements = '
609 < #                req=req + 'Member("VO-cms-' + \
610 < #                     common.analisys_common_info['sw_version'] + \
611 < #                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
612 < #            if len(common.analisys_common_info['sites'])>0:
613 < #                req = req + ' && ('
614 < #                for i in range(len(common.analisys_common_info['sites'])):
615 < #                    req = req + 'other.GlueCEInfoHostName == "' \
616 < #                         + common.analisys_common_info['sites'][i] + '"'
617 < #                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
618 < #                        req = req + ' || '
619 < #            req = req + ')'
620 <        #### and USER REQUIREMENT
621 <        if self.EDG_requirements:
622 <            if (req == 'Requirement = '):
623 <                req = req + self.EDG_requirements
624 <            else:
625 <                req = req +  ' && ' + self.EDG_requirements
626 <        if self.EDG_clock_time:
627 <            if (req == 'Requirement = '):
628 <                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
629 <            else:
630 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
631 <                
632 <        if self.EDG_cpu_time:
633 <            if (req == 'Requirement = '):
634 <                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
635 <            else:
636 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
637 <        if (req != 'Requirement = '):
638 <            req = req + ';\n'
639 <            jdl.write(req)
640 <                                                                                                                                                            
641 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
974 >        xml.write('</iterator>\n')
975 >        xml.write('</task>\n')
976  
977 <        if ( self.EDG_retry_count ):              
978 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
645 <            pass
977 >        xml.close()
978 >      
979  
647        jdl.close()
980          return
981  
982      def checkProxy(self):
# Line 652 | Line 984 | class SchedulerEdg(Scheduler):
984          Function to check the Globus proxy.
985          """
986          if (self.proxyValid): return
987 <        timeleft = -999
988 <        minTimeLeft=10 # in hours
989 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
990 <        # SL Here I have to use os.system since the stupid command exit with >0 if no valid proxy is found
991 <        cmd_out = os.system(cmd)
992 <        if (cmd_out>0):
993 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
994 <            cmd = 'grid-proxy-init -valid 100:00'
987 >
988 >        ### Just return if asked to do so
989 >        if (self.dontCheckProxy==1):
990 >            self.proxyValid=1
991 >            return
992 >
993 >        minTimeLeft=10*3600 # in seconds
994 >
995 >        minTimeLeftServer = 100 # in hours
996 >
997 >        mustRenew = 0
998 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
999 >        timeLeftServer = -999
1000 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
1001 >            mustRenew = 1
1002 >        else:
1003 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
1004 >            if not timeLeftServer or not isInt(timeLeftServer):
1005 >                mustRenew = 1
1006 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
1007 >                mustRenew = 1
1008 >            pass
1009 >        pass
1010 >
1011 >        if mustRenew:
1012 >            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 192h\n")
1013 >            cmd = 'voms-proxy-init -voms '+self.VO
1014 >            if self.group:
1015 >                cmd += ':/'+self.VO+'/'+self.group
1016 >            if self.role:
1017 >                cmd += '/role='+self.role
1018 >            cmd += ' -valid 192:00'
1019              try:
1020                  # SL as above: damn it!
1021 +                common.logger.debug(10,cmd)
1022                  out = os.system(cmd)
1023                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
1024              except:
1025                  msg = "Unable to create a valid proxy!\n"
1026                  raise CrabException(msg)
670            # cmd = 'grid-proxy-info -timeleft'
671            # cmd_out = runCommand(cmd,0,20)
1027              pass
1028 +
1029 +        ## now I do have a voms proxy valid, and I check the myproxy server
1030 +        renewProxy = 0
1031 +        cmd = 'myproxy-info -d -s '+self.proxyServer
1032 +        cmd_out = runCommand(cmd,0,20)
1033 +        if not cmd_out:
1034 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
1035 +            renewProxy = 1
1036 +        else:
1037 +            # if myproxy exist but not long enough, renew
1038 +            reTime = re.compile( r'timeleft: (\d+)' )
1039 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
1040 +            if reTime.match( cmd_out ):
1041 +                time = reTime.search( cmd_out ).group(1)
1042 +                if time < minTimeLeftServer:
1043 +                    renewProxy = 1
1044 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
1045 +                pass
1046 +            pass
1047 +        
1048 +        # if not, create one.
1049 +        if renewProxy:
1050 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
1051 +            out = os.system(cmd)
1052 +            if (out>0):
1053 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
1054 +            pass
1055 +
1056 +        # cache proxy validity
1057          self.proxyValid=1
1058          return
1059 <    
1059 >
1060      def configOpt_(self):
1061          edg_ui_cfg_opt = ' '
1062          if self.edg_config:
1063 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
1063 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
1064          if self.edg_config_vo:
1065 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
1065 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
1066          return edg_ui_cfg_opt
1067 +
1068 +    def submitTout(self, list):
1069 +        return 120
1070 +
1071 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines