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.12 by fanzago, Mon Sep 26 08:59:06 2005 UTC vs.
Revision 1.64 by gutsche, Tue Jun 27 02:31:31 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):
# Line 21 | Line 22 | class SchedulerEdg(Scheduler):
22  
23      def configure(self, cfg_params):
24  
25 <        try: self.edg_config = cfg_params["EDG.config"]
26 <        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: self.LCG_version = cfg_params["EDG.lcg_version"]
41          except KeyError: self.LCG_version = '2'
# Line 36 | Line 46 | class SchedulerEdg(Scheduler):
46          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
47          except KeyError: self.EDG_retry_count = ''
48  
49 +        try:
50 +            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
51 +            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
52 +        except KeyError:
53 +            self.EDG_ce_black_list  = ''
54 +
55 +        try:
56 +            self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
57 +            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
58 +        except KeyError: self.EDG_ce_white_list = ''
59 +
60 +        try: self.VO = cfg_params['EDG.virtual_organization']
61 +        except KeyError: self.VO = 'cms'
62 +
63 +        try: self.return_data = cfg_params['USER.return_data']
64 +        except KeyError: self.return_data = 1
65 +
66 +        try:
67 +             self.copy_input_data = common.analisys_common_info['copy_input_data']
68 +             #print "self.copy_input_data = ", self.copy_input_data
69 +        except KeyError: self.copy_input_data = 0
70 +
71 +        try:
72 +            self.copy_data = cfg_params["USER.copy_data"]
73 +            if int(self.copy_data) == 1:
74 +                try:
75 +                    self.SE = cfg_params['USER.storage_element']
76 +                    self.SE_PATH = cfg_params['USER.storage_path']
77 +                except KeyError:
78 +                    msg = "Error. The [USER] section does not have 'storage_element'"
79 +                    msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
80 +                    common.logger.message(msg)
81 +                    raise CrabException(msg)
82 +        except KeyError: self.copy_data = 0
83 +
84 +        if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
85 +           msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
86 +           msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
87 +           raise CrabException(msg)
88 +
89 +        try:
90 +            self.lfc_host = cfg_params['EDG.lfc_host']
91 +        except KeyError:
92 +            msg = "Error. The [EDG] section does not have 'lfc_host' value"
93 +            msg = msg + " it's necessary to know the LFC host name"
94 +            common.logger.message(msg)
95 +            raise CrabException(msg)
96 +        try:
97 +            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
98 +        except KeyError:
99 +            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
100 +            msg = msg + " it's necessary to know the catalog type"
101 +            common.logger.message(msg)
102 +            raise CrabException(msg)
103          try:
104 <            self.VO = cfg_params['EDG.virtual_organization']
104 >            self.lfc_home = cfg_params['EDG.lfc_home']
105          except KeyError:
106 <            self.VO = 'cms'
106 >            msg = "Error. The [EDG] section does not have 'lfc_home' value"
107 >            msg = msg + " it's necessary to know the home catalog dir"
108 >            common.logger.message(msg)
109 >            raise CrabException(msg)
110 >      
111 >        try:
112 >            self.register_data = cfg_params["USER.register_data"]
113 >            if int(self.register_data) == 1:
114 >                try:
115 >                    self.LFN = cfg_params['USER.lfn_dir']
116 >                except KeyError:
117 >                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
118 >                    msg = msg + " it's necessary for LCF registration"
119 >                    common.logger.message(msg)
120 >                    raise CrabException(msg)
121 >        except KeyError: self.register_data = 0
122 >
123 >        if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
124 >           msg = 'Warning: register_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 >        try: self.EDG_requirements = cfg_params['EDG.requirements']
130 >        except KeyError: self.EDG_requirements = ''
131 >                                                                                                                                                            
132 >        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
133 >        except KeyError: self.EDG_retry_count = ''
134 >                                                                                                                                                            
135 >        try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
136 >        except KeyError: self.EDG_clock_time= ''
137 >                                                                                                                                                            
138 >        try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
139 >        except KeyError: self.EDG_cpu_time = ''
140  
141          # Add EDG_WL_LOCATION to the python path
142  
143          try:
47 #            path = os.environ['GLITE_WMS_LOCATION']
144              path = os.environ['EDG_WL_LOCATION']
145          except:
50 #            msg = "Error: the GLITE_WMS_LOCATION variable is not set."
146              msg = "Error: the EDG_WL_LOCATION variable is not set."
147              raise CrabException(msg)
148  
# Line 56 | Line 151 | class SchedulerEdg(Scheduler):
151          libPath=os.path.join(path, "lib", "python")
152          sys.path.append(libPath)
153  
154 <        self.checkProxy_()
154 >        self.proxyValid=0
155 >
156 >        try:
157 >            self._taskId = cfg_params['taskId']
158 >        except:
159 >            self._taskId = ''
160 >
161          return
162      
163  
# Line 74 | Line 175 | class SchedulerEdg(Scheduler):
175              return 1
176          else:
177              return 0
178 +
179      def wsSetupEnvironment(self):
180          """
181          Returns part of a job script which does scheduler-specific work.
182          """
183 <        txt = '\n'
184 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
185 <        # MARCO
186 <        #txt += 'CloseCEs=`glite-brokerinfo getCE`\n'
187 <        # MARCO
188 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
189 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
190 <        txt += 'echo "CE = $CE"\n'
183 >        txt = ''
184 >        txt += "# job number (first parameter for job wrapper)\n"
185 >        txt += "NJob=$1\n"
186 >
187 >        txt += '# job identification to DashBoard \n'
188 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
189 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
190 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
191 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
192 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
193 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
194 >
195 >        txt += 'echo "middleware discovery " \n'
196 >        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
197 >        txt += '    middleware=LCG \n'
198 >        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
199 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
200 >        txt += '    echo "middleware =$middleware" \n'
201 >        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
202 >        txt += '    middleware=OSG \n'
203 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
204 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
205 >        txt += '    echo "middleware =$middleware" \n'
206 >        txt += 'elif [ $OSG_APP ]; then \n'
207 >        txt += '    middleware=OSG \n'
208 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
209 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
210 >        txt += '    echo "middleware =$middleware" \n'
211 >        txt += 'else \n'
212 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
213 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
214 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
215 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
216 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
217 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
218 >        txt += '    echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
219 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
220 >        txt += '    exit 1 \n'
221 >        txt += 'fi \n'
222 >
223 >        txt += '# report first time to DashBoard \n'
224 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
225 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
226 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
227 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
228 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
229 >        
230 >        txt += '\n\n'
231 >
232 >        if int(self.copy_data) == 1:
233 >           if self.SE:
234 >              txt += 'export SE='+self.SE+'\n'
235 >              txt += 'echo "SE = $SE"\n'
236 >           if self.SE_PATH:
237 >              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
238 >              txt += 'export SE_PATH='+self.SE_PATH+'\n'
239 >              txt += 'echo "SE_PATH = $SE_PATH"\n'
240 >
241 >        txt += 'export VO='+self.VO+'\n'
242 >        ### FEDE: add some line for LFC catalog setting
243 >        txt += 'if [ $middleware == LCG ]; then \n'
244 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
245 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
246 >        txt += '    fi\n'
247 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
248 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
249 >        txt += '    fi\n'
250 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
251 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
252 >        txt += '    fi\n'
253 >        txt += 'elif [ $middleware == OSG ]; then\n'
254 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
255 >        txt += 'fi\n'
256 >        #####
257 >        if int(self.register_data) == 1:
258 >           txt += 'if [ $middleware == LCG ]; then \n'
259 >           txt += '    export LFN='+self.LFN+'\n'
260 >           txt += '    lfc-ls $LFN\n'
261 >           txt += '    result=$?\n'
262 >           txt += '    echo $result\n'
263 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
264 >           txt += '    if [ $result != 0 ]; then\n'
265 >           txt += '       lfc-mkdir $LFN\n'
266 >           txt += '       result=$?\n'
267 >           txt += '       echo $result\n'
268 >           txt += '    fi\n'
269 >           txt += 'elif [ $middleware == OSG ]; then\n'
270 >           txt += '    echo " Files registration to be implemented for OSG"\n'
271 >           txt += 'fi\n'
272 >           txt += '\n'
273 >
274 >           if self.VO:
275 >              txt += 'export VO='+self.VO+'\n'
276 >           if self.LFN:
277 >              txt += 'if [ $middleware == LCG ]; then \n'
278 >              txt += '    export LFN='+self.LFN+'\n'
279 >              txt += 'fi\n'
280 >              txt += '\n'
281 >
282 >        txt += 'if [ $middleware == LCG ]; then\n'
283 >        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
284 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
285 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
286 >        txt += '    echo "CE = $CE"\n'
287 >        txt += 'elif [ $middleware == OSG ]; then \n'
288 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
289 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
290 >        txt += '    else \n'
291 >        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
292 >        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
293 >        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
294 >        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
295 >        txt += '        rm -f $RUNTIME_AREA/$repo \n'
296 >        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
297 >        txt += '        echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
298 >        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
299 >        txt += '        exit 1 \n'
300 >        txt += '    fi \n'
301 >        txt += 'fi \n'
302 >
303 >        return txt
304 >
305 >    def wsCopyInput(self):
306 >        """
307 >        Copy input data from SE to WN    
308 >        """
309 >        txt = ''
310 >        try:
311 >            self.copy_input_data = common.analisys_common_info['copy_input_data']
312 >            #print "self.copy_input_data = ", self.copy_input_data
313 >        except KeyError: self.copy_input_data = 0
314 >        if int(self.copy_input_data) == 1:
315 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
316 >           txt += 'if [ $middleware == OSG ]; then\n'
317 >           txt += '   #\n'
318 >           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
319 >           txt += '   #\n'
320 >           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
321 >           txt += 'elif [ $middleware == LCG ]; then \n'
322 >           txt += '   #\n'
323 >           txt += '   #   Copy Input Data from SE to this WN\n'
324 >           txt += '   #\n'
325 > ### changed by georgia (put a loop copying more than one input files per jobs)          
326 >           txt += '   for input_file in $cur_file_list \n'
327 >           txt += '   do \n'
328 >           txt += '    lcg-cp --vo $VO lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
329 >           txt += '    copy_input_exit_status=$?\n'
330 >           txt += '    echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
331 >           txt += '    if [ $copy_input_exit_status -ne 0 ]; then \n'
332 >           txt += '       echo "Problems with copying to WN" \n'
333 >           txt += '    else \n'
334 >           txt += '       echo "input copied into WN" \n'
335 >           txt += '    fi \n'
336 >           txt += '   done \n'
337 > ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
338 >           txt += '   for file in $cur_pu_list \n'
339 >           txt += '   do \n'
340 >           txt += '    lcg-cp --vo $VO lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
341 >           txt += '    copy_input_exit_status=$?\n'
342 >           txt += '    echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
343 >           txt += '    if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
344 >           txt += '       echo "Problems with copying pu to WN" \n'
345 >           txt += '    else \n'
346 >           txt += '       echo "input pu files copied into WN" \n'
347 >           txt += '    fi \n'
348 >           txt += '   done \n'
349 >           txt += '   \n'
350 >           txt += '   ### Check SCRATCH space available on WN : \n'
351 >           txt += '   df -h \n'
352 >           txt += 'fi \n'
353 >          
354 >        return txt
355 >
356 >    def wsCopyOutput(self):
357 >        """
358 >        Write a CopyResults part of a job script, e.g.
359 >        to copy produced output into a storage element.
360 >        """
361 >        txt = ''
362 >        if int(self.copy_data) == 1:
363 >           txt += '#\n'
364 >           txt += '#   Copy output to SE = $SE\n'
365 >           txt += '#\n'
366 >           txt += 'if [ $exe_result -eq 0 ]; then\n'
367 >           txt += '    for out_file in $file_list ; do\n'
368 >           txt += '        echo "Trying to copy output file to $SE "\n'
369 >           ## OLI_Daniele globus-* for OSG, lcg-* for LCG
370 >           txt += '        if [ $middleware == OSG ]; then\n'
371 >           txt += '           echo "globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
372 >           txt += '           globus-url-copy file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1 \n'
373 >           txt += '           copy_exit_status=$? \n'
374 >           txt += '        elif [ $middleware == LCG ]; then \n'
375 >           txt += '           echo "lcg-cp --vo cms -t 1200 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
376 >           txt += '           lcg-cp --vo cms -t 1200 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1\n'
377 >           txt += '           copy_exit_status=$? \n'
378 >           txt += '        fi \n'
379 >           txt += '        echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
380 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
381 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
382 >           txt += '            echo "Problems with SE = $SE"\n'
383 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
384 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
385 >           txt += '        else\n'
386 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
387 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
388 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
389 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
390 >           txt += '         fi\n'
391 >           txt += '     done\n'
392 >           txt += 'fi\n'
393 >        return txt
394 >
395 >    def wsRegisterOutput(self):
396 >        """
397 >        Returns part of a job script which does scheduler-specific work.
398 >        """
399 >
400 >        txt = ''
401 >        if int(self.register_data) == 1:
402 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
403 >           txt += 'if [ $middleware == OSG ]; then\n'
404 >           txt += '   #\n'
405 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
406 >           txt += '   #\n'
407 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
408 >           txt += 'elif [ $middleware == LCG ]; then \n'
409 >           txt += '#\n'
410 >           txt += '#  Register output to LFC\n'
411 >           txt += '#\n'
412 >           txt += '   if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
413 >           txt += '      for out_file in $file_list ; do\n'
414 >           txt += '         echo "Trying to register the output file into LFC"\n'
415 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
416 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
417 >           txt += '         register_exit_status=$?\n'
418 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
419 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
420 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
421 >           txt += '            echo "Problems with the registration to LFC" \n'
422 >           txt += '            echo "Try with srm protocol" \n'
423 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
424 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
425 >           txt += '            register_exit_status=$?\n'
426 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
427 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
428 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
429 >           txt += '               echo "Problems with the registration into LFC" \n'
430 >           txt += '            fi \n'
431 >           txt += '         else \n'
432 >           txt += '            echo "output registered to LFC"\n'
433 >           txt += '         fi \n'
434 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
435 >           txt += '      done\n'
436 >           txt += '   elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
437 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
438 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
439 >           txt += '      for out_file in $file_list ; do\n'
440 >           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
441 >           txt += '         lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
442 >           txt += '         register_exit_status=$?\n'
443 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
444 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
445 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
446 >           txt += '            echo "Problems with CloseSE" \n'
447 >           txt += '         else \n'
448 >           txt += '            echo "The program was successfully executed"\n'
449 >           txt += '            echo "SE = $CLOSE_SE"\n'
450 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
451 >           txt += '         fi \n'
452 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
453 >           txt += '      done\n'
454 >           txt += '   else\n'
455 >           txt += '      echo "Problem with the executable"\n'
456 >           txt += '   fi \n'
457 >           txt += 'fi \n'
458          return txt
459  
460 <    def loggingInfo(self, nj):
460 >    def loggingInfo(self, id):
461          """
462          retrieve the logging info from logging and bookkeeping and return it
463          """
464 <        id = common.jobDB.jobId(nj)
465 <        edg_ui_cfg_opt = ''
466 <        if self.edg_config:
467 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
99 <        cmd = 'edg-job-get-logging-info -v 2 ' + edg_ui_cfg_opt + id
100 <        print cmd
101 <        myCmd = os.popen(cmd)
102 <        cmd_out = myCmd.readlines()
103 <        myCmd.close()
464 >        self.checkProxy()
465 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
466 >        #cmd_out = os.popen(cmd)
467 >        cmd_out = runCommand(cmd)
468          return cmd_out
469  
470      def listMatch(self, nj):
471          """
472          Check the compatibility of available resources
473          """
474 +        self.checkProxy()
475          jdl = common.job_list[nj].jdlFilename()
476 <        edg_ui_cfg_opt = ''
477 <        if self.edg_config:
478 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
479 <        if self.edg_config_vo:
480 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
116 <        cmd = 'edg-job-list-match ' + edg_ui_cfg_opt + jdl
117 <        myCmd = os.popen(cmd)
118 <        cmd_out = myCmd.readlines()
119 <        myCmd.close()
476 >        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
477 >        cmd_out = runCommand(cmd,0,10)
478 >        if not cmd_out:
479 >            raise CrabException("ERROR: "+cmd+" failed!")
480 >
481          return self.parseListMatch_(cmd_out, jdl)
482  
483      def parseListMatch_(self, out, jdl):
484 +        """
485 +        Parse the f* output of edg-list-match and produce something sensible
486 +        """
487          reComment = re.compile( r'^\**$' )
488          reEmptyLine = re.compile( r'^$' )
489          reVO = re.compile( r'Selected Virtual Organisation name.*' )
490 <        reCE = re.compile( r'CEId' )
490 >        reLine = re.compile( r'.*')
491 >        reCE = re.compile( r'(.*:.*)')
492 >        reCEId = re.compile( r'CEId.*')
493          reNO = re.compile( r'No Computing Element matching' )
494          reRB = re.compile( r'Connecting to host' )
495          next = 0
496          CEs=[]
497          Match=0
498 <        for line in out:
499 <            line = line.strip()
500 <            if reComment.match( line ):
501 <                next = 0
502 <                continue
503 <            if reEmptyLine.match(line):
504 <                continue
498 >
499 >        #print out
500 >        lines = reLine.findall(out)
501 >
502 >        i=0
503 >        CEs=[]
504 >        for line in lines:
505 >            string.strip(line)
506 >            #print line
507 >            if reNO.match( line ):
508 >                common.logger.debug(5,line)
509 >                return 0
510 >                pass
511              if reVO.match( line ):
512 <                VO =line.split()[-1]
513 <                common.logger.debug(5, 'VO           :'+VO)
512 >                VO =reVO.match( line ).group()
513 >                common.logger.debug(5,"VO "+VO)
514                  pass
515 +
516              if reRB.match( line ):
517 <                RB =line.split()[3]
518 <                common.logger.debug(5, 'Using RB     :'+RB)
517 >                RB = reRB.match(line).group()
518 >                common.logger.debug(5,"RB "+RB)
519                  pass
520 <            if reCE.search( line ):
521 <                next = 1
522 <                continue
523 <            if next:
524 <                CE=line.split(':')[0]
525 <                CEs.append(CE)
526 <                common.logger.debug(5, 'Matched CE   :'+CE)
527 <                Match=Match+1
155 <                pass
156 <            if reNO.match( line ):
157 <                common.logger.debug(5,line)
158 <                self.noMatchFound_(jdl)
159 <                Match=0
520 >
521 >            if reCEId.search( line ):
522 >                for lineCE in lines[i:-1]:
523 >                    if reCE.match( lineCE ):
524 >                        CE = string.strip(reCE.search(lineCE).group(1))
525 >                        CEs.append(CE.split(':')[0])
526 >                        pass
527 >                    pass
528                  pass
529 <        return Match
529 >            i=i+1
530 >            pass
531 >
532 >        common.logger.debug(5,"All CE :"+str(CEs))
533 >
534 >        sites = []
535 >        [sites.append(it) for it in CEs if not sites.count(it)]
536 >
537 >        common.logger.debug(5,"All Sites :"+str(sites))
538 >        common.logger.message("Matched Sites :"+str(sites))
539 >        return len(sites)
540  
541      def noMatchFound_(self, jdl):
542          reReq = re.compile( r'Requirements' )
# Line 184 | Line 562 | class SchedulerEdg(Scheduler):
562          Submit one EDG job.
563          """
564  
565 +        self.checkProxy()
566          jid = None
567          jdl = common.job_list[nj].jdlFilename()
568 <        id_tmp = tempfile.mktemp()
569 <        edg_ui_cfg_opt = ' '
191 <        if self.edg_config:
192 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
193 <        if self.edg_config_vo:
194 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
195 <        cmd = 'edg-job-submit -o ' + id_tmp + edg_ui_cfg_opt + jdl
568 >
569 >        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
570          cmd_out = runCommand(cmd)
571          if cmd_out != None:
572 <            idfile = open(id_tmp)
573 <            jid_line = idfile.readline()
200 <            while jid_line[0] == '#':
201 <                jid_line = idfile.readline()
202 <                pass
203 <            jid = string.strip(jid_line)
204 <            os.unlink(id_tmp)
572 >            reSid = re.compile( r'https.+' )
573 >            jid = reSid.search(cmd_out).group()
574              pass
575          return jid
576  
577 +    def resubmit(self, nj_list):
578 +        """
579 +        Prepare jobs to be submit
580 +        """
581 +        return
582 +
583      def getExitStatus(self, id):
584          return self.getStatusAttribute_(id, 'exit_code')
585  
# Line 218 | Line 593 | class SchedulerEdg(Scheduler):
593      def getStatusAttribute_(self, id, attr):
594          """ Query a status of the job with id """
595  
596 +        self.checkProxy()
597          hstates = {}
598          Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
223 #        Status = importName('glite_wmsui_LbWrapper', 'Status')
599          # Bypass edg-job-status interfacing directly to C++ API
600          # Job attribute vector to retrieve status without edg-job-status
601          level = 0
# Line 230 | Line 605 | class SchedulerEdg(Scheduler):
605          jobStat.getStatus(id, level)
606          err, apiMsg = jobStat.get_error()
607          if err:
608 <            print 'Error caught', apiMsg
234 <            common.log.message(apiMsg)
608 >            common.logger.debug(5,'Error caught' + apiMsg)
609              return None
610          else:
611              for i in range(len(self.states)):
238                #print "states = ", states
612                  # Fill an hash table with all information retrieved from LB API
613                  hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
614              result = jobStat.loadStatus(st)[ self.states.index(attr) ]
# Line 253 | Line 626 | class SchedulerEdg(Scheduler):
626          Returns the name of directory with results.
627          """
628  
629 +        self.checkProxy()
630          cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
631          cmd_out = runCommand(cmd)
632  
633          # Determine the output directory name
634          dir = common.work_space.resDir()
635 <        dir += os.getlogin()
635 >        dir += os.environ['USER']
636          dir += '_' + os.path.basename(id)
637          return dir
638  
639      def cancel(self, id):
640          """ Cancel the EDG job with id """
641 +        self.checkProxy()
642          cmd = 'edg-job-cancel --noint ' + id
643          cmd_out = runCommand(cmd)
644          return cmd_out
645  
271    def checkProxy_(self):
272        """
273        Function to check the Globus proxy.
274        """
275        cmd = 'grid-proxy-info -timeleft'
276        cmd_out = runCommand(cmd)
277        ok = 1
278        timeleft = -999
279        try: timeleft = int(cmd_out)
280        except ValueError: ok=0
281        except TypeError: ok=0
282        if timeleft < 1:  ok=0
283
284        if ok==0:
285            print "No valid proxy found !\n"
286            print "Creating a user proxy with default length of 100h\n"
287            msg = "Unable to create a valid proxy!\n"
288            if os.system("grid-proxy-init -valid 100:00"):
289                raise CrabException(msg)
290        return
291    
646      def createSchScript(self, nj):
647          """
648          Create a JDL-file for EDG.
# Line 303 | Line 657 | class SchedulerEdg(Scheduler):
657          title = '# This JDL was generated by '+\
658                  common.prog_name+' (version '+common.prog_version_str+')\n'
659          jt_string = ''
660 +
661 +
662          
663          SPL = inp_storage_subdir
664          if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
# Line 315 | Line 671 | class SchedulerEdg(Scheduler):
671          jdl.write('Executable = "' + os.path.basename(script) +'";\n')
672          jdl.write(jt_string)
673  
674 <        firstEvent = common.jobDB.firstEvent(nj)
319 <        maxEvents = common.jobDB.maxEvents(nj)
320 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
674 >        ### only one .sh  JDL has arguments:
675  
676 +        ### Fabio
677 +        jdl.write('Arguments = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'";\n')
678          inp_box = 'InputSandbox = { '
679          inp_box = inp_box + '"' + script + '",'
680  
# Line 331 | Line 687 | class SchedulerEdg(Scheduler):
687          #if common.use_jam:
688          #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
689  
690 <        for addFile in jbt.additional_inbox_files:
691 <            addFile = os.path.abspath(addFile)
692 <            inp_box = inp_box+' "'+addFile+'",'
693 <            pass
690 >        # Marco (VERY TEMPORARY ML STUFF)
691 >        inp_box = inp_box+' "' + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + '", "' +\
692 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + '", "'+\
693 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + '", "'+\
694 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + '", "'+\
695 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py') + '"'
696 >        # End Marco
697 >
698 >        if (not jbt.additional_inbox_files == []):
699 >            inp_box = inp_box + ', '
700 >            for addFile in jbt.additional_inbox_files:
701 >                addFile = os.path.abspath(addFile)
702 >                inp_box = inp_box+' "'+addFile+'",'
703 >                pass
704  
705          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
706          inp_box = inp_box + ' };\n'
# Line 342 | Line 708 | class SchedulerEdg(Scheduler):
708  
709          jdl.write('StdOutput     = "' + job.stdout() + '";\n')
710          jdl.write('StdError      = "' + job.stderr() + '";\n')
711 <
712 <        #if common.flag_return_data :
713 <        #    for fl in job.outputDataFiles():
714 <        #        out_box = out_box + ' "' + fl + '",'
715 <        #        pass
716 <        #    pass
717 <
718 <        out_box = 'OutputSandbox = { '
719 <        if out_sandbox != None:
720 <            for fl in out_sandbox:
721 <                out_box = out_box + ' "' + fl + '",'
711 >        
712 >        
713 >        if job.stdout() == job.stderr():
714 >          out_box = 'OutputSandbox = { "' + \
715 >                    job.stdout() + '", ".BrokerInfo",'
716 >        else:
717 >          out_box = 'OutputSandbox = { "' + \
718 >                    job.stdout() + '", "' + \
719 >                    job.stderr() + '", ".BrokerInfo",'
720 >
721 >        if int(self.return_data) == 1:
722 >            if out_sandbox != None:
723 >                for fl in out_sandbox:
724 >                    out_box = out_box + ' "' + fl + '",'
725 >                    pass
726                  pass
727              pass
728 <
728 >                                                                                                                                                            
729          if out_box[-1] == ',' : out_box = out_box[:-1]
730          out_box = out_box + ' };'
731          jdl.write(out_box+'\n')
732  
363        # If CloseCE is used ...
364        #if common.flag_usecloseCE and job.inputDataFiles():
365        #    indata = 'InputData = { '
366        #    for fl in job.inputDataFiles():
367        #       indata = indata + ' "lfn:' + SPL + fl + '",'
368        #    if indata[-1] == ',' : indata = indata[:-1]
369        #    indata = indata + ' };'
370        #    jdl.write(indata+'\n')
371        #    jdl.write('DataAccessProtocol = { "gsiftp" };\n')
372
373        if common.analisys_common_info['sites']:
374           if common.analisys_common_info['sw_version']:
375
376             req='Requirements = '
377         ### First ORCA version
378             req=req + 'Member("VO-cms-' + \
379                 common.analisys_common_info['sw_version'] + \
380                 '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
381         ## then sites
382             if len(common.analisys_common_info['sites'])>0:
383               req = req + ' && ('
384             for i in range(len(common.analisys_common_info['sites'])):
385                req = req + 'other.GlueCEInfoHostName == "' \
386                     + common.analisys_common_info['sites'][i] + '"'
387                if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
388                    req = req + ' || '
389             req = req + ')'
390         ## then user requirement
391             if self.EDG_requirements:
392               req = req +  ' && ' + self.EDG_requirements
393             req = req + ';\n'
394        jdl.write(req)
733  
734 +        req='Requirements = '
735 +        noreq=req
736 +        req = req + jbt.getRequirements()
737 +        #### and USER REQUIREMENT
738 +        if self.EDG_requirements:
739 +            if (req != noreq):
740 +                req = req +  ' && '
741 +            req = req + self.EDG_requirements
742 +        #### FEDE #####
743 +        if self.EDG_ce_white_list:
744 +            ce_white_list = string.split(self.EDG_ce_white_list,',')
745 +            #print "req = ", req
746 +            for i in range(len(ce_white_list)):
747 +                if i == 0:
748 +                    if (req != noreq):
749 +                        req = req +  ' && '
750 +                    req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
751 +                    pass
752 +                else:
753 +                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
754 +            req = req + ')'
755 +        
756 +        if self.EDG_ce_black_list:
757 +            ce_black_list = string.split(self.EDG_ce_black_list,',')
758 +            for ce in ce_black_list:
759 +                if (req != noreq):
760 +                    req = req +  ' && '
761 +                req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
762 +                pass
763 +
764 +        ###############
765 +        clockTime=480
766 +        if self.EDG_clock_time:
767 +            clockTime= self.EDG_clock_time
768 +        if (req != noreq):
769 +            req = req + ' && '
770 +        req = req + '((other.GlueCEPolicyMaxWallClockTime == 0) || (other.GlueCEPolicyMaxWallClockTime>='+str(clockTime)+'))'
771 +
772 +        cpuTime=1000
773 +        if self.EDG_cpu_time:
774 +            cpuTime=self.EDG_cpu_time
775 +        if (req != noreq):
776 +            req = req + ' && '
777 +        req = req + '((other.GlueCEPolicyMaxCPUTime == 0) || (other.GlueCEPolicyMaxCPUTime>='+str(cpuTime)+'))'
778 +
779 +        if (req != noreq):
780 +            req = req + ';\n'
781 +            jdl.write(req)
782 +                                                                                                                                                            
783          jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
784  
785          if ( self.EDG_retry_count ):              
786              jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
787              pass
788  
789 +        jdl.write('MyProxyServer = "' + self.proxyServer + '";\n')
790 +
791          jdl.close()
792          return
793 +
794 +    def checkProxy(self):
795 +        """
796 +        Function to check the Globus proxy.
797 +        """
798 +        if (self.proxyValid): return
799 +        timeleft = -999
800 +        minTimeLeft=10*3600 # in seconds
801 +
802 +        minTimeLeftServer = 100 # in hours
803 +
804 +        #cmd = 'voms-proxy-info -exists -valid '+str(minTimeLeft)+':00'
805 +        #cmd = 'voms-proxy-info -timeleft'
806 +        mustRenew = 0
807 +        timeLeftLocal = runCommand('voms-proxy-info -timeleft')
808 +        timeLeftServer = -999
809 +        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
810 +            mustRenew = 1
811 +        else:
812 +            timeLeftServer = runCommand('voms-proxy-info -actimeleft | head -1')
813 +            if not timeLeftServer or not isInt(timeLeftServer):
814 +                mustRenew = 1
815 +            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
816 +                mustRenew = 1
817 +            pass
818 +        pass
819 +
820 +        if mustRenew:
821 +            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")
822 +            cmd = 'voms-proxy-init -voms cms -valid 96:00'
823 +            try:
824 +                # SL as above: damn it!
825 +                out = os.system(cmd)
826 +                if (out>0): raise CrabException("Unable to create a valid proxy!\n")
827 +            except:
828 +                msg = "Unable to create a valid proxy!\n"
829 +                raise CrabException(msg)
830 +            # cmd = 'grid-proxy-info -timeleft'
831 +            # cmd_out = runCommand(cmd,0,20)
832 +            pass
833 +
834 +        ## now I do have a voms proxy valid, and I check the myproxy server
835 +        renewProxy = 0
836 +        cmd = 'myproxy-info -d -s '+self.proxyServer
837 +        cmd_out = runCommand(cmd,0,20)
838 +        if not cmd_out:
839 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
840 +            renewProxy = 1
841 +        else:
842 +            # if myproxy exist but not long enough, renew
843 +            reTime = re.compile( r'timeleft: (\d+)' )
844 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
845 +            if reTime.match( cmd_out ):
846 +                time = reTime.search( line ).group(1)
847 +                if time < minTimeLeftServer:
848 +                    renewProxy = 1
849 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
850 +                pass
851 +            pass
852 +        
853 +        # if not, create one.
854 +        if renewProxy:
855 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
856 +            out = os.system(cmd)
857 +            if (out>0):
858 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
859 +            pass
860 +
861 +        # cache proxy validity
862 +        self.proxyValid=1
863 +        return
864 +
865 +    def configOpt_(self):
866 +        edg_ui_cfg_opt = ' '
867 +        if self.edg_config:
868 +            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
869 +        if self.edg_config_vo:
870 +            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
871 +        return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines