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.23 by spiga, Tue Nov 8 13:27:11 2005 UTC vs.
Revision 1.150 by fanzago, Wed Nov 7 13:18:09 2007 UTC

# Line 2 | Line 2 | from Scheduler import Scheduler
2   from crab_logger import Logger
3   from crab_exceptions import *
4   from crab_util import *
5 + from EdgConfig import *
6 + from BlackWhiteListParser import BlackWhiteListParser
7   import common
8  
9   import os, sys, time
# Line 21 | Line 23 | class SchedulerEdg(Scheduler):
23  
24      def configure(self, cfg_params):
25  
26 <        try: self.edg_config = cfg_params["EDG.config"]
27 <        except KeyError: self.edg_config = ''
26 >        # init BlackWhiteListParser
27 >        self.blackWhiteListParser = BlackWhiteListParser(cfg_params)
28  
29 <        try: self.edg_config_vo = cfg_params["EDG.config_vo"]
30 <        except KeyError: self.edg_config_vo = ''
29 >        self.proxyValid=0
30 >        try: self.dontCheckProxy=int(cfg_params["EDG.dont_check_proxy"])
31 >        except KeyError: self.dontCheckProxy = 0
32  
33 <        try: self.LCG_version = cfg_params["EDG.lcg_version"]
34 <        except KeyError: self.LCG_version = '2'
33 >        try:
34 >            RB=cfg_params["EDG.rb"]
35 >            self.rb_param_file=self.rb_configure(RB)
36 >        except KeyError:
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: self.EDG_requirements = cfg_params['EDG.requirements']
46 <        except KeyError: self.EDG_requirements = ''
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  
58 <        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
59 <        except KeyError: self.EDG_retry_count = ''
58 >        try:
59 >            self.EDG_ce_black_list = cfg_params['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']
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.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 = ''
74 >        except KeyError: self.return_data = 0
75  
76          try:
77              self.copy_data = cfg_params["USER.copy_data"]
78 <            try:
79 <                self.SE = cfg_params['USER.storage_element']
80 <                self.SE_PATH = cfg_params['USER.storage_path']
81 <            except KeyError:
82 <                msg = "Error. The [USER] section does not have 'storage_element'"
83 <                msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
84 <                common.logger.message(msg)
85 <                raise CrabException(msg)
86 <        except KeyError: self.copy_data = ''
78 >            if int(self.copy_data) == 1:
79 >                try:
80 >                    self.SE = cfg_params['USER.storage_element']
81 >                    self.SE_PATH = cfg_params['USER.storage_path']
82 >                except KeyError:
83 >                    msg = "Error. The [USER] section does not have 'storage_element'"
84 >                    msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
85 >                    common.logger.message(msg)
86 >                    raise CrabException(msg)
87 >        except KeyError: self.copy_data = 0
88 >
89 >        if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
90 >           msg = 'Error: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
91 >           msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
92 >           raise CrabException(msg)
93 >
94 >        if ( int(self.return_data) == 1 and int(self.copy_data) == 1 ):
95 >           msg = 'Error: return_data and copy_data cannot be set both to 1\n'
96 >           msg = msg + 'Please modify return_data or copy_data value in your crab.cfg file\n'
97 >           raise CrabException(msg)
98  
99 +        ########### FEDE FOR DBS2 ##############################
100          try:
101 <            self.register_data = cfg_params["USER.register_data"]
102 <            try:
103 <                 self.LFN = cfg_params['USER.lfn_dir']
104 <            except KeyError:
105 <                msg = "Error. The [USER] section does not have 'lfn_dir' value"
106 <                msg = msg + " it's necessary for RLS registration"
107 <                common.logger.message(msg)
108 <                raise CrabException(msg)
109 <        except KeyError: self.register_data= ''
101 >            self.publish_data = cfg_params["USER.publish_data"]
102 >            self.checkProxy()
103 >            if int(self.publish_data) == 1:
104 >                try:
105 >                    self.publish_data_name = cfg_params['USER.publish_data_name']
106 >                except KeyError:
107 >                    msg = "Error. The [USER] section does not have 'publish_data_name'"
108 >                    raise CrabException(msg)
109 >                try:
110 >                    tmp = runCommand("voms-proxy-info -identity")
111 >                    tmp = string.split(tmp,'/')
112 >                    reCN=re.compile(r'CN=')
113 >                    for t in tmp:
114 >                        if reCN.match(t):
115 >                            self.UserGridName=string.strip((t.replace('CN=','')).replace(' ',''))
116 >                        
117 >                    #self.UserGridName = string.strip(runCommand("voms-proxy-info -identity | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'"))
118 >                except:
119 >                    msg = "Error. Problem with voms-proxy-info -identity command"
120 >                    raise CrabException(msg)
121 >        except KeyError: self.publish_data = 0
122 >
123 >        if ( int(self.copy_data) == 0 and int(self.publish_data) == 1 ):
124 >           msg = 'Warning: publish_data = 1 must be used with copy_data = 1\n'
125 >           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
126 >           common.logger.message(msg)
127 >           raise CrabException(msg)
128 >        #################################################
129 >
130 >        #try:
131 >        #    self.lfc_host = cfg_params['EDG.lfc_host']
132 >        #except KeyError:
133 >        #    msg = "Error. The [EDG] section does not have 'lfc_host' value"
134 >        #    msg = msg + " it's necessary to know the LFC host name"
135 >        #    common.logger.message(msg)
136 >        #    raise CrabException(msg)
137 >        #try:
138 >        #    self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
139 >        #except KeyError:
140 >        #    msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
141 >        #    msg = msg + " it's necessary to know the catalog type"
142 >        #    common.logger.message(msg)
143 >        #    raise CrabException(msg)
144 >        #try:
145 >        #    self.lfc_home = cfg_params['EDG.lfc_home']
146 >        #except KeyError:
147 >        #    msg = "Error. The [EDG] section does not have 'lfc_home' value"
148 >        #    msg = msg + " it's necessary to know the home catalog dir"
149 >        #    common.logger.message(msg)
150 >        #    raise CrabException(msg)
151 >      
152 >        #try:
153 >        #    self.register_data = cfg_params["USER.register_data"]
154 >        #    if int(self.register_data) == 1:
155 >        #        try:
156 >        #            self.LFN = cfg_params['USER.lfn_dir']
157 >        #        except KeyError:
158 >        #            msg = "Error. The [USER] section does not have 'lfn_dir' value"
159 >        #            msg = msg + " it's necessary for LCF registration"
160 >        #            common.logger.message(msg)
161 >        #            raise CrabException(msg)
162 >        #except KeyError: self.register_data = 0
163 >
164 >        #if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
165 >        #   msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
166 >        #   msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
167 >        #   common.logger.message(msg)
168 >        #   raise CrabException(msg)
169  
170          try: self.EDG_requirements = cfg_params['EDG.requirements']
171          except KeyError: self.EDG_requirements = ''
172 <                                                                                                                                                            
172 >
173 >        try: self.EDG_addJdlParam = string.split(cfg_params['EDG.additional_jdl_parameters'],',')
174 >        except KeyError: self.EDG_addJdlParam = []
175 >
176          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
177          except KeyError: self.EDG_retry_count = ''
178 <                                                                                                                                                            
178 >
179 >        try: self.EDG_shallow_retry_count= cfg_params['EDG.shallow_retry_count']
180 >        except KeyError: self.EDG_shallow_retry_count = ''
181 >
182          try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
183          except KeyError: self.EDG_clock_time= ''
184 <                                                                                                                                                            
184 >
185          try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
186          except KeyError: self.EDG_cpu_time = ''
187  
# Line 90 | Line 198 | class SchedulerEdg(Scheduler):
198          libPath=os.path.join(path, "lib", "python")
199          sys.path.append(libPath)
200  
201 <        self.proxyValid=0
201 >        try:
202 >            self._taskId = cfg_params['taskId']
203 >        except:
204 >            self._taskId = ''
205 >
206 >        try: self.jobtypeName = cfg_params['CRAB.jobtype']
207 >        except KeyError: self.jobtypeName = ''
208 >
209 >        try: self.schedulerName = cfg_params['CRAB.scheduler']
210 >        except KeyError: self.scheduler = ''
211 >
212          return
213      
214  
215 +    def rb_configure(self, RB):
216 +        self.edg_config = ''
217 +        self.edg_config_vo = ''
218 +        self.rb_param_file = ''
219 +
220 +        edgConfig = EdgConfig(RB)
221 +        self.edg_config = edgConfig.config()
222 +        self.edg_config_vo = edgConfig.configVO()
223 +
224 +        if (self.edg_config and self.edg_config_vo != ''):
225 +            self.rb_param_file = 'RBconfig = "'+self.edg_config+'";\nRBconfigVO = "'+self.edg_config_vo+'";\n'
226 +            #print "rb_param_file = ", self.rb_param_file
227 +        return self.rb_param_file
228 +      
229 +
230      def sched_parameter(self):
231          """
232 <        Returns file with scheduler-specific parameters
232 >        Returns file with requirements and scheduler-specific parameters
233          """
234 <      
235 <        if (self.edg_config and self.edg_config_vo != ''):
236 <            self.param='sched_param.clad'
234 >        index = int(common.jobDB.nJobs()) - 1
235 >        job = common.job_list[index]
236 >        jbt = job.type()
237 >        
238 >        lastBlock=-1
239 >        first = []
240 >        for n in range(common.jobDB.nJobs()):
241 >            currBlock=common.jobDB.block(n)
242 >            if (currBlock!=lastBlock):
243 >                lastBlock = currBlock
244 >                first.append(n)
245 >  
246 >        req = ''
247 >        req = req + jbt.getRequirements()
248 >    
249 >        if self.EDG_requirements:
250 >            if (req == ' '):
251 >                req = req + self.EDG_requirements
252 >            else:
253 >                req = req +  ' && ' + self.EDG_requirements
254 >
255 >        if self.EDG_ce_white_list:
256 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
257 >            for i in range(len(ce_white_list)):
258 >                if i == 0:
259 >                    if (req == ' '):
260 >                        req = req + '((RegExp("' + string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
261 >                    else:
262 >                        req = req +  ' && ((RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
263 >                    pass
264 >                else:
265 >                    req = req +  ' || (RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
266 >            req = req + ')'
267 >        
268 >        if self.EDG_ce_black_list:
269 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
270 >            for ce in ce_black_list:
271 >                if (req == ' '):
272 >                    req = req + '(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
273 >                else:
274 >                    req = req +  ' && (!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
275 >                pass
276 >        if self.EDG_clock_time:
277 >            if (req == ' '):
278 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
279 >            else:
280 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
281 >
282 >        if self.EDG_cpu_time:
283 >            if (req == ' '):
284 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
285 >            else:
286 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
287 >                
288 >        for i in range(len(first)): # Add loop DS
289 >            groupReq = req
290 >            self.param='sched_param_'+str(i)+'.clad'
291              param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
292 <            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
293 <            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
292 >
293 >            itr4=self.findSites_(first[i])
294 >            for arg in itr4:
295 >                groupReq = groupReq + ' && anyMatch(other.storage.CloseSEs, ('+str(arg)+'))'
296 >            param_file.write('Requirements = '+groupReq +';\n')  
297 >  
298 >            if (self.rb_param_file != ''):
299 >                param_file.write(self.rb_param_file)  
300 >
301 >            if len(self.EDG_addJdlParam):
302 >                for p in self.EDG_addJdlParam:
303 >                    param_file.write(p)
304 >
305              param_file.close()  
306 <            return 1
109 <        else:
110 <            return 0
306 >
307  
308      def wsSetupEnvironment(self):
309          """
310          Returns part of a job script which does scheduler-specific work.
311          """
116
312          txt = ''
313 <        if self.copy_data:
314 <           if self.SE:
315 <              txt += 'export SE='+self.SE+'\n'
316 <              txt += 'echo "SE = $SE"\n'
317 <           if self.SE_PATH:
318 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
319 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
320 <              txt += 'echo "SE_PATH = $SE_PATH"\n'
321 <                                                                                                                                                            
322 <        if self.register_data:
323 <           if self.VO:
324 <              txt += 'export VO='+self.VO+'\n'
325 <           if self.LFN:
326 <              txt += 'export LFN='+self.LFN+'\n'
327 <              txt += '\n'
328 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
329 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
330 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
331 <        txt += 'echo "CE = $CE"\n'
313 >        txt += '# strip arguments\n'
314 >        txt += 'echo "strip arguments"\n'
315 >        txt += 'args=("$@")\n'
316 >        txt += 'nargs=$#\n'
317 >        txt += 'shift $nargs\n'
318 >        txt += "# job number (first parameter for job wrapper)\n"
319 >        #txt += "NJob=$1\n"
320 >        txt += "NJob=${args[0]}\n"
321 >
322 >        txt += '# job identification to DashBoard \n'
323 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
324 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
325 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
326 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
327 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
328 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
329 >
330 >        txt += 'echo "middleware discovery: " \n'
331 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
332 >        txt += '    middleware=OSG \n'
333 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
334 >        txt += '        SyncCE="$OSG_JOB_CONTACT"; \n'
335 >        txt += '        echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
336 >        txt += '    else\n'
337 >        txt += '        echo "not reporting SyncCE";\n'
338 >        txt += '    fi\n';
339 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
340 >        txt += '    echo ">>> middleware =$middleware" \n'
341 >        txt += 'elif [ $OSG_APP ]; then \n'
342 >        txt += '    middleware=OSG \n'
343 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
344 >        txt += '        SyncCE="$OSG_JOB_CONTACT"; \n'
345 >        txt += '        echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
346 >        txt += '    else\n'
347 >        txt += '        echo "not reporting SyncCE";\n'
348 >        txt += '    fi\n';
349 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
350 >        txt += '    echo ">>> middleware =$middleware" \n'
351 >        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
352 >        txt += '    middleware=LCG \n'
353 >   #     txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
354 >        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
355 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
356 >        txt += '    echo ">>> middleware =$middleware" \n'
357 >        txt += 'else \n'
358 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
359 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
360 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
361 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
362 >        txt += '    exit 1 \n'
363 >        txt += 'fi \n'
364 >
365 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
366 >        
367 >        txt += '\n\n'
368 >
369 >        txt += 'export VO='+self.VO+'\n'
370 >        txt += 'if [ $middleware == LCG ]; then\n'
371 >        txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
372 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
373 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
374 >        txt += '    echo "CE = $CE"\n'
375 >        txt += 'elif [ $middleware == OSG ]; then \n'
376 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
377 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
378 >        txt += '    else \n'
379 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
380 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
381 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
382 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
383 >        txt += '        exit 1 \n'
384 >        txt += '    fi \n'
385 >        txt += 'fi \n'
386 >
387          return txt
388  
389 <    def wsCopyOutput(self):
389 >    def wsCopyInput(self):
390          """
391 <        Write a CopyResults part of a job script, e.g.
142 <        to copy produced output into a storage element.
391 >        Copy input data from SE to WN    
392          """
393          txt = ''
394 <        if self.copy_data:
395 <           copy = 'globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file'
396 <           txt += '#\n'
397 <           txt += '#   Copy output to SE = $SE\n'
398 <           txt += '#\n'
399 <           #### per orca l'exit_status non e' affidabile.....
400 <           #txt += 'if [ $executable_exit_status -eq 0 ]; then\n'
401 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
402 <           txt += '  for out_file in $file_list ; do\n'
403 <           txt += '    echo "Trying to copy output file to $SE "\n'
404 <           txt += '    echo "'+copy+'"\n'
405 <           txt += '    '+copy+' 2>&1\n'
406 <           txt += '    copy_exit_status=$?\n'
407 <           txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
408 <           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
409 <           txt += '    if [ $copy_exit_status -ne 0 ]; then \n'
410 <           txt += '       echo "Problems with SE= $SE" \n'
411 <           txt += '    else \n'
412 <           txt += '       echo "output copied into $SE/$SE_PATH directory"\n'
413 <           txt += '    fi \n'
414 <           txt += '  done\n'
415 <           txt += 'fi \n'
394 >        if not self.copy_input_data: return txt
395 >
396 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
397 >        txt += 'if [ $middleware == OSG ]; then\n'
398 >        txt += '   #\n'
399 >        txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
400 >        txt += '   #\n'
401 >        txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
402 >        txt += 'elif [ $middleware == LCG ]; then \n'
403 >        txt += '   #\n'
404 >        txt += '   #   Copy Input Data from SE to this WN\n'
405 >        txt += '   #\n'
406 >        ### changed by georgia (put a loop copying more than one input files per jobs)          
407 >        txt += '   for input_file in $cur_file_list \n'
408 >        txt += '   do \n'
409 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
410 >        txt += '      copy_input_exit_status=$?\n'
411 >        txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
412 >        txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
413 >        txt += '         echo "Problems with copying to WN" \n'
414 >        txt += '      else \n'
415 >        txt += '         echo "input copied into WN" \n'
416 >        txt += '      fi \n'
417 >        txt += '   done \n'
418 >        ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
419 >        txt += '   for file in $cur_pu_list \n'
420 >        txt += '   do \n'
421 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
422 >        txt += '      copy_input_pu_exit_status=$?\n'
423 >        txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
424 >        txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
425 >        txt += '         echo "Problems with copying pu to WN" \n'
426 >        txt += '      else \n'
427 >        txt += '         echo "input pu files copied into WN" \n'
428 >        txt += '      fi \n'
429 >        txt += '   done \n'
430 >        txt += '   \n'
431 >        txt += '   ### Check SCRATCH space available on WN : \n'
432 >        txt += '   df -h \n'
433 >        txt += 'fi \n'
434 >          
435          return txt
436  
437 <    def wsRegisterOutput(self):
437 >    def wsCopyOutput(self):
438          """
439 <        Returns part of a job script which does scheduler-specific work.
439 >        Write a CopyResults part of a job script, e.g.
440 >        to copy produced output into a storage element.
441          """
442 +        txt = '\n'
443  
444 <        txt = ''
445 <        if self.register_data:
446 <           txt += '#\n'
447 <           txt += '#  Register output to RLS\n'
448 <           txt += '#\n'
449 <           ### analogo
450 <           #txt += 'if [[ $executable_exit_status -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
451 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
452 <           txt += '   for out_file in $file_list ; do\n'
453 <           txt += '      echo "Trying to register the output file into RLS"\n'
454 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
455 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
456 <           txt += '      register_exit_status=$?\n'
457 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
458 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
459 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
460 <           txt += '         echo "Problems with the registration to RLS" \n'
461 <           txt += '         echo "Try with srm protocol" \n'
462 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
463 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
464 <           txt += '         register_exit_status=$?\n'
465 <           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
466 <           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
467 <           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
468 <           txt += '            echo "Problems with the registration into RLS" \n'
469 <           txt += '         fi \n'
470 <           txt += '      else \n'
471 <           txt += '         echo "output registered to RLS"\n'
472 <           txt += '      fi \n'
473 <           txt += '   done\n'
474 <           txt += 'elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
475 <           txt += '   echo "Trying to copy output file to CloseSE"\n'
476 <           txt += '   CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
477 <           txt += '   for out_file in $file_list ; do\n'
478 <           txt += '      echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
479 <           txt += '      lcg-cr -v -l lfn:${LFN}/$out_file -d $SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
480 <           txt += '      register_exit_status=$?\n'
481 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
482 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
483 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
484 <           txt += '         echo "Problems with CloseSE" \n'
485 <           txt += '      else \n'
486 <           txt += '         echo "The program was successfully executed"\n'
487 <           txt += '         echo "SE = $CLOSE_SE"\n'
488 <           txt += '         echo "LFN for the file is LFN=${LFN}/$out_file"\n'
489 <           txt += '      fi \n'
490 <           txt += '   done\n'
491 <           txt += 'else\n'
492 <           txt += '   echo "Problem with the executable"\n'
493 <           txt += 'fi \n'
444 >        txt += '#\n'
445 >        txt += '# COPY OUTPUT FILE TO SE\n'
446 >        txt += '#\n\n'
447 >
448 >        SE_PATH=''
449 >        if int(self.copy_data) == 1:
450 >            if self.SE:
451 >                txt += 'export SE='+self.SE+'\n'
452 >                txt += 'echo "SE = $SE"\n'
453 >            if self.SE_PATH:
454 >                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
455 >                SE_PATH=self.SE_PATH
456 >            if int(self.publish_data) == 1:
457 >                txt += '### publish_data = 1 so the SE path where to copy the output is: \n'
458 >                path_add = self.UserGridName + '/' + self.publish_data_name +'_${PSETHASH}/'
459 >                SE_PATH = SE_PATH + path_add
460 >            txt += 'export SE_PATH='+SE_PATH+'\n'
461 >            txt += 'echo "SE_PATH = $SE_PATH"\n'
462 >            
463 >            txt += 'echo ">>> Copy output files from WN = `hostname` to SE = $SE :"\n'
464 >            
465 >            txt += 'if [ $output_exit_status -eq 60302 ]; then\n'
466 >            txt += '    echo "--> No output file to copy to $SE"\n'
467 >            txt += '    copy_exit_status=$output_exit_status\n'
468 >            txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
469 >            txt += 'else\n'
470 >            txt += '    for out_file in $file_list ; do\n'
471 >            txt += '        echo "Trying to copy output file to $SE"\n'
472 >            txt += '        cmscp $out_file ${SE} ${SE_PATH} $out_file $middleware\n'
473 >            txt += '        copy_exit_status=$?\n'
474 >            txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
475 >            txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
476 >            txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
477 >            txt += '            echo "Problem copying $out_file to $SE $SE_PATH"\n'
478 >            txt += '            echo "StageOutExitStatus = $copy_exit_status " | tee -a $RUNTIME_AREA/$repo\n'
479 >            txt += '            copy_exit_status=60307\n'
480 >            txt += '        else\n'
481 >            txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
482 >            txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
483 >            txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
484 >            txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
485 >            txt += '        fi\n'
486 >            txt += '    done\n'
487 >            txt += '    if [ $copy_exit_status -ne 0 ]; then\n'
488 >            txt += '        SE=""\n'
489 >            txt += '        echo "SE = $SE"\n'
490 >            txt += '        SE_PATH=""\n'
491 >            txt += '        echo "SE_PATH = $SE_PATH"\n'
492 >            txt += '    fi\n'
493 >            txt += 'fi\n'
494 >            txt += 'exit_status=$copy_exit_status\n'
495 >            pass
496          return txt
225        #####################
497  
498      def loggingInfo(self, id):
499          """
500          retrieve the logging info from logging and bookkeeping and return it
501          """
502          self.checkProxy()
503 <      #  id = common.jobDB.jobId(nj)
233 <        cmd = 'edg-job-get-logging-info -v 2 ' + self.configOpt_() + id
503 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
504          cmd_out = runCommand(cmd)
505          return cmd_out
506  
237    def listMatch(self, nj):
238        """
239        Check the compatibility of available resources
240        """
241        self.checkProxy()
242        jdl = common.job_list[nj].jdlFilename()
243        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
244        cmd_out = runCommand(cmd)
245        return self.parseListMatch_(cmd_out, jdl)
246
247    def parseListMatch_(self, out, jdl):
248        reComment = re.compile( r'^\**$' )
249        reEmptyLine = re.compile( r'^$' )
250        reVO = re.compile( r'Selected Virtual Organisation name.*' )
251        reCE = re.compile( r'CEId.*\n((.*:.*)\n)*' )
252        reNO = re.compile( r'No Computing Element matching' )
253        reRB = re.compile( r'Connecting to host' )
254        next = 0
255        CEs=[]
256        Match=0
257
258        if reNO.match( out ):
259            common.logger.debug(5,out)
260            self.noMatchFound_(jdl)
261            Match=0
262            pass
263        if reVO.match( out ):
264            VO =reVO.match( out ).group()
265            common.logger.debug(5, 'VO           :'+VO)
266            pass
267
268        if reRB.match( out ):
269            RB =reRB.match(out).group()
270            common.logger.debug(5, 'Using RB     :'+RB)
271            pass
272
273        if reCE.search( out ):
274            groups=reCE.search(out).groups()
275            for CE in groups:
276                tmp = string.strip(CE)
277                CEs.append(tmp)
278                common.logger.debug(5, 'Matched CE   :'+tmp)
279                Match=Match+1
280            pass
281
282        return Match
283
284    def noMatchFound_(self, jdl):
285        reReq = re.compile( r'Requirements' )
286        reString = re.compile( r'"\S*"' )
287        f = file(jdl,'r')
288        for line in f.readlines():
289            line= line.strip()
290            if reReq.match(line):
291                for req in reString.findall(line):
292                    if re.search("VO",req):
293                        common.logger.message( "SW required: "+req)
294                        continue
295                    if re.search('"\d+',req):
296                        common.logger.message("Other req  : "+req)
297                        continue
298                    common.logger.message( "CE required: "+req)
299                break
300            pass
301        raise CrabException("No compatible resources found!")
302
303    def submit(self, nj):
304        """
305        Submit one EDG job.
306        """
307
308        self.checkProxy()
309        jid = None
310        jdl = common.job_list[nj].jdlFilename()
311
312        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
313        cmd_out = runCommand(cmd)
314        if cmd_out != None:
315            reSid = re.compile( r'https.+' )
316            jid = reSid.search(cmd_out).group()
317            pass
318        return jid
319
320    def getExitStatus(self, id):
321        return self.getStatusAttribute_(id, 'exit_code')
322
323    def queryStatus(self, id):
324        return self.getStatusAttribute_(id, 'status')
325
326    def queryDest(self, id):  
327        return self.getStatusAttribute_(id, 'destination')
328
329
330    def getStatusAttribute_(self, id, attr):
331        """ Query a status of the job with id """
332
333        self.checkProxy()
334        hstates = {}
335        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
336        # Bypass edg-job-status interfacing directly to C++ API
337        # Job attribute vector to retrieve status without edg-job-status
338        level = 0
339        # Instance of the Status class provided by LB API
340        jobStat = Status()
341        st = 0
342        jobStat.getStatus(id, level)
343        err, apiMsg = jobStat.get_error()
344        if err:
345            print 'Error caught', apiMsg
346            common.log.message(apiMsg)
347            return None
348        else:
349            for i in range(len(self.states)):
350                # Fill an hash table with all information retrieved from LB API
351                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
352            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
353            return result
354
507      def queryDetailedStatus(self, id):
508          """ Query a detailed status of the job with id """
509          cmd = 'edg-job-status '+id
510          cmd_out = runCommand(cmd)
511          return cmd_out
512  
513 <    def getOutput(self, id):
514 <        """
363 <        Get output for a finished job with id.
364 <        Returns the name of directory with results.
365 <        """
513 >    def findSites_(self, n):
514 >        itr4 =[]
515  
516 <        self.checkProxy()
368 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
369 <        cmd_out = runCommand(cmd)
516 >        sites = common.jobDB.destination(n)
517  
518 <        # Determine the output directory name
519 <        dir = common.work_space.resDir()
373 <        dir += os.getlogin()
374 <        dir += '_' + os.path.basename(id)
375 <        return dir
518 >        if len(sites)>0 and sites[0]=="":
519 >            return itr4
520  
521 <    def cancel(self, id):
522 <        """ Cancel the EDG job with id """
523 <        self.checkProxy()
524 <        cmd = 'edg-job-cancel --noint ' + id
525 <        cmd_out = runCommand(cmd)
526 <        return cmd_out
521 >        itr = ''
522 >        if sites != [""]:#CarlosDaniele
523 >            ##Addedd Daniele
524 >            replicas = self.blackWhiteListParser.checkBlackList(sites,n)
525 >            if len(replicas)!=0:
526 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
527 >              
528 >            if len(replicas)==0:
529 >                itr = itr + 'target.GlueSEUniqueID=="NONE" '
530 >                #msg = 'No sites remaining that host any part of the requested data! Exiting... '
531 >                #raise CrabException(msg)
532 >            #####        
533 >           # for site in sites:
534 >            for site in replicas:
535 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
536 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
537 >            itr = itr[0:-4]
538 >            itr4.append( itr )
539 >        return itr4
540  
541 <    def createSchScript(self, nj):
541 >    def createXMLSchScript(self, nj, argsList):
542 >      
543          """
544 <        Create a JDL-file for EDG.
544 >        Create a XML-file for BOSS4.
545          """
546 <
547 <        job = common.job_list[nj]
546 >  #      job = common.job_list[nj]
547 >        """
548 >        INDY
549 >        [begin] FIX-ME:
550 >        I would pass jobType instead of job
551 >        """
552 >        index = nj - 1
553 >        job = common.job_list[index]
554          jbt = job.type()
391        inp_sandbox = jbt.inputSandbox(nj)
392        out_sandbox = jbt.outputSandbox(nj)
393        inp_storage_subdir = ''
555          
556 <        title = '# This JDL was generated by '+\
557 <                common.prog_name+' (version '+common.prog_version_str+')\n'
558 <        jt_string = ''
556 >        inp_sandbox = jbt.inputSandbox(index)
557 >        #out_sandbox = jbt.outputSandbox(index)
558 >        """
559 >        [end] FIX-ME
560 >        """
561  
562 +        
563 +        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
564 +        jt_string = ''
565 +        
566 +        xml_fname = str(self.jobtypeName)+'.xml'
567 +        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
568  
569 +        #TaskName  
570 +        dir = string.split(common.work_space.topDir(), '/')
571 +        taskName = dir[len(dir)-2]
572 +  
573 +        to_write = ''
574 +
575 +        req=' '
576 +        req = req + jbt.getRequirements()
577 +
578 +        if self.EDG_requirements:
579 +            if (req == ' '):
580 +                req = req + self.EDG_requirements
581 +            else:
582 +                req = req +  ' && ' + self.EDG_requirements
583 +        if self.EDG_ce_white_list:
584 +            ce_white_list = string.split(self.EDG_ce_white_list,',')
585 +            for i in range(len(ce_white_list)):
586 +                if i == 0:
587 +                    if (req == ' '):
588 +                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
589 +                    else:
590 +                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
591 +                    pass
592 +                else:
593 +                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
594 +            req = req + ')'
595          
596 <        SPL = inp_storage_subdir
597 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
596 >        if self.EDG_ce_black_list:
597 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
598 >            for ce in ce_black_list:
599 >                if (req == ' '):
600 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
601 >                else:
602 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
603 >                pass
604 >        if self.EDG_clock_time:
605 >            if (req == ' '):
606 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
607 >            else:
608 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
609 >
610 >        if self.EDG_cpu_time:
611 >            if (req == ' '):
612 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
613 >            else:
614 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
615 >                                                                                          
616 >        if ( self.EDG_retry_count ):              
617 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
618 >            pass
619  
620 <        jdl_fname = job.jdlFilename()
621 <        jdl = open(jdl_fname, 'w')
622 <        jdl.write(title)
620 >        if ( self.EDG_shallow_retry_count ):              
621 >            to_write = to_write + 'ShallowRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
622 >            pass
623  
624 <        script = job.scriptFilename()
625 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
626 <        jdl.write(jt_string)
624 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
625 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
626 >
627 >        #TaskName  
628 >        dir = string.split(common.work_space.topDir(), '/')
629 >        taskName = dir[len(dir)-2]
630 >
631 >        xml.write(str(title))
632 >        #xml.write('<task name="' +str(taskName)+'" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache">\n')
633 >
634 >        #xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + '" task_info="' + os.path.expandvars('X509_USER_PROXY') + '">\n')
635 >        x509_cmd = 'ls /tmp/x509up_u`id -u`'
636 >        x509=runCommand(x509_cmd).strip()
637 >        xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + ' task_info="' + str(x509) + '">\n')
638 >        xml.write(jt_string)
639 >        
640 >        if (to_write != ''):
641 >            xml.write('<extraTags\n')
642 >            xml.write(to_write)
643 >            xml.write('/>\n')
644 >            pass
645  
646 <        ### only one .sh  JDL has arguments:
647 <        firstEvent = common.jobDB.firstEvent(nj)
648 <        maxEvents = common.jobDB.maxEvents(nj)
649 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
646 >        xml.write('<iterator>\n')
647 >        xml.write('\t<iteratorRule name="ITR1">\n')
648 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
649 >        xml.write('\t</iteratorRule>\n')
650 >        xml.write('\t<iteratorRule name="ITR2">\n')
651 >        for arg in argsList:
652 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
653 >            pass
654 >        xml.write('\t</iteratorRule>\n')
655 >        #print jobList
656 >        xml.write('\t<iteratorRule name="ITR3">\n')
657 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
658 >        xml.write('\t</iteratorRule>\n')
659 >
660 >        '''
661 >        indy: here itr4
662 >        '''
663 >        
664 >        xml.write('<chain name="' +str(taskName)+'__ITR1_" scheduler="'+str(self.schedulerName)+'">\n')
665 >       # xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
666 >        xml.write(jt_string)
667  
668 <        inp_box = 'InputSandbox = { '
669 <        inp_box = inp_box + '"' + script + '",'
668 >        #executable
669 >
670 >        """
671 >        INDY
672 >        script depends on jobType: it should be probably get in a different way
673 >        """        
674 >        script = job.scriptFilename()
675 >        xml.write('<program>\n')
676 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
677 >        xml.write(jt_string)
678 >
679 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
680 >        xml.write('<program_types> crabjob </program_types>\n')
681 >        inp_box = common.work_space.pathForTgz() + 'job/' + jbt.scriptName + ','
682  
683          if inp_sandbox != None:
684              for fl in inp_sandbox:
685 <                inp_box = inp_box + ' "' + fl + '",'
685 >                inp_box = inp_box + '' + fl + ','
686                  pass
687              pass
688  
689 <        #if common.use_jam:
690 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
691 <
692 <        for addFile in jbt.additional_inbox_files:
693 <            addFile = os.path.abspath(addFile)
694 <            inp_box = inp_box+' "'+addFile+'",'
432 <            pass
689 > #        if (not jbt.additional_inbox_files == []):
690 > #            inp_box = inp_box + ','
691 > #            for addFile in jbt.additional_inbox_files:
692 > #                #addFile = os.path.abspath(addFile)
693 > #                inp_box = inp_box+''+addFile+','
694 > #                pass
695  
696          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
697 <        inp_box = inp_box + ' };\n'
698 <        jdl.write(inp_box)
437 <
438 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
439 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
697 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
698 >        xml.write(inp_box)
699          
700 +        base = jbt.name()
701 +        stdout = base + '__ITR3_.stdout'
702 +        stderr = base + '__ITR3_.stderr'
703          
704 <        if job.stdout() == job.stderr():
705 <          out_box = 'OutputSandbox = { "' + \
706 <                    job.stdout() + '", ".BrokerInfo",'
707 <        else:
708 <          out_box = 'OutputSandbox = { "' + \
709 <                    job.stdout() + '", "' + \
448 <                    job.stderr() + '", ".BrokerInfo",'
704 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
705 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
706 >        
707 >
708 >        out_box = stdout + ',' + \
709 >                  stderr + ',.BrokerInfo,'
710  
711 <        if self.return_data :
711 >        """
712 >        if int(self.return_data) == 1:
713              if out_sandbox != None:
714                  for fl in out_sandbox:
715 <                    out_box = out_box + ' "' + fl + '",'
715 >                    out_box = out_box + '' + fl + ','
716                      pass
717                  pass
718              pass
719 <                                                                                                                                                            
719 >        """
720 >
721 >        """
722 >        INDY
723 >        something similar should be also done for infiles (if it makes sense!)
724 >        """
725 >        # Stuff to be returned _always_ via sandbox
726 >        for fl in jbt.output_file_sandbox:
727 >            out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
728 >            pass
729 >        pass
730 >
731 >        # via sandbox iif required return_data
732 >        if int(self.return_data) == 1:
733 >            for fl in jbt.output_file:
734 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
735 >                pass
736 >            pass
737 >
738          if out_box[-1] == ',' : out_box = out_box[:-1]
739 <        out_box = out_box + ' };'
740 <        jdl.write(out_box+'\n')
739 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
740 >        xml.write(out_box)
741 >
742 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
743  
744 <        ### if at least a CE exists ...
745 <        if common.analisys_common_info['sites']:
464 <            if common.analisys_common_info['sw_version']:
465 <                req='Requirements = '
466 <                req=req + 'Member("VO-cms-' + \
467 <                     common.analisys_common_info['sw_version'] + \
468 <                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
469 <            if len(common.analisys_common_info['sites'])>0:
470 <                req = req + ' && ('
471 <                for i in range(len(common.analisys_common_info['sites'])):
472 <                    req = req + 'other.GlueCEInfoHostName == "' \
473 <                         + common.analisys_common_info['sites'][i] + '"'
474 <                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
475 <                        req = req + ' || '
476 <            req = req + ')'
744 >        xml.write('</program>\n')
745 >        xml.write('</chain>\n')
746  
747 <            #### and USER REQUIREMENT
748 <            if self.EDG_requirements:
480 <                req = req +  ' && ' + self.EDG_requirements
481 <            if self.EDG_clock_time:
482 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
483 <            if self.EDG_cpu_time:
484 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
485 <            req = req + ';\n'
486 <            jdl.write(req)
487 <                                                                                                                                                            
488 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
747 >        xml.write('</iterator>\n')
748 >        xml.write('</task>\n')
749  
750 <        if ( self.EDG_retry_count ):              
751 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
492 <            pass
750 >        xml.close()
751 >      
752  
494        jdl.close()
753          return
754  
755      def checkProxy(self):
# Line 499 | Line 757 | class SchedulerEdg(Scheduler):
757          Function to check the Globus proxy.
758          """
759          if (self.proxyValid): return
760 <        timeleft = -999
761 <        minTimeLeft=10 # in hours
762 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
763 <        try: cmd_out = runCommand(cmd,0)
764 <        except: print cmd_out
765 <        if (cmd_out == None or cmd_out=='1'):
766 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
767 <            cmd = 'grid-proxy-init -valid 100:00'
760 >
761 >        ### Just return if asked to do so
762 >        if (self.dontCheckProxy==1):
763 >            self.proxyValid=1
764 >            return
765 >
766 >        minTimeLeft=10*3600 # in seconds
767 >
768 >        minTimeLeftServer = 100 # in hours
769 >
770 >        mustRenew = 0
771 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
772 >        timeLeftServer = -999
773 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
774 >            mustRenew = 1
775 >        else:
776 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
777 >            if not timeLeftServer or not isInt(timeLeftServer):
778 >                mustRenew = 1
779 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
780 >                mustRenew = 1
781 >            pass
782 >        pass
783 >
784 >        if mustRenew:
785 >            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")
786 >            cmd = 'voms-proxy-init -voms '+self.VO
787 >            if self.group:
788 >                cmd += ':/'+self.VO+'/'+self.group
789 >            if self.role:
790 >                cmd += '/role='+self.role
791 >            cmd += ' -valid 192:00'
792              try:
793 +                # SL as above: damn it!
794 +                common.logger.debug(10,cmd)
795                  out = os.system(cmd)
796                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
797              except:
798                  msg = "Unable to create a valid proxy!\n"
799                  raise CrabException(msg)
516            cmd = 'grid-proxy-info -timeleft'
517            cmd_out = runCommand(cmd,0)
518            #print cmd_out, time.time()
519            #time.time(cms_out)
800              pass
801 +
802 +        ## now I do have a voms proxy valid, and I check the myproxy server
803 +        renewProxy = 0
804 +        cmd = 'myproxy-info -d -s '+self.proxyServer
805 +        cmd_out = runCommand(cmd,0,20)
806 +        if not cmd_out:
807 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
808 +            renewProxy = 1
809 +        else:
810 +            ## minimum time: 5 days
811 +            minTime = 4 * 24 * 3600
812 +            ## regex to extract the right information
813 +            myproxyRE = re.compile("timeleft: (?P<hours>[\\d]*):(?P<minutes>[\\d]*):(?P<seconds>[\\d]*)")
814 +            for row in cmd_out.split("\n"):
815 +                g = myproxyRE.search(row)
816 +                if g:
817 +                    hours = g.group("hours")
818 +                    minutes = g.group("minutes")
819 +                    seconds = g.group("seconds")
820 +                    timeleft = int(hours)*3600 + int(minutes)*60 + int(seconds)
821 +                    if timeleft < minTime:
822 +                        renewProxy = 1
823 +                        common.logger.message('Your proxy will expire in:\n\t'+hours+' hours '+minutes+' minutes '+seconds+' seconds\n')
824 +                        common.logger.message('Need to renew it:')
825 +                    pass
826 +                pass
827 +            pass
828 +        
829 +        # if not, create one.
830 +        if renewProxy:
831 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
832 +            out = os.system(cmd)
833 +            if (out>0):
834 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
835 +            pass
836 +
837 +        # cache proxy validity
838          self.proxyValid=1
839          return
840 <    
840 >
841      def configOpt_(self):
842          edg_ui_cfg_opt = ' '
843          if self.edg_config:
844 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
844 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
845          if self.edg_config_vo:
846 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
846 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
847          return edg_ui_cfg_opt
848 +
849 +    def submitTout(self, list):
850 +        return 120
851 +
852 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines