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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines