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.29 by fanzago, Fri Nov 18 15:50:23 2005 UTC vs.
Revision 1.97 by slacapra, Tue Oct 10 15:45:41 2006 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   import common
7  
8   import os, sys, time
# Line 21 | Line 22 | class SchedulerEdg(Scheduler):
22  
23      def configure(self, cfg_params):
24  
25 <        try: self.edg_config = cfg_params["EDG.config"]
26 <        except KeyError: self.edg_config = ''
25 >        try:
26 >            RB = cfg_params["EDG.rb"]
27 >            edgConfig = EdgConfig(RB)
28 >            self.edg_config = edgConfig.config()
29 >            self.edg_config_vo = edgConfig.configVO()
30 >        except KeyError:
31 >            self.edg_config = ''
32 >            self.edg_config_vo = ''
33  
34 <        try: self.edg_config_vo = cfg_params["EDG.config_vo"]
35 <        except KeyError: self.edg_config_vo = ''
34 >        try:
35 >            self.proxyServer = cfg_params["EDG.proxy_server"]
36 >        except KeyError:
37 >            self.proxyServer = 'myproxy.cern.ch'
38 >        common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
39  
40 +        try:
41 +            self.group = cfg_params["EDG.group"]
42 +        except KeyError:
43 +            self.group = None
44 +            
45 +        try:
46 +            self.role = cfg_params["EDG.role"]
47 +        except KeyError:
48 +            self.role = None
49 +            
50          try: self.LCG_version = cfg_params["EDG.lcg_version"]
51          except KeyError: self.LCG_version = '2'
52  
# Line 36 | Line 56 | class SchedulerEdg(Scheduler):
56          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
57          except KeyError: self.EDG_retry_count = ''
58  
59 +        try:
60 +            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
61 +            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
62 +        except KeyError:
63 +            self.EDG_ce_black_list  = ''
64 +
65 +        try:
66 +            self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
67 +            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
68 +        except KeyError: self.EDG_ce_white_list = ''
69 +
70          try: self.VO = cfg_params['EDG.virtual_organization']
71          except KeyError: self.VO = 'cms'
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 = 'Warning: 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 +        try:
95 +            self.lfc_host = cfg_params['EDG.lfc_host']
96 +        except KeyError:
97 +            msg = "Error. The [EDG] section does not have 'lfc_host' value"
98 +            msg = msg + " it's necessary to know the LFC host name"
99 +            common.logger.message(msg)
100 +            raise CrabException(msg)
101 +        try:
102 +            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
103 +        except KeyError:
104 +            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
105 +            msg = msg + " it's necessary to know the catalog type"
106 +            common.logger.message(msg)
107 +            raise CrabException(msg)
108 +        try:
109 +            self.lfc_home = cfg_params['EDG.lfc_home']
110 +        except KeyError:
111 +            msg = "Error. The [EDG] section does not have 'lfc_home' value"
112 +            msg = msg + " it's necessary to know the home catalog dir"
113 +            common.logger.message(msg)
114 +            raise CrabException(msg)
115 +      
116          try:
117              self.register_data = cfg_params["USER.register_data"]
118 <            try:
119 <                 self.LFN = cfg_params['USER.lfn_dir']
120 <            except KeyError:
121 <                msg = "Error. The [USER] section does not have 'lfn_dir' value"
122 <                msg = msg + " it's necessary for RLS registration"
123 <                common.logger.message(msg)
124 <                raise CrabException(msg)
125 <        except KeyError: self.register_data= ''
118 >            if int(self.register_data) == 1:
119 >                try:
120 >                    self.LFN = cfg_params['USER.lfn_dir']
121 >                except KeyError:
122 >                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
123 >                    msg = msg + " it's necessary for LCF registration"
124 >                    common.logger.message(msg)
125 >                    raise CrabException(msg)
126 >        except KeyError: self.register_data = 0
127 >
128 >        if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
129 >           msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
130 >           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
131 >           common.logger.message(msg)
132 >           raise CrabException(msg)
133  
134          try: self.EDG_requirements = cfg_params['EDG.requirements']
135          except KeyError: self.EDG_requirements = ''
136 <                                                                                                                                                            
136 >
137          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
138          except KeyError: self.EDG_retry_count = ''
139 <                                                                                                                                                            
139 >
140 >        try: self.EDG_shallow_retry_count= cfg_params['EDG.shallow_retry_count']
141 >        except KeyError: self.EDG_shallow_retry_count = ''
142 >
143          try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
144          except KeyError: self.EDG_clock_time= ''
145 <                                                                                                                                                            
145 >
146          try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
147          except KeyError: self.EDG_cpu_time = ''
148  
# Line 91 | Line 160 | class SchedulerEdg(Scheduler):
160          sys.path.append(libPath)
161  
162          self.proxyValid=0
163 +
164 +        try:
165 +            self._taskId = cfg_params['taskId']
166 +        except:
167 +            self._taskId = ''
168 +
169 +        try: self.jobtypeName = cfg_params['CRAB.jobtype']
170 +        except KeyError: self.jobtypeName = ''
171 +
172 +        try: self.schedulerName = cfg_params['CRAB.scheduler']
173 +        except KeyError: self.scheduler = ''
174 +
175          return
176      
177  
178      def sched_parameter(self):
179          """
180 <        Returns file with scheduler-specific parameters
180 >        Returns file with requirements and scheduler-specific parameters
181          """
182 <      
183 <        if (self.edg_config and self.edg_config_vo != ''):
184 <            self.param='sched_param.clad'
182 >        index = int(common.jobDB.nJobs()) - 1
183 >        job = common.job_list[index]
184 >        jbt = job.type()
185 >        
186 >        lastBlock=-1
187 >        first = []
188 >        for n in range(common.jobDB.nJobs()):
189 >            currBlock=common.jobDB.block(n)
190 >            if (currBlock!=lastBlock):
191 >                lastBlock = currBlock
192 >                first.append(n)
193 >  
194 >        req = ''
195 >        req = req + jbt.getRequirements()
196 >    
197 >        if self.EDG_requirements:
198 >            if (req == ' '):
199 >                req = req + self.EDG_requirements
200 >            else:
201 >                req = req +  ' && ' + self.EDG_requirements
202 >
203 >        if self.EDG_ce_white_list:
204 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
205 >            for i in range(len(ce_white_list)):
206 >                if i == 0:
207 >                    if (req == ' '):
208 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
209 >                    else:
210 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
211 >                    pass
212 >                else:
213 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
214 >            req = req + ')'
215 >        
216 >        if self.EDG_ce_black_list:
217 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
218 >            for ce in ce_black_list:
219 >                if (req == ' '):
220 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
221 >                else:
222 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
223 >                pass
224 >        if self.EDG_clock_time:
225 >            if (req == ' '):
226 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
227 >            else:
228 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
229 >
230 >        if self.EDG_cpu_time:
231 >            if (req == ' '):
232 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
233 >            else:
234 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
235 >                
236 >        for i in range(len(first)): # Add loop DS
237 >            self.param='sched_param_'+str(i)+'.clad'
238              param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
239 <            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
240 <            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
239 >
240 >            itr4=self.findSites_(first[i])
241 >            for arg in itr4:
242 >                req = req + ' && anyMatch(other.storage.CloseSEs, ('+str(arg)+'))'
243 >            param_file.write('Requirements = '+req +';\n')  
244 >  
245 >            if (self.edg_config and self.edg_config_vo != ''):
246 >                param_file.write('RBconfig = "'+self.edg_config+'";\n')  
247 >                param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
248 >
249              param_file.close()  
250 <            return 1
109 <        else:
110 <            return 0
250 >
251  
252      def wsSetupEnvironment(self):
253          """
254          Returns part of a job script which does scheduler-specific work.
255          """
116
256          txt = ''
257 <        if self.copy_data:
257 >        txt += '# strip arguments\n'
258 >        txt += 'echo "strip arguments"\n'
259 >        txt += 'args=("$@")\n'
260 >        txt += 'nargs=$#\n'
261 >        txt += 'shift $nargs\n'
262 >        txt += "# job number (first parameter for job wrapper)\n"
263 >        #txt += "NJob=$1\n"
264 >        txt += "NJob=${args[0]}\n"
265 >
266 >        txt += '# job identification to DashBoard \n'
267 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
268 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
269 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
270 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
271 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
272 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
273 >
274 >        txt += 'echo "middleware discovery " \n'
275 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
276 >        txt += '    middleware=OSG \n'
277 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
278 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
279 >        txt += '    echo "middleware =$middleware" \n'
280 >        txt += 'elif [ $OSG_APP ]; then \n'
281 >        txt += '    middleware=OSG \n'
282 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
283 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
284 >        txt += '    echo "middleware =$middleware" \n'
285 >        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
286 >        txt += '    middleware=LCG \n'
287 >        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
288 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
289 >        txt += '    echo "middleware =$middleware" \n'
290 >        txt += 'else \n'
291 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
292 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
293 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
294 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
295 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
296 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
297 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
298 >        txt += '    exit 1 \n'
299 >        txt += 'fi \n'
300 >
301 >        txt += '# report first time to DashBoard \n'
302 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
303 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
304 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
305 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
306 >        
307 >        txt += '\n\n'
308 >
309 >        if int(self.copy_data) == 1:
310             if self.SE:
311                txt += 'export SE='+self.SE+'\n'
312                txt += 'echo "SE = $SE"\n'
# Line 123 | Line 314 | class SchedulerEdg(Scheduler):
314                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
315                txt += 'export SE_PATH='+self.SE_PATH+'\n'
316                txt += 'echo "SE_PATH = $SE_PATH"\n'
317 <                                                                                                                                                            
318 <        if self.register_data:
317 >
318 >        txt += 'export VO='+self.VO+'\n'
319 >        ### add some line for LFC catalog setting
320 >        txt += 'if [ $middleware == LCG ]; then \n'
321 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
322 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
323 >        txt += '    fi\n'
324 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
325 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
326 >        txt += '    fi\n'
327 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
328 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
329 >        txt += '    fi\n'
330 >        txt += 'elif [ $middleware == OSG ]; then\n'
331 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
332 >        txt += 'fi\n'
333 >        #####
334 >        if int(self.register_data) == 1:
335 >           txt += 'if [ $middleware == LCG ]; then \n'
336 >           txt += '    export LFN='+self.LFN+'\n'
337 >           txt += '    lfc-ls $LFN\n'
338 >           txt += '    result=$?\n'
339 >           txt += '    echo $result\n'
340 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
341 >           txt += '    if [ $result != 0 ]; then\n'
342 >           txt += '       lfc-mkdir $LFN\n'
343 >           txt += '       result=$?\n'
344 >           txt += '       echo $result\n'
345 >           txt += '    fi\n'
346 >           txt += 'elif [ $middleware == OSG ]; then\n'
347 >           txt += '    echo " Files registration to be implemented for OSG"\n'
348 >           txt += 'fi\n'
349 >           txt += '\n'
350 >
351             if self.VO:
352                txt += 'export VO='+self.VO+'\n'
353             if self.LFN:
354 <              txt += 'export LFN='+self.LFN+'\n'
354 >              txt += 'if [ $middleware == LCG ]; then \n'
355 >              txt += '    export LFN='+self.LFN+'\n'
356 >              txt += 'fi\n'
357                txt += '\n'
358 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
359 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
360 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
361 <        txt += 'echo "CE = $CE"\n'
358 >
359 >        txt += 'if [ $middleware == LCG ]; then\n'
360 >        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
361 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
362 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
363 >        txt += '    echo "CE = $CE"\n'
364 >        txt += 'elif [ $middleware == OSG ]; then \n'
365 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
366 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
367 >        txt += '    else \n'
368 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
369 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
370 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
371 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
372 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
373 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
374 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
375 >        txt += '        exit 1 \n'
376 >        txt += '    fi \n'
377 >        txt += 'fi \n'
378 >
379 >        return txt
380 >
381 >    def wsCopyInput(self):
382 >        """
383 >        Copy input data from SE to WN    
384 >        """
385 >        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 wsCopyOutput(self):
# Line 142 | Line 431 | class SchedulerEdg(Scheduler):
431          to copy produced output into a storage element.
432          """
433          txt = ''
434 <        if self.copy_data:
146 <           copy = 'globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file'
434 >        if int(self.copy_data) == 1:
435             txt += '#\n'
436             txt += '#   Copy output to SE = $SE\n'
437             txt += '#\n'
438 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
439 <           txt += '  for out_file in $file_list ; do\n'
440 <           txt += '    echo "Trying to copy output file to $SE "\n'
441 <           txt += '    echo "'+copy+'"\n'
442 <           txt += '    '+copy+' 2>&1\n'
443 <           txt += '    copy_exit_status=$?\n'
156 <           txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
157 <           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
158 <           txt += '    if [ $copy_exit_status -ne 0 ]; then \n'
159 <           txt += '       echo "Problems with SE= $SE" \n'
160 <           txt += '    else \n'
161 <           txt += '       echo "output copied into $SE/$SE_PATH directory"\n'
438 >           txt += '    if [ $middleware == OSG ]; then\n'
439 >           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
440 >           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
441 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
442 >           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
443 >           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
444             txt += '    fi \n'
445 <           txt += '  done\n'
446 <           txt += 'fi \n'
445 >
446 >           txt += '    for out_file in $file_list ; do\n'
447 >           txt += '        echo "Trying to copy output file to $SE using srmcp"\n'
448 >           txt += '        echo "mkdir -p $HOME/.srmconfig"\n'
449 >           txt += '        mkdir -p $HOME/.srmconfig\n'
450 >           txt += '        if [ $middleware == LCG ]; then\n'
451 >           txt += '           echo "srmcp -retry_num 3 -retry_timeout 480000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
452 >           txt += '           exitstring=`srmcp -retry_num 3 -retry_timeout 480000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
453 >           txt += '        elif [ $middleware == OSG ]; then\n'
454 >           txt += '           echo "srmcp -retry_num 3 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
455 >           txt += '           exitstring=`srmcp -retry_num 3 -retry_timeout 240000 -x509_user_trusted_certificates $X509_CERT_DIR file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
456 >           txt += '        fi \n'
457 >           txt += '        copy_exit_status=$?\n'
458 >           txt += '        echo "COPY_EXIT_STATUS for srmcp = $copy_exit_status"\n'
459 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
460 >
461 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
462 >           txt += '            echo "Possible problem with SE = $SE"\n'
463 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
464 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
465 >           txt += '            echo "srmcp failed, attempting lcg-cp."\n'
466 >           if common.logger.debugLevel() >= 5:
467 >               txt += '            echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
468 >               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
469 >           else:              
470 >               txt += '            echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
471 >               txt += '            exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
472 >           txt += '            copy_exit_status=$?\n'
473 >           txt += '            echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
474 >           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
475 >
476 >           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
477 >           txt += '               echo "Problems with SE = $SE"\n'
478 >           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
479 >           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
480 >           txt += '               echo "srmcp and lcg-cp and failed!"\n'
481 >           txt += '            else\n'
482 >           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
483 >           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
484 >           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
485 >           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
486 >           txt += '               echo "lcg-cp succeeded"\n'
487 >           txt += '            fi\n'
488 >           txt += '        else\n'
489 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
490 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
491 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
492 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
493 >           txt += '            echo "srmcp succeeded"\n'
494 >           txt += '         fi\n'
495 >           txt += '     done\n'
496          return txt
497  
498      def wsRegisterOutput(self):
# Line 170 | Line 501 | class SchedulerEdg(Scheduler):
501          """
502  
503          txt = ''
504 <        if self.register_data:
504 >        if int(self.register_data) == 1:
505 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
506 >           txt += 'if [ $middleware == OSG ]; then\n'
507 >           txt += '   #\n'
508 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
509 >           txt += '   #\n'
510 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
511 >           txt += 'elif [ $middleware == LCG ]; then \n'
512             txt += '#\n'
513 <           txt += '#  Register output to RLS\n'
513 >           txt += '#  Register output to LFC\n'
514             txt += '#\n'
515 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
516 <           txt += '   for out_file in $file_list ; do\n'
517 <           txt += '      echo "Trying to register the output file into RLS"\n'
518 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
519 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
182 <           txt += '      register_exit_status=$?\n'
183 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
184 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
185 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
186 <           txt += '         echo "Problems with the registration to RLS" \n'
187 <           txt += '         echo "Try with srm protocol" \n'
188 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
189 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
515 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
516 >           txt += '      for out_file in $file_list ; do\n'
517 >           txt += '         echo "Trying to register the output file into LFC"\n'
518 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
519 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
520             txt += '         register_exit_status=$?\n'
521             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
522             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
523             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
524 <           txt += '            echo "Problems with the registration into RLS" \n'
524 >           txt += '            echo "Problems with the registration to LFC" \n'
525 >           txt += '            echo "Try with srm protocol" \n'
526 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
527 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
528 >           txt += '            register_exit_status=$?\n'
529 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
530 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
531 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
532 >           txt += '               echo "Problems with the registration into LFC" \n'
533 >           txt += '            fi \n'
534 >           txt += '         else \n'
535 >           txt += '            echo "output registered to LFC"\n'
536             txt += '         fi \n'
537 <           txt += '      else \n'
538 <           txt += '         echo "output registered to RLS"\n'
539 <           txt += '      fi \n'
540 <           txt += '   done\n'
541 <           txt += 'elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
542 <           txt += '   echo "Trying to copy output file to CloseSE"\n'
543 <           txt += '   CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
544 <           txt += '   for out_file in $file_list ; do\n'
545 <           txt += '      echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
546 <           txt += '      lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
547 <           txt += '      register_exit_status=$?\n'
548 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
549 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
550 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
551 <           txt += '         echo "Problems with CloseSE" \n'
552 <           txt += '      else \n'
553 <           txt += '         echo "The program was successfully executed"\n'
554 <           txt += '         echo "SE = $CLOSE_SE"\n'
555 <           txt += '         echo "LFN for the file is LFN=${LFN}/$out_file"\n'
556 <           txt += '      fi \n'
557 <           txt += '   done\n'
558 <           txt += 'else\n'
218 <           txt += '   echo "Problem with the executable"\n'
537 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
538 >           txt += '      done\n'
539 >           txt += '   else \n'
540 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
541 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
542 >           txt += '      for out_file in $file_list ; do\n'
543 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1" \n'
544 >           txt += '         lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1 \n'
545 >           txt += '         register_exit_status=$?\n'
546 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
547 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
548 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
549 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
550 >           txt += '         else \n'
551 >           txt += '            echo "The program was successfully executed"\n'
552 >           txt += '            echo "SE = $CLOSE_SE"\n'
553 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
554 >           txt += '         fi \n'
555 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
556 >           txt += '      done\n'
557 >           txt += '   fi \n'
558 >           txt += '   exit_status=$register_exit_status\n'
559             txt += 'fi \n'
560          return txt
561  
# Line 224 | Line 564 | class SchedulerEdg(Scheduler):
564          retrieve the logging info from logging and bookkeeping and return it
565          """
566          self.checkProxy()
227      #  id = common.jobDB.jobId(nj)
567          cmd = 'edg-job-get-logging-info -v 2 ' + id
568 <        cmd_out = os.popen(cmd)
230 <      #  cmd_out = runCommand(cmd)
231 <        return cmd_out
232 <
233 <    def listMatch(self, nj):
234 <        """
235 <        Check the compatibility of available resources
236 <        """
237 <        self.checkProxy()
238 <        jdl = common.job_list[nj].jdlFilename()
239 <        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
240 <        myCmd = os.popen(cmd)
241 <        cmd_out = myCmd.readlines()
242 <        myCmd.close()
243 <        return self.parseListMatch_(cmd_out, jdl)
244 <
245 <    def parseListMatch_(self, out, jdl):
246 <
247 <        reComment = re.compile( r'^\**$' )
248 <        reEmptyLine = re.compile( r'^$' )
249 <        reVO = re.compile( r'Selected Virtual Organisation name.*' )
250 <        reCE = re.compile( r'CEId' )
251 <        reNO = re.compile( r'No Computing Element matching' )
252 <        reRB = re.compile( r'Connecting to host' )
253 <        next = 0
254 <        CEs=[]
255 <        Match=0
256 <
257 <        for line in out:
258 <            line = line.strip()
259 <            if reComment.match( line ):
260 <                next = 0
261 <                continue
262 <            if reEmptyLine.match(line):
263 <                continue
264 <            if reVO.match( line ):
265 <                VO =line.split()[-1]
266 <                common.logger.debug(5, 'VO           :'+VO)
267 <                pass
268 <            if reRB.match( line ):
269 <                RB =line.split()[3]
270 <                common.logger.debug(5, 'Using RB     :'+RB)
271 <                pass
272 <            if reCE.search( line ):
273 <                next = 1
274 <                continue
275 <            if next:
276 <                CE=line.split(':')[0]
277 <                if (CEs.count(CE) > 0):
278 <                   pass
279 <                else:
280 <                   CEs.append(CE)  
281 <                   Match=Match+1
282 <                common.logger.debug(5, 'Matched CE   :'+CE)
283 <                pass
284 <            if reNO.match( line ):
285 <                common.logger.debug(5,line)
286 <                self.noMatchFound_(jdl)
287 <                Match=0
288 <                pass
289 <        return Match
290 <
291 <    def noMatchFound_(self, jdl):
292 <        reReq = re.compile( r'Requirements' )
293 <        reString = re.compile( r'"\S*"' )
294 <        f = file(jdl,'r')
295 <        for line in f.readlines():
296 <            line= line.strip()
297 <            if reReq.match(line):
298 <                for req in reString.findall(line):
299 <                    if re.search("VO",req):
300 <                        common.logger.message( "SW required: "+req)
301 <                        continue
302 <                    if re.search('"\d+',req):
303 <                        common.logger.message("Other req  : "+req)
304 <                        continue
305 <                    common.logger.message( "CE required: "+req)
306 <                break
307 <            pass
308 <        raise CrabException("No compatible resources found!")
309 <
310 <    def submit(self, nj):
311 <        """
312 <        Submit one EDG job.
313 <        """
314 <
315 <        self.checkProxy()
316 <        jid = None
317 <        jdl = common.job_list[nj].jdlFilename()
318 <
319 <        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
568 >        #cmd_out = os.popen(cmd)
569          cmd_out = runCommand(cmd)
570 <        if cmd_out != None:
322 <            reSid = re.compile( r'https.+' )
323 <            jid = reSid.search(cmd_out).group()
324 <            pass
325 <        return jid
570 >        return cmd_out
571  
572      def getExitStatus(self, id):
573          return self.getStatusAttribute_(id, 'exit_code')
# Line 346 | Line 591 | class SchedulerEdg(Scheduler):
591          # Instance of the Status class provided by LB API
592          jobStat = Status()
593          st = 0
594 +        #print id, level, attr, self.states.index(attr)
595          jobStat.getStatus(id, level)
596 +        #print jobStat.loadStatus(st)
597          err, apiMsg = jobStat.get_error()
598          if err:
352            #print 'Error caught', apiMsg
353            #common.log.message(apiMsg)
599              common.logger.debug(5,'Error caught' + apiMsg)
600              return None
601          else:
602              for i in range(len(self.states)):
603                  # Fill an hash table with all information retrieved from LB API
604                  hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
605 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
605 >                #print i, jobStat.loadStatus(st)[i]
606 >            result = jobStat.loadStatus(st)[self.states.index(attr)]
607 >            #print str(result)
608              return result
609  
610      def queryDetailedStatus(self, id):
# Line 366 | Line 613 | class SchedulerEdg(Scheduler):
613          cmd_out = runCommand(cmd)
614          return cmd_out
615  
616 <    def getOutput(self, id):
616 >    ##### FEDE ######        
617 >    def findSites_(self, n):
618 >        itr4 =[]
619 >        sites = common.jobDB.destination(n)
620 >        if len(sites)>0 and sites[0]=="Any":
621 >            return itr4
622 >        itr = ''
623 >        if sites != [""]:#CarlosDaniele
624 >            for site in sites:
625 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
626 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
627 >            itr = itr[0:-4]
628 >            itr4.append( itr )
629 >        return itr4
630 >
631 >    def createXMLSchScript(self, nj, argsList):
632 >   # def createXMLSchScript(self, nj):
633 >      
634          """
635 <        Get output for a finished job with id.
372 <        Returns the name of directory with results.
635 >        Create a XML-file for BOSS4.
636          """
637 <
375 <        self.checkProxy()
376 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
377 <        cmd_out = runCommand(cmd)
378 <
379 <        # Determine the output directory name
380 <        dir = common.work_space.resDir()
381 <        dir += os.getlogin()
382 <        dir += '_' + os.path.basename(id)
383 <        return dir
384 <
385 <    def cancel(self, id):
386 <        """ Cancel the EDG job with id """
387 <        self.checkProxy()
388 <        cmd = 'edg-job-cancel --noint ' + id
389 <        cmd_out = runCommand(cmd)
390 <        return cmd_out
391 <
392 <    def createSchScript(self, nj):
637 >  #      job = common.job_list[nj]
638          """
639 <        Create a JDL-file for EDG.
639 >        INDY
640 >        [begin] FIX-ME:
641 >        I would pass jobType instead of job
642          """
643 <
644 <        job = common.job_list[nj]
643 >        index = nj - 1
644 >        job = common.job_list[index]
645          jbt = job.type()
399        inp_sandbox = jbt.inputSandbox(nj)
400        out_sandbox = jbt.outputSandbox(nj)
401        inp_storage_subdir = ''
646          
647 <        title = '# This JDL was generated by '+\
648 <                common.prog_name+' (version '+common.prog_version_str+')\n'
647 >        inp_sandbox = jbt.inputSandbox(index)
648 >        out_sandbox = jbt.outputSandbox(index)
649 >        """
650 >        [end] FIX-ME
651 >        """
652 >
653 >        
654 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
655          jt_string = ''
656 +        
657 +        xml_fname = str(self.jobtypeName)+'.xml'
658 +        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
659  
660 +        #TaskName  
661 +        dir = string.split(common.work_space.topDir(), '/')
662 +        taskName = dir[len(dir)-2]
663 +  
664 +        to_writeReq = ''
665 +        to_write = ''
666 +
667 +        req=' '
668 +        req = req + jbt.getRequirements()
669 +
670 +
671 +        #sites = common.jobDB.destination(nj)
672 +        #if len(sites)>0 and sites[0]!="Any":
673 +        #    req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
674 +        #req = req    
675 +    
676 +        if self.EDG_requirements:
677 +            if (req == ' '):
678 +                req = req + self.EDG_requirements
679 +            else:
680 +                req = req +  ' && ' + self.EDG_requirements
681 +        if self.EDG_ce_white_list:
682 +            ce_white_list = string.split(self.EDG_ce_white_list,',')
683 +            for i in range(len(ce_white_list)):
684 +                if i == 0:
685 +                    if (req == ' '):
686 +                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
687 +                    else:
688 +                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
689 +                    pass
690 +                else:
691 +                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
692 +            req = req + ')'
693 +        
694 +        if self.EDG_ce_black_list:
695 +            ce_black_list = string.split(self.EDG_ce_black_list,',')
696 +            for ce in ce_black_list:
697 +                if (req == ' '):
698 +                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
699 +                else:
700 +                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
701 +                pass
702 +        if self.EDG_clock_time:
703 +            if (req == ' '):
704 +                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
705 +            else:
706 +                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
707 +
708 +        if self.EDG_cpu_time:
709 +            if (req == ' '):
710 +                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
711 +            else:
712 +                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
713 +                                                                                          
714 +        if ( self.EDG_retry_count ):              
715 +            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
716 +            pass
717 +
718 +        if ( self.EDG_shallow_retry_count ):              
719 +            to_write = to_write + 'ShallowResubmissionRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
720 +            pass
721 +
722 +        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
723 +        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
724  
725 +                #TaskName  
726 +        dir = string.split(common.work_space.topDir(), '/')
727 +        taskName = dir[len(dir)-2]
728 +
729 +        xml.write(str(title))
730 +        xml.write('<task name="' +str(taskName)+'">\n')
731 +        xml.write(jt_string)
732          
733 <        SPL = inp_storage_subdir
734 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
733 >        if (to_write != ''):
734 >            xml.write('<extraTags\n')
735 >            xml.write(to_write)
736 >            xml.write('/>\n')
737 >            pass
738  
739 <        jdl_fname = job.jdlFilename()
740 <        jdl = open(jdl_fname, 'w')
741 <        jdl.write(title)
739 >        xml.write('<iterator>\n')
740 >        xml.write('\t<iteratorRule name="ITR1">\n')
741 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
742 >        xml.write('\t</iteratorRule>\n')
743 >        xml.write('\t<iteratorRule name="ITR2">\n')
744 >        for arg in argsList:
745 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
746 >            pass
747 >        xml.write('\t</iteratorRule>\n')
748 >        #print jobList
749 >        xml.write('\t<iteratorRule name="ITR3">\n')
750 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
751 >        xml.write('\t</iteratorRule>\n')
752 >
753 >        '''
754 >        indy: here itr4
755 >        '''
756 >        
757  
758 <        script = job.scriptFilename()
759 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
418 <        jdl.write(jt_string)
758 >        xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
759 >        xml.write(jt_string)
760  
761 <        ### only one .sh  JDL has arguments:
421 <        firstEvent = common.jobDB.firstEvent(nj)
422 <        maxEvents = common.jobDB.maxEvents(nj)
423 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
761 >        #executable
762  
763 <        inp_box = 'InputSandbox = { '
764 <        inp_box = inp_box + '"' + script + '",'
763 >        """
764 >        INDY
765 >        script depends on jobType: it should be probably get in a different way
766 >        """        
767 >        script = job.scriptFilename()
768 >        xml.write('<program>\n')
769 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
770 >        xml.write(jt_string)
771 >    
772 >          
773 >        ### only one .sh  JDL has arguments:
774 >        ### Fabio
775 > #        xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
776 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
777 >        xml.write('<program_types> crabjob </program_types>\n')
778 >        inp_box = script + ','
779  
780          if inp_sandbox != None:
781              for fl in inp_sandbox:
782 <                inp_box = inp_box + ' "' + fl + '",'
782 >                inp_box = inp_box + '' + fl + ','
783                  pass
784              pass
785  
786 <        #if common.use_jam:
787 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
788 <
789 <        for addFile in jbt.additional_inbox_files:
790 <            addFile = os.path.abspath(addFile)
791 <            inp_box = inp_box+' "'+addFile+'",'
792 <            pass
786 >        inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
787 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
788 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
789 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
790 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + ','+\
791 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'parseCrabFjr.py')
792 >
793 >        if (not jbt.additional_inbox_files == []):
794 >            inp_box = inp_box + ','
795 >            for addFile in jbt.additional_inbox_files:
796 >                addFile = os.path.abspath(addFile)
797 >                inp_box = inp_box+''+addFile+','
798 >                pass
799  
800          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
801 <        inp_box = inp_box + ' };\n'
802 <        jdl.write(inp_box)
445 <
446 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
447 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
801 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
802 >        xml.write(inp_box)
803          
804 +        base = jbt.name()
805 +        stdout = base + '__ITR3_.stdout'
806 +        stderr = base + '__ITR3_.stderr'
807 +        
808 +        xml.write('<stderr> ' + stderr + '</stderr>\n')
809 +        xml.write('<stdout> ' + stdout + '</stdout>\n')
810          
450        if job.stdout() == job.stderr():
451          out_box = 'OutputSandbox = { "' + \
452                    job.stdout() + '", ".BrokerInfo",'
453        else:
454          out_box = 'OutputSandbox = { "' + \
455                    job.stdout() + '", "' + \
456                    job.stderr() + '", ".BrokerInfo",'
811  
812 <        if self.return_data :
812 >        out_box = stdout + ',' + \
813 >                  stderr + ',.BrokerInfo,'
814 >
815 >        """
816 >        if int(self.return_data) == 1:
817              if out_sandbox != None:
818                  for fl in out_sandbox:
819 <                    out_box = out_box + ' "' + fl + '",'
819 >                    out_box = out_box + '' + fl + ','
820                      pass
821                  pass
822              pass
823 <                                                                                                                                                            
823 >        """
824 >
825 >        """
826 >        INDY
827 >        something similar should be also done for infiles (if it makes sense!)
828 >        """
829 >        if int(self.return_data) == 1:
830 >            for fl in jbt.output_file:
831 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
832 >                pass
833 >            pass
834 >
835          if out_box[-1] == ',' : out_box = out_box[:-1]
836 <        out_box = out_box + ' };'
837 <        jdl.write(out_box+'\n')
836 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
837 >        xml.write(out_box)
838 >
839 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
840  
841 <        ### if at least a CE exists ...
842 <        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 + ')'
841 >        xml.write('</program>\n')
842 >        xml.write('</chain>\n')
843  
844 <            #### and USER REQUIREMENT
845 <            if self.EDG_requirements:
488 <                req = req +  ' && ' + self.EDG_requirements
489 <            if self.EDG_clock_time:
490 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
491 <            if self.EDG_cpu_time:
492 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
493 <            req = req + ';\n'
494 <            jdl.write(req)
495 <                                                                                                                                                            
496 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
844 >        xml.write('</iterator>\n')
845 >        xml.write('</task>\n')
846  
847 <        if ( self.EDG_retry_count ):              
848 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
500 <            pass
847 >        xml.close()
848 >      
849  
502        jdl.close()
850          return
851  
852      def checkProxy(self):
# Line 508 | Line 855 | class SchedulerEdg(Scheduler):
855          """
856          if (self.proxyValid): return
857          timeleft = -999
858 <        minTimeLeft=10 # in hours
859 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
860 <        try: cmd_out = runCommand(cmd,0)
861 <        except: print cmd_out
862 <        if (cmd_out == None or cmd_out=='1'):
863 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
864 <            cmd = 'grid-proxy-init -valid 100:00'
858 >        minTimeLeft=10*3600 # in seconds
859 >
860 >        minTimeLeftServer = 100 # in hours
861 >
862 >        mustRenew = 0
863 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
864 >        timeLeftServer = -999
865 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
866 >            mustRenew = 1
867 >        else:
868 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
869 >            if not timeLeftServer or not isInt(timeLeftServer):
870 >                mustRenew = 1
871 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
872 >                mustRenew = 1
873 >            pass
874 >        pass
875 >
876 >        if mustRenew:
877 >            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")
878 >            cmd = 'voms-proxy-init -voms '+self.VO
879 >            if self.group:
880 >                cmd += ':/'+self.VO+'/'+self.group
881 >            if self.role:
882 >                cmd += '/role='+self.role
883 >            cmd += ' -valid 192:00'
884              try:
885 +                # SL as above: damn it!
886 +                common.logger.debug(10,cmd)
887                  out = os.system(cmd)
888                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
889              except:
890                  msg = "Unable to create a valid proxy!\n"
891                  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)
892              pass
893 +
894 +        ## now I do have a voms proxy valid, and I check the myproxy server
895 +        renewProxy = 0
896 +        cmd = 'myproxy-info -d -s '+self.proxyServer
897 +        cmd_out = runCommand(cmd,0,20)
898 +        if not cmd_out:
899 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
900 +            renewProxy = 1
901 +        else:
902 +            # if myproxy exist but not long enough, renew
903 +            reTime = re.compile( r'timeleft: (\d+)' )
904 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
905 +            if reTime.match( cmd_out ):
906 +                time = reTime.search( line ).group(1)
907 +                if time < minTimeLeftServer:
908 +                    renewProxy = 1
909 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
910 +                pass
911 +            pass
912 +        
913 +        # if not, create one.
914 +        if renewProxy:
915 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
916 +            out = os.system(cmd)
917 +            if (out>0):
918 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
919 +            pass
920 +
921 +        # cache proxy validity
922          self.proxyValid=1
923          return
924 <    
924 >
925      def configOpt_(self):
926          edg_ui_cfg_opt = ' '
927          if self.edg_config:
928 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
928 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
929          if self.edg_config_vo:
930 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
930 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
931          return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines