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.49 by spiga, Fri Apr 7 12:58:38 2006 UTC vs.
Revision 1.145 by fanzago, Tue Oct 9 14:34:40 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, time
# Line 21 | Line 23 | class SchedulerEdg(Scheduler):
23  
24      def configure(self, cfg_params):
25  
26 <        try:
27 <            RB = cfg_params["EDG.rb"]
26 <            edgConfig = EdgConfig(RB)
27 <            self.edg_config = edgConfig.config()
28 <            self.edg_config_vo = edgConfig.configVO()
29 <        except KeyError:
30 <            self.edg_config = ''
31 <            self.edg_config_vo = ''
32 <
26 >        # init BlackWhiteListParser
27 >        self.blackWhiteListParser = BlackWhiteListParser(cfg_params)
28  
29 <        try: self.LCG_version = cfg_params["EDG.lcg_version"]
30 <        except KeyError: self.LCG_version = '2'
29 >        self.proxyValid=0
30 >        try: self.dontCheckProxy=int(cfg_params["EDG.dont_check_proxy"])
31 >        except KeyError: self.dontCheckProxy = 0
32  
33 <        try: self.EDG_requirements = cfg_params['EDG.requirements']
34 <        except KeyError: self.EDG_requirements = ''
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: self.EDG_retry_count = cfg_params['EDG.retry_count']
46 <        except KeyError: self.EDG_retry_count = ''
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:
59              self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
45            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
60          except KeyError:
61              self.EDG_ce_black_list  = ''
62  
63          try:
64              self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
51            #print "self.EDG_ce_white_list = ", self.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.return_data = cfg_params['USER.return_data']
58 <        except KeyError: self.return_data = 1
59 <
60 <        try:
61 <             self.copy_input_data = common.analisys_common_info['copy_input_data']
62 <             #print "self.copy_input_data = ", self.copy_input_data
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 = 0
75 +
76          try:
77              self.copy_data = cfg_params["USER.copy_data"]
78              if int(self.copy_data) == 1:
# Line 80 | Line 91 | class SchedulerEdg(Scheduler):
91             msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
92             raise CrabException(msg)
93  
94 <        try:
84 <            self.lfc_host = cfg_params['EDG.lfc_host']
85 <        except KeyError:
86 <            msg = "Error. The [EDG] section does not have 'lfc_host' value"
87 <            msg = msg + " it's necessary to know the LFC host name"
88 <            common.logger.message(msg)
89 <            raise CrabException(msg)
90 <        try:
91 <            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
92 <        except KeyError:
93 <            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
94 <            msg = msg + " it's necessary to know the catalog type"
95 <            common.logger.message(msg)
96 <            raise CrabException(msg)
97 <        try:
98 <            self.lfc_home = cfg_params['EDG.lfc_home']
99 <        except KeyError:
100 <            msg = "Error. The [EDG] section does not have 'lfc_home' value"
101 <            msg = msg + " it's necessary to know the home catalog dir"
102 <            common.logger.message(msg)
103 <            raise CrabException(msg)
104 <      
94 >        ########### FEDE FOR DBS2 ##############################
95          try:
96 <            self.register_data = cfg_params["USER.register_data"]
97 <            if int(self.register_data) == 1:
96 >            self.publish_data = cfg_params["USER.publish_data"]
97 >            self.checkProxy()
98 >            if int(self.publish_data) == 1:
99                  try:
100 <                    self.LFN = cfg_params['USER.lfn_dir']
100 >                    self.publish_data_name = cfg_params['USER.publish_data_name']
101                  except KeyError:
102 <                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
112 <                    msg = msg + " it's necessary for LCF registration"
113 <                    common.logger.message(msg)
102 >                    msg = "Error. The [USER] section does not have 'publish_data_name'"
103                      raise CrabException(msg)
104 <        except KeyError: self.register_data = 0
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.register_data) == 1 ):
119 <           msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
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 +        #    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  
# Line 145 | Line 193 | class SchedulerEdg(Scheduler):
193          libPath=os.path.join(path, "lib", "python")
194          sys.path.append(libPath)
195  
196 <        self.proxyValid=0
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 >
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
164 <        else:
165 <            return 0
301 >
302  
303      def wsSetupEnvironment(self):
304          """
305          Returns part of a job script which does scheduler-specific work.
306          """
307          txt = ''
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 [ $VO_CMS_SW_DIR ]; then\n'
174 <        txt += '    middleware=LCG \n'
175 <        txt += '    echo "middleware =$middleware" \n'
176 <        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
326 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
327          txt += '    middleware=OSG \n'
328 +        txt += '    if [ $GLOBUS_GRAM_JOB_CONTACT ]; then \n'
329 +        txt += '        SyncCE=`echo "echo $GLOBUS_GRAM_JOB_CONTACT" | cut -d: -f2 | sed \'s/\/\///\'`;\n'
330 +        txt += '        echo "SyncCE=$SyncCE"  | tee -a $RUNTIME_AREA/$repo ;\n'
331 +        txt += '    else\n'
332 +        txt += '        echo "not reporting SyncCE";\n'
333 +        txt += '    fi\n';
334 +        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
335          txt += '    echo "middleware =$middleware" \n'
336          txt += 'elif [ $OSG_APP ]; then \n'
337          txt += '    middleware=OSG \n'
338 +        txt += '    if [ $GLOBUS_GRAM_JOB_CONTACT ]; then \n'
339 +        txt += '        SyncCE=`echo "echo $GLOBUS_GRAM_JOB_CONTACT" | cut -d: -f2 | sed \'s/\/\///\'`;\n'
340 +        txt += '        echo "SyncCE=$SyncCE"  | tee -a $RUNTIME_AREA/$repo ;\n'
341 +        txt += '    else\n'
342 +        txt += '        echo "not reporting SyncCE";\n'
343 +        txt += '    fi\n';
344 +        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
345 +        txt += '    echo "middleware =$middleware" \n'
346 +        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
347 +        txt += '    middleware=LCG \n'
348 +   #     txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
349 +        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
350 +        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
351          txt += '    echo "middleware =$middleware" \n'
352          txt += 'else \n'
353 <        txt += '    echo "SET_CMS_ENV 1 ==> middleware not identified" \n'
354 <        txt += '    echo "JOB_EXIT_STATUS = 1"\n'
355 <        txt += '    exit 1\n'
356 <        txt += 'fi\n'
357 <
353 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
354 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
355 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
356 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
357 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
358 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
359 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
360 >        txt += '    exit 1 \n'
361 >        txt += 'fi \n'
362 >
363 >        txt += '# report first time to DashBoard \n'
364 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
365 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
366 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
367 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
368 >        
369          txt += '\n\n'
370  
371 <        txt += 'if [ $middleware == LCG ]; then \n'
372 <        txt += '    echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
373 <        txt += 'fi\n'
374 <
375 <        if int(self.copy_data) == 1:
376 <           if self.SE:
377 <              txt += 'export SE='+self.SE+'\n'
378 <              txt += 'echo "SE = $SE"\n'
198 <           if self.SE_PATH:
199 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
200 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
201 <              txt += 'echo "SE_PATH = $SE_PATH"\n'
371 > #        if int(self.copy_data) == 1:
372 > #           if self.SE:
373 > #              txt += 'export SE='+self.SE+'\n'
374 > #              txt += 'echo "SE = $SE"\n'
375 > #           if self.SE_PATH:
376 > #              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
377 > #              txt += 'export SE_PATH='+self.SE_PATH+'\n'
378 > #              txt += 'echo "SE_PATH = $SE_PATH"\n'
379  
380          txt += 'export VO='+self.VO+'\n'
381 <        ### FEDE: add some line for LFC catalog setting
382 <        txt += 'if [ $middleware == LCG ]; then \n'
383 <        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
384 <        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
385 <        txt += '    fi\n'
386 <        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
387 <        txt += '        export LFC_HOST='+self.lfc_host+'\n'
388 <        txt += '    fi\n'
389 <        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
390 <        txt += '        export LFC_HOME='+self.lfc_home+'\n'
391 <        txt += '    fi\n'
392 <        txt += 'elif [ $middleware == OSG ]; then\n'
393 <        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
394 <        txt += 'fi\n'
381 >        ### add some line for LFC catalog setting
382 >        #txt += 'if [ $middleware == LCG ]; then \n'
383 >        #txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
384 >        #txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
385 >        #txt += '    fi\n'
386 >        #txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
387 >        #txt += '        export LFC_HOST='+self.lfc_host+'\n'
388 >        #txt += '    fi\n'
389 >        #txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
390 >        #txt += '        export LFC_HOME='+self.lfc_home+'\n'
391 >        #txt += '    fi\n'
392 >        #txt += 'elif [ $middleware == OSG ]; then\n'
393 >        #txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
394 >        #txt += 'fi\n'
395          #####
396 <        if int(self.register_data) == 1:
397 <           txt += 'if [ $middleware == LCG ]; then \n'
398 <           txt += '    export LFN='+self.LFN+'\n'
399 <           txt += '    lfc-ls $LFN\n'
400 <           txt += '    result=$?\n'
401 <           txt += '    echo $result\n'
402 <           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
403 <           txt += '    if [ $result != 0 ]; then\n'
404 <           txt += '       lfc-mkdir $LFN\n'
405 <           txt += '       result=$?\n'
406 <           txt += '       echo $result\n'
407 <           txt += '    fi\n'
408 <           txt += 'elif [ $middleware == OSG ]; then\n'
409 <           txt += '    echo " Files registration to be implemented for OSG"\n'
410 <           txt += 'fi\n'
411 <           txt += '\n'
412 <
413 <           if self.VO:
414 <              txt += 'export VO='+self.VO+'\n'
415 <           if self.LFN:
416 <              txt += 'if [ $middleware == LCG ]; then \n'
417 <              txt += '    export LFN='+self.LFN+'\n'
418 <              txt += 'fi\n'
242 <              txt += '\n'
396 >        #if int(self.register_data) == 1:
397 >        #   txt += 'if [ $middleware == LCG ]; then \n'
398 >        #   txt += '    export LFN='+self.LFN+'\n'
399 >        #   txt += '    lfc-ls $LFN\n'
400 >        #   txt += '    result=$?\n'
401 >        #   txt += '    echo $result\n'
402 >        #   ### creation of LFN dir in LFC catalog, under /grid/cms dir  
403 >        #   txt += '    if [ $result != 0 ]; then\n'
404 >        #   txt += '       lfc-mkdir $LFN\n'
405 >        #   txt += '       result=$?\n'
406 >        #   txt += '       echo $result\n'
407 >        #   txt += '    fi\n'
408 >        #   txt += 'elif [ $middleware == OSG ]; then\n'
409 >        #   txt += '    echo " Files registration to be implemented for OSG"\n'
410 >        #   txt += 'fi\n'
411 >        #   txt += '\n'
412 >        #   if self.VO:
413 >        #      txt += 'export VO='+self.VO+'\n'
414 >        #   if self.LFN:
415 >        #      txt += 'if [ $middleware == LCG ]; then \n'
416 >        #      txt += '    export LFN='+self.LFN+'\n'
417 >        #      txt += 'fi\n'
418 >        #      txt += '\n'
419  
420          txt += 'if [ $middleware == LCG ]; then\n'
421 <        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
421 >    #    txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
422 >        txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
423          txt += '    echo "CloseCEs = $CloseCEs"\n'
424          txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
425          txt += '    echo "CE = $CE"\n'
# Line 250 | Line 427 | class SchedulerEdg(Scheduler):
427          txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
428          txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
429          txt += '    else \n'
430 <        txt += '        echo "SET_ENV 1 ==> ERROR in setting CE name - OSG mode -" \n'
430 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
431 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
432 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
433 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
434 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
435 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
436 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
437          txt += '        exit 1 \n'
438          txt += '    fi \n'
439          txt += 'fi \n'
# Line 262 | Line 445 | class SchedulerEdg(Scheduler):
445          Copy input data from SE to WN    
446          """
447          txt = ''
448 <        try:
449 <            self.copy_input_data = common.analisys_common_info['copy_input_data']
267 <            #print "self.copy_input_data = ", self.copy_input_data
268 <        except KeyError: self.copy_input_data = 0
269 <        if int(self.copy_input_data) == 1:
448 >        if not self.copy_input_data: return txt
449 >
450          ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
451 <           txt += 'if [ $middleware == OSG ]; then\n'
452 <           txt += '   #\n'
453 <           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
454 <           txt += '   #\n'
455 <           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
456 <           txt += 'elif [ $middleware == LCG ]; then \n'
457 <           txt += '   #\n'
458 <           txt += '   #   Copy Input Data from SE to this WN\n'
459 <           txt += '   #\n'
460 < ### changed by georgia (put a loop copying more than one input files per jobs)          
461 <           txt += '   for input_file in $cur_file_list \n'
462 <           txt += '   do \n'
463 <           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
464 <           txt += '    copy_input_exit_status=$?\n'
465 <           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
466 <           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
467 <           txt += '       echo "Problems with copying to WN" \n'
468 <           txt += '    else \n'
469 <           txt += '       echo "input copied into WN" \n'
470 <           txt += '    fi \n'
471 <           txt += '   done \n'
472 < ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
473 <           txt += '   for file in $cur_pu_list \n'
474 <           txt += '   do \n'
475 <           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
476 <           txt += '    copy_input_exit_status=$?\n'
477 <           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
478 <           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
479 <           txt += '       echo "Problems with copying pu to WN" \n'
480 <           txt += '    else \n'
481 <           txt += '       echo "input pu files copied into WN" \n'
482 <           txt += '    fi \n'
483 <           txt += '   done \n'
484 <           txt += '   \n'
485 <           txt += '   ### Check SCRATCH space available on WN : \n'
486 <           txt += '   df -h \n'
487 <           txt += 'fi \n'
451 >        txt += 'if [ $middleware == OSG ]; then\n'
452 >        txt += '   #\n'
453 >        txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
454 >        txt += '   #\n'
455 >        txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
456 >        txt += 'elif [ $middleware == LCG ]; then \n'
457 >        txt += '   #\n'
458 >        txt += '   #   Copy Input Data from SE to this WN\n'
459 >        txt += '   #\n'
460 >        ### changed by georgia (put a loop copying more than one input files per jobs)          
461 >        txt += '   for input_file in $cur_file_list \n'
462 >        txt += '   do \n'
463 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
464 >        txt += '      copy_input_exit_status=$?\n'
465 >        txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
466 >        txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
467 >        txt += '         echo "Problems with copying to WN" \n'
468 >        txt += '      else \n'
469 >        txt += '         echo "input copied into WN" \n'
470 >        txt += '      fi \n'
471 >        txt += '   done \n'
472 >        ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
473 >        txt += '   for file in $cur_pu_list \n'
474 >        txt += '   do \n'
475 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
476 >        txt += '      copy_input_pu_exit_status=$?\n'
477 >        txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
478 >        txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
479 >        txt += '         echo "Problems with copying pu to WN" \n'
480 >        txt += '      else \n'
481 >        txt += '         echo "input pu files copied into WN" \n'
482 >        txt += '      fi \n'
483 >        txt += '   done \n'
484 >        txt += '   \n'
485 >        txt += '   ### Check SCRATCH space available on WN : \n'
486 >        txt += '   df -h \n'
487 >        txt += 'fi \n'
488            
489          return txt
490  
# Line 313 | Line 493 | class SchedulerEdg(Scheduler):
493          Write a CopyResults part of a job script, e.g.
494          to copy produced output into a storage element.
495          """
496 <        txt = ''
317 <        if int(self.copy_data) == 1:
318 <           txt += '#\n'
319 <           txt += '#   Copy output to SE = $SE\n'
320 <           txt += '#\n'
321 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
322 <           txt += '    for out_file in $file_list ; do\n'
323 <           txt += '        echo "Trying to copy output file to $SE "\n'
324 <           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
325 <           txt += '        if [ $middleware == OSG ]; then\n'
326 <           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
327 <           txt += '           copy_exit_status=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
328 <           #txt += '           exitstring=`globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
329 <           txt += '        elif [ $middleware == LCG ]; then \n'
330 <           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
331 <           txt += '           copy_exit_status=`lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
332 <           #txt += '           exitstring=`lcg-cp --vo cms -t 30 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
333 <           txt += '        fi \n'
334 <           #txt += '        copy_exit_status=$?\n'
335 <           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
336 <           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
337 <           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
338 <           txt += '            echo "Problems with SE = $SE"\n'
339 <           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
340 <           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
341 <           txt += '        else\n'
342 <           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
343 <           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
344 <           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
345 <           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
346 <           txt += '         fi\n'
347 <           txt += '     done\n'
348 <           txt += 'fi\n'
349 <        return txt
496 >        txt = '\n'
497  
498 <    def wsRegisterOutput(self):
499 <        """
500 <        Returns part of a job script which does scheduler-specific work.
354 <        """
498 >        txt += '#\n'
499 >        txt += '# COPY OUTPUT FILE TO SE\n'
500 >        txt += '#\n\n'
501  
502 <        txt = ''
503 <        if int(self.register_data) == 1:
504 <        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
505 <           txt += 'if [ $middleware == OSG ]; then\n'
506 <           txt += '   #\n'
507 <           txt += '   #   Register output to LFC deactivated in OSG mode\n'
508 <           txt += '   #\n'
509 <           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
510 <           txt += 'elif [ $middleware == LCG ]; then \n'
511 <           txt += '#\n'
512 <           txt += '#  Register output to LFC\n'
513 <           txt += '#\n'
514 <           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
515 <           txt += '      for out_file in $file_list ; do\n'
516 <           txt += '         echo "Trying to register the output file into LFC"\n'
517 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
518 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
519 <           txt += '         register_exit_status=$?\n'
520 <           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
521 <           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
522 <           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
523 <           txt += '            echo "Problems with the registration to LFC" \n'
524 <           txt += '            echo "Try with srm protocol" \n'
525 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
526 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
527 <           txt += '            register_exit_status=$?\n'
528 <           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
529 <           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
530 <           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
531 <           txt += '               echo "Problems with the registration into LFC" \n'
532 <           txt += '            fi \n'
533 <           txt += '         else \n'
534 <           txt += '            echo "output registered to LFC"\n'
535 <           txt += '         fi \n'
536 <           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
537 <           txt += '      done\n'
538 <           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
539 <           txt += '      echo "Trying to copy output file to CloseSE"\n'
540 <           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
541 <           txt += '      for out_file in $file_list ; do\n'
542 <           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
543 <           txt += '         lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
544 <           txt += '         register_exit_status=$?\n'
545 <           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
546 <           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
547 <           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
548 <           txt += '            echo "Problems with CloseSE" \n'
549 <           txt += '         else \n'
550 <           txt += '            echo "The program was successfully executed"\n'
551 <           txt += '            echo "SE = $CLOSE_SE"\n'
406 <           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
407 <           txt += '         fi \n'
408 <           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
409 <           txt += '      done\n'
410 <           txt += '   else\n'
411 <           txt += '      echo "Problem with the executable"\n'
412 <           txt += '   fi \n'
413 <           txt += 'fi \n'
502 >        SE_PATH=''
503 >        if int(self.copy_data) == 1:
504 >            if self.SE:
505 >                txt += 'export SE='+self.SE+'\n'
506 >                txt += 'echo "SE = $SE"\n'
507 >            if self.SE_PATH:
508 >                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
509 >                SE_PATH=self.SE_PATH
510 >            if int(self.publish_data) == 1:
511 >                txt += '### publish_data = 1 so the SE path where to copy the output is: \n'
512 >                path_add = self.UserGridName + '/' + self.publish_data_name +'_${PSETHASH}/'
513 >                SE_PATH = SE_PATH + path_add
514 >            txt += 'export SE_PATH='+SE_PATH+'\n'
515 >            txt += 'echo "SE_PATH = $SE_PATH"\n'
516 >            
517 >            txt += 'echo "####################################################"\n'
518 >            txt += 'echo "# Copy output files from WN = `hostname` to SE = $SE"\n'
519 >            txt += 'echo "####################################################"\n'
520 >            
521 >            txt += 'if [ $output_exit_status -eq 60302 ]; then\n'
522 >            txt += '    echo "--> No output file to copy to $SE"\n'
523 >            txt += '    copy_exit_status=$output_exit_status\n'
524 >            txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
525 >            txt += 'else\n'
526 >            txt += '    for out_file in $file_list ; do\n'
527 >            txt += '        echo "Trying to copy output file to $SE"\n'
528 >            txt += '        cmscp $out_file ${SE} ${SE_PATH} $out_file $middleware\n'
529 >            txt += '        copy_exit_status=$?\n'
530 >            txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
531 >            txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
532 >            txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
533 >            txt += '            echo "Problem copying $out_file to $SE $SE_PATH"\n'
534 >            txt += '            echo "StageOutExitStatus = $copy_exit_status " | tee -a $RUNTIME_AREA/$repo\n'
535 >            txt += '            copy_exit_status=60307\n'
536 >            txt += '        else\n'
537 >            txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
538 >            txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
539 >            txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
540 >            txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
541 >            txt += '        fi\n'
542 >            txt += '    done\n'
543 >            txt += '    if [ $copy_exit_status -ne 0 ]; then\n'
544 >            txt += '        SE=""\n'
545 >            txt += '        echo "SE = $SE"\n'
546 >            txt += '        SE_PATH=""\n'
547 >            txt += '        echo "SE_PATH = $SE_PATH"\n'
548 >            txt += '    fi\n'
549 >            txt += 'fi\n'
550 >            txt += 'exit_status=$copy_exit_status\n'
551 >            pass
552          return txt
553  
554      def loggingInfo(self, id):
# Line 419 | Line 557 | class SchedulerEdg(Scheduler):
557          """
558          self.checkProxy()
559          cmd = 'edg-job-get-logging-info -v 2 ' + id
422        #cmd_out = os.popen(cmd)
560          cmd_out = runCommand(cmd)
561          return cmd_out
562  
426    def listMatch(self, nj):
427        """
428        Check the compatibility of available resources
429        """
430        self.checkProxy()
431        jdl = common.job_list[nj].jdlFilename()
432        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
433        cmd_out = runCommand(cmd,0,10)
434        if not cmd_out:
435            raise CrabException("ERROR: "+cmd+" failed!")
436
437        return self.parseListMatch_(cmd_out, jdl)
438
439    def parseListMatch_(self, out, jdl):
440        """
441        Parse the f* output of edg-list-match and produce something sensible
442        """
443        reComment = re.compile( r'^\**$' )
444        reEmptyLine = re.compile( r'^$' )
445        reVO = re.compile( r'Selected Virtual Organisation name.*' )
446        reLine = re.compile( r'.*')
447        reCE = re.compile( r'(.*:.*)')
448        reCEId = re.compile( r'CEId.*')
449        reNO = re.compile( r'No Computing Element matching' )
450        reRB = re.compile( r'Connecting to host' )
451        next = 0
452        CEs=[]
453        Match=0
454
455        #print out
456        lines = reLine.findall(out)
457
458        i=0
459        CEs=[]
460        for line in lines:
461            string.strip(line)
462            #print line
463            if reNO.match( line ):
464                common.logger.debug(5,line)
465                return 0
466                pass
467            if reVO.match( line ):
468                VO =reVO.match( line ).group()
469                common.logger.debug(5,"VO "+VO)
470                pass
471
472            if reRB.match( line ):
473                RB = reRB.match(line).group()
474                common.logger.debug(5,"RB "+RB)
475                pass
476
477            if reCEId.search( line ):
478                for lineCE in lines[i:-1]:
479                    if reCE.match( lineCE ):
480                        CE = string.strip(reCE.search(lineCE).group(1))
481                        CEs.append(CE.split(':')[0])
482                        pass
483                    pass
484                pass
485            i=i+1
486            pass
487
488        common.logger.debug(5,"All CE :"+str(CEs))
489
490        sites = []
491        [sites.append(it) for it in CEs if not sites.count(it)]
492
493        common.logger.debug(5,"All Sites :"+str(sites))
494        return len(sites)
495
496    def noMatchFound_(self, jdl):
497        reReq = re.compile( r'Requirements' )
498        reString = re.compile( r'"\S*"' )
499        f = file(jdl,'r')
500        for line in f.readlines():
501            line= line.strip()
502            if reReq.match(line):
503                for req in reString.findall(line):
504                    if re.search("VO",req):
505                        common.logger.message( "SW required: "+req)
506                        continue
507                    if re.search('"\d+',req):
508                        common.logger.message("Other req  : "+req)
509                        continue
510                    common.logger.message( "CE required: "+req)
511                break
512            pass
513        raise CrabException("No compatible resources found!")
514
515    def submit(self, nj):
516        """
517        Submit one EDG job.
518        """
519
520        self.checkProxy()
521        jid = None
522        jdl = common.job_list[nj].jdlFilename()
523
524        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
525        cmd_out = runCommand(cmd)
526        if cmd_out != None:
527            reSid = re.compile( r'https.+' )
528            jid = reSid.search(cmd_out).group()
529            pass
530        return jid
531
532    def resubmit(self, nj_list):
533        """
534        Prepare jobs to be submit
535        """
536        return
537
538    def getExitStatus(self, id):
539        return self.getStatusAttribute_(id, 'exit_code')
540
541    def queryStatus(self, id):
542        return self.getStatusAttribute_(id, 'status')
543
544    def queryDest(self, id):  
545        return self.getStatusAttribute_(id, 'destination')
546
547
548    def getStatusAttribute_(self, id, attr):
549        """ Query a status of the job with id """
550
551        self.checkProxy()
552        hstates = {}
553        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
554        # Bypass edg-job-status interfacing directly to C++ API
555        # Job attribute vector to retrieve status without edg-job-status
556        level = 0
557        # Instance of the Status class provided by LB API
558        jobStat = Status()
559        st = 0
560        jobStat.getStatus(id, level)
561        err, apiMsg = jobStat.get_error()
562        if err:
563            common.logger.debug(5,'Error caught' + apiMsg)
564            return None
565        else:
566            for i in range(len(self.states)):
567                # Fill an hash table with all information retrieved from LB API
568                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
569            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
570            return result
571
563      def queryDetailedStatus(self, id):
564          """ Query a detailed status of the job with id """
565          cmd = 'edg-job-status '+id
566          cmd_out = runCommand(cmd)
567          return cmd_out
568  
569 <    def getOutput(self, id):
570 <        """
580 <        Get output for a finished job with id.
581 <        Returns the name of directory with results.
582 <        """
569 >    def findSites_(self, n):
570 >        itr4 =[]
571  
572 <        self.checkProxy()
585 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
586 <        cmd_out = runCommand(cmd)
572 >        sites = common.jobDB.destination(n)
573  
574 <        # Determine the output directory name
575 <        dir = common.work_space.resDir()
590 <        dir += os.getlogin()
591 <        dir += '_' + os.path.basename(id)
592 <        return dir
574 >        if len(sites)>0 and sites[0]=="":
575 >            return itr4
576  
577 <    def cancel(self, id):
578 <        """ Cancel the EDG job with id """
579 <        self.checkProxy()
580 <        cmd = 'edg-job-cancel --noint ' + id
581 <        cmd_out = runCommand(cmd)
582 <        return cmd_out
577 >        itr = ''
578 >        if sites != [""]:#CarlosDaniele
579 >            ##Addedd Daniele
580 >            replicas = self.blackWhiteListParser.checkBlackList(sites,n)
581 >            if len(replicas)!=0:
582 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
583 >              
584 >            if len(replicas)==0:
585 >                msg = 'No sites remaining that host any part of the requested data! Exiting... '
586 >                raise CrabException(msg)
587 >            #####        
588 >           # for site in sites:
589 >            for site in replicas:
590 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
591 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
592 >            itr = itr[0:-4]
593 >            itr4.append( itr )
594 >        return itr4
595  
596 <    def createSchScript(self, nj):
596 >    def createXMLSchScript(self, nj, argsList):
597 >      
598          """
599 <        Create a JDL-file for EDG.
599 >        Create a XML-file for BOSS4.
600          """
601 <
602 <        job = common.job_list[nj]
601 >  #      job = common.job_list[nj]
602 >        """
603 >        INDY
604 >        [begin] FIX-ME:
605 >        I would pass jobType instead of job
606 >        """
607 >        index = nj - 1
608 >        job = common.job_list[index]
609          jbt = job.type()
608        inp_sandbox = jbt.inputSandbox(nj)
609        out_sandbox = jbt.outputSandbox(nj)
610        inp_storage_subdir = ''
611        
612        title = '# This JDL was generated by '+\
613                common.prog_name+' (version '+common.prog_version_str+')\n'
614        jt_string = ''
615
616
610          
611 <        SPL = inp_storage_subdir
612 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
613 <
614 <        jdl_fname = job.jdlFilename()
615 <        jdl = open(jdl_fname, 'w')
623 <        jdl.write(title)
624 <
625 <        script = job.scriptFilename()
626 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
627 <        jdl.write(jt_string)
628 <
629 <        ### only one .sh  JDL has arguments:
630 <        firstEvent = common.jobDB.firstEvent(nj)
631 <        maxEvents = common.jobDB.maxEvents(nj)
632 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
633 <
634 <        inp_box = 'InputSandbox = { '
635 <        inp_box = inp_box + '"' + script + '",'
636 <
637 <        if inp_sandbox != None:
638 <            for fl in inp_sandbox:
639 <                inp_box = inp_box + ' "' + fl + '",'
640 <                pass
641 <            pass
642 <
643 <        #if common.use_jam:
644 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
645 <
646 <        # Marco (VERY TEMPORARY ML STUFF)
647 <        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
648 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
649 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
650 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
651 <                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
652 <        # End Marco
653 <
654 <        if (not jbt.additional_inbox_files == []):
655 <            inp_box = inp_box + ', '
656 <            for addFile in jbt.additional_inbox_files:
657 <                addFile = os.path.abspath(addFile)
658 <                inp_box = inp_box+' "'+addFile+'",'
659 <                pass
660 <
661 <        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
662 <        inp_box = inp_box + ' };\n'
663 <        jdl.write(inp_box)
611 >        inp_sandbox = jbt.inputSandbox(index)
612 >        #out_sandbox = jbt.outputSandbox(index)
613 >        """
614 >        [end] FIX-ME
615 >        """
616  
665        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
666        jdl.write('StdError      = "' + job.stderr() + '";\n')
617          
618 +        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
619 +        jt_string = ''
620          
621 <        if job.stdout() == job.stderr():
622 <          out_box = 'OutputSandbox = { "' + \
671 <                    job.stdout() + '", ".BrokerInfo",'
672 <        else:
673 <          out_box = 'OutputSandbox = { "' + \
674 <                    job.stdout() + '", "' + \
675 <                    job.stderr() + '", ".BrokerInfo",'
676 <
677 <        if int(self.return_data) == 1:
678 <            if out_sandbox != None:
679 <                for fl in out_sandbox:
680 <                    out_box = out_box + ' "' + fl + '",'
681 <                    pass
682 <                pass
683 <            pass
684 <                                                                                                                                                            
685 <        if out_box[-1] == ',' : out_box = out_box[:-1]
686 <        out_box = out_box + ' };'
687 <        jdl.write(out_box+'\n')
621 >        xml_fname = str(self.jobtypeName)+'.xml'
622 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
623  
624 +        #TaskName  
625 +        dir = string.split(common.work_space.topDir(), '/')
626 +        taskName = dir[len(dir)-2]
627 +  
628 +        to_write = ''
629  
630 <        req='Requirements = '
630 >        req=' '
631          req = req + jbt.getRequirements()
632 < #        ### if at least a CE exists ...
693 < #        if common.analisys_common_info['sites']:
694 < #           if common.analisys_common_info['sw_version']:
695 < #                req='Requirements = '
696 < #                req=req + 'Member("VO-cms-' + \
697 < #                     common.analisys_common_info['sw_version'] + \
698 < #                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
699 < #            if len(common.analisys_common_info['sites'])>0:
700 < #                req = req + ' && ('
701 < #                for i in range(len(common.analisys_common_info['sites'])):
702 < #                    req = req + 'other.GlueCEInfoHostName == "' \
703 < #                         + common.analisys_common_info['sites'][i] + '"'
704 < #                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
705 < #                        req = req + ' || '
706 < #            req = req + ')'
707 <        #### and USER REQUIREMENT
632 >
633          if self.EDG_requirements:
634 <            if (req == 'Requirement = '):
634 >            if (req == ' '):
635                  req = req + self.EDG_requirements
636              else:
637                  req = req +  ' && ' + self.EDG_requirements
713        #### FEDE #####
638          if self.EDG_ce_white_list:
639              ce_white_list = string.split(self.EDG_ce_white_list,',')
716            #print "req = ", req
640              for i in range(len(ce_white_list)):
641                  if i == 0:
642 <                    if (req == 'Requirement = '):
642 >                    if (req == ' '):
643                          req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
644                      else:
645                          req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
# Line 728 | Line 651 | class SchedulerEdg(Scheduler):
651          if self.EDG_ce_black_list:
652              ce_black_list = string.split(self.EDG_ce_black_list,',')
653              for ce in ce_black_list:
654 <                if (req == 'Requirement = '):
654 >                if (req == ' '):
655                      req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
656                  else:
657                      req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
658                  pass
736        ###############
659          if self.EDG_clock_time:
660 <            if (req == 'Requirement = '):
660 >            if (req == ' '):
661                  req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
662              else:
663                  req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
664  
665          if self.EDG_cpu_time:
666 <            if (req == 'Requirement = '):
666 >            if (req == ' '):
667                  req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
668              else:
669                  req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
670 <        if (req != 'Requirement = '):
749 <            req = req + ';\n'
750 <            jdl.write(req)
751 <                                                                                                                                                            
752 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
753 <
670 >                                                                                          
671          if ( self.EDG_retry_count ):              
672 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
672 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
673 >            pass
674 >
675 >        if ( self.EDG_shallow_retry_count ):              
676 >            to_write = to_write + 'ShallowRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
677 >            pass
678 >
679 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
680 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
681 >
682 >        #TaskName  
683 >        dir = string.split(common.work_space.topDir(), '/')
684 >        taskName = dir[len(dir)-2]
685 >
686 >        xml.write(str(title))
687 >        #xml.write('<task name="' +str(taskName)+'" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache">\n')
688 >
689 >        #xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + '" task_info="' + os.path.expandvars('X509_USER_PROXY') + '">\n')
690 >        x509_cmd = 'ls /tmp/x509up_u`id -u`'
691 >        x509=runCommand(x509_cmd).strip()
692 >        xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + ' task_info="' + str(x509) + '">\n')
693 >        xml.write(jt_string)
694 >        
695 >        if (to_write != ''):
696 >            xml.write('<extraTags\n')
697 >            xml.write(to_write)
698 >            xml.write('/>\n')
699              pass
700  
701 <        jdl.close()
701 >        xml.write('<iterator>\n')
702 >        xml.write('\t<iteratorRule name="ITR1">\n')
703 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
704 >        xml.write('\t</iteratorRule>\n')
705 >        xml.write('\t<iteratorRule name="ITR2">\n')
706 >        for arg in argsList:
707 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
708 >            pass
709 >        xml.write('\t</iteratorRule>\n')
710 >        #print jobList
711 >        xml.write('\t<iteratorRule name="ITR3">\n')
712 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
713 >        xml.write('\t</iteratorRule>\n')
714 >
715 >        '''
716 >        indy: here itr4
717 >        '''
718 >        
719 >        xml.write('<chain name="' +str(taskName)+'__ITR1_" scheduler="'+str(self.schedulerName)+'">\n')
720 >       # xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
721 >        xml.write(jt_string)
722 >
723 >        #executable
724 >
725 >        """
726 >        INDY
727 >        script depends on jobType: it should be probably get in a different way
728 >        """        
729 >        script = job.scriptFilename()
730 >        xml.write('<program>\n')
731 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
732 >        xml.write(jt_string)
733 >
734 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
735 >        xml.write('<program_types> crabjob </program_types>\n')
736 >        inp_box = common.work_space.pathForTgz() + 'job/' + jbt.scriptName + ','
737 >
738 >        if inp_sandbox != None:
739 >            for fl in inp_sandbox:
740 >                inp_box = inp_box + '' + fl + ','
741 >                pass
742 >            pass
743 >
744 > #        if (not jbt.additional_inbox_files == []):
745 > #            inp_box = inp_box + ','
746 > #            for addFile in jbt.additional_inbox_files:
747 > #                #addFile = os.path.abspath(addFile)
748 > #                inp_box = inp_box+''+addFile+','
749 > #                pass
750 >
751 >        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
752 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
753 >        xml.write(inp_box)
754 >        
755 >        base = jbt.name()
756 >        stdout = base + '__ITR3_.stdout'
757 >        stderr = base + '__ITR3_.stderr'
758 >        
759 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
760 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
761 >        
762 >
763 >        out_box = stdout + ',' + \
764 >                  stderr + ',.BrokerInfo,'
765 >
766 >        """
767 >        if int(self.return_data) == 1:
768 >            if out_sandbox != None:
769 >                for fl in out_sandbox:
770 >                    out_box = out_box + '' + fl + ','
771 >                    pass
772 >                pass
773 >            pass
774 >        """
775 >
776 >        """
777 >        INDY
778 >        something similar should be also done for infiles (if it makes sense!)
779 >        """
780 >        # Stuff to be returned _always_ via sandbox
781 >        for fl in jbt.output_file_sandbox:
782 >            out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
783 >            pass
784 >        pass
785 >
786 >        # via sandbox iif required return_data
787 >        if int(self.return_data) == 1:
788 >            for fl in jbt.output_file:
789 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
790 >                pass
791 >            pass
792 >
793 >        if out_box[-1] == ',' : out_box = out_box[:-1]
794 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
795 >        xml.write(out_box)
796 >
797 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
798 >
799 >        xml.write('</program>\n')
800 >        xml.write('</chain>\n')
801 >
802 >        xml.write('</iterator>\n')
803 >        xml.write('</task>\n')
804 >
805 >        xml.close()
806 >      
807 >
808          return
809  
810      def checkProxy(self):
# Line 763 | Line 812 | class SchedulerEdg(Scheduler):
812          Function to check the Globus proxy.
813          """
814          if (self.proxyValid): return
815 <        timeleft = -999
816 <        minTimeLeft=10 # in hours
817 <        cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
818 <        # SL Here I have to use os.system since the stupid command exit with >0 if no valid proxy is found
819 <        cmd_out = os.system(cmd)
820 <        if (cmd_out>0):
821 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 24h\n")
822 <            cmd = 'voms-proxy-init -voms cms -valid 100:00'
815 >
816 >        ### Just return if asked to do so
817 >        if (self.dontCheckProxy==1):
818 >            self.proxyValid=1
819 >            return
820 >
821 >        minTimeLeft=10*3600 # in seconds
822 >
823 >        minTimeLeftServer = 100 # in hours
824 >
825 >        mustRenew = 0
826 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
827 >        timeLeftServer = -999
828 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
829 >            mustRenew = 1
830 >        else:
831 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
832 >            if not timeLeftServer or not isInt(timeLeftServer):
833 >                mustRenew = 1
834 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
835 >                mustRenew = 1
836 >            pass
837 >        pass
838 >
839 >        if mustRenew:
840 >            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")
841 >            cmd = 'voms-proxy-init -voms '+self.VO
842 >            if self.group:
843 >                cmd += ':/'+self.VO+'/'+self.group
844 >            if self.role:
845 >                cmd += '/role='+self.role
846 >            cmd += ' -valid 192:00'
847              try:
848                  # SL as above: damn it!
849 +                common.logger.debug(10,cmd)
850                  out = os.system(cmd)
851                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
852              except:
853                  msg = "Unable to create a valid proxy!\n"
854                  raise CrabException(msg)
781            # cmd = 'grid-proxy-info -timeleft'
782            # cmd_out = runCommand(cmd,0,20)
855              pass
856 +
857 +        ## now I do have a voms proxy valid, and I check the myproxy server
858 +        renewProxy = 0
859 +        cmd = 'myproxy-info -d -s '+self.proxyServer
860 +        cmd_out = runCommand(cmd,0,20)
861 +        if not cmd_out:
862 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
863 +            renewProxy = 1
864 +        else:
865 +            # if myproxy exist but not long enough, renew
866 +            reTime = re.compile( r'timeleft: (\d+)' )
867 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
868 +            if reTime.match( cmd_out ):
869 +                time = reTime.search( cmd_out ).group(1)
870 +                if time < minTimeLeftServer:
871 +                    renewProxy = 1
872 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
873 +                pass
874 +            pass
875 +        
876 +        # if not, create one.
877 +        if renewProxy:
878 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
879 +            out = os.system(cmd)
880 +            if (out>0):
881 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
882 +            pass
883 +
884 +        # cache proxy validity
885          self.proxyValid=1
886          return
887  
888      def configOpt_(self):
889          edg_ui_cfg_opt = ' '
890          if self.edg_config:
891 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
891 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
892          if self.edg_config_vo:
893 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
893 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
894          return edg_ui_cfg_opt
895 +
896 +    def submitTout(self, list):
897 +        return 120
898 +
899 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines