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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines