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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines