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.134 by fanzago, Fri Aug 17 16:00:32 2007 UTC

# Line 3 | Line 3 | from crab_logger import Logger
3   from crab_exceptions import *
4   from crab_util import *
5   from EdgConfig import *
6 + from BlackWhiteListParser import BlackWhiteListParser
7   import common
8  
9   import os, sys, time
# Line 22 | Line 23 | class SchedulerEdg(Scheduler):
23  
24      def configure(self, cfg_params):
25  
26 +        # init BlackWhiteListParser
27 +        self.blackWhiteListParser = BlackWhiteListParser(cfg_params)
28 +
29 +        self.proxyValid=0
30 +        try: self.dontCheckProxy=int(cfg_params["EDG.dont_check_proxy"])
31 +        except KeyError: self.dontCheckProxy = 0
32 +
33          try:
34 <            RB = cfg_params["EDG.rb"]
35 <            edgConfig = EdgConfig(RB)
28 <            self.edg_config = edgConfig.config()
29 <            self.edg_config_vo = edgConfig.configVO()
34 >            RB=cfg_params["EDG.rb"]
35 >            self.rb_param_file=self.rb_configure(RB)
36          except KeyError:
37 <            self.edg_config = ''
38 <            self.edg_config_vo = ''
33 <
37 >            self.rb_param_file=''
38 >            pass
39          try:
40              self.proxyServer = cfg_params["EDG.proxy_server"]
41          except KeyError:
42              self.proxyServer = 'myproxy.cern.ch'
43          common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
44  
45 +        try:
46 +            self.group = cfg_params["EDG.group"]
47 +        except KeyError:
48 +            self.group = None
49 +            
50 +        try:
51 +            self.role = cfg_params["EDG.role"]
52 +        except KeyError:
53 +            self.role = None
54 +            
55          try: self.LCG_version = cfg_params["EDG.lcg_version"]
56          except KeyError: self.LCG_version = '2'
57  
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
58          try:
59              self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
51            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
60          except KeyError:
61              self.EDG_ce_black_list  = ''
62  
63          try:
64              self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
57            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
65          except KeyError: self.EDG_ce_white_list = ''
66  
67          try: self.VO = cfg_params['EDG.virtual_organization']
68          except KeyError: self.VO = 'cms'
69  
70 <        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
70 >        try: self.copy_input_data = cfg_params["USER.copy_input_data"]
71          except KeyError: self.copy_input_data = 0
72  
73 +        try: self.return_data = cfg_params['USER.return_data']
74 +        except KeyError: self.return_data = 0
75 +
76          try:
77              self.copy_data = cfg_params["USER.copy_data"]
78              if int(self.copy_data) == 1:
# Line 86 | Line 91 | class SchedulerEdg(Scheduler):
91             msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
92             raise CrabException(msg)
93  
94 +        ########### FEDE FOR DBS2 ##############################
95 +        try:
96 +            self.publish_data = cfg_params["USER.publish_data"]
97 +            self.checkProxy()
98 +            if int(self.publish_data) == 1:
99 +                try:
100 +                    self.publish_data_name = cfg_params['USER.publish_data_name']
101 +                except KeyError:
102 +                    msg = "Error. The [USER] section does not have 'publish_data_name'"
103 +                    raise CrabException(msg)
104 +                try:
105 +                    tmp = runCommand("voms-proxy-info -identity")
106 +                    tmp = string.split(tmp,'/')
107 +                    reCN=re.compile(r'CN=')
108 +                    for t in tmp:
109 +                        if reCN.match(t):
110 +                            self.UserGridName=string.strip((t.replace('CN=','')).replace(' ',''))
111 +                        
112 +                    #self.UserGridName = string.strip(runCommand("voms-proxy-info -identity | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'"))
113 +                except:
114 +                    msg = "Error. Problem with voms-proxy-info -identity command"
115 +                    raise CrabException(msg)
116 +        except KeyError: self.publish_data = 0
117 +
118 +        if ( int(self.copy_data) == 0 and int(self.publish_data) == 1 ):
119 +           msg = 'Warning: publish_data = 1 must be used with copy_data = 1\n'
120 +           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
121 +           common.logger.message(msg)
122 +           raise CrabException(msg)
123 +        #################################################
124 +
125          try:
126              self.lfc_host = cfg_params['EDG.lfc_host']
127          except KeyError:
# Line 128 | Line 164 | class SchedulerEdg(Scheduler):
164  
165          try: self.EDG_requirements = cfg_params['EDG.requirements']
166          except KeyError: self.EDG_requirements = ''
167 <                                                                                                                                                            
167 >
168 >        try: self.EDG_addJdlParam = string.split(cfg_params['EDG.additional_jdl_parameters'],',')
169 >        except KeyError: self.EDG_addJdlParam = []
170 >
171          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
172          except KeyError: self.EDG_retry_count = ''
173 <                                                                                                                                                            
173 >
174 >        try: self.EDG_shallow_retry_count= cfg_params['EDG.shallow_retry_count']
175 >        except KeyError: self.EDG_shallow_retry_count = ''
176 >
177          try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
178          except KeyError: self.EDG_clock_time= ''
179 <                                                                                                                                                            
179 >
180          try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
181          except KeyError: self.EDG_cpu_time = ''
182  
# Line 151 | Line 193 | class SchedulerEdg(Scheduler):
193          libPath=os.path.join(path, "lib", "python")
194          sys.path.append(libPath)
195  
154        self.proxyValid=0
155
196          try:
197              self._taskId = cfg_params['taskId']
198          except:
199              self._taskId = ''
200  
201 +        try: self.jobtypeName = cfg_params['CRAB.jobtype']
202 +        except KeyError: self.jobtypeName = ''
203 +
204 +        try: self.schedulerName = cfg_params['CRAB.scheduler']
205 +        except KeyError: self.scheduler = ''
206 +
207          return
208      
209  
210 +    def rb_configure(self, RB):
211 +        self.edg_config = ''
212 +        self.edg_config_vo = ''
213 +        self.rb_param_file = ''
214 +
215 +        edgConfig = EdgConfig(RB)
216 +        self.edg_config = edgConfig.config()
217 +        self.edg_config_vo = edgConfig.configVO()
218 +
219 +        if (self.edg_config and self.edg_config_vo != ''):
220 +            self.rb_param_file = 'RBconfig = "'+self.edg_config+'";\nRBconfigVO = "'+self.edg_config_vo+'";\n'
221 +            #print "rb_param_file = ", self.rb_param_file
222 +        return self.rb_param_file
223 +      
224 +
225      def sched_parameter(self):
226          """
227 <        Returns file with scheduler-specific parameters
227 >        Returns file with requirements and scheduler-specific parameters
228          """
229 <      
230 <        if (self.edg_config and self.edg_config_vo != ''):
231 <            self.param='sched_param.clad'
229 >        index = int(common.jobDB.nJobs()) - 1
230 >        job = common.job_list[index]
231 >        jbt = job.type()
232 >        
233 >        lastBlock=-1
234 >        first = []
235 >        for n in range(common.jobDB.nJobs()):
236 >            currBlock=common.jobDB.block(n)
237 >            if (currBlock!=lastBlock):
238 >                lastBlock = currBlock
239 >                first.append(n)
240 >  
241 >        req = ''
242 >        req = req + jbt.getRequirements()
243 >    
244 >        if self.EDG_requirements:
245 >            if (req == ' '):
246 >                req = req + self.EDG_requirements
247 >            else:
248 >                req = req +  ' && ' + self.EDG_requirements
249 >
250 >        if self.EDG_ce_white_list:
251 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
252 >            for i in range(len(ce_white_list)):
253 >                if i == 0:
254 >                    if (req == ' '):
255 >                        req = req + '((RegExp("' + string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
256 >                    else:
257 >                        req = req +  ' && ((RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
258 >                    pass
259 >                else:
260 >                    req = req +  ' || (RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
261 >            req = req + ')'
262 >        
263 >        if self.EDG_ce_black_list:
264 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
265 >            for ce in ce_black_list:
266 >                if (req == ' '):
267 >                    req = req + '(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
268 >                else:
269 >                    req = req +  ' && (!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
270 >                pass
271 >        if self.EDG_clock_time:
272 >            if (req == ' '):
273 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
274 >            else:
275 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
276 >
277 >        if self.EDG_cpu_time:
278 >            if (req == ' '):
279 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
280 >            else:
281 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
282 >                
283 >        for i in range(len(first)): # Add loop DS
284 >            groupReq = req
285 >            self.param='sched_param_'+str(i)+'.clad'
286              param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
287 <            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
288 <            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
287 >
288 >            itr4=self.findSites_(first[i])
289 >            for arg in itr4:
290 >                groupReq = groupReq + ' && anyMatch(other.storage.CloseSEs, ('+str(arg)+'))'
291 >            param_file.write('Requirements = '+groupReq +';\n')  
292 >  
293 >            if (self.rb_param_file != ''):
294 >                param_file.write(self.rb_param_file)  
295 >
296 >            if len(self.EDG_addJdlParam):
297 >                for p in self.EDG_addJdlParam:
298 >                    param_file.write(p)
299 >
300              param_file.close()  
301 <            return 1
176 <        else:
177 <            return 0
301 >
302  
303      def wsSetupEnvironment(self):
304          """
305          Returns part of a job script which does scheduler-specific work.
306          """
307          txt = ''
308 +        txt += '# strip arguments\n'
309 +        txt += 'echo "strip arguments"\n'
310 +        txt += 'args=("$@")\n'
311 +        txt += 'nargs=$#\n'
312 +        txt += 'shift $nargs\n'
313          txt += "# job number (first parameter for job wrapper)\n"
314 <        txt += "NJob=$1\n"
314 >        #txt += "NJob=$1\n"
315 >        txt += "NJob=${args[0]}\n"
316  
317          txt += '# job identification to DashBoard \n'
318          txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
# Line 193 | Line 323 | class SchedulerEdg(Scheduler):
323          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
324  
325          txt += 'echo "middleware discovery " \n'
326 <        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'
326 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
327          txt += '    middleware=OSG \n'
328          txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
329          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
# Line 208 | Line 333 | class SchedulerEdg(Scheduler):
333          txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
334          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
335          txt += '    echo "middleware =$middleware" \n'
336 +        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
337 +        txt += '    middleware=LCG \n'
338 +   #     txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
339 +        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
340 +        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
341 +        txt += '    echo "middleware =$middleware" \n'
342          txt += 'else \n'
343          txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
344          txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
# Line 215 | Line 346 | class SchedulerEdg(Scheduler):
346          txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
347          txt += '    rm -f $RUNTIME_AREA/$repo \n'
348          txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
218        txt += '    echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
349          txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
350          txt += '    exit 1 \n'
351          txt += 'fi \n'
# Line 224 | Line 354 | class SchedulerEdg(Scheduler):
354          txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
355          txt += 'rm -f $RUNTIME_AREA/$repo \n'
356          txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
227        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
357          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
358          
359          txt += '\n\n'
360  
361 <        if int(self.copy_data) == 1:
362 <           if self.SE:
363 <              txt += 'export SE='+self.SE+'\n'
364 <              txt += 'echo "SE = $SE"\n'
365 <           if self.SE_PATH:
366 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
367 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
368 <              txt += 'echo "SE_PATH = $SE_PATH"\n'
361 > #        if int(self.copy_data) == 1:
362 > #           if self.SE:
363 > #              txt += 'export SE='+self.SE+'\n'
364 > #              txt += 'echo "SE = $SE"\n'
365 > #           if self.SE_PATH:
366 > #              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
367 > #              txt += 'export SE_PATH='+self.SE_PATH+'\n'
368 > #              txt += 'echo "SE_PATH = $SE_PATH"\n'
369  
370          txt += 'export VO='+self.VO+'\n'
371 <        ### FEDE: add some line for LFC catalog setting
371 >        ### add some line for LFC catalog setting
372          txt += 'if [ $middleware == LCG ]; then \n'
373          txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
374          txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
# Line 280 | Line 409 | class SchedulerEdg(Scheduler):
409                txt += '\n'
410  
411          txt += 'if [ $middleware == LCG ]; then\n'
412 <        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
412 >    #    txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
413 >        txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
414          txt += '    echo "CloseCEs = $CloseCEs"\n'
415          txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
416          txt += '    echo "CE = $CE"\n'
# Line 294 | Line 424 | class SchedulerEdg(Scheduler):
424          txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
425          txt += '        rm -f $RUNTIME_AREA/$repo \n'
426          txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
297        txt += '        echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
427          txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
428          txt += '        exit 1 \n'
429          txt += '    fi \n'
# Line 307 | Line 436 | class SchedulerEdg(Scheduler):
436          Copy input data from SE to WN    
437          """
438          txt = ''
439 <        try:
440 <            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:
439 >        if not self.copy_input_data: return txt
440 >
441          ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
442 <           txt += 'if [ $middleware == OSG ]; then\n'
443 <           txt += '   #\n'
444 <           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
445 <           txt += '   #\n'
446 <           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
447 <           txt += 'elif [ $middleware == LCG ]; then \n'
448 <           txt += '   #\n'
449 <           txt += '   #   Copy Input Data from SE to this WN\n'
450 <           txt += '   #\n'
451 < ### changed by georgia (put a loop copying more than one input files per jobs)          
452 <           txt += '   for input_file in $cur_file_list \n'
453 <           txt += '   do \n'
454 <           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
455 <           txt += '    copy_input_exit_status=$?\n'
456 <           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
457 <           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
458 <           txt += '       echo "Problems with copying to WN" \n'
459 <           txt += '    else \n'
460 <           txt += '       echo "input copied into WN" \n'
461 <           txt += '    fi \n'
462 <           txt += '   done \n'
463 < ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
464 <           txt += '   for file in $cur_pu_list \n'
465 <           txt += '   do \n'
466 <           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
467 <           txt += '    copy_input_exit_status=$?\n'
468 <           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
469 <           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
470 <           txt += '       echo "Problems with copying pu to WN" \n'
471 <           txt += '    else \n'
472 <           txt += '       echo "input pu files copied into WN" \n'
473 <           txt += '    fi \n'
474 <           txt += '   done \n'
475 <           txt += '   \n'
476 <           txt += '   ### Check SCRATCH space available on WN : \n'
477 <           txt += '   df -h \n'
478 <           txt += 'fi \n'
442 >        txt += 'if [ $middleware == OSG ]; then\n'
443 >        txt += '   #\n'
444 >        txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
445 >        txt += '   #\n'
446 >        txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
447 >        txt += 'elif [ $middleware == LCG ]; then \n'
448 >        txt += '   #\n'
449 >        txt += '   #   Copy Input Data from SE to this WN\n'
450 >        txt += '   #\n'
451 >        ### changed by georgia (put a loop copying more than one input files per jobs)          
452 >        txt += '   for input_file in $cur_file_list \n'
453 >        txt += '   do \n'
454 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
455 >        txt += '      copy_input_exit_status=$?\n'
456 >        txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
457 >        txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
458 >        txt += '         echo "Problems with copying to WN" \n'
459 >        txt += '      else \n'
460 >        txt += '         echo "input copied into WN" \n'
461 >        txt += '      fi \n'
462 >        txt += '   done \n'
463 >        ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
464 >        txt += '   for file in $cur_pu_list \n'
465 >        txt += '   do \n'
466 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
467 >        txt += '      copy_input_pu_exit_status=$?\n'
468 >        txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
469 >        txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
470 >        txt += '         echo "Problems with copying pu to WN" \n'
471 >        txt += '      else \n'
472 >        txt += '         echo "input pu files copied into WN" \n'
473 >        txt += '      fi \n'
474 >        txt += '   done \n'
475 >        txt += '   \n'
476 >        txt += '   ### Check SCRATCH space available on WN : \n'
477 >        txt += '   df -h \n'
478 >        txt += 'fi \n'
479            
480          return txt
481  
# Line 358 | Line 484 | class SchedulerEdg(Scheduler):
484          Write a CopyResults part of a job script, e.g.
485          to copy produced output into a storage element.
486          """
487 <        txt = ''
487 >        txt = '\n'
488 >
489 >        txt += '#\n'
490 >        txt += '# COPY OUTPUT FILE TO SE\n'
491 >        txt += '#\n\n'
492 >
493 >        SE_PATH=''
494          if int(self.copy_data) == 1:
495 <           txt += '#\n'
496 <           txt += '#   Copy output to SE = $SE\n'
497 <           txt += '#\n'
498 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
499 <           txt += '    for out_file in $file_list ; do\n'
500 <           txt += '        echo "Trying to copy output file to $SE "\n'
501 <           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
502 <           txt += '        if [ $middleware == OSG ]; then\n'
503 <           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
504 <           txt += '           globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1 \n'
505 <           txt += '           copy_exit_status=$? \n'
506 <           txt += '        elif [ $middleware == LCG ]; then \n'
507 <           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
508 <           txt += '           lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1\n'
509 <           txt += '           copy_exit_status=$? \n'
510 <           txt += '        fi \n'
511 <           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
512 <           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
513 <           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
514 <           txt += '            echo "Problems with SE = $SE"\n'
515 <           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
516 <           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
517 <           txt += '        else\n'
518 <           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
519 <           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
520 <           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
521 <           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
522 <           txt += '         fi\n'
523 <           txt += '     done\n'
495 >           if self.SE:
496 >              txt += 'export SE='+self.SE+'\n'
497 >              txt += 'echo "SE = $SE"\n'
498 >           if self.SE_PATH:
499 >              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
500 >              SE_PATH=self.SE_PATH
501 >              if int(self.publish_data) == 1:
502 >                  txt += '### publish_data = 1 so the SE path where to copy the output is: \n'
503 >                  path_add = self.UserGridName + '/' + self.publish_data_name +'_${PSETHASH}/'
504 >                  SE_PATH = SE_PATH + path_add
505 >              txt += 'export SE_PATH='+SE_PATH+'\n'
506 >              txt += 'echo "SE_PATH = $SE_PATH"\n'
507 >
508 >           txt += 'echo "####################################################"\n'
509 >           txt += 'echo "# Copy output files from WN = `hostname` to SE = $SE"\n'
510 >           txt += 'echo "####################################################"\n'
511 >           txt += 'if [ $middleware == OSG ]; then\n'
512 >           txt += '    echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
513 >           txt += '    echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
514 >           txt += '    source $OSG_APP/glite/setup_glite_ui.sh\n'
515 >           txt += '    export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
516 >           txt += '    echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
517 >           txt += 'fi \n'
518 >
519 >           txt += 'for out_file in $file_list ; do\n'
520 >           txt += '    echo "Trying to copy output file $out_file to $SE using srmcp"\n'
521 >           txt += '    if [ $middleware == LCG ]; then\n'
522 >           txt += '        echo "srmcp -retry_num 3 -retry_timeout 480000 file:///`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
523 >           txt += '        exitstring=`srmcp -retry_num 3 -retry_timeout 480000 file:///\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
524 >           txt += '    elif [ $middleware == OSG ]; then\n'
525 >           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'
526 >           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'
527 >           txt += '    fi \n'
528 >           txt += '    copy_exit_status=$?\n'
529 >           txt += '    echo "COPY_EXIT_STATUS for srmcp = $copy_exit_status"\n'
530 >           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
531 >
532 >           txt += '    if [ $copy_exit_status -ne 0 ]; then\n'
533 >           txt += '        echo ">>>>> srmcp failed <<<<<"\n'
534 >           txt += '        echo "Problem reason:"\n'
535 >           txt += '        echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
536 >           txt += '        echo ">>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<"\n'
537 >           txt += '        echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
538 >           #txt += '        echo "srmcp failed, attempting lcg-cp."\n'
539 >           #if common.logger.debugLevel() >= 5:
540 >           #    txt += '        echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
541 >           #    txt += '        exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
542 >           #else:              
543 >           #    txt += '        echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
544 >           #    txt += '        exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
545 >           #txt += '        copy_exit_status=$?\n'
546 >           #txt += '        echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
547 >           #txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
548 >           #txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
549 >           #txt += '            echo "Problems with SE = $SE"\n'
550 >           #txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
551 >           #txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
552 >           #txt += '            echo "srmcp and lcg-cp and failed!"\n'
553 >           #txt += '        else\n'
554 >           #txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
555 >           #txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
556 >           #txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
557 >           #txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
558 >           #txt += '            echo "lcg-cp succeeded"\n'
559 >           #txt += '        fi\n'
560 >           txt += '    else\n'
561 >           txt += '        echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
562 >           txt += '        echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
563 >           txt += '        echo "output copied into $SE/$SE_PATH directory"\n'
564 >           txt += '        echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
565 >           txt += '        echo "srmcp succeeded"\n'
566 >           txt += '    fi\n'
567 >           txt += 'done\n'
568 >           txt += 'if [ $copy_exit_status -ne 0 ]; then\n'
569 >           txt += '    SE=""\n'
570 >           txt += '    echo "SE = $SE"\n'
571 >           txt += '    SE_PATH=""\n'
572 >           txt += '    echo "SE_PATH = $SE_PATH"\n'
573             txt += 'fi\n'
574 +           txt += 'exit_status=$copy_exit_status\n'
575          return txt
576  
577      def wsRegisterOutput(self):
# Line 409 | Line 591 | class SchedulerEdg(Scheduler):
591             txt += '#\n'
592             txt += '#  Register output to LFC\n'
593             txt += '#\n'
594 <           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
594 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
595             txt += '      for out_file in $file_list ; do\n'
596             txt += '         echo "Trying to register the output file into LFC"\n'
597 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
598 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
597 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
598 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
599             txt += '         register_exit_status=$?\n'
600             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
601             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
602             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
603             txt += '            echo "Problems with the registration to LFC" \n'
604             txt += '            echo "Try with srm protocol" \n'
605 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
606 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
605 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
606 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
607             txt += '            register_exit_status=$?\n'
608             txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
609             txt += '            echo "STAGE_OUT = $register_exit_status"\n'
# Line 433 | Line 615 | class SchedulerEdg(Scheduler):
615             txt += '         fi \n'
616             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
617             txt += '      done\n'
618 <           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
618 >           txt += '   else \n'
619             txt += '      echo "Trying to copy output file to CloseSE"\n'
620 <           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
620 > #          txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
621 >           txt += '      CLOSE_SE=`glite-brokerinfo getCloseSEs | head -1`\n'
622             txt += '      for out_file in $file_list ; do\n'
623 <           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
624 <           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'
623 >           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'
624 >           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'
625             txt += '         register_exit_status=$?\n'
626             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
627             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
628             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
629 <           txt += '            echo "Problems with CloseSE" \n'
629 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
630             txt += '         else \n'
631             txt += '            echo "The program was successfully executed"\n'
632             txt += '            echo "SE = $CLOSE_SE"\n'
# Line 451 | Line 634 | class SchedulerEdg(Scheduler):
634             txt += '         fi \n'
635             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
636             txt += '      done\n'
454           txt += '   else\n'
455           txt += '      echo "Problem with the executable"\n'
637             txt += '   fi \n'
638 +           txt += '   exit_status=$register_exit_status\n'
639             txt += 'fi \n'
640          return txt
641  
# Line 463 | Line 645 | class SchedulerEdg(Scheduler):
645          """
646          self.checkProxy()
647          cmd = 'edg-job-get-logging-info -v 2 ' + id
466        #cmd_out = os.popen(cmd)
648          cmd_out = runCommand(cmd)
649          return cmd_out
650  
651 <    def listMatch(self, nj):
652 <        """
653 <        Check the compatibility of available resources
654 <        """
655 <        self.checkProxy()
475 <        jdl = common.job_list[nj].jdlFilename()
476 <        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
477 <        cmd_out = runCommand(cmd,0,10)
478 <        if not cmd_out:
479 <            raise CrabException("ERROR: "+cmd+" failed!")
480 <
481 <        return self.parseListMatch_(cmd_out, jdl)
482 <
483 <    def parseListMatch_(self, out, jdl):
484 <        """
485 <        Parse the f* output of edg-list-match and produce something sensible
486 <        """
487 <        reComment = re.compile( r'^\**$' )
488 <        reEmptyLine = re.compile( r'^$' )
489 <        reVO = re.compile( r'Selected Virtual Organisation name.*' )
490 <        reLine = re.compile( r'.*')
491 <        reCE = re.compile( r'(.*:.*)')
492 <        reCEId = re.compile( r'CEId.*')
493 <        reNO = re.compile( r'No Computing Element matching' )
494 <        reRB = re.compile( r'Connecting to host' )
495 <        next = 0
496 <        CEs=[]
497 <        Match=0
498 <
499 <        #print out
500 <        lines = reLine.findall(out)
501 <
502 <        i=0
503 <        CEs=[]
504 <        for line in lines:
505 <            string.strip(line)
506 <            #print line
507 <            if reNO.match( line ):
508 <                common.logger.debug(5,line)
509 <                return 0
510 <                pass
511 <            if reVO.match( line ):
512 <                VO =reVO.match( line ).group()
513 <                common.logger.debug(5,"VO "+VO)
514 <                pass
515 <
516 <            if reRB.match( line ):
517 <                RB = reRB.match(line).group()
518 <                common.logger.debug(5,"RB "+RB)
519 <                pass
651 >    def queryDetailedStatus(self, id):
652 >        """ Query a detailed status of the job with id """
653 >        cmd = 'edg-job-status '+id
654 >        cmd_out = runCommand(cmd)
655 >        return cmd_out
656  
657 <            if reCEId.search( line ):
658 <                for lineCE in lines[i:-1]:
523 <                    if reCE.match( lineCE ):
524 <                        CE = string.strip(reCE.search(lineCE).group(1))
525 <                        CEs.append(CE.split(':')[0])
526 <                        pass
527 <                    pass
528 <                pass
529 <            i=i+1
530 <            pass
657 >    def findSites_(self, n):
658 >        itr4 =[]
659  
660 <        common.logger.debug(5,"All CE :"+str(CEs))
660 >        sites = common.jobDB.destination(n)
661  
662 <        sites = []
663 <        [sites.append(it) for it in CEs if not sites.count(it)]
662 >        if len(sites)>0 and sites[0]=="":
663 >            return itr4
664  
665 <        common.logger.debug(5,"All Sites :"+str(sites))
666 <        common.logger.message("Matched Sites :"+str(sites))
667 <        return len(sites)
668 <
669 <    def noMatchFound_(self, jdl):
670 <        reReq = re.compile( r'Requirements' )
671 <        reString = re.compile( r'"\S*"' )
672 <        f = file(jdl,'r')
673 <        for line in f.readlines():
674 <            line= line.strip()
675 <            if reReq.match(line):
676 <                for req in reString.findall(line):
677 <                    if re.search("VO",req):
678 <                        common.logger.message( "SW required: "+req)
679 <                        continue
680 <                    if re.search('"\d+',req):
681 <                        common.logger.message("Other req  : "+req)
682 <                        continue
555 <                    common.logger.message( "CE required: "+req)
556 <                break
557 <            pass
558 <        raise CrabException("No compatible resources found!")
665 >        itr = ''
666 >        if sites != [""]:#CarlosDaniele
667 >            ##Addedd Daniele
668 >            replicas = self.blackWhiteListParser.checkBlackList(sites,n)
669 >            if len(replicas)!=0:
670 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
671 >              
672 >            if len(replicas)==0:
673 >                msg = 'No sites remaining that host any part of the requested data! Exiting... '
674 >                raise CrabException(msg)
675 >            #####        
676 >           # for site in sites:
677 >            for site in replicas:
678 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
679 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
680 >            itr = itr[0:-4]
681 >            itr4.append( itr )
682 >        return itr4
683  
684 <    def submit(self, nj):
684 >    def createXMLSchScript(self, nj, argsList):
685 >      
686          """
687 <        Submit one EDG job.
687 >        Create a XML-file for BOSS4.
688          """
689 <
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):
689 >  #      job = common.job_list[nj]
690          """
691 <        Prepare jobs to be submit
691 >        INDY
692 >        [begin] FIX-ME:
693 >        I would pass jobType instead of job
694 >        """
695 >        index = nj - 1
696 >        job = common.job_list[index]
697 >        jbt = job.type()
698 >        
699 >        inp_sandbox = jbt.inputSandbox(index)
700 >        #out_sandbox = jbt.outputSandbox(index)
701 >        """
702 >        [end] FIX-ME
703          """
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 """
704  
705 <        self.checkProxy()
706 <        hstates = {}
707 <        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
708 <        # Bypass edg-job-status interfacing directly to C++ API
709 <        # Job attribute vector to retrieve status without edg-job-status
710 <        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
705 >        
706 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
707 >        jt_string = ''
708 >        
709 >        xml_fname = str(self.jobtypeName)+'.xml'
710 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
711  
712 <    def queryDetailedStatus(self, id):
713 <        """ Query a detailed status of the job with id """
714 <        cmd = 'edg-job-status '+id
715 <        cmd_out = runCommand(cmd)
716 <        return cmd_out
712 >        #TaskName  
713 >        dir = string.split(common.work_space.topDir(), '/')
714 >        taskName = dir[len(dir)-2]
715 >  
716 >        to_write = ''
717  
718 <    def getOutput(self, id):
719 <        """
625 <        Get output for a finished job with id.
626 <        Returns the name of directory with results.
627 <        """
718 >        req=' '
719 >        req = req + jbt.getRequirements()
720  
721 <        self.checkProxy()
722 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
723 <        cmd_out = runCommand(cmd)
721 >        if self.EDG_requirements:
722 >            if (req == ' '):
723 >                req = req + self.EDG_requirements
724 >            else:
725 >                req = req +  ' && ' + self.EDG_requirements
726 >        if self.EDG_ce_white_list:
727 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
728 >            for i in range(len(ce_white_list)):
729 >                if i == 0:
730 >                    if (req == ' '):
731 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
732 >                    else:
733 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
734 >                    pass
735 >                else:
736 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
737 >            req = req + ')'
738 >        
739 >        if self.EDG_ce_black_list:
740 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
741 >            for ce in ce_black_list:
742 >                if (req == ' '):
743 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
744 >                else:
745 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
746 >                pass
747 >        if self.EDG_clock_time:
748 >            if (req == ' '):
749 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
750 >            else:
751 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
752  
753 <        # Determine the output directory name
754 <        dir = common.work_space.resDir()
755 <        dir += os.environ['USER']
756 <        dir += '_' + os.path.basename(id)
757 <        return dir
753 >        if self.EDG_cpu_time:
754 >            if (req == ' '):
755 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
756 >            else:
757 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
758 >                                                                                          
759 >        if ( self.EDG_retry_count ):              
760 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
761 >            pass
762  
763 <    def cancel(self, id):
764 <        """ Cancel the EDG job with id """
765 <        self.checkProxy()
642 <        cmd = 'edg-job-cancel --noint ' + id
643 <        cmd_out = runCommand(cmd)
644 <        return cmd_out
763 >        if ( self.EDG_shallow_retry_count ):              
764 >            to_write = to_write + 'ShallowRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
765 >            pass
766  
767 <    def createSchScript(self, nj):
768 <        """
648 <        Create a JDL-file for EDG.
649 <        """
767 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
768 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
769  
770 <        job = common.job_list[nj]
771 <        jbt = job.type()
772 <        inp_sandbox = jbt.inputSandbox(nj)
773 <        out_sandbox = jbt.outputSandbox(nj)
774 <        inp_storage_subdir = ''
770 >        #TaskName  
771 >        dir = string.split(common.work_space.topDir(), '/')
772 >        taskName = dir[len(dir)-2]
773 >
774 >        xml.write(str(title))
775 >        #xml.write('<task name="' +str(taskName)+'" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache">\n')
776 >
777 >        #xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + '" task_info="' + os.path.expandvars('X509_USER_PROXY') + '">\n')
778 >        xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + ' task_info="' + os.environ["X509_USER_PROXY"] + '">\n')
779 >        xml.write(jt_string)
780          
781 <        title = '# This JDL was generated by '+\
782 <                common.prog_name+' (version '+common.prog_version_str+')\n'
783 <        jt_string = ''
784 <
781 >        if (to_write != ''):
782 >            xml.write('<extraTags\n')
783 >            xml.write(to_write)
784 >            xml.write('/>\n')
785 >            pass
786  
787 +        xml.write('<iterator>\n')
788 +        xml.write('\t<iteratorRule name="ITR1">\n')
789 +        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
790 +        xml.write('\t</iteratorRule>\n')
791 +        xml.write('\t<iteratorRule name="ITR2">\n')
792 +        for arg in argsList:
793 +            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
794 +            pass
795 +        xml.write('\t</iteratorRule>\n')
796 +        #print jobList
797 +        xml.write('\t<iteratorRule name="ITR3">\n')
798 +        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
799 +        xml.write('\t</iteratorRule>\n')
800 +
801 +        '''
802 +        indy: here itr4
803 +        '''
804          
805 <        SPL = inp_storage_subdir
806 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
805 >        xml.write('<chain name="' +str(taskName)+'__ITR1_" scheduler="'+str(self.schedulerName)+'">\n')
806 >       # xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
807 >        xml.write(jt_string)
808  
809 <        jdl_fname = job.jdlFilename()
667 <        jdl = open(jdl_fname, 'w')
668 <        jdl.write(title)
809 >        #executable
810  
811 +        """
812 +        INDY
813 +        script depends on jobType: it should be probably get in a different way
814 +        """        
815          script = job.scriptFilename()
816 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
817 <        jdl.write(jt_string)
818 <
819 <        ### only one .sh  JDL has arguments:
820 <
821 <        ### Fabio
822 <        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
678 <        inp_box = 'InputSandbox = { '
679 <        inp_box = inp_box + '"' + script + '",'
816 >        xml.write('<program>\n')
817 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
818 >        xml.write(jt_string)
819 >
820 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
821 >        xml.write('<program_types> crabjob </program_types>\n')
822 >        inp_box = common.work_space.pathForTgz() + 'job/' + jbt.scriptName + ','
823  
824          if inp_sandbox != None:
825              for fl in inp_sandbox:
826 <                inp_box = inp_box + ' "' + fl + '",'
826 >                inp_box = inp_box + '' + fl + ','
827                  pass
828              pass
829  
830 <        #if common.use_jam:
831 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
832 <
833 <        # Marco (VERY TEMPORARY ML STUFF)
834 <        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
835 <                  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
830 > #        if (not jbt.additional_inbox_files == []):
831 > #            inp_box = inp_box + ','
832 > #            for addFile in jbt.additional_inbox_files:
833 > #                #addFile = os.path.abspath(addFile)
834 > #                inp_box = inp_box+''+addFile+','
835 > #                pass
836  
837          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
838 <        inp_box = inp_box + ' };\n'
839 <        jdl.write(inp_box)
708 <
709 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
710 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
838 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
839 >        xml.write(inp_box)
840          
841 +        base = jbt.name()
842 +        stdout = base + '__ITR3_.stdout'
843 +        stderr = base + '__ITR3_.stderr'
844 +        
845 +        xml.write('<stderr> ' + stderr + '</stderr>\n')
846 +        xml.write('<stdout> ' + stdout + '</stdout>\n')
847          
713        if job.stdout() == job.stderr():
714          out_box = 'OutputSandbox = { "' + \
715                    job.stdout() + '", ".BrokerInfo",'
716        else:
717          out_box = 'OutputSandbox = { "' + \
718                    job.stdout() + '", "' + \
719                    job.stderr() + '", ".BrokerInfo",'
848  
849 +        out_box = stdout + ',' + \
850 +                  stderr + ',.BrokerInfo,'
851 +
852 +        """
853          if int(self.return_data) == 1:
854              if out_sandbox != None:
855                  for fl in out_sandbox:
856 <                    out_box = out_box + ' "' + fl + '",'
856 >                    out_box = out_box + '' + fl + ','
857                      pass
858                  pass
859              pass
860 <                                                                                                                                                            
729 <        if out_box[-1] == ',' : out_box = out_box[:-1]
730 <        out_box = out_box + ' };'
731 <        jdl.write(out_box+'\n')
860 >        """
861  
862 +        """
863 +        INDY
864 +        something similar should be also done for infiles (if it makes sense!)
865 +        """
866 +        # Stuff to be returned _always_ via sandbox
867 +        for fl in jbt.output_file_sandbox:
868 +            out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
869 +            pass
870 +        pass
871  
872 <        req='Requirements = '
873 <        noreq=req
874 <        req = req + jbt.getRequirements()
875 <        #### 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))'
872 >        # via sandbox iif required return_data
873 >        if int(self.return_data) == 1:
874 >            for fl in jbt.output_file:
875 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
876                  pass
877 +            pass
878  
879 <        ###############
880 <        clockTime=480
881 <        if self.EDG_clock_time:
882 <            clockTime= self.EDG_clock_time
883 <        if (req != noreq):
769 <            req = req + ' && '
770 <        req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
879 >        if out_box[-1] == ',' : out_box = out_box[:-1]
880 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
881 >        xml.write(out_box)
882 >
883 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
884  
885 <        cpuTime=1000
886 <        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')
885 >        xml.write('</program>\n')
886 >        xml.write('</chain>\n')
887  
888 <        if ( self.EDG_retry_count ):              
889 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
787 <            pass
888 >        xml.write('</iterator>\n')
889 >        xml.write('</task>\n')
890  
891 <        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
891 >        xml.close()
892 >      
893  
791        jdl.close()
894          return
895  
896      def checkProxy(self):
# Line 796 | Line 898 | class SchedulerEdg(Scheduler):
898          Function to check the Globus proxy.
899          """
900          if (self.proxyValid): return
901 <        timeleft = -999
901 >
902 >        ### Just return if asked to do so
903 >        if (self.dontCheckProxy==1):
904 >            self.proxyValid=1
905 >            return
906 >
907          minTimeLeft=10*3600 # in seconds
908  
909          minTimeLeftServer = 100 # in hours
910  
804        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
805        #cmd = 'voms-proxy-info -timeleft'
911          mustRenew = 0
912 <        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
912 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
913          timeLeftServer = -999
914          if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
915              mustRenew = 1
916          else:
917 <            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
917 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
918              if not timeLeftServer or not isInt(timeLeftServer):
919                  mustRenew = 1
920              elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
# Line 818 | Line 923 | class SchedulerEdg(Scheduler):
923          pass
924  
925          if mustRenew:
926 <            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")
927 <            cmd = 'voms-proxy-init -voms cms -valid 96:00'
926 >            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")
927 >            cmd = 'voms-proxy-init -voms '+self.VO
928 >            if self.group:
929 >                cmd += ':/'+self.VO+'/'+self.group
930 >            if self.role:
931 >                cmd += '/role='+self.role
932 >            cmd += ' -valid 192:00'
933              try:
934                  # SL as above: damn it!
935 +                common.logger.debug(10,cmd)
936                  out = os.system(cmd)
937                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
938              except:
939                  msg = "Unable to create a valid proxy!\n"
940                  raise CrabException(msg)
830            # cmd = 'grid-proxy-info -timeleft'
831            # cmd_out = runCommand(cmd,0,20)
941              pass
942  
943          ## now I do have a voms proxy valid, and I check the myproxy server
# Line 843 | Line 952 | class SchedulerEdg(Scheduler):
952              reTime = re.compile( r'timeleft: (\d+)' )
953              #print "<"+str(reTime.search( cmd_out ).group(1))+">"
954              if reTime.match( cmd_out ):
955 <                time = reTime.search( line ).group(1)
955 >                time = reTime.search( cmd_out ).group(1)
956                  if time < minTimeLeftServer:
957                      renewProxy = 1
958                      common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
# Line 869 | Line 978 | class SchedulerEdg(Scheduler):
978          if self.edg_config_vo:
979              edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
980          return edg_ui_cfg_opt
981 +
982 +    def submitTout(self, list):
983 +        return 120
984 +
985 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines