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.14 by fanzago, Tue Oct 4 18:19:33 2005 UTC vs.
Revision 1.133 by fanzago, Wed Aug 15 14:08:18 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines