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.55 by corvo, Wed May 3 08:44:30 2006 UTC vs.
Revision 1.130 by gutsche, Thu Jul 26 03:02:55 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          try:
30 <            RB = cfg_params["EDG.rb"]
31 <            edgConfig = EdgConfig(RB)
28 <            self.edg_config = edgConfig.config()
29 <            self.edg_config_vo = edgConfig.configVO()
30 >            RB=cfg_params["EDG.rb"]
31 >            self.rb_param_file=self.rb_configure(RB)
32          except KeyError:
33 <            self.edg_config = ''
34 <            self.edg_config_vo = ''
33 <
33 >            self.rb_param_file=''
34 >            pass
35          try:
36              self.proxyServer = cfg_params["EDG.proxy_server"]
37          except KeyError:
38              self.proxyServer = 'myproxy.cern.ch'
39          common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
40  
41 +        try:
42 +            self.group = cfg_params["EDG.group"]
43 +        except KeyError:
44 +            self.group = None
45 +            
46 +        try:
47 +            self.role = cfg_params["EDG.role"]
48 +        except KeyError:
49 +            self.role = None
50 +            
51          try: self.LCG_version = cfg_params["EDG.lcg_version"]
52          except KeyError: self.LCG_version = '2'
53  
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
54          try:
55              self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
51            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
56          except KeyError:
57              self.EDG_ce_black_list  = ''
58  
59          try:
60              self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
57            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
61          except KeyError: self.EDG_ce_white_list = ''
62  
63          try: self.VO = cfg_params['EDG.virtual_organization']
64          except KeyError: self.VO = 'cms'
65  
66 <        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
66 >        try: self.copy_input_data = cfg_params["USER.copy_input_data"]
67          except KeyError: self.copy_input_data = 0
68  
69 +        try: self.return_data = cfg_params['USER.return_data']
70 +        except KeyError: self.return_data = 0
71 +
72          try:
73              self.copy_data = cfg_params["USER.copy_data"]
74              if int(self.copy_data) == 1:
# Line 86 | Line 87 | class SchedulerEdg(Scheduler):
87             msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
88             raise CrabException(msg)
89  
90 +        ########### FEDE FOR DBS2 ##############################
91 +        try:
92 +            self.publish_data = cfg_params["USER.publish_data"]
93 +            if int(self.publish_data) == 1:
94 +                try:
95 +                    self.publish_data_name = cfg_params['USER.publish_data_name']
96 +                except KeyError:
97 +                    msg = "Error. The [USER] section does not have 'publish_data_name'"
98 +                    raise CrabException(msg)
99 +                try:
100 +                    tmp = runCommand("voms-proxy-info -identity")
101 +                    tmp = string.split(tmp,'/')
102 +                    reCN=re.compile(r'CN=')
103 +                    for t in tmp:
104 +                        if reCN.match(t):
105 +                            self.UserGridName=string.strip((t.replace('CN=','')).replace(' ',''))
106 +                        
107 +                    #self.UserGridName = string.strip(runCommand("voms-proxy-info -identity | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'"))
108 +                except:
109 +                    msg = "Error. Problem with voms-proxy-info -identity command"
110 +                    raise CrabException(msg)
111 +        except KeyError: self.publish_data = 0
112 +
113 +        if ( int(self.copy_data) == 0 and int(self.publish_data) == 1 ):
114 +           msg = 'Warning: publish_data = 1 must be used with copy_data = 1\n'
115 +           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
116 +           common.logger.message(msg)
117 +           raise CrabException(msg)
118 +        #################################################
119 +
120          try:
121              self.lfc_host = cfg_params['EDG.lfc_host']
122          except KeyError:
# Line 128 | Line 159 | class SchedulerEdg(Scheduler):
159  
160          try: self.EDG_requirements = cfg_params['EDG.requirements']
161          except KeyError: self.EDG_requirements = ''
162 <                                                                                                                                                            
162 >
163 >        try: self.EDG_addJdlParam = string.split(cfg_params['EDG.additional_jdl_parameters'],',')
164 >        except KeyError: self.EDG_addJdlParam = []
165 >
166          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
167          except KeyError: self.EDG_retry_count = ''
168 <                                                                                                                                                            
168 >
169 >        try: self.EDG_shallow_retry_count= cfg_params['EDG.shallow_retry_count']
170 >        except KeyError: self.EDG_shallow_retry_count = ''
171 >
172          try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
173          except KeyError: self.EDG_clock_time= ''
174 <                                                                                                                                                            
174 >
175          try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
176          except KeyError: self.EDG_cpu_time = ''
177  
# Line 152 | Line 189 | class SchedulerEdg(Scheduler):
189          sys.path.append(libPath)
190  
191          self.proxyValid=0
192 +
193 +        try:
194 +            self._taskId = cfg_params['taskId']
195 +        except:
196 +            self._taskId = ''
197 +
198 +        try: self.jobtypeName = cfg_params['CRAB.jobtype']
199 +        except KeyError: self.jobtypeName = ''
200 +
201 +        try: self.schedulerName = cfg_params['CRAB.scheduler']
202 +        except KeyError: self.scheduler = ''
203 +
204 +        try: self.dontCheckProxy=int(cfg_params["EDG.dont_check_proxy"])
205 +        except KeyError: self.dontCheckProxy = 0
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
170 <        else:
171 <            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"
315 +        txt += "NJob=${args[0]}\n"
316 +
317 +        txt += '# job identification to DashBoard \n'
318 +        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
319 +        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
320 +        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
321 +        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
322 +        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
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'
180 <        txt += '    middleware=LCG \n'
181 <        txt += '    echo "middleware =$middleware" \n'
182 <        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'
330          txt += '    echo "middleware =$middleware" \n'
331          txt += 'elif [ $OSG_APP ]; then \n'
332          txt += '    middleware=OSG \n'
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 1 ==> middleware not identified" \n'
344 <        txt += '    echo "JOB_EXIT_STATUS = 1"\n'
345 <        txt += '    exit 1\n'
346 <        txt += 'fi\n'
347 <
343 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
344 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
345 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
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'
349 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
350 >        txt += '    exit 1 \n'
351 >        txt += 'fi \n'
352 >
353 >        txt += '# report first time to DashBoard \n'
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'
357 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
358 >        
359          txt += '\n\n'
360  
361 <        txt += 'if [ $middleware == LCG ]; then \n'
362 <        txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
363 <        txt += 'fi\n'
364 <
365 <        if int(self.copy_data) == 1:
366 <           if self.SE:
367 <              txt += 'export SE='+self.SE+'\n'
368 <              txt += 'echo "SE = $SE"\n'
204 <           if self.SE_PATH:
205 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
206 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
207 <              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 248 | 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 256 | Line 418 | class SchedulerEdg(Scheduler):
418          txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
419          txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
420          txt += '    else \n'
421 <        txt += '        echo "SET_ENV 1 ==> ERROR in setting CE name - OSG mode -" \n'
421 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
422 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
423 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
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'
427 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
428          txt += '        exit 1 \n'
429          txt += '    fi \n'
430          txt += 'fi \n'
# Line 268 | 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']
273 <            #print "self.copy_input_data = ", self.copy_input_data
274 <        except KeyError: self.copy_input_data = 0
275 <        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 320 | Line 485 | class SchedulerEdg(Scheduler):
485          to copy produced output into a storage element.
486          """
487          txt = ''
488 +
489 +        ##### FEDE MOVED FROM SET_ENVIRONMENT ##############
490 +        
491 +        SE_PATH=''
492          if int(self.copy_data) == 1:
493 +           if self.SE:
494 +              txt += 'export SE='+self.SE+'\n'
495 +              txt += 'echo "SE = $SE"\n'
496 +           if self.SE_PATH:
497 +              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
498 +              SE_PATH=self.SE_PATH
499 +              ####### FEDE FOR DBS2
500 +              if int(self.publish_data) == 1:
501 +                  txt += '### publish_data = 1 so the SE path where to copy the output is: \n'
502 +                  #txt += 'subject=`voms-proxy-info -subject | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'` \n'
503 +                  #txt += 'echo "subject = $subject" \n'
504 +                  #path_add = '${subject}/'+ self.publish_data_name +'_${PSETHASH}/'
505 +                  path_add = self.UserGridName + '/' + self.publish_data_name +'_${PSETHASH}/'
506 +                  SE_PATH = SE_PATH + path_add
507 +
508 +              txt += 'export SE_PATH='+SE_PATH+'\n'
509 +              txt += 'echo "SE_PATH = $SE_PATH"\n'
510 +
511 +        ##########################################################  
512 +
513 +        #if int(self.copy_data) == 1:
514             txt += '#\n'
515             txt += '#   Copy output to SE = $SE\n'
516             txt += '#\n'
517 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
517 >           txt += '    if [ $middleware == OSG ]; then\n'
518 >           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
519 >           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
520 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
521 >           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
522 >           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
523 >           txt += '    fi \n'
524 >
525             txt += '    for out_file in $file_list ; do\n'
526 <           txt += '        echo "Trying to copy output file to $SE "\n'
527 <           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
528 <           txt += '        if [ $middleware == OSG ]; then\n'
529 <           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
530 <           txt += '           copy_exit_status=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
531 <           #txt += '           exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
532 <           txt += '        elif [ $middleware == LCG ]; then \n'
533 <           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
534 <           txt += '           copy_exit_status=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
535 <           #txt += '           exitstring=`lcg-cp --vo cms -t 30 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
536 <           txt += '        fi \n'
537 <           #txt += '        copy_exit_status=$?\n'
341 <           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
526 >           txt += '        echo "Trying to copy output file to $SE using srmcp"\n'
527 >           # txt += '        echo "mkdir -p $HOME/.srmconfig"\n'
528 >           # txt += '        mkdir -p $HOME/.srmconfig\n'
529 >           txt += '        if [ $middleware == LCG ]; then\n'
530 >           txt += '           echo "srmcp -retry_num 3 -retry_timeout 480000 file:///`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
531 >           txt += '           exitstring=`srmcp -retry_num 3 -retry_timeout 480000 file:///\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
532 >           txt += '        elif [ $middleware == OSG ]; then\n'
533 >           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'
534 >           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'
535 >           txt += '        fi \n'
536 >           txt += '        copy_exit_status=$?\n'
537 >           txt += '        echo "COPY_EXIT_STATUS for srmcp = $copy_exit_status"\n'
538             txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
539 +
540             txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
541 <           txt += '            echo "Problems with SE = $SE"\n'
541 >           txt += '            echo "Possible problem with SE = $SE"\n'
542             txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
543             txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
544 +           txt += '            echo "srmcp failed, attempting lcg-cp."\n'
545 +           if common.logger.debugLevel() >= 5:
546 +               ########### FEDE CHANGES TO WRITE IN SRM LNL.INFN.IT #################
547 +               txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
548 +               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
549 +               #txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
550 +               #txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
551 +           else:              
552 +               txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
553 +               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
554 +               #txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
555 +               #txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
556 +           txt += '            copy_exit_status=$?\n'
557 +           txt += '            echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
558 +           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
559 +
560 +           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
561 +           txt += '               echo "Problems with SE = $SE"\n'
562 +           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
563 +           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
564 +           txt += '               echo "srmcp and lcg-cp and failed!"\n'
565 +           txt += '               SE=""\n'
566 +           txt += '               echo "SE = $SE"\n'
567 +           txt += '               SE_PATH=""\n'
568 +           txt += '               echo "SE_PATH = $SE_PATH"\n'
569 +           txt += '            else\n'
570 +           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
571 +           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
572 +           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
573 +           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
574 +           txt += '               echo "lcg-cp succeeded"\n'
575 +           txt += '            fi\n'
576             txt += '        else\n'
577             txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
578             txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
579             txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
580             txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
581 +           txt += '            echo "srmcp succeeded"\n'
582             txt += '         fi\n'
583             txt += '     done\n'
584 <           txt += 'fi\n'
584 >           txt += '     exit_status=$copy_exit_status\n'
585          return txt
586  
587      def wsRegisterOutput(self):
# Line 371 | Line 601 | class SchedulerEdg(Scheduler):
601             txt += '#\n'
602             txt += '#  Register output to LFC\n'
603             txt += '#\n'
604 <           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
604 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
605             txt += '      for out_file in $file_list ; do\n'
606             txt += '         echo "Trying to register the output file into LFC"\n'
607 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
608 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
607 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
608 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
609             txt += '         register_exit_status=$?\n'
610             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
611             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
612             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
613             txt += '            echo "Problems with the registration to LFC" \n'
614             txt += '            echo "Try with srm protocol" \n'
615 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
616 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
615 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
616 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
617             txt += '            register_exit_status=$?\n'
618             txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
619             txt += '            echo "STAGE_OUT = $register_exit_status"\n'
# Line 395 | Line 625 | class SchedulerEdg(Scheduler):
625             txt += '         fi \n'
626             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
627             txt += '      done\n'
628 <           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
628 >           txt += '   else \n'
629             txt += '      echo "Trying to copy output file to CloseSE"\n'
630 <           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
630 > #          txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
631 >           txt += '      CLOSE_SE=`glite-brokerinfo getCloseSEs | head -1`\n'
632             txt += '      for out_file in $file_list ; do\n'
633 <           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
634 <           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'
633 >           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'
634 >           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'
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 CloseSE" \n'
639 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
640             txt += '         else \n'
641             txt += '            echo "The program was successfully executed"\n'
642             txt += '            echo "SE = $CLOSE_SE"\n'
# Line 413 | Line 644 | class SchedulerEdg(Scheduler):
644             txt += '         fi \n'
645             txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
646             txt += '      done\n'
416           txt += '   else\n'
417           txt += '      echo "Problem with the executable"\n'
647             txt += '   fi \n'
648 +           txt += '   exit_status=$register_exit_status\n'
649             txt += 'fi \n'
650          return txt
651  
# Line 425 | Line 655 | class SchedulerEdg(Scheduler):
655          """
656          self.checkProxy()
657          cmd = 'edg-job-get-logging-info -v 2 ' + id
428        #cmd_out = os.popen(cmd)
658          cmd_out = runCommand(cmd)
659          return cmd_out
660  
432    def listMatch(self, nj):
433        """
434        Check the compatibility of available resources
435        """
436        self.checkProxy()
437        jdl = common.job_list[nj].jdlFilename()
438        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
439        cmd_out = runCommand(cmd,0,10)
440        if not cmd_out:
441            raise CrabException("ERROR: "+cmd+" failed!")
442
443        return self.parseListMatch_(cmd_out, jdl)
444
445    def parseListMatch_(self, out, jdl):
446        """
447        Parse the f* output of edg-list-match and produce something sensible
448        """
449        reComment = re.compile( r'^\**$' )
450        reEmptyLine = re.compile( r'^$' )
451        reVO = re.compile( r'Selected Virtual Organisation name.*' )
452        reLine = re.compile( r'.*')
453        reCE = re.compile( r'(.*:.*)')
454        reCEId = re.compile( r'CEId.*')
455        reNO = re.compile( r'No Computing Element matching' )
456        reRB = re.compile( r'Connecting to host' )
457        next = 0
458        CEs=[]
459        Match=0
460
461        #print out
462        lines = reLine.findall(out)
463
464        i=0
465        CEs=[]
466        for line in lines:
467            string.strip(line)
468            #print line
469            if reNO.match( line ):
470                common.logger.debug(5,line)
471                return 0
472                pass
473            if reVO.match( line ):
474                VO =reVO.match( line ).group()
475                common.logger.debug(5,"VO "+VO)
476                pass
477
478            if reRB.match( line ):
479                RB = reRB.match(line).group()
480                common.logger.debug(5,"RB "+RB)
481                pass
482
483            if reCEId.search( line ):
484                for lineCE in lines[i:-1]:
485                    if reCE.match( lineCE ):
486                        CE = string.strip(reCE.search(lineCE).group(1))
487                        CEs.append(CE.split(':')[0])
488                        pass
489                    pass
490                pass
491            i=i+1
492            pass
493
494        common.logger.debug(5,"All CE :"+str(CEs))
495
496        sites = []
497        [sites.append(it) for it in CEs if not sites.count(it)]
498
499        common.logger.debug(5,"All Sites :"+str(sites))
500        return len(sites)
501
502    def noMatchFound_(self, jdl):
503        reReq = re.compile( r'Requirements' )
504        reString = re.compile( r'"\S*"' )
505        f = file(jdl,'r')
506        for line in f.readlines():
507            line= line.strip()
508            if reReq.match(line):
509                for req in reString.findall(line):
510                    if re.search("VO",req):
511                        common.logger.message( "SW required: "+req)
512                        continue
513                    if re.search('"\d+',req):
514                        common.logger.message("Other req  : "+req)
515                        continue
516                    common.logger.message( "CE required: "+req)
517                break
518            pass
519        raise CrabException("No compatible resources found!")
520
521    def submit(self, nj):
522        """
523        Submit one EDG job.
524        """
525
526        self.checkProxy()
527        jid = None
528        jdl = common.job_list[nj].jdlFilename()
529
530        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
531        cmd_out = runCommand(cmd)
532        if cmd_out != None:
533            reSid = re.compile( r'https.+' )
534            jid = reSid.search(cmd_out).group()
535            pass
536        return jid
537
538    def resubmit(self, nj_list):
539        """
540        Prepare jobs to be submit
541        """
542        return
543
544    def getExitStatus(self, id):
545        return self.getStatusAttribute_(id, 'exit_code')
546
547    def queryStatus(self, id):
548        return self.getStatusAttribute_(id, 'status')
549
550    def queryDest(self, id):  
551        return self.getStatusAttribute_(id, 'destination')
552
553
554    def getStatusAttribute_(self, id, attr):
555        """ Query a status of the job with id """
556
557        self.checkProxy()
558        hstates = {}
559        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
560        # Bypass edg-job-status interfacing directly to C++ API
561        # Job attribute vector to retrieve status without edg-job-status
562        level = 0
563        # Instance of the Status class provided by LB API
564        jobStat = Status()
565        st = 0
566        jobStat.getStatus(id, level)
567        err, apiMsg = jobStat.get_error()
568        if err:
569            common.logger.debug(5,'Error caught' + apiMsg)
570            return None
571        else:
572            for i in range(len(self.states)):
573                # Fill an hash table with all information retrieved from LB API
574                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
575            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
576            return result
577
661      def queryDetailedStatus(self, id):
662          """ Query a detailed status of the job with id """
663          cmd = 'edg-job-status '+id
664          cmd_out = runCommand(cmd)
665          return cmd_out
666  
667 <    def getOutput(self, id):
668 <        """
586 <        Get output for a finished job with id.
587 <        Returns the name of directory with results.
588 <        """
667 >    def findSites_(self, n):
668 >        itr4 =[]
669  
670 <        self.checkProxy()
591 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
592 <        cmd_out = runCommand(cmd)
670 >        sites = common.jobDB.destination(n)
671  
672 <        # Determine the output directory name
673 <        dir = common.work_space.resDir()
596 <        dir += os.environ['USER']
597 <        dir += '_' + os.path.basename(id)
598 <        return dir
672 >        if len(sites)>0 and sites[0]=="":
673 >            return itr4
674  
675 <    def cancel(self, id):
676 <        """ Cancel the EDG job with id """
677 <        self.checkProxy()
678 <        cmd = 'edg-job-cancel --noint ' + id
679 <        cmd_out = runCommand(cmd)
680 <        return cmd_out
675 >        itr = ''
676 >        if sites != [""]:#CarlosDaniele
677 >            ##Addedd Daniele
678 >            replicas = self.blackWhiteListParser.checkBlackList(sites,n)
679 >            if len(replicas)!=0:
680 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
681 >              
682 >            if len(replicas)==0:
683 >                msg = 'No sites remaining that host any part of the requested data! Exiting... '
684 >                raise CrabException(msg)
685 >            #####        
686 >           # for site in sites:
687 >            for site in replicas:
688 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
689 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
690 >            itr = itr[0:-4]
691 >            itr4.append( itr )
692 >        return itr4
693  
694 <    def createSchScript(self, nj):
694 >    def createXMLSchScript(self, nj, argsList):
695 >      
696          """
697 <        Create a JDL-file for EDG.
697 >        Create a XML-file for BOSS4.
698          """
699 <
700 <        job = common.job_list[nj]
699 >  #      job = common.job_list[nj]
700 >        """
701 >        INDY
702 >        [begin] FIX-ME:
703 >        I would pass jobType instead of job
704 >        """
705 >        index = nj - 1
706 >        job = common.job_list[index]
707          jbt = job.type()
614        inp_sandbox = jbt.inputSandbox(nj)
615        out_sandbox = jbt.outputSandbox(nj)
616        inp_storage_subdir = ''
708          
709 <        title = '# This JDL was generated by '+\
710 <                common.prog_name+' (version '+common.prog_version_str+')\n'
711 <        jt_string = ''
712 <
713 <
623 <        
624 <        SPL = inp_storage_subdir
625 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
626 <
627 <        jdl_fname = job.jdlFilename()
628 <        jdl = open(jdl_fname, 'w')
629 <        jdl.write(title)
630 <
631 <        script = job.scriptFilename()
632 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
633 <        jdl.write(jt_string)
634 <
635 <        ### only one .sh  JDL has arguments:
636 <        firstEvent = common.jobDB.firstEvent(nj)
637 <        maxEvents = common.jobDB.maxEvents(nj)
638 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
639 <
640 <        inp_box = 'InputSandbox = { '
641 <        inp_box = inp_box + '"' + script + '",'
642 <
643 <        if inp_sandbox != None:
644 <            for fl in inp_sandbox:
645 <                inp_box = inp_box + ' "' + fl + '",'
646 <                pass
647 <            pass
648 <
649 <        #if common.use_jam:
650 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
651 <
652 <        # Marco (VERY TEMPORARY ML STUFF)
653 <        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
654 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
655 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
656 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
657 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
658 <        # End Marco
659 <
660 <        if (not jbt.additional_inbox_files == []):
661 <            inp_box = inp_box + ', '
662 <            for addFile in jbt.additional_inbox_files:
663 <                addFile = os.path.abspath(addFile)
664 <                inp_box = inp_box+' "'+addFile+'",'
665 <                pass
666 <
667 <        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
668 <        inp_box = inp_box + ' };\n'
669 <        jdl.write(inp_box)
709 >        inp_sandbox = jbt.inputSandbox(index)
710 >        #out_sandbox = jbt.outputSandbox(index)
711 >        """
712 >        [end] FIX-ME
713 >        """
714  
671        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
672        jdl.write('StdError      = "' + job.stderr() + '";\n')
715          
716 +        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
717 +        jt_string = ''
718          
719 <        if job.stdout() == job.stderr():
720 <          out_box = 'OutputSandbox = { "' + \
677 <                    job.stdout() + '", ".BrokerInfo",'
678 <        else:
679 <          out_box = 'OutputSandbox = { "' + \
680 <                    job.stdout() + '", "' + \
681 <                    job.stderr() + '", ".BrokerInfo",'
719 >        xml_fname = str(self.jobtypeName)+'.xml'
720 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
721  
722 <        if int(self.return_data) == 1:
723 <            if out_sandbox != None:
724 <                for fl in out_sandbox:
725 <                    out_box = out_box + ' "' + fl + '",'
726 <                    pass
688 <                pass
689 <            pass
690 <                                                                                                                                                            
691 <        if out_box[-1] == ',' : out_box = out_box[:-1]
692 <        out_box = out_box + ' };'
693 <        jdl.write(out_box+'\n')
722 >        #TaskName  
723 >        dir = string.split(common.work_space.topDir(), '/')
724 >        taskName = dir[len(dir)-2]
725 >  
726 >        to_write = ''
727  
728 <
696 <        req='Requirements = '
728 >        req=' '
729          req = req + jbt.getRequirements()
730 < #        ### if at least a CE exists ...
699 < #        if common.analisys_common_info['sites']:
700 < #           if common.analisys_common_info['sw_version']:
701 < #                req='Requirements = '
702 < #                req=req + 'Member("VO-cms-' + \
703 < #                     common.analisys_common_info['sw_version'] + \
704 < #                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
705 < #            if len(common.analisys_common_info['sites'])>0:
706 < #                req = req + ' && ('
707 < #                for i in range(len(common.analisys_common_info['sites'])):
708 < #                    req = req + 'other.GlueCEInfoHostName == "' \
709 < #                         + common.analisys_common_info['sites'][i] + '"'
710 < #                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
711 < #                        req = req + ' || '
712 < #            req = req + ')'
713 <        #### and USER REQUIREMENT
730 >
731          if self.EDG_requirements:
732 <            if (req == 'Requirement = '):
732 >            if (req == ' '):
733                  req = req + self.EDG_requirements
734              else:
735                  req = req +  ' && ' + self.EDG_requirements
719        #### FEDE #####
736          if self.EDG_ce_white_list:
737              ce_white_list = string.split(self.EDG_ce_white_list,',')
722            #print "req = ", req
738              for i in range(len(ce_white_list)):
739                  if i == 0:
740 <                    if (req == 'Requirement = '):
740 >                    if (req == ' '):
741                          req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
742                      else:
743                          req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
# Line 734 | Line 749 | class SchedulerEdg(Scheduler):
749          if self.EDG_ce_black_list:
750              ce_black_list = string.split(self.EDG_ce_black_list,',')
751              for ce in ce_black_list:
752 <                if (req == 'Requirement = '):
752 >                if (req == ' '):
753                      req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
754                  else:
755                      req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
756                  pass
742        ###############
757          if self.EDG_clock_time:
758 <            if (req == 'Requirement = '):
758 >            if (req == ' '):
759                  req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
760              else:
761                  req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
762  
763          if self.EDG_cpu_time:
764 <            if (req == 'Requirement = '):
764 >            if (req == ' '):
765                  req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
766              else:
767                  req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
768 <        if (req != 'Requirement = '):
755 <            req = req + ';\n'
756 <            jdl.write(req)
757 <                                                                                                                                                            
758 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
759 <
768 >                                                                                          
769          if ( self.EDG_retry_count ):              
770 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
770 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
771 >            pass
772 >
773 >        if ( self.EDG_shallow_retry_count ):              
774 >            to_write = to_write + 'ShallowRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
775 >            pass
776 >
777 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
778 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
779 >
780 >        #TaskName  
781 >        dir = string.split(common.work_space.topDir(), '/')
782 >        taskName = dir[len(dir)-2]
783 >
784 >        xml.write(str(title))
785 >        #xml.write('<task name="' +str(taskName)+'" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache">\n')
786 >
787 >        #xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + '" task_info="' + os.path.expandvars('X509_USER_PROXY') + '">\n')
788 >        xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + ' task_info="' + os.environ["X509_USER_PROXY"] + '">\n')
789 >        xml.write(jt_string)
790 >        
791 >        if (to_write != ''):
792 >            xml.write('<extraTags\n')
793 >            xml.write(to_write)
794 >            xml.write('/>\n')
795 >            pass
796 >
797 >        xml.write('<iterator>\n')
798 >        xml.write('\t<iteratorRule name="ITR1">\n')
799 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
800 >        xml.write('\t</iteratorRule>\n')
801 >        xml.write('\t<iteratorRule name="ITR2">\n')
802 >        for arg in argsList:
803 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
804 >            pass
805 >        xml.write('\t</iteratorRule>\n')
806 >        #print jobList
807 >        xml.write('\t<iteratorRule name="ITR3">\n')
808 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
809 >        xml.write('\t</iteratorRule>\n')
810 >
811 >        '''
812 >        indy: here itr4
813 >        '''
814 >        
815 >        xml.write('<chain name="' +str(taskName)+'__ITR1_" scheduler="'+str(self.schedulerName)+'">\n')
816 >       # xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
817 >        xml.write(jt_string)
818 >
819 >        #executable
820 >
821 >        """
822 >        INDY
823 >        script depends on jobType: it should be probably get in a different way
824 >        """        
825 >        script = job.scriptFilename()
826 >        xml.write('<program>\n')
827 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
828 >        xml.write(jt_string)
829 >
830 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
831 >        xml.write('<program_types> crabjob </program_types>\n')
832 >        inp_box = common.work_space.pathForTgz() + 'job/' + jbt.scriptName + ','
833 >
834 >        if inp_sandbox != None:
835 >            for fl in inp_sandbox:
836 >                inp_box = inp_box + '' + fl + ','
837 >                pass
838 >            pass
839 >
840 > #        if (not jbt.additional_inbox_files == []):
841 > #            inp_box = inp_box + ','
842 > #            for addFile in jbt.additional_inbox_files:
843 > #                #addFile = os.path.abspath(addFile)
844 > #                inp_box = inp_box+''+addFile+','
845 > #                pass
846 >
847 >        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
848 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
849 >        xml.write(inp_box)
850 >        
851 >        base = jbt.name()
852 >        stdout = base + '__ITR3_.stdout'
853 >        stderr = base + '__ITR3_.stderr'
854 >        
855 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
856 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
857 >        
858 >
859 >        out_box = stdout + ',' + \
860 >                  stderr + ',.BrokerInfo,'
861 >
862 >        """
863 >        if int(self.return_data) == 1:
864 >            if out_sandbox != None:
865 >                for fl in out_sandbox:
866 >                    out_box = out_box + '' + fl + ','
867 >                    pass
868 >                pass
869              pass
870 +        """
871  
872 <        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
872 >        """
873 >        INDY
874 >        something similar should be also done for infiles (if it makes sense!)
875 >        """
876 >        # Stuff to be returned _always_ via sandbox
877 >        for fl in jbt.output_file_sandbox:
878 >            out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
879 >            pass
880 >        pass
881 >
882 >        # via sandbox iif required return_data
883 >        if int(self.return_data) == 1:
884 >            for fl in jbt.output_file:
885 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
886 >                pass
887 >            pass
888 >
889 >        if out_box[-1] == ',' : out_box = out_box[:-1]
890 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
891 >        xml.write(out_box)
892 >
893 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
894 >
895 >        xml.write('</program>\n')
896 >        xml.write('</chain>\n')
897 >
898 >        xml.write('</iterator>\n')
899 >        xml.write('</task>\n')
900 >
901 >        xml.close()
902 >      
903  
766        jdl.close()
904          return
905  
906      def checkProxy(self):
# Line 771 | Line 908 | class SchedulerEdg(Scheduler):
908          Function to check the Globus proxy.
909          """
910          if (self.proxyValid): return
911 <        timeleft = -999
911 >
912 >        ### Just return if asked to do so
913 >        if (self.dontCheckProxy==1):
914 >            self.proxyValid=1
915 >            return
916 >
917          minTimeLeft=10*3600 # in seconds
918  
919          minTimeLeftServer = 100 # in hours
920  
779        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
780        #cmd = 'voms-proxy-info -timeleft'
921          mustRenew = 0
922 <        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
922 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
923          timeLeftServer = -999
924          if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
925              mustRenew = 1
926          else:
927 <            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
927 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
928              if not timeLeftServer or not isInt(timeLeftServer):
929                  mustRenew = 1
930              elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
# Line 793 | Line 933 | class SchedulerEdg(Scheduler):
933          pass
934  
935          if mustRenew:
936 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 24h\n")
937 <            cmd = 'voms-proxy-init -voms cms -valid 24:00'
936 >            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")
937 >            cmd = 'voms-proxy-init -voms '+self.VO
938 >            if self.group:
939 >                cmd += ':/'+self.VO+'/'+self.group
940 >            if self.role:
941 >                cmd += '/role='+self.role
942 >            cmd += ' -valid 192:00'
943              try:
944                  # SL as above: damn it!
945 +                common.logger.debug(10,cmd)
946                  out = os.system(cmd)
947                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
948              except:
949                  msg = "Unable to create a valid proxy!\n"
950                  raise CrabException(msg)
805            # cmd = 'grid-proxy-info -timeleft'
806            # cmd_out = runCommand(cmd,0,20)
951              pass
952  
953          ## now I do have a voms proxy valid, and I check the myproxy server
# Line 818 | Line 962 | class SchedulerEdg(Scheduler):
962              reTime = re.compile( r'timeleft: (\d+)' )
963              #print "<"+str(reTime.search( cmd_out ).group(1))+">"
964              if reTime.match( cmd_out ):
965 <                time = reTime.search( line ).group(1)
965 >                time = reTime.search( cmd_out ).group(1)
966                  if time < minTimeLeftServer:
967                      renewProxy = 1
968                      common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
# Line 844 | Line 988 | class SchedulerEdg(Scheduler):
988          if self.edg_config_vo:
989              edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
990          return edg_ui_cfg_opt
991 +
992 +    def submitTout(self, list):
993 +        return 120
994 +
995 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines