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.122 by corvo, Tue Jun 26 15:31:23 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines