ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerEdg.py
(Generate patch)

Comparing COMP/CRAB/python/SchedulerEdg.py (file contents):
Revision 1.64 by gutsche, Tue Jun 27 02:31:31 2006 UTC vs.
Revision 1.129 by slacapra, Tue Jul 17 14:08:24 2007 UTC

# Line 21 | Line 21 | class SchedulerEdg(Scheduler):
21          return
22  
23      def configure(self, cfg_params):
24 + ##Addedd Daniele
25 + ######################################        
26  
27 +        SEBlackList = []
28          try:
29 <            RB = cfg_params["EDG.rb"]
30 <            edgConfig = EdgConfig(RB)
31 <            self.edg_config = edgConfig.config()
32 <            self.edg_config_vo = edgConfig.configVO()
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 <            self.edg_config = ''
35 <            self.edg_config_vo = ''
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 >
53  
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  
43        try: self.EDG_requirements = cfg_params['EDG.requirements']
44        except KeyError: self.EDG_requirements = ''
45
46        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
47        except KeyError: self.EDG_retry_count = ''
48
80          try:
81              self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
51            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
82          except KeyError:
83              self.EDG_ce_black_list  = ''
84  
85          try:
86              self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
57            #print "self.EDG_ce_white_list = ", self.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: self.return_data = cfg_params['USER.return_data']
64 <        except KeyError: self.return_data = 1
65 <
66 <        try:
67 <             self.copy_input_data = common.analisys_common_info['copy_input_data']
68 <             #print "self.copy_input_data = ", self.copy_input_data
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 = 0
97 +
98          try:
99              self.copy_data = cfg_params["USER.copy_data"]
100              if int(self.copy_data) == 1:
# Line 86 | 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 128 | 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 158 | Line 221 | class SchedulerEdg(Scheduler):
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
176 <        else:
177 <            return 0
327 >
328  
329      def wsSetupEnvironment(self):
330          """
331          Returns part of a job script which does scheduler-specific work.
332          """
333          txt = ''
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"
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'
# Line 193 | Line 349 | class SchedulerEdg(Scheduler):
349          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
350  
351          txt += 'echo "middleware discovery " \n'
352 <        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
197 <        txt += '    middleware=LCG \n'
198 <        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
199 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
200 <        txt += '    echo "middleware =$middleware" \n'
201 <        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
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'
# Line 208 | Line 359 | class SchedulerEdg(Scheduler):
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'
# Line 215 | Line 372 | class SchedulerEdg(Scheduler):
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'
218        txt += '    echo "SyncGridJobId=`echo $SyncGridJobId`" | 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'
# Line 224 | Line 380 | class SchedulerEdg(Scheduler):
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'
227        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | 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'
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
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'
# Line 280 | Line 435 | class SchedulerEdg(Scheduler):
435                txt += '\n'
436  
437          txt += 'if [ $middleware == LCG ]; then\n'
438 <        txt += '    CloseCEs=`edg-brokerinfo getCE`\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'
# Line 294 | Line 450 | class SchedulerEdg(Scheduler):
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'
297        txt += '        echo "SyncGridJobId=`echo $SyncGridJobId`" | 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'
# Line 307 | 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']
312 <            #print "self.copy_input_data = ", self.copy_input_data
313 <        except KeyError: self.copy_input_data = 0
314 <        if int(self.copy_input_data) == 1:
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 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 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
493 <           txt += '    copy_input_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'
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  
# Line 359 | 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 <           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
554 <           txt += '        if [ $middleware == OSG ]; then\n'
555 <           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
556 <           txt += '           globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1 \n'
557 <           txt += '           copy_exit_status=$? \n'
558 <           txt += '        elif [ $middleware == LCG ]; then \n'
559 <           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
560 <           txt += '           lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1\n'
561 <           txt += '           copy_exit_status=$? \n'
562 <           txt += '        fi \n'
563 <           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\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 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 409 | Line 627 | class SchedulerEdg(Scheduler):
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'
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 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'
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 to LFC" \n'
640             txt += '            echo "Try with srm protocol" \n'
641 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
642 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \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'
# Line 433 | Line 651 | class SchedulerEdg(Scheduler):
651             txt += '         fi \n'
652             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
653             txt += '      done\n'
654 <           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \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'
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://`pwd`/$out_file" \n'
660 <           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'
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" \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'
# Line 451 | Line 670 | class SchedulerEdg(Scheduler):
670             txt += '         fi \n'
671             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
672             txt += '      done\n'
454           txt += '   else\n'
455           txt += '      echo "Problem with the executable"\n'
673             txt += '   fi \n'
674 +           txt += '   exit_status=$register_exit_status\n'
675             txt += 'fi \n'
676          return txt
677  
# Line 463 | Line 681 | class SchedulerEdg(Scheduler):
681          """
682          self.checkProxy()
683          cmd = 'edg-job-get-logging-info -v 2 ' + id
466        #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()
475 <        jdl = common.job_list[nj].jdlFilename()
476 <        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
477 <        cmd_out = runCommand(cmd,0,10)
478 <        if not cmd_out:
479 <            raise CrabException("ERROR: "+cmd+" failed!")
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' )
495 <        next = 0
496 <        CEs=[]
497 <        Match=0
498 <
499 <        #print out
500 <        lines = reLine.findall(out)
501 <
502 <        i=0
503 <        CEs=[]
504 <        for line in lines:
505 <            string.strip(line)
506 <            #print line
507 <            if reNO.match( line ):
508 <                common.logger.debug(5,line)
509 <                return 0
510 <                pass
511 <            if reVO.match( line ):
512 <                VO =reVO.match( line ).group()
513 <                common.logger.debug(5,"VO "+VO)
514 <                pass
515 <
516 <            if reRB.match( line ):
517 <                RB = reRB.match(line).group()
518 <                common.logger.debug(5,"RB "+RB)
519 <                pass
520 <
521 <            if reCEId.search( line ):
522 <                for lineCE in lines[i:-1]:
523 <                    if reCE.match( lineCE ):
524 <                        CE = string.strip(reCE.search(lineCE).group(1))
525 <                        CEs.append(CE.split(':')[0])
526 <                        pass
527 <                    pass
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 <            i=i+1
732 <            pass
733 <
734 <        common.logger.debug(5,"All CE :"+str(CEs))
735 <
736 <        sites = []
737 <        [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 <        common.logger.message("Matched Sites :"+str(sites))
744 <        return len(sites)
745 <
746 <    def noMatchFound_(self, jdl):
747 <        reReq = re.compile( r'Requirements' )
748 <        reString = re.compile( r'"\S*"' )
749 <        f = file(jdl,'r')
750 <        for line in f.readlines():
751 <            line= line.strip()
752 <            if reReq.match(line):
753 <                for req in reString.findall(line):
754 <                    if re.search("VO",req):
755 <                        common.logger.message( "SW required: "+req)
756 <                        continue
757 <                    if re.search('"\d+',req):
758 <                        common.logger.message("Other req  : "+req)
759 <                        continue
760 <                    common.logger.message( "CE required: "+req)
761 <                break
762 <            pass
763 <        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 <
565 <        self.checkProxy()
566 <        jid = None
567 <        jdl = common.job_list[nj].jdlFilename()
568 <
569 <        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
570 <        cmd_out = runCommand(cmd)
571 <        if cmd_out != None:
572 <            reSid = re.compile( r'https.+' )
573 <            jid = reSid.search(cmd_out).group()
574 <            pass
575 <        return jid
576 <
577 <    def resubmit(self, nj_list):
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          """
581        return
582
583    def getExitStatus(self, id):
584        return self.getStatusAttribute_(id, 'exit_code')
585
586    def queryStatus(self, id):
587        return self.getStatusAttribute_(id, 'status')
588
589    def queryDest(self, id):  
590        return self.getStatusAttribute_(id, 'destination')
591
592
593    def getStatusAttribute_(self, id, attr):
594        """ 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
602 <        # Instance of the Status class provided by LB API
603 <        jobStat = Status()
604 <        st = 0
605 <        jobStat.getStatus(id, level)
606 <        err, apiMsg = jobStat.get_error()
607 <        if err:
608 <            common.logger.debug(5,'Error caught' + apiMsg)
609 <            return None
610 <        else:
611 <            for i in range(len(self.states)):
612 <                # Fill an hash table with all information retrieved from LB API
613 <                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
614 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
615 <            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 <        """
625 <        Get output for a finished job with id.
626 <        Returns the name of directory with results.
627 <        """
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.environ['USER']
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()
642 <        cmd = 'edg-job-cancel --noint ' + id
643 <        cmd_out = runCommand(cmd)
644 <        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 <        """
648 <        Create a JDL-file for EDG.
649 <        """
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()
667 <        jdl = open(jdl_fname, 'w')
668 <        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 <
907 <        ### Fabio
908 <        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
678 <        inp_box = 'InputSandbox = { '
679 <        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/'+'DashboardAPI.py') + '", "'+\
693 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
694 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
695 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
696 <        # End Marco
697 <
698 <        if (not jbt.additional_inbox_files == []):
699 <            inp_box = inp_box + ', '
700 <            for addFile in jbt.additional_inbox_files:
701 <                addFile = os.path.abspath(addFile)
702 <                inp_box = inp_box+' "'+addFile+'",'
703 <                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)
708 <
709 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
710 <        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() + '", "' + \
719 <                    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 <                                                                                                                                                            
729 <        if out_box[-1] == ',' : out_box = out_box[:-1]
730 <        out_box = out_box + ' };'
731 <        jdl.write(out_box+'\n')
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 <        req='Requirements = '
959 <        noreq=req
960 <        req = req + jbt.getRequirements()
961 <        #### and USER REQUIREMENT
738 <        if self.EDG_requirements:
739 <            if (req != noreq):
740 <                req = req +  ' && '
741 <            req = req + self.EDG_requirements
742 <        #### FEDE #####
743 <        if self.EDG_ce_white_list:
744 <            ce_white_list = string.split(self.EDG_ce_white_list,',')
745 <            #print "req = ", req
746 <            for i in range(len(ce_white_list)):
747 <                if i == 0:
748 <                    if (req != noreq):
749 <                        req = req +  ' && '
750 <                    req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
751 <                    pass
752 <                else:
753 <                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
754 <            req = req + ')'
755 <        
756 <        if self.EDG_ce_black_list:
757 <            ce_black_list = string.split(self.EDG_ce_black_list,',')
758 <            for ce in ce_black_list:
759 <                if (req != noreq):
760 <                    req = req +  ' && '
761 <                req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
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 <        ###############
966 <        clockTime=480
967 <        if self.EDG_clock_time:
968 <            clockTime= self.EDG_clock_time
969 <        if (req != noreq):
769 <            req = req + ' && '
770 <        req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
965 >        if out_box[-1] == ',' : out_box = out_box[:-1]
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 <        cpuTime=1000
972 <        if self.EDG_cpu_time:
774 <            cpuTime=self.EDG_cpu_time
775 <        if (req != noreq):
776 <            req = req + ' && '
777 <        req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+str(cpuTime)+'))'
778 <
779 <        if (req != noreq):
780 <            req = req + ';\n'
781 <            jdl.write(req)
782 <                                                                                                                                                            
783 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
971 >        xml.write('</program>\n')
972 >        xml.write('</chain>\n')
973  
974 <        if ( self.EDG_retry_count ):              
975 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
787 <            pass
974 >        xml.write('</iterator>\n')
975 >        xml.write('</task>\n')
976  
977 <        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
977 >        xml.close()
978 >      
979  
791        jdl.close()
980          return
981  
982      def checkProxy(self):
# Line 796 | Line 984 | class SchedulerEdg(Scheduler):
984          Function to check the Globus proxy.
985          """
986          if (self.proxyValid): return
987 <        timeleft = -999
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  
804        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
805        #cmd = 'voms-proxy-info -timeleft'
997          mustRenew = 0
998 <        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
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 | head -1')
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:
# Line 818 | Line 1009 | class SchedulerEdg(Scheduler):
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 96h\n")
1013 <            cmd = 'voms-proxy-init -voms cms -valid 96:00'
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)
830            # cmd = 'grid-proxy-info -timeleft'
831            # cmd_out = runCommand(cmd,0,20)
1027              pass
1028  
1029          ## now I do have a voms proxy valid, and I check the myproxy server
# Line 843 | Line 1038 | class SchedulerEdg(Scheduler):
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( line ).group(1)
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')
# Line 869 | Line 1064 | class SchedulerEdg(Scheduler):
1064          if 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