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.7 by slacapra, Mon Jul 25 14:31:24 2005 UTC vs.
Revision 1.151 by mcinquil, Wed Nov 7 18:13:31 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):
13          Scheduler.__init__(self,"EDG")
14 +        self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
15 +                      "children_hist","children_num","children_states","condorId","condor_jdl", \
16 +                      "cpuTime","destination", "done_code","exit_code","expectFrom", \
17 +                      "expectUpdate","globusId","jdl","jobId","jobtype", \
18 +                      "lastUpdateTime","localId","location", "matched_jdl","network_server", \
19 +                      "owner","parent_job", "reason","resubmitted","rsl","seed",\
20 +                      "stateEnterTime","stateEnterTimes","subjob_failed", \
21 +                      "user tags" , "status" , "status_code","hierarchy"]
22          return
23  
24      def configure(self, cfg_params):
25  
26 <        try: self.edg_ui_cfg = cfg_params["EDG.rb_config"]
27 <        except KeyError: self.edg_ui_cfg = ''
26 >        # init BlackWhiteListParser
27 >        self.blackWhiteListParser = BlackWhiteListParser(cfg_params)
28  
29 <        try: self.edg_config = cfg_params["EDG.config"]
30 <        except KeyError: self.edg_config = ''
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_config_vo = cfg_params["EDG.config_vo"]
34 <        except KeyError: self.edg_config_vo = ''
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.LCG_version = cfg_params["EDG.lcg_version"]
46 <        except KeyError: self.LCG_version = '2'
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']
60 >        except KeyError:
61 >            self.EDG_ce_black_list  = ''
62 >
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 = 0
75 >
76 >        try:
77 >            self.copy_data = cfg_params["USER.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 = 'Error: 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 >        if ( int(self.return_data) == 1 and int(self.copy_data) == 1 ):
95 >           msg = 'Error: return_data and copy_data cannot be set both to 1\n'
96 >           msg = msg + 'Please modify return_data or copy_data value in your crab.cfg file\n'
97 >           raise CrabException(msg)
98 >
99 >        ########### FEDE FOR DBS2 ##############################
100 >        try:
101 >            self.publish_data = cfg_params["USER.publish_data"]
102 >            self.checkProxy()
103 >            if int(self.publish_data) == 1:
104 >                try:
105 >                    self.publish_data_name = cfg_params['USER.publish_data_name']
106 >                except KeyError:
107 >                    msg = "Error. The [USER] section does not have 'publish_data_name'"
108 >                    raise CrabException(msg)
109 >                try:
110 >                    tmp = runCommand("voms-proxy-info -identity")
111 >                    tmp = string.split(tmp,'/')
112 >                    reCN=re.compile(r'CN=')
113 >                    for t in tmp:
114 >                        if reCN.match(t):
115 >                            self.UserGridName=string.strip((t.replace('CN=','')).replace(' ',''))
116 >                        
117 >                    #self.UserGridName = string.strip(runCommand("voms-proxy-info -identity | awk -F\'CN\' \'{print $2$3$4}\' | tr -d \'=/ \'"))
118 >                except:
119 >                    msg = "Error. Problem with voms-proxy-info -identity command"
120 >                    raise CrabException(msg)
121 >        except KeyError: self.publish_data = 0
122 >
123 >        if ( int(self.copy_data) == 0 and int(self.publish_data) == 1 ):
124 >           msg = 'Warning: publish_data = 1 must be used with copy_data = 1\n'
125 >           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
126 >           common.logger.message(msg)
127 >           raise CrabException(msg)
128 >        #################################################
129 >
130 >        #try:
131 >        #    self.lfc_host = cfg_params['EDG.lfc_host']
132 >        #except KeyError:
133 >        #    msg = "Error. The [EDG] section does not have 'lfc_host' value"
134 >        #    msg = msg + " it's necessary to know the LFC host name"
135 >        #    common.logger.message(msg)
136 >        #    raise CrabException(msg)
137 >        #try:
138 >        #    self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
139 >        #except KeyError:
140 >        #    msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
141 >        #    msg = msg + " it's necessary to know the catalog type"
142 >        #    common.logger.message(msg)
143 >        #    raise CrabException(msg)
144 >        #try:
145 >        #    self.lfc_home = cfg_params['EDG.lfc_home']
146 >        #except KeyError:
147 >        #    msg = "Error. The [EDG] section does not have 'lfc_home' value"
148 >        #    msg = msg + " it's necessary to know the home catalog dir"
149 >        #    common.logger.message(msg)
150 >        #    raise CrabException(msg)
151 >      
152 >        #try:
153 >        #    self.register_data = cfg_params["USER.register_data"]
154 >        #    if int(self.register_data) == 1:
155 >        #        try:
156 >        #            self.LFN = cfg_params['USER.lfn_dir']
157 >        #        except KeyError:
158 >        #            msg = "Error. The [USER] section does not have 'lfn_dir' value"
159 >        #            msg = msg + " it's necessary for LCF registration"
160 >        #            common.logger.message(msg)
161 >        #            raise CrabException(msg)
162 >        #except KeyError: self.register_data = 0
163 >
164 >        #if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
165 >        #   msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
166 >        #   msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
167 >        #   common.logger.message(msg)
168 >        #   raise CrabException(msg)
169  
170          try: self.EDG_requirements = cfg_params['EDG.requirements']
171          except KeyError: self.EDG_requirements = ''
172  
173 +        try: self.EDG_addJdlParam = string.split(cfg_params['EDG.additional_jdl_parameters'],',')
174 +        except KeyError: self.EDG_addJdlParam = []
175 +
176          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
177          except KeyError: self.EDG_retry_count = ''
178  
179 <        try:
180 <            self.VO = cfg_params['EDG.virtual_organization']
36 <        except KeyError:
37 <            msg = 'EDG.virtual_organization is mandatory.'
38 <            raise CrabException(msg)
179 >        try: self.EDG_shallow_retry_count= cfg_params['EDG.shallow_retry_count']
180 >        except KeyError: self.EDG_shallow_retry_count = ''
181  
182 <        
183 <        #self.scripts_dir = common.bin_dir + '/scripts'
184 <        #self.cmd_prefix = 'edg'
185 <        #if common.LCG_version == '0' : self.cmd_prefix = 'dg'
182 >        try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
183 >        except KeyError: self.EDG_clock_time= ''
184 >
185 >        try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
186 >        except KeyError: self.EDG_cpu_time = ''
187  
188          # Add EDG_WL_LOCATION to the python path
189  
# Line 55 | Line 198 | class SchedulerEdg(Scheduler):
198          libPath=os.path.join(path, "lib", "python")
199          sys.path.append(libPath)
200  
201 <        self.checkProxy_()
201 >        try:
202 >            self._taskId = cfg_params['taskId']
203 >        except:
204 >            self._taskId = ''
205 >
206 >        try: self.jobtypeName = cfg_params['CRAB.jobtype']
207 >        except KeyError: self.jobtypeName = ''
208 >
209 >        try: self.schedulerName = cfg_params['CRAB.scheduler']
210 >        except KeyError: self.scheduler = ''
211 >
212          return
213      
214 +
215 +    def rb_configure(self, RB):
216 +        self.edg_config = ''
217 +        self.edg_config_vo = ''
218 +        self.rb_param_file = ''
219 +
220 +        edgConfig = EdgConfig(RB)
221 +        self.edg_config = edgConfig.config()
222 +        self.edg_config_vo = edgConfig.configVO()
223 +
224 +        if (self.edg_config and self.edg_config_vo != ''):
225 +            self.rb_param_file = 'RBconfig = "'+self.edg_config+'";\nRBconfigVO = "'+self.edg_config_vo+'";\n'
226 +            #print "rb_param_file = ", self.rb_param_file
227 +        return self.rb_param_file
228 +      
229 +
230 +    def sched_parameter(self):
231 +        """
232 +        Returns file with requirements and scheduler-specific parameters
233 +        """
234 +        index = int(common.jobDB.nJobs()) - 1
235 +        job = common.job_list[index]
236 +        jbt = job.type()
237 +        
238 +        lastBlock=-1
239 +        first = []
240 +        for n in range(common.jobDB.nJobs()):
241 +            currBlock=common.jobDB.block(n)
242 +            if (currBlock!=lastBlock):
243 +                lastBlock = currBlock
244 +                first.append(n)
245 +  
246 +        req = ''
247 +        req = req + jbt.getRequirements()
248 +    
249 +        if self.EDG_requirements:
250 +            if (req == ' '):
251 +                req = req + self.EDG_requirements
252 +            else:
253 +                req = req +  ' && ' + self.EDG_requirements
254 +
255 +        if self.EDG_ce_white_list:
256 +            ce_white_list = string.split(self.EDG_ce_white_list,',')
257 +            for i in range(len(ce_white_list)):
258 +                if i == 0:
259 +                    if (req == ' '):
260 +                        req = req + '((RegExp("' + string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
261 +                    else:
262 +                        req = req +  ' && ((RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
263 +                    pass
264 +                else:
265 +                    req = req +  ' || (RegExp("' +  string.strip(ce_white_list[i]) + '", other.GlueCEUniqueId))'
266 +            req = req + ')'
267 +        
268 +        if self.EDG_ce_black_list:
269 +            ce_black_list = string.split(self.EDG_ce_black_list,',')
270 +            for ce in ce_black_list:
271 +                if (req == ' '):
272 +                    req = req + '(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
273 +                else:
274 +                    req = req +  ' && (!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))'
275 +                pass
276 +        if self.EDG_clock_time:
277 +            if (req == ' '):
278 +                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
279 +            else:
280 +                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
281 +
282 +        if self.EDG_cpu_time:
283 +            if (req == ' '):
284 +                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
285 +            else:
286 +                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
287 +                
288 +        for i in range(len(first)): # Add loop DS
289 +            groupReq = req
290 +            self.param='sched_param_'+str(i)+'.clad'
291 +            param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
292 +
293 +            itr4=self.findSites_(first[i])
294 +            for arg in itr4:
295 +                groupReq = groupReq + ' && anyMatch(other.storage.CloseSEs, ('+str(arg)+'))'
296 +            param_file.write('Requirements = '+groupReq +';\n')  
297 +  
298 +            if (self.rb_param_file != ''):
299 +                param_file.write(self.rb_param_file)  
300 +
301 +            if len(self.EDG_addJdlParam):
302 +                for p in self.EDG_addJdlParam:
303 +                    param_file.write(p)
304 +
305 +            param_file.close()  
306 +
307 +
308      def wsSetupEnvironment(self):
309          """
310          Returns part of a job script which does scheduler-specific work.
311          """
312 <        txt = '\n'
313 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
314 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
315 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
316 <        txt += 'echo "CE = $CE"\n'
312 >        txt = ''
313 >        txt += '# strip arguments\n'
314 >        txt += 'echo "strip arguments"\n'
315 >        txt += 'args=("$@")\n'
316 >        txt += 'nargs=$#\n'
317 >        txt += 'shift $nargs\n'
318 >        txt += "# job number (first parameter for job wrapper)\n"
319 >        #txt += "NJob=$1\n"
320 >        txt += "NJob=${args[0]}\n"
321 >
322 >        txt += '# job identification to DashBoard \n'
323 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
324 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
325 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
326 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
327 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
328 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
329 >
330 >        txt += 'echo "middleware discovery: " \n'
331 >        txt += 'if [ $GRID3_APP_DIR ]; then\n'
332 >        txt += '    middleware=OSG \n'
333 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
334 >        txt += '        SyncCE="$OSG_JOB_CONTACT"; \n'
335 >        txt += '        echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
336 >        txt += '    else\n'
337 >        txt += '        echo "not reporting SyncCE";\n'
338 >        txt += '    fi\n';
339 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
340 >        txt += '    echo ">>> middleware =$middleware" \n'
341 >        txt += 'elif [ $OSG_APP ]; then \n'
342 >        txt += '    middleware=OSG \n'
343 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
344 >        txt += '        SyncCE="$OSG_JOB_CONTACT"; \n'
345 >        txt += '        echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
346 >        txt += '    else\n'
347 >        txt += '        echo "not reporting SyncCE";\n'
348 >        txt += '    fi\n';
349 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
350 >        txt += '    echo ">>> middleware =$middleware" \n'
351 >        txt += 'elif [ $VO_CMS_SW_DIR ]; then \n'
352 >        txt += '    middleware=LCG \n'
353 >   #     txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
354 >        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
355 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
356 >        txt += '    echo ">>> middleware =$middleware" \n'
357 >        txt += 'else \n'
358 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
359 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
360 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
361 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
362 >        txt += '    exit 1 \n'
363 >        txt += 'fi \n'
364 >
365 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
366 >        
367 >        txt += '\n\n'
368 >
369 >        txt += 'export VO='+self.VO+'\n'
370 >        txt += 'if [ $middleware == LCG ]; then\n'
371 >        txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
372 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
373 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
374 >        txt += '    echo "CE = $CE"\n'
375 >        txt += 'elif [ $middleware == OSG ]; then \n'
376 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
377 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
378 >        txt += '    else \n'
379 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
380 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
381 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
382 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
383 >        txt += '        exit 1 \n'
384 >        txt += '    fi \n'
385 >        txt += 'fi \n'
386 >
387          return txt
388  
389 <    def loggingInfo(self, nj):
389 >    def wsCopyInput(self):
390          """
391 <        retrieve the logging info from logging and bookkeeping and return it
391 >        Copy input data from SE to WN    
392          """
393 <        id = common.jobDB.jobId(nj)
394 <        edg_ui_cfg_opt = ''
78 <        if self.edg_config:
79 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
80 <        cmd = 'edg-job-get-logging-info -v 2 ' + edg_ui_cfg_opt + id
81 <        print cmd
82 <        myCmd = os.popen(cmd)
83 <        cmd_out = myCmd.readlines()
84 <        myCmd.close()
85 <        return cmd_out
393 >        txt = ''
394 >        if not self.copy_input_data: return txt
395  
396 <    def listMatch(self, nj):
396 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
397 >        txt += 'if [ $middleware == OSG ]; then\n'
398 >        txt += '   #\n'
399 >        txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
400 >        txt += '   #\n'
401 >        txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
402 >        txt += 'elif [ $middleware == LCG ]; then \n'
403 >        txt += '   #\n'
404 >        txt += '   #   Copy Input Data from SE to this WN\n'
405 >        txt += '   #\n'
406 >        ### changed by georgia (put a loop copying more than one input files per jobs)          
407 >        txt += '   for input_file in $cur_file_list \n'
408 >        txt += '   do \n'
409 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
410 >        txt += '      copy_input_exit_status=$?\n'
411 >        txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
412 >        txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
413 >        txt += '         echo "Problems with copying to WN" \n'
414 >        txt += '      else \n'
415 >        txt += '         echo "input copied into WN" \n'
416 >        txt += '      fi \n'
417 >        txt += '   done \n'
418 >        ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
419 >        txt += '   for file in $cur_pu_list \n'
420 >        txt += '   do \n'
421 >        txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
422 >        txt += '      copy_input_pu_exit_status=$?\n'
423 >        txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
424 >        txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
425 >        txt += '         echo "Problems with copying pu to WN" \n'
426 >        txt += '      else \n'
427 >        txt += '         echo "input pu files copied into WN" \n'
428 >        txt += '      fi \n'
429 >        txt += '   done \n'
430 >        txt += '   \n'
431 >        txt += '   ### Check SCRATCH space available on WN : \n'
432 >        txt += '   df -h \n'
433 >        txt += 'fi \n'
434 >          
435 >        return txt
436 >
437 >    def wsCopyOutput(self):
438          """
439 <        Check the compatibility of available resources
439 >        Write a CopyResults part of a job script, e.g.
440 >        to copy produced output into a storage element.
441          """
442 <        jdl = common.job_list[nj].jdlFilename()
92 <        edg_ui_cfg_opt = ''
93 <        if self.edg_config:
94 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
95 <        if self.edg_config_vo:
96 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
97 <        cmd = 'edg-job-list-match ' + edg_ui_cfg_opt + jdl
98 <        myCmd = os.popen(cmd)
99 <        cmd_out = myCmd.readlines()
100 <        myCmd.close()
101 <        return self.parseListMatch_(cmd_out, jdl)
102 <
103 <    def parseListMatch_(self, out, jdl):
104 <        reComment = re.compile( r'^\**$' )
105 <        reEmptyLine = re.compile( r'^$' )
106 <        reVO = re.compile( r'Selected Virtual Organisation name.*' )
107 <        reCE = re.compile( r'CEId' )
108 <        reNO = re.compile( r'No Computing Element matching' )
109 <        reRB = re.compile( r'Connecting to host' )
110 <        next = 0
111 <        CEs=[]
112 <        Match=0
113 <        for line in out:
114 <            line = line.strip()
115 <            #print line
116 <            if reComment.match( line ):
117 <                next = 0
118 <                continue
119 <            if reEmptyLine.match(line):
120 <                continue
121 <            if reVO.match( line ):
122 <                VO =line.split()[-1]
123 <                common.logger.debug(5, 'VO           :'+VO)
124 <                pass
125 <            if reRB.match( line ):
126 <                RB =line.split()[3]
127 <                common.logger.debug(5, 'Using RB     :'+RB)
128 <                pass
129 <            if reCE.search( line ):
130 <                next = 1
131 <                continue
132 <            if next:
133 <                CE=line.split(':')[0]
134 <                CEs.append(CE)
135 <                common.logger.debug(5, 'Matched CE   :'+CE)
136 <                Match=Match+1
137 <                pass
138 <            if reNO.match( line ):
139 <                common.logger.debug(5,line)
140 <                self.noMatchFound_(jdl)
141 <                Match=0
142 <                pass
143 <        return Match
442 >        txt = '\n'
443  
444 <    def noMatchFound_(self, jdl):
445 <        reReq = re.compile( r'Requirements' )
446 <        reString = re.compile( r'"\S*"' )
447 <        f = file(jdl,'r')
448 <        for line in f.readlines():
449 <            line= line.strip()
450 <            if reReq.match(line):
451 <                for req in reString.findall(line):
452 <                    if re.search("VO",req):
453 <                        common.logger.message( "SW required: "+req)
454 <                        continue
455 <                    if re.search('"\d+',req):
456 <                        common.logger.message("Other req  : "+req)
457 <                        continue
458 <                    common.logger.message( "CE required: "+req)
459 <                break
460 <            pass
461 <        raise CrabException("No compatible resources found!")
462 <
463 <    def submit(self, nj):
464 <        """
465 <        Submit one EDG job.
466 <        """
467 <
468 <        jid = None
469 <        jdl = common.job_list[nj].jdlFilename()
470 <        id_tmp = tempfile.mktemp()
471 <        edg_ui_cfg_opt = ' '
472 <        if self.edg_config:
473 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
474 <        if self.edg_config_vo:
475 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
476 <        cmd = 'edg-job-submit -o ' + id_tmp + edg_ui_cfg_opt + jdl
477 <        cmd_out = runCommand(cmd)
478 <        if cmd_out != None:
479 <            idfile = open(id_tmp)
480 <            jid_line = idfile.readline()
481 <            while jid_line[0] == '#':
482 <                jid_line = idfile.readline()
483 <                pass
484 <            jid = string.strip(jid_line)
485 <            os.unlink(id_tmp)
444 >        txt += '#\n'
445 >        txt += '# COPY OUTPUT FILE TO SE\n'
446 >        txt += '#\n\n'
447 >
448 >        SE_PATH=''
449 >        if int(self.copy_data) == 1:
450 >            if self.SE:
451 >                txt += 'export SE='+self.SE+'\n'
452 >                txt += 'echo "SE = $SE"\n'
453 >            if self.SE_PATH:
454 >                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
455 >                SE_PATH=self.SE_PATH
456 >            if int(self.publish_data) == 1:
457 >                txt += '### publish_data = 1 so the SE path where to copy the output is: \n'
458 >                path_add = self.UserGridName + '/' + self.publish_data_name +'_${PSETHASH}/'
459 >                SE_PATH = SE_PATH + path_add
460 >            txt += 'export SE_PATH='+SE_PATH+'\n'
461 >            txt += 'echo "SE_PATH = $SE_PATH"\n'
462 >            
463 >            txt += 'echo ">>> Copy output files from WN = `hostname` to SE = $SE :"\n'
464 >            
465 >            txt += 'if [ $output_exit_status -eq 60302 ]; then\n'
466 >            txt += '    echo "--> No output file to copy to $SE"\n'
467 >            txt += '    copy_exit_status=$output_exit_status\n'
468 >            txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
469 >            txt += 'else\n'
470 >            txt += '    for out_file in $file_list ; do\n'
471 >            txt += '        echo "Trying to copy output file to $SE"\n'
472 >            txt += '        cmscp $out_file ${SE} ${SE_PATH} $out_file $middleware\n'
473 >            txt += '        copy_exit_status=$?\n'
474 >            txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
475 >            txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
476 >            txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
477 >            txt += '            echo "Problem copying $out_file to $SE $SE_PATH"\n'
478 >            txt += '            echo "StageOutExitStatus = $copy_exit_status " | tee -a $RUNTIME_AREA/$repo\n'
479 >            txt += '            copy_exit_status=60307\n'
480 >            txt += '        else\n'
481 >            txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
482 >            txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
483 >            txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
484 >            txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
485 >            txt += '        fi\n'
486 >            txt += '    done\n'
487 >            txt += '    if [ $copy_exit_status -ne 0 ]; then\n'
488 >            txt += '        SE=""\n'
489 >            txt += '        echo "SE = $SE"\n'
490 >            txt += '        SE_PATH=""\n'
491 >            txt += '        echo "SE_PATH = $SE_PATH"\n'
492 >            txt += '    fi\n'
493 >            txt += 'fi\n'
494 >            txt += 'exit_status=$copy_exit_status\n'
495              pass
496 <        return jid
496 >        return txt
497  
498 <    def queryStatus(self, id):
499 <        """ Query a status of the job with id """
500 <        cmd0 = 'edg-job-status '
501 <        cmd = cmd0 + id
498 >    def loggingInfo(self, id):
499 >        """
500 >        retrieve the logging info from logging and bookkeeping and return it
501 >        """
502 >        self.checkProxy()
503 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
504          cmd_out = runCommand(cmd)
505 <        if cmd_out == None:
196 <            common.logger.message('Error. No output from `'+cmd+'`')
197 <            return None
198 <        # parse output
199 <        status_prefix = 'Current Status:'
200 <        status_index = string.find(cmd_out, status_prefix)
201 <        if status_index == -1:
202 <            common.logger.message('Error. Bad output of `'+cmd0+'`:\n'+cmd_out)
203 <            return None
204 <        status = cmd_out[(status_index+len(status_prefix)):]
205 <        nl = string.find(status,'\n')
206 <        status = string.strip(status[0:nl])
207 <        return status
505 >        return cmd_out
506  
507      def queryDetailedStatus(self, id):
508          """ Query a detailed status of the job with id """
# Line 212 | Line 510 | class SchedulerEdg(Scheduler):
510          cmd_out = runCommand(cmd)
511          return cmd_out
512  
513 <    def getOutput(self, id):
514 <        """
217 <        Get output for a finished job with id.
218 <        Returns the name of directory with results.
219 <        """
513 >    def findSites_(self, n):
514 >        itr4 =[]
515  
516 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
222 <        cmd_out = runCommand(cmd)
516 >        sites = common.jobDB.destination(n)
517  
518 <        # Determine the output directory name
519 <        dir = common.work_space.resDir()
226 <        dir += os.getlogin()
227 <        dir += '_' + os.path.basename(id)
228 <        return dir
229 <
230 <    def cancel(self, id):
231 <        """ Cancel the EDG job with id """
232 <        cmd = 'edg-job-cancel --noint ' + id
233 <        cmd_out = runCommand(cmd)
234 <        return cmd_out
518 >        if len(sites)>0 and sites[0]=="":
519 >            return itr4
520  
521 <    def checkProxy_(self):
522 <        """
523 <        Function to check the Globus proxy.
521 >        itr = ''
522 >        if sites != [""]:#CarlosDaniele
523 >            ##Addedd Daniele
524 >            replicas = self.blackWhiteListParser.checkBlackList(sites,n)
525 >            if len(replicas)!=0:
526 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
527 >              
528 >            if len(replicas)==0:
529 >                itr = itr + 'target.GlueSEUniqueID=="NONE" '
530 >                #msg = 'No sites remaining that host any part of the requested data! Exiting... '
531 >                #raise CrabException(msg)
532 >            #####        
533 >           # for site in sites:
534 >            for site in replicas:
535 >                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
536 >                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
537 >            itr = itr[0:-4]
538 >            itr4.append( itr )
539 >        return itr4
540 >
541 >    def createXMLSchScript(self, nj, argsList):
542 >      
543 >        """
544 >        Create a XML-file for BOSS4.
545 >        """
546 >  #      job = common.job_list[nj]
547 >        """
548 >        INDY
549 >        [begin] FIX-ME:
550 >        I would pass jobType instead of job
551          """
552 <        cmd = 'grid-proxy-info -timeleft'
553 <        cmd_out = runCommand(cmd)
554 <        ok = 1
555 <        timeleft = -999
556 <        try: timeleft = int(cmd_out)
557 <        except ValueError: ok=0
246 <        except TypeError: ok=0
247 <        if timeleft < 1:  ok=0
248 <
249 <        if ok==0:
250 <            msg = 'No valid proxy found !\n'
251 <            msg += "Please do 'grid-proxy-init'."
252 <            raise CrabException(msg)
253 <        return
254 <    
255 <    def createJDL(self, nj):
552 >        index = nj - 1
553 >        job = common.job_list[index]
554 >        jbt = job.type()
555 >        
556 >        inp_sandbox = jbt.inputSandbox(index)
557 >        #out_sandbox = jbt.outputSandbox(index)
558          """
559 <        Create a JDL-file for EDG.
559 >        [end] FIX-ME
560          """
561  
260        job = common.job_list[nj]
261        jbt = job.type()
262 #        jbt.loadJobInfo()
263        inp_sandbox = jbt.inputSandbox(nj)
264        out_sandbox = jbt.outputSandbox(nj)
265        inp_storage_subdir = ''#jbt.inputStorageSubdir()
562          
563 <        title = '# This JDL was generated by '+\
268 <                common.prog_name+' (version '+common.prog_version_str+')\n'
563 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
564          jt_string = ''
565          
566 <        SPL = inp_storage_subdir
567 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
566 >        xml_fname = str(self.jobtypeName)+'.xml'
567 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
568  
569 <        jdl_fname = job.jdlFilename()
570 <        jdl = open(jdl_fname, 'w')
571 <        jdl.write(title)
569 >        #TaskName  
570 >        dir = string.split(common.work_space.topDir(), '/')
571 >        taskName = dir[len(dir)-2]
572 >  
573 >        to_write = ''
574 >
575 >        req=' '
576 >        req = req + jbt.getRequirements()
577 >
578 >        if self.EDG_requirements:
579 >            if (req == ' '):
580 >                req = req + self.EDG_requirements
581 >            else:
582 >                req = req +  ' && ' + self.EDG_requirements
583 >        if self.EDG_ce_white_list:
584 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
585 >            for i in range(len(ce_white_list)):
586 >                if i == 0:
587 >                    if (req == ' '):
588 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
589 >                    else:
590 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
591 >                    pass
592 >                else:
593 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
594 >            req = req + ')'
595 >        
596 >        if self.EDG_ce_black_list:
597 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
598 >            for ce in ce_black_list:
599 >                if (req == ' '):
600 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
601 >                else:
602 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
603 >                pass
604 >        if self.EDG_clock_time:
605 >            if (req == ' '):
606 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
607 >            else:
608 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
609 >
610 >        if self.EDG_cpu_time:
611 >            if (req == ' '):
612 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
613 >            else:
614 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
615 >                                                                                          
616 >        if ( self.EDG_retry_count ):              
617 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
618 >            pass
619  
620 <        script = job.scriptFilename()
621 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
622 <        jdl.write(jt_string)
620 >        if ( self.EDG_shallow_retry_count ):              
621 >            to_write = to_write + 'ShallowRetryCount = "'+self.EDG_shallow_retry_count+'"\n'
622 >            pass
623  
624 <        inp_box = 'InputSandbox = { '
625 <        inp_box = inp_box + '"' + script + '",'
624 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
625 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
626 >
627 >        #TaskName  
628 >        dir = string.split(common.work_space.topDir(), '/')
629 >        taskName = dir[len(dir)-2]
630 >
631 >        xml.write(str(title))
632 >        #xml.write('<task name="' +str(taskName)+'" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache">\n')
633 >
634 >        #xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + '" task_info="' + os.path.expandvars('X509_USER_PROXY') + '">\n')
635 >        x509_cmd = 'ls /tmp/x509up_u`id -u`'
636 >        x509=runCommand(x509_cmd).strip()
637 >        xml.write('<task name="' +str(taskName)+ '" sub_path="' +common.work_space.pathForTgz() + 'share/.boss_cache"' + ' task_info="' + str(x509) + '">\n')
638 >        xml.write(jt_string)
639 >        
640 >        if (to_write != ''):
641 >            xml.write('<extraTags\n')
642 >            xml.write(to_write)
643 >            xml.write('/>\n')
644 >            pass
645 >
646 >        xml.write('<iterator>\n')
647 >        xml.write('\t<iteratorRule name="ITR1">\n')
648 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
649 >        xml.write('\t</iteratorRule>\n')
650 >        xml.write('\t<iteratorRule name="ITR2">\n')
651 >        for arg in argsList:
652 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
653 >            pass
654 >        xml.write('\t</iteratorRule>\n')
655 >        #print jobList
656 >        xml.write('\t<iteratorRule name="ITR3">\n')
657 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
658 >        xml.write('\t</iteratorRule>\n')
659 >
660 >        '''
661 >        indy: here itr4
662 >        '''
663 >        
664 >        xml.write('<chain name="' +str(taskName)+'__ITR1_" scheduler="'+str(self.schedulerName)+'">\n')
665 >       # xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
666 >        xml.write(jt_string)
667 >
668 >        #executable
669 >
670 >        """
671 >        INDY
672 >        script depends on jobType: it should be probably get in a different way
673 >        """        
674 >        script = job.scriptFilename()
675 >        xml.write('<program>\n')
676 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
677 >        xml.write(jt_string)
678 >
679 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
680 >        xml.write('<program_types> crabjob </program_types>\n')
681 >        inp_box = common.work_space.pathForTgz() + 'job/' + jbt.scriptName + ','
682  
683          if inp_sandbox != None:
684              for fl in inp_sandbox:
685 <                inp_box = inp_box + ' "' + fl + '",'
685 >                inp_box = inp_box + '' + fl + ','
686                  pass
687              pass
688  
689 <        #if common.use_jam:
690 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
691 <
692 <        for addFile in jbt.additional_inbox_files:
693 <            addFile = os.path.abspath(addFile)
694 <            inp_box = inp_box+' "'+addFile+'",'
297 <            pass
689 > #        if (not jbt.additional_inbox_files == []):
690 > #            inp_box = inp_box + ','
691 > #            for addFile in jbt.additional_inbox_files:
692 > #                #addFile = os.path.abspath(addFile)
693 > #                inp_box = inp_box+''+addFile+','
694 > #                pass
695  
696          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
697 <        inp_box = inp_box + ' };\n'
698 <        jdl.write(inp_box)
697 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
698 >        xml.write(inp_box)
699 >        
700 >        base = jbt.name()
701 >        stdout = base + '__ITR3_.stdout'
702 >        stderr = base + '__ITR3_.stderr'
703 >        
704 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
705 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
706 >        
707  
708 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
709 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
708 >        out_box = stdout + ',' + \
709 >                  stderr + ',.BrokerInfo,'
710  
711 <        #if common.flag_return_data :
712 <        #    for fl in job.outputDataFiles():
713 <        #        out_box = out_box + ' "' + fl + '",'
714 <        #        pass
715 <        #    pass
716 <
717 <        out_box = 'OutputSandbox = { '
718 <        if out_sandbox != None:
719 <            for fl in out_sandbox:
720 <                out_box = out_box + ' "' + fl + '",'
711 >        """
712 >        if int(self.return_data) == 1:
713 >            if out_sandbox != None:
714 >                for fl in out_sandbox:
715 >                    out_box = out_box + '' + fl + ','
716 >                    pass
717 >                pass
718 >            pass
719 >        """
720 >
721 >        """
722 >        INDY
723 >        something similar should be also done for infiles (if it makes sense!)
724 >        """
725 >        # Stuff to be returned _always_ via sandbox
726 >        for fl in jbt.output_file_sandbox:
727 >            out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
728 >            pass
729 >        pass
730 >
731 >        # via sandbox iif required return_data
732 >        if int(self.return_data) == 1:
733 >            for fl in jbt.output_file:
734 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
735                  pass
736              pass
737  
738          if out_box[-1] == ',' : out_box = out_box[:-1]
739 <        out_box = out_box + ' };'
740 <        jdl.write(out_box+'\n')
739 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
740 >        xml.write(out_box)
741 >
742 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
743  
744 <        # If CloseCE is used ...
745 <        #if common.flag_usecloseCE and job.inputDataFiles():
325 <        #    indata = 'InputData = { '
326 <        #    for fl in job.inputDataFiles():
327 <        #       indata = indata + ' "lfn:' + SPL + fl + '",'
328 <        #    if indata[-1] == ',' : indata = indata[:-1]
329 <        #    indata = indata + ' };'
330 <        #    jdl.write(indata+'\n')
331 <        #    jdl.write('DataAccessProtocol = { "gsiftp" };\n')
332 <
333 <        if common.analisys_common_info['sites']:
334 <           if common.analisys_common_info['sw_version']:
335 <
336 <             req='Requirements = '
337 <         ### First ORCA version
338 <             req=req + 'Member("VO-cms-' + \
339 <                 common.analisys_common_info['sw_version'] + \
340 <                 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
341 <         ## then sites
342 <             if len(common.analisys_common_info['sites'])>0:
343 <               req = req + ' && ('
344 <             for i in range(len(common.analisys_common_info['sites'])):
345 <                req = req + 'other.GlueCEInfoHostName == "' \
346 <                      + common.analisys_common_info['sites'][i] + '"'
347 <                if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
348 <                    req = req + ' || '
349 <             req = req + ')'
350 <         ## then user requirement
351 <             if self.EDG_requirements:
352 <               req = req +  ' && ' + self.EDG_requirements
353 <             req = req + ';\n'
354 <        jdl.write(req)
744 >        xml.write('</program>\n')
745 >        xml.write('</chain>\n')
746  
747 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
747 >        xml.write('</iterator>\n')
748 >        xml.write('</task>\n')
749  
750 <        if ( self.EDG_retry_count ):              
751 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
750 >        xml.close()
751 >      
752 >
753 >        return
754 >
755 >    def checkProxy(self):
756 >        """
757 >        Function to check the Globus proxy.
758 >        """
759 >        if (self.proxyValid): return
760 >
761 >        ### Just return if asked to do so
762 >        if (self.dontCheckProxy==1):
763 >            self.proxyValid=1
764 >            return
765 >
766 >        minTimeLeft=10*3600 # in seconds
767 >
768 >        minTimeLeftServer = 100 # in hours
769 >
770 >        mustRenew = 0
771 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
772 >        timeLeftServer = -999
773 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
774 >            mustRenew = 1
775 >        else:
776 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
777 >            if not timeLeftServer or not isInt(timeLeftServer):
778 >                mustRenew = 1
779 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
780 >                mustRenew = 1
781 >            pass
782 >        pass
783 >
784 >        if mustRenew:
785 >            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")
786 >            cmd = 'voms-proxy-init -voms '+self.VO
787 >            if self.group:
788 >                cmd += ':/'+self.VO+'/'+self.group
789 >            if self.role:
790 >                cmd += '/role='+self.role
791 >            cmd += ' -valid 192:00'
792 >            try:
793 >                # SL as above: damn it!
794 >                common.logger.debug(10,cmd)
795 >                out = os.system(cmd)
796 >                if (out>0): raise CrabException("Unable to create a valid proxy!\n")
797 >            except:
798 >                msg = "Unable to create a valid proxy!\n"
799 >                raise CrabException(msg)
800              pass
801  
802 <        jdl.close()
802 >        ## now I do have a voms proxy valid, and I check the myproxy server
803 >        renewProxy = 0
804 >        cmd = 'myproxy-info -d -s '+self.proxyServer
805 >        cmd_out = runCommand(cmd,0,20)
806 >        if not cmd_out:
807 >            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
808 >            renewProxy = 1
809 >        else:
810 >            ## minimum time: 5 days
811 >            minTime = 4 * 24 * 3600
812 >            ## regex to extract the right information
813 >            myproxyRE = re.compile("timeleft: (?P<hours>[\\d]*):(?P<minutes>[\\d]*):(?P<seconds>[\\d]*)")
814 >            for row in cmd_out.split("\n"):
815 >                g = myproxyRE.search(row)
816 >                if g:
817 >                    hours = g.group("hours")
818 >                    minutes = g.group("minutes")
819 >                    seconds = g.group("seconds")
820 >                    timeleft = int(hours)*3600 + int(minutes)*60 + int(seconds)
821 >                    if timeleft < minTime:
822 >                        renewProxy = 1
823 >                        common.logger.message('Your proxy will expire in:\n\t'+hours+' hours '+minutes+' minutes '+seconds+' seconds\n')
824 >                        common.logger.message('Need to renew it:')
825 >                    pass
826 >                pass
827 >            pass
828 >        
829 >        # if not, create one.
830 >        if renewProxy:
831 >            cmd = 'myproxy-init -d -n -s '+self.proxyServer
832 >            out = os.system(cmd)
833 >            if (out>0):
834 >                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
835 >            pass
836 >
837 >        # cache proxy validity
838 >        self.proxyValid=1
839          return
840 +
841 +    def configOpt_(self):
842 +        edg_ui_cfg_opt = ' '
843 +        if self.edg_config:
844 +            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
845 +        if self.edg_config_vo:
846 +            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
847 +        return edg_ui_cfg_opt
848 +
849 +    def tOut(self, list):
850 +        return 120
851 +
852 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines