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.79 by slacapra, Wed Aug 16 16:49:51 2006 UTC

# Line 2 | Line 2 | from Scheduler import Scheduler
2   from crab_logger import Logger
3   from crab_exceptions import *
4   from crab_util import *
5 + from EdgConfig import *
6   import common
7  
8 < import os, sys, tempfile
8 > import os, sys, time
9  
10   class SchedulerEdg(Scheduler):
11      def __init__(self):
12          Scheduler.__init__(self,"EDG")
13 +        self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
14 +                      "children_hist","children_num","children_states","condorId","condor_jdl", \
15 +                      "cpuTime","destination", "done_code","exit_code","expectFrom", \
16 +                      "expectUpdate","globusId","jdl","jobId","jobtype", \
17 +                      "lastUpdateTime","localId","location", "matched_jdl","network_server", \
18 +                      "owner","parent_job", "reason","resubmitted","rsl","seed",\
19 +                      "stateEnterTime","stateEnterTimes","subjob_failed", \
20 +                      "user tags" , "status" , "status_code","hierarchy"]
21          return
22  
23      def configure(self, cfg_params):
24  
25 <        try: self.edg_ui_cfg = cfg_params["EDG.rb_config"]
26 <        except KeyError: self.edg_ui_cfg = ''
27 <
28 <        try: self.edg_config = cfg_params["EDG.config"]
29 <        except KeyError: self.edg_config = ''
25 >        try:
26 >            RB = cfg_params["EDG.rb"]
27 >            edgConfig = EdgConfig(RB)
28 >            self.edg_config = edgConfig.config()
29 >            self.edg_config_vo = edgConfig.configVO()
30 >        except KeyError:
31 >            self.edg_config = ''
32 >            self.edg_config_vo = ''
33  
34 <        try: self.edg_config_vo = cfg_params["EDG.config_vo"]
35 <        except KeyError: self.edg_config_vo = ''
34 >        try:
35 >            self.proxyServer = cfg_params["EDG.proxy_server"]
36 >        except KeyError:
37 >            self.proxyServer = 'myproxy.cern.ch'
38 >        common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
39  
40 +        try:
41 +            self.role = cfg_params["EDG.rb"]
42 +        except KeyError:
43 +            self.role = None
44 +            
45 +        try:
46 +            self.role = cfg_params["EDG.role"]
47 +        except KeyError:
48 +            self.role = None
49 +            
50          try: self.LCG_version = cfg_params["EDG.lcg_version"]
51          except KeyError: self.LCG_version = '2'
52  
# Line 31 | Line 56 | class SchedulerEdg(Scheduler):
56          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
57          except KeyError: self.EDG_retry_count = ''
58  
59 +        try:
60 +            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
61 +            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
62 +        except KeyError:
63 +            self.EDG_ce_black_list  = ''
64 +
65 +        try:
66 +            self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
67 +            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
68 +        except KeyError: self.EDG_ce_white_list = ''
69 +
70 +        try: self.VO = cfg_params['EDG.virtual_organization']
71 +        except KeyError: self.VO = 'cms'
72 +
73 +        try: self.return_data = cfg_params['USER.return_data']
74 +        except KeyError: self.return_data = 1
75 +
76 +        try:
77 +             self.copy_input_data = common.analisys_common_info['copy_input_data']
78 +             #print "self.copy_input_data = ", self.copy_input_data
79 +        except KeyError: self.copy_input_data = 0
80 +
81 +        try:
82 +            self.copy_data = cfg_params["USER.copy_data"]
83 +            if int(self.copy_data) == 1:
84 +                try:
85 +                    self.SE = cfg_params['USER.storage_element']
86 +                    self.SE_PATH = cfg_params['USER.storage_path']
87 +                except KeyError:
88 +                    msg = "Error. The [USER] section does not have 'storage_element'"
89 +                    msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
90 +                    common.logger.message(msg)
91 +                    raise CrabException(msg)
92 +        except KeyError: self.copy_data = 0
93 +
94 +        if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
95 +           msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
96 +           msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
97 +           raise CrabException(msg)
98 +
99 +        try:
100 +            self.lfc_host = cfg_params['EDG.lfc_host']
101 +        except KeyError:
102 +            msg = "Error. The [EDG] section does not have 'lfc_host' value"
103 +            msg = msg + " it's necessary to know the LFC host name"
104 +            common.logger.message(msg)
105 +            raise CrabException(msg)
106          try:
107 <            self.VO = cfg_params['EDG.virtual_organization']
107 >            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
108          except KeyError:
109 <            msg = 'EDG.virtual_organization is mandatory.'
109 >            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
110 >            msg = msg + " it's necessary to know the catalog type"
111 >            common.logger.message(msg)
112              raise CrabException(msg)
113 +        try:
114 +            self.lfc_home = cfg_params['EDG.lfc_home']
115 +        except KeyError:
116 +            msg = "Error. The [EDG] section does not have 'lfc_home' value"
117 +            msg = msg + " it's necessary to know the home catalog dir"
118 +            common.logger.message(msg)
119 +            raise CrabException(msg)
120 +      
121 +        try:
122 +            self.register_data = cfg_params["USER.register_data"]
123 +            if int(self.register_data) == 1:
124 +                try:
125 +                    self.LFN = cfg_params['USER.lfn_dir']
126 +                except KeyError:
127 +                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
128 +                    msg = msg + " it's necessary for LCF registration"
129 +                    common.logger.message(msg)
130 +                    raise CrabException(msg)
131 +        except KeyError: self.register_data = 0
132 +
133 +        if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
134 +           msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
135 +           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
136 +           common.logger.message(msg)
137 +           raise CrabException(msg)
138  
139 <        
140 <        #self.scripts_dir = common.bin_dir + '/scripts'
141 <        #self.cmd_prefix = 'edg'
142 <        #if common.LCG_version == '0' : self.cmd_prefix = 'dg'
139 >        try: self.EDG_requirements = cfg_params['EDG.requirements']
140 >        except KeyError: self.EDG_requirements = ''
141 >                                                                                                                                                            
142 >        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
143 >        except KeyError: self.EDG_retry_count = ''
144 >                                                                                                                                                            
145 >        try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
146 >        except KeyError: self.EDG_clock_time= ''
147 >                                                                                                                                                            
148 >        try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
149 >        except KeyError: self.EDG_cpu_time = ''
150  
151          # Add EDG_WL_LOCATION to the python path
152  
# Line 55 | Line 161 | class SchedulerEdg(Scheduler):
161          libPath=os.path.join(path, "lib", "python")
162          sys.path.append(libPath)
163  
164 <        self.checkProxy_()
164 >        self.proxyValid=0
165 >
166 >        try:
167 >            self._taskId = cfg_params['taskId']
168 >        except:
169 >            self._taskId = ''
170 >
171          return
172      
173 +
174 +    def sched_parameter(self):
175 +        """
176 +        Returns file with scheduler-specific parameters
177 +        """
178 +      
179 +        if (self.edg_config and self.edg_config_vo != ''):
180 +            self.param='sched_param.clad'
181 +            param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
182 +            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
183 +            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
184 +            param_file.close()  
185 +            return 1
186 +        else:
187 +            return 0
188 +
189      def wsSetupEnvironment(self):
190          """
191          Returns part of a job script which does scheduler-specific work.
192          """
193 <        txt = '\n'
194 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
195 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
196 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
197 <        txt += 'echo "CE = $CE"\n'
193 >        txt = ''
194 >        txt += '# strip arguments\n'
195 >        txt += 'echo "strip arguments"\n'
196 >        txt += 'args=("$@")\n'
197 >        txt += 'nargs=$#\n'
198 >        txt += 'shift $nargs\n'
199 >        txt += "# job number (first parameter for job wrapper)\n"
200 >        #txt += "NJob=$1\n"
201 >        txt += "NJob=${args[0]}\n"
202 >
203 >        txt += '# job identification to DashBoard \n'
204 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
205 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
206 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
207 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
208 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
209 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
210 >
211 >        txt += 'echo "middleware discovery " \n'
212 >        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
213 >        txt += '    middleware=LCG \n'
214 >        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
215 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
216 >        txt += '    echo "middleware =$middleware" \n'
217 >        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
218 >        txt += '    middleware=OSG \n'
219 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
220 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
221 >        txt += '    echo "middleware =$middleware" \n'
222 >        txt += 'elif [ $OSG_APP ]; then \n'
223 >        txt += '    middleware=OSG \n'
224 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
225 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
226 >        txt += '    echo "middleware =$middleware" \n'
227 >        txt += 'else \n'
228 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
229 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
230 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
231 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
232 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
233 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
234 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
235 >        txt += '    exit 1 \n'
236 >        txt += 'fi \n'
237 >
238 >        txt += '# report first time to DashBoard \n'
239 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
240 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
241 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
242 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
243 >        
244 >        txt += '\n\n'
245 >
246 >        if int(self.copy_data) == 1:
247 >           if self.SE:
248 >              txt += 'export SE='+self.SE+'\n'
249 >              txt += 'echo "SE = $SE"\n'
250 >           if self.SE_PATH:
251 >              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
252 >              txt += 'export SE_PATH='+self.SE_PATH+'\n'
253 >              txt += 'echo "SE_PATH = $SE_PATH"\n'
254 >
255 >        txt += 'export VO='+self.VO+'\n'
256 >        ### FEDE: add some line for LFC catalog setting
257 >        txt += 'if [ $middleware == LCG ]; then \n'
258 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
259 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
260 >        txt += '    fi\n'
261 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
262 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
263 >        txt += '    fi\n'
264 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
265 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
266 >        txt += '    fi\n'
267 >        txt += 'elif [ $middleware == OSG ]; then\n'
268 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
269 >        txt += 'fi\n'
270 >        #####
271 >        if int(self.register_data) == 1:
272 >           txt += 'if [ $middleware == LCG ]; then \n'
273 >           txt += '    export LFN='+self.LFN+'\n'
274 >           txt += '    lfc-ls $LFN\n'
275 >           txt += '    result=$?\n'
276 >           txt += '    echo $result\n'
277 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
278 >           txt += '    if [ $result != 0 ]; then\n'
279 >           txt += '       lfc-mkdir $LFN\n'
280 >           txt += '       result=$?\n'
281 >           txt += '       echo $result\n'
282 >           txt += '    fi\n'
283 >           txt += 'elif [ $middleware == OSG ]; then\n'
284 >           txt += '    echo " Files registration to be implemented for OSG"\n'
285 >           txt += 'fi\n'
286 >           txt += '\n'
287 >
288 >           if self.VO:
289 >              txt += 'export VO='+self.VO+'\n'
290 >           if self.LFN:
291 >              txt += 'if [ $middleware == LCG ]; then \n'
292 >              txt += '    export LFN='+self.LFN+'\n'
293 >              txt += 'fi\n'
294 >              txt += '\n'
295 >
296 >        txt += 'if [ $middleware == LCG ]; then\n'
297 >        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
298 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
299 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
300 >        txt += '    echo "CE = $CE"\n'
301 >        txt += 'elif [ $middleware == OSG ]; then \n'
302 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
303 > #        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
304 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print ${args[0]}}\'` \n'
305 >        txt += '    else \n'
306 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
307 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
308 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
309 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
310 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
311 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
312 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
313 >        txt += '        exit 1 \n'
314 >        txt += '    fi \n'
315 >        txt += 'fi \n'
316 >
317 >        return txt
318 >
319 >    def wsCopyInput(self):
320 >        """
321 >        Copy input data from SE to WN    
322 >        """
323 >        txt = ''
324 >        try:
325 >            self.copy_input_data = common.analisys_common_info['copy_input_data']
326 >            #print "self.copy_input_data = ", self.copy_input_data
327 >        except KeyError: self.copy_input_data = 0
328 >        if int(self.copy_input_data) == 1:
329 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
330 >           txt += 'if [ $middleware == OSG ]; then\n'
331 >           txt += '   #\n'
332 >           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
333 >           txt += '   #\n'
334 >           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
335 >           txt += 'elif [ $middleware == LCG ]; then \n'
336 >           txt += '   #\n'
337 >           txt += '   #   Copy Input Data from SE to this WN\n'
338 >           txt += '   #\n'
339 > ### changed by georgia (put a loop copying more than one input files per jobs)          
340 >           txt += '   for input_file in $cur_file_list \n'
341 >           txt += '   do \n'
342 >           #### FEDE
343 >           #txt += '      echo "which lcg-cp" \n'
344 >           #txt += '      which lcg-cp \n'
345 >           #########
346 >           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
347 >           txt += '      copy_input_exit_status=$?\n'
348 >           txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
349 >           txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
350 >           txt += '         echo "Problems with copying to WN" \n'
351 >           txt += '      else \n'
352 >           txt += '         echo "input copied into WN" \n'
353 >           txt += '      fi \n'
354 >           txt += '   done \n'
355 > ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
356 >           txt += '   for file in $cur_pu_list \n'
357 >           txt += '   do \n'
358 >           #### FEDE
359 >           #txt += '      echo "which lcg-cp" \n'
360 >           #txt += '      which lcg-cp \n'
361 >           #########
362 >           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
363 >           txt += '      copy_input_pu_exit_status=$?\n'
364 >           txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
365 >           txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
366 >           txt += '         echo "Problems with copying pu to WN" \n'
367 >           txt += '      else \n'
368 >           txt += '         echo "input pu files copied into WN" \n'
369 >           txt += '      fi \n'
370 >           txt += '   done \n'
371 >           txt += '   \n'
372 >           txt += '   ### Check SCRATCH space available on WN : \n'
373 >           txt += '   df -h \n'
374 >           txt += 'fi \n'
375 >          
376 >        return txt
377 >
378 >    def wsCopyOutput(self):
379 >        """
380 >        Write a CopyResults part of a job script, e.g.
381 >        to copy produced output into a storage element.
382 >        """
383 >        txt = ''
384 >        if int(self.copy_data) == 1:
385 >           txt += '#\n'
386 >           txt += '#   Copy output to SE = $SE\n'
387 >           txt += '#\n'
388 >           #txt += 'if [ $exe_result -eq 0 ]; then\n'
389 >           txt += '    if [ $middleware == OSG ]; then\n'
390 >           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
391 >           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
392 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
393 >           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
394 >           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
395 >           txt += '    fi \n'
396 >           txt += '    for out_file in $file_list ; do\n'
397 >           txt += '        echo "Trying to copy output file to $SE using lcg-cp"\n'
398 >           if common.logger.debugLevel() >= 5:
399 >               txt += '        echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
400 >               txt += '        exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
401 >           else:
402 >               txt += '        echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
403 >               txt += '        exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
404 >           txt += '        copy_exit_status=$?\n'
405 >           txt += '        echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
406 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
407 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
408 >           txt += '            echo "Possible problem with SE = $SE"\n'
409 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
410 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
411 >           txt += '            echo "lcg-cp failed.  For verbose lcg-cp output, use command line option -debug 5."\n'
412 >           txt += '            echo "lcg-cp failed, attempting srmcp"\n'
413 >           txt += '            echo "mkdir -p $HOME/.srmconfig"\n'
414 >           txt += '            mkdir -p $HOME/.srmconfig\n'
415 >           txt += '            if [ $middleware == LCG ]; then\n'
416 >           txt += '               echo "srmcp -retry_num 5 -retry_timeout 480000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
417 >           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 480000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
418 >           txt += '            elif [ $middleware == OSG ]; then\n'
419 >           txt += '               echo "srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
420 >           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
421 >           txt += '            fi \n'
422 >           txt += '            copy_exit_status=$?\n'
423 >           txt += '            echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
424 >           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
425 >           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
426 >           txt += '               echo "Problems with SE = $SE"\n'
427 >           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
428 >           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
429 >           txt += '               echo "lcg-cp and srm failed"\n'
430 >           txt += '               echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
431 >           txt += '            else\n'
432 >           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
433 >           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
434 >           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
435 >           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
436 >           txt += '               echo "srmcp succeeded"\n'
437 >           txt += '            fi\n'
438 >           txt += '        else\n'
439 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
440 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
441 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
442 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
443 >           txt += '            echo "lcg-cp succeeded"\n'
444 >           txt += '         fi\n'
445 >           txt += '     done\n'
446 >           #txt += 'fi\n'
447 >        return txt
448 >
449 >    def wsRegisterOutput(self):
450 >        """
451 >        Returns part of a job script which does scheduler-specific work.
452 >        """
453 >
454 >        txt = ''
455 >        if int(self.register_data) == 1:
456 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
457 >           txt += 'if [ $middleware == OSG ]; then\n'
458 >           txt += '   #\n'
459 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
460 >           txt += '   #\n'
461 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
462 >           txt += 'elif [ $middleware == LCG ]; then \n'
463 >           txt += '#\n'
464 >           txt += '#  Register output to LFC\n'
465 >           txt += '#\n'
466 >           #txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
467 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
468 >           txt += '      for out_file in $file_list ; do\n'
469 >           txt += '         echo "Trying to register the output file into LFC"\n'
470 >           #### FEDE
471 >           #txt += '         echo "which lcg-rf" \n'
472 >           #txt += '         which lcg-rf \n'
473 >           #########
474 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
475 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
476 >           txt += '         register_exit_status=$?\n'
477 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
478 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
479 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
480 >           txt += '            echo "Problems with the registration to LFC" \n'
481 >           txt += '            echo "Try with srm protocol" \n'
482 >           #### FEDE
483 >           #txt += '            echo "which lcg-rf" \n'
484 >           #txt += '            which lcg-rf \n'
485 >           #########
486 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
487 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
488 >           txt += '            register_exit_status=$?\n'
489 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
490 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
491 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
492 >           txt += '               echo "Problems with the registration into LFC" \n'
493 >           txt += '            fi \n'
494 >           txt += '         else \n'
495 >           txt += '            echo "output registered to LFC"\n'
496 >           txt += '         fi \n'
497 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
498 >           txt += '      done\n'
499 >           #txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
500 >           txt += '   else \n'
501 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
502 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
503 >           txt += '      for out_file in $file_list ; do\n'
504 >           #### FEDE
505 >           #txt += '         echo "which lcg-cr" \n'
506 >           #txt += '         which lcg-cr \n'
507 >           #########
508 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1" \n'
509 >           txt += '         lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1 \n'
510 >           txt += '         register_exit_status=$?\n'
511 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
512 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
513 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
514 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
515 >           txt += '         else \n'
516 >           txt += '            echo "The program was successfully executed"\n'
517 >           txt += '            echo "SE = $CLOSE_SE"\n'
518 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
519 >           txt += '         fi \n'
520 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
521 >           txt += '      done\n'
522 >           #txt += '   else\n'
523 >           #txt += '      echo "Problem with the executable"\n'
524 >           txt += '   fi \n'
525 >           txt += '   exit_status=$register_exit_status\n'
526 >           txt += 'fi \n'
527          return txt
528  
529 <    def loggingInfo(self, nj):
529 >    def loggingInfo(self, id):
530          """
531          retrieve the logging info from logging and bookkeeping and return it
532          """
533 <        id = common.jobDB.jobId(nj)
534 <        edg_ui_cfg_opt = ''
535 <        if self.edg_config:
536 <          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()
533 >        self.checkProxy()
534 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
535 >        #cmd_out = os.popen(cmd)
536 >        cmd_out = runCommand(cmd)
537          return cmd_out
538  
539      def listMatch(self, nj):
540          """
541          Check the compatibility of available resources
542          """
543 +        self.checkProxy()
544          jdl = common.job_list[nj].jdlFilename()
545 <        edg_ui_cfg_opt = ''
546 <        if self.edg_config:
547 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
548 <        if self.edg_config_vo:
549 <          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()
545 >        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
546 >        cmd_out = runCommand(cmd,0,45)
547 >        if not cmd_out:
548 >            raise CrabException("ERROR: "+cmd+" failed!")
549 >
550          return self.parseListMatch_(cmd_out, jdl)
551  
552      def parseListMatch_(self, out, jdl):
553 +        """
554 +        Parse the f* output of edg-list-match and produce something sensible
555 +        """
556          reComment = re.compile( r'^\**$' )
557          reEmptyLine = re.compile( r'^$' )
558          reVO = re.compile( r'Selected Virtual Organisation name.*' )
559 <        reCE = re.compile( r'CEId' )
559 >        reLine = re.compile( r'.*')
560 >        reCE = re.compile( r'(.*:.*)')
561 >        reCEId = re.compile( r'CEId.*')
562          reNO = re.compile( r'No Computing Element matching' )
563          reRB = re.compile( r'Connecting to host' )
564          next = 0
565          CEs=[]
566          Match=0
567 <        for line in out:
568 <            line = line.strip()
567 >
568 >        #print out
569 >        lines = reLine.findall(out)
570 >
571 >        i=0
572 >        CEs=[]
573 >        for line in lines:
574 >            string.strip(line)
575              #print line
576 <            if reComment.match( line ):
577 <                next = 0
578 <                continue
579 <            if reEmptyLine.match(line):
120 <                continue
576 >            if reNO.match( line ):
577 >                common.logger.debug(5,line)
578 >                return 0
579 >                pass
580              if reVO.match( line ):
581 <                VO =line.split()[-1]
582 <                common.logger.debug(5, 'VO           :'+VO)
581 >                VO =reVO.match( line ).group()
582 >                common.logger.debug(5,"VO "+VO)
583                  pass
584 +
585              if reRB.match( line ):
586 <                RB =line.split()[3]
587 <                common.logger.debug(5, 'Using RB     :'+RB)
586 >                RB = reRB.match(line).group()
587 >                common.logger.debug(5,"RB "+RB)
588                  pass
589 <            if reCE.search( line ):
590 <                next = 1
591 <                continue
592 <            if next:
593 <                CE=line.split(':')[0]
594 <                CEs.append(CE)
595 <                common.logger.debug(5, 'Matched CE   :'+CE)
596 <                Match=Match+1
137 <                pass
138 <            if reNO.match( line ):
139 <                common.logger.debug(5,line)
140 <                self.noMatchFound_(jdl)
141 <                Match=0
589 >
590 >            if reCEId.search( line ):
591 >                for lineCE in lines[i:-1]:
592 >                    if reCE.match( lineCE ):
593 >                        CE = string.strip(reCE.search(lineCE).group(1))
594 >                        CEs.append(CE.split(':')[0])
595 >                        pass
596 >                    pass
597                  pass
598 <        return Match
598 >            i=i+1
599 >            pass
600 >
601 >        common.logger.debug(5,"All CE :"+str(CEs))
602 >
603 >        sites = []
604 >        [sites.append(it) for it in CEs if not sites.count(it)]
605 >
606 >        common.logger.debug(5,"All Sites :"+str(sites))
607 >        common.logger.message("Matched Sites :"+str(sites))
608 >        return len(sites)
609  
610      def noMatchFound_(self, jdl):
611          reReq = re.compile( r'Requirements' )
# Line 166 | Line 631 | class SchedulerEdg(Scheduler):
631          Submit one EDG job.
632          """
633  
634 +        self.checkProxy()
635          jid = None
636          jdl = common.job_list[nj].jdlFilename()
637 <        id_tmp = tempfile.mktemp()
638 <        edg_ui_cfg_opt = ' '
173 <        if self.edg_config:
174 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
175 <        if self.edg_config_vo:
176 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
177 <        cmd = 'edg-job-submit -o ' + id_tmp + edg_ui_cfg_opt + jdl
637 >
638 >        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
639          cmd_out = runCommand(cmd)
640          if cmd_out != None:
641 <            idfile = open(id_tmp)
642 <            jid_line = idfile.readline()
182 <            while jid_line[0] == '#':
183 <                jid_line = idfile.readline()
184 <                pass
185 <            jid = string.strip(jid_line)
186 <            os.unlink(id_tmp)
641 >            reSid = re.compile( r'https.+' )
642 >            jid = reSid.search(cmd_out).group()
643              pass
644          return jid
645  
646 +    def resubmit(self, nj_list):
647 +        """
648 +        Prepare jobs to be submit
649 +        """
650 +        return
651 +
652 +    def getExitStatus(self, id):
653 +        return self.getStatusAttribute_(id, 'exit_code')
654 +
655      def queryStatus(self, id):
656 +        return self.getStatusAttribute_(id, 'status')
657 +
658 +    def queryDest(self, id):  
659 +        return self.getStatusAttribute_(id, 'destination')
660 +
661 +
662 +    def getStatusAttribute_(self, id, attr):
663          """ Query a status of the job with id """
664 <        cmd0 = 'edg-job-status '
665 <        cmd = cmd0 + id
666 <        cmd_out = runCommand(cmd)
667 <        if cmd_out == None:
668 <            common.logger.message('Error. No output from `'+cmd+'`')
669 <            return None
670 <        # parse output
671 <        status_prefix = 'Current Status:'
672 <        status_index = string.find(cmd_out, status_prefix)
673 <        if status_index == -1:
674 <            common.logger.message('Error. Bad output of `'+cmd0+'`:\n'+cmd_out)
664 >
665 >        self.checkProxy()
666 >        hstates = {}
667 >        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
668 >        # Bypass edg-job-status interfacing directly to C++ API
669 >        # Job attribute vector to retrieve status without edg-job-status
670 >        level = 0
671 >        # Instance of the Status class provided by LB API
672 >        jobStat = Status()
673 >        st = 0
674 >        jobStat.getStatus(id, level)
675 >        err, apiMsg = jobStat.get_error()
676 >        if err:
677 >            common.logger.debug(5,'Error caught' + apiMsg)
678              return None
679 <        status = cmd_out[(status_index+len(status_prefix)):]
680 <        nl = string.find(status,'\n')
681 <        status = string.strip(status[0:nl])
682 <        return status
679 >        else:
680 >            for i in range(len(self.states)):
681 >                # Fill an hash table with all information retrieved from LB API
682 >                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
683 >            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
684 >            return result
685  
686      def queryDetailedStatus(self, id):
687          """ Query a detailed status of the job with id """
# Line 218 | Line 695 | class SchedulerEdg(Scheduler):
695          Returns the name of directory with results.
696          """
697  
698 +        self.checkProxy()
699          cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
700          cmd_out = runCommand(cmd)
701  
702          # Determine the output directory name
703          dir = common.work_space.resDir()
704 <        dir += os.getlogin()
704 >        dir += os.environ['USER']
705          dir += '_' + os.path.basename(id)
706          return dir
707  
708      def cancel(self, id):
709          """ Cancel the EDG job with id """
710 +        self.checkProxy()
711          cmd = 'edg-job-cancel --noint ' + id
712          cmd_out = runCommand(cmd)
713          return cmd_out
714  
715 <    def checkProxy_(self):
237 <        """
238 <        Function to check the Globus proxy.
239 <        """
240 <        cmd = 'grid-proxy-info -timeleft'
241 <        cmd_out = runCommand(cmd)
242 <        ok = 1
243 <        timeleft = -999
244 <        try: timeleft = int(cmd_out)
245 <        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):
715 >    def createSchScript(self, nj):
716          """
717          Create a JDL-file for EDG.
718          """
719  
720          job = common.job_list[nj]
721          jbt = job.type()
262 #        jbt.loadJobInfo()
722          inp_sandbox = jbt.inputSandbox(nj)
723          out_sandbox = jbt.outputSandbox(nj)
724 <        inp_storage_subdir = ''#jbt.inputStorageSubdir()
724 >        inp_storage_subdir = ''
725          
726          title = '# This JDL was generated by '+\
727                  common.prog_name+' (version '+common.prog_version_str+')\n'
728          jt_string = ''
729 +
730 +
731          
732          SPL = inp_storage_subdir
733          if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
# Line 279 | Line 740 | class SchedulerEdg(Scheduler):
740          jdl.write('Executable = "' + os.path.basename(script) +'";\n')
741          jdl.write(jt_string)
742  
743 +        ### only one .sh  JDL has arguments:
744 +
745 +        ### Fabio
746 +        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
747          inp_box = 'InputSandbox = { '
748          inp_box = inp_box + '"' + script + '",'
749  
# Line 291 | Line 756 | class SchedulerEdg(Scheduler):
756          #if common.use_jam:
757          #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
758  
759 <        for addFile in jbt.additional_inbox_files:
760 <            addFile = os.path.abspath(addFile)
761 <            inp_box = inp_box+' "'+addFile+'",'
762 <            pass
759 >        # Marco (VERY TEMPORARY ML STUFF)
760 >        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
761 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
762 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
763 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
764 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
765 >        # End Marco
766 >
767 >        if (not jbt.additional_inbox_files == []):
768 >            inp_box = inp_box + ', '
769 >            for addFile in jbt.additional_inbox_files:
770 >                addFile = os.path.abspath(addFile)
771 >                inp_box = inp_box+' "'+addFile+'",'
772 >                pass
773  
774          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
775          inp_box = inp_box + ' };\n'
# Line 302 | Line 777 | class SchedulerEdg(Scheduler):
777  
778          jdl.write('StdOutput     = "' + job.stdout() + '";\n')
779          jdl.write('StdError      = "' + job.stderr() + '";\n')
780 <
781 <        #if common.flag_return_data :
782 <        #    for fl in job.outputDataFiles():
783 <        #        out_box = out_box + ' "' + fl + '",'
784 <        #        pass
785 <        #    pass
786 <
787 <        out_box = 'OutputSandbox = { '
788 <        if out_sandbox != None:
789 <            for fl in out_sandbox:
790 <                out_box = out_box + ' "' + fl + '",'
780 >        
781 >        
782 >        if job.stdout() == job.stderr():
783 >          out_box = 'OutputSandbox = { "' + \
784 >                    job.stdout() + '", ".BrokerInfo",'
785 >        else:
786 >          out_box = 'OutputSandbox = { "' + \
787 >                    job.stdout() + '", "' + \
788 >                    job.stderr() + '", ".BrokerInfo",'
789 >
790 >        if int(self.return_data) == 1:
791 >            if out_sandbox != None:
792 >                for fl in out_sandbox:
793 >                    out_box = out_box + ' "' + fl + '",'
794 >                    pass
795                  pass
796              pass
797 <
797 >                                                                                                                                                            
798          if out_box[-1] == ',' : out_box = out_box[:-1]
799          out_box = out_box + ' };'
800          jdl.write(out_box+'\n')
801  
323        # If CloseCE is used ...
324        #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)
802  
803 +        req='Requirements = '
804 +        noreq=req
805 +        req = req + jbt.getRequirements(nj)
806 +        #### and USER REQUIREMENT
807 +        if self.EDG_requirements:
808 +            if (req != noreq):
809 +                req = req +  ' && '
810 +            req = req + self.EDG_requirements
811 +        #### FEDE #####
812 +        if self.EDG_ce_white_list:
813 +            ce_white_list = string.split(self.EDG_ce_white_list,',')
814 +            #print "req = ", req
815 +            for i in range(len(ce_white_list)):
816 +                if i == 0:
817 +                    if (req != noreq):
818 +                        req = req +  ' && '
819 +                    req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
820 +                    pass
821 +                else:
822 +                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
823 +            req = req + ')'
824 +        
825 +        if self.EDG_ce_black_list:
826 +            ce_black_list = string.split(self.EDG_ce_black_list,',')
827 +            for ce in ce_black_list:
828 +                if (req != noreq):
829 +                    req = req +  ' && '
830 +                req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
831 +                pass
832 +
833 +        ###############
834 +        clockTime=480
835 +        if self.EDG_clock_time:
836 +            clockTime= self.EDG_clock_time
837 +        if (req != noreq):
838 +            req = req + ' && '
839 +        req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
840 +
841 +        cpuTime=1000
842 +        if self.EDG_cpu_time:
843 +            cpuTime=self.EDG_cpu_time
844 +        if (req != noreq):
845 +            req = req + ' && '
846 +        req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+str(cpuTime)+'))'
847 +
848 +        if (req != noreq):
849 +            req = req + ';\n'
850 +            jdl.write(req)
851 +                                                                                                                                                            
852          jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
853  
854          if ( self.EDG_retry_count ):              
855              jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
856              pass
857  
858 +        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
859 +
860          jdl.close()
861          return
862 +
863 +    def checkProxy(self):
864 +        """
865 +        Function to check the Globus proxy.
866 +        """
867 +        if (self.proxyValid): return
868 +        timeleft = -999
869 +        minTimeLeft=10*3600 # in seconds
870 +
871 +        minTimeLeftServer = 100 # in hours
872 +
873 +        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
874 +        #cmd = 'voms-proxy-info -timeleft'
875 +        mustRenew = 0
876 +        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
877 +        timeLeftServer = -999
878 +        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
879 +            mustRenew = 1
880 +        else:
881 +            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
882 +            if not timeLeftServer or not isInt(timeLeftServer):
883 +                mustRenew = 1
884 +            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
885 +                mustRenew = 1
886 +            pass
887 +        pass
888 +
889 +        if mustRenew:
890 +            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 96h\n")
891 +            cmd = 'voms-proxy-init -voms '+self.VO+' -valid 96:00'
892 +            if self.role:
893 +                cmd = 'voms-proxy-init -voms '+self.VO+':/'+self.VO+'/role='+self.role+' -valid 96:00'
894 +            try:
895 +                # SL as above: damn it!
896 +                out = os.system(cmd)
897 +                if (out>0): raise CrabException("Unable to create a valid proxy!\n")
898 +            except:
899 +                msg = "Unable to create a valid proxy!\n"
900 +                raise CrabException(msg)
901 +            pass
902 +
903 +        ## now I do have a voms proxy valid, and I check the myproxy server
904 +        renewProxy = 0
905 +        cmd = 'myproxy-info -d -s '+self.proxyServer
906 +        cmd_out = runCommand(cmd,0,20)
907 +        if not cmd_out:
908 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
909 +            renewProxy = 1
910 +        else:
911 +            # if myproxy exist but not long enough, renew
912 +            reTime = re.compile( r'timeleft: (\d+)' )
913 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
914 +            if reTime.match( cmd_out ):
915 +                time = reTime.search( line ).group(1)
916 +                if time < minTimeLeftServer:
917 +                    renewProxy = 1
918 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
919 +                pass
920 +            pass
921 +        
922 +        # if not, create one.
923 +        if renewProxy:
924 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
925 +            out = os.system(cmd)
926 +            if (out>0):
927 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
928 +            pass
929 +
930 +        # cache proxy validity
931 +        self.proxyValid=1
932 +        return
933 +
934 +    def configOpt_(self):
935 +        edg_ui_cfg_opt = ' '
936 +        if self.edg_config:
937 +            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
938 +        if self.edg_config_vo:
939 +            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
940 +        return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines