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.23 by spiga, Tue Nov 8 13:27:11 2005 UTC vs.
Revision 1.83 by spiga, Thu Sep 21 19:15:43 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, time
# 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:
41 +            self.role = cfg_params["EDG.role"]
42 +        except KeyError:
43 +            self.role = None
44 +            
45          try: self.LCG_version = cfg_params["EDG.lcg_version"]
46          except KeyError: self.LCG_version = '2'
47  
# Line 36 | Line 51 | class SchedulerEdg(Scheduler):
51          try: self.EDG_retry_count = cfg_params['EDG.retry_count']
52          except KeyError: self.EDG_retry_count = ''
53  
54 +        try:
55 +            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
56 +            #print "self.EDG_ce_black_list = ", self.EDG_ce_black_list
57 +        except KeyError:
58 +            self.EDG_ce_black_list  = ''
59 +
60 +        try:
61 +            self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
62 +            #print "self.EDG_ce_white_list = ", self.EDG_ce_white_list
63 +        except KeyError: self.EDG_ce_white_list = ''
64 +
65          try: self.VO = cfg_params['EDG.virtual_organization']
66          except KeyError: self.VO = 'cms'
67  
68          try: self.return_data = cfg_params['USER.return_data']
69 <        except KeyError: self.return_data = ''
69 >        except KeyError: self.return_data = 1
70 >
71 >        try:
72 >             self.copy_input_data = common.analisys_common_info['copy_input_data']
73 >             #print "self.copy_input_data = ", self.copy_input_data
74 >        except KeyError: self.copy_input_data = 0
75  
76          try:
77              self.copy_data = cfg_params["USER.copy_data"]
78 <            try:
79 <                self.SE = cfg_params['USER.storage_element']
80 <                self.SE_PATH = cfg_params['USER.storage_path']
81 <            except KeyError:
82 <                msg = "Error. The [USER] section does not have 'storage_element'"
83 <                msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
84 <                common.logger.message(msg)
85 <                raise CrabException(msg)
86 <        except KeyError: self.copy_data = ''
78 >            if int(self.copy_data) == 1:
79 >                try:
80 >                    self.SE = cfg_params['USER.storage_element']
81 >                    self.SE_PATH = cfg_params['USER.storage_path']
82 >                except KeyError:
83 >                    msg = "Error. The [USER] section does not have 'storage_element'"
84 >                    msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
85 >                    common.logger.message(msg)
86 >                    raise CrabException(msg)
87 >        except KeyError: self.copy_data = 0
88 >
89 >        if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
90 >           msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
91 >           msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
92 >           raise CrabException(msg)
93  
94 +        try:
95 +            self.lfc_host = cfg_params['EDG.lfc_host']
96 +        except KeyError:
97 +            msg = "Error. The [EDG] section does not have 'lfc_host' value"
98 +            msg = msg + " it's necessary to know the LFC host name"
99 +            common.logger.message(msg)
100 +            raise CrabException(msg)
101 +        try:
102 +            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
103 +        except KeyError:
104 +            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
105 +            msg = msg + " it's necessary to know the catalog type"
106 +            common.logger.message(msg)
107 +            raise CrabException(msg)
108 +        try:
109 +            self.lfc_home = cfg_params['EDG.lfc_home']
110 +        except KeyError:
111 +            msg = "Error. The [EDG] section does not have 'lfc_home' value"
112 +            msg = msg + " it's necessary to know the home catalog dir"
113 +            common.logger.message(msg)
114 +            raise CrabException(msg)
115 +      
116          try:
117              self.register_data = cfg_params["USER.register_data"]
118 <            try:
119 <                 self.LFN = cfg_params['USER.lfn_dir']
120 <            except KeyError:
121 <                msg = "Error. The [USER] section does not have 'lfn_dir' value"
122 <                msg = msg + " it's necessary for RLS registration"
123 <                common.logger.message(msg)
124 <                raise CrabException(msg)
125 <        except KeyError: self.register_data= ''
118 >            if int(self.register_data) == 1:
119 >                try:
120 >                    self.LFN = cfg_params['USER.lfn_dir']
121 >                except KeyError:
122 >                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
123 >                    msg = msg + " it's necessary for LCF registration"
124 >                    common.logger.message(msg)
125 >                    raise CrabException(msg)
126 >        except KeyError: self.register_data = 0
127 >
128 >        if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
129 >           msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
130 >           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
131 >           common.logger.message(msg)
132 >           raise CrabException(msg)
133  
134          try: self.EDG_requirements = cfg_params['EDG.requirements']
135          except KeyError: self.EDG_requirements = ''
# Line 91 | Line 157 | class SchedulerEdg(Scheduler):
157          sys.path.append(libPath)
158  
159          self.proxyValid=0
160 +
161 +        try:
162 +            self._taskId = cfg_params['taskId']
163 +        except:
164 +            self._taskId = ''
165 +
166 +        try: self.jobtypeName = cfg_params['CRAB.jobtype']
167 +        except KeyError: self.jobtypeName = ''
168 +
169 +        try: self.schedulerName = cfg_params['CRAB.scheduler']
170 +        except KeyError: self.scheduler = ''
171 +
172          return
173      
174  
# Line 113 | Line 191 | class SchedulerEdg(Scheduler):
191          """
192          Returns part of a job script which does scheduler-specific work.
193          """
116
194          txt = ''
195 <        if self.copy_data:
195 >        txt += '# strip arguments\n'
196 >        txt += 'echo "strip arguments"\n'
197 >        txt += 'args=("$@")\n'
198 >        txt += 'nargs=$#\n'
199 >        txt += 'shift $nargs\n'
200 >        txt += "# job number (first parameter for job wrapper)\n"
201 >        #txt += "NJob=$1\n"
202 >        txt += "NJob=${args[0]}\n"
203 >
204 >        txt += '# job identification to DashBoard \n'
205 >        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
206 >        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
207 >        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
208 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
209 >        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
210 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
211 >
212 >        txt += 'echo "middleware discovery " \n'
213 >        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
214 >        txt += '    middleware=LCG \n'
215 >        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
216 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
217 >        txt += '    echo "middleware =$middleware" \n'
218 >        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
219 >        txt += '    middleware=OSG \n'
220 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
221 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
222 >        txt += '    echo "middleware =$middleware" \n'
223 >        txt += 'elif [ $OSG_APP ]; then \n'
224 >        txt += '    middleware=OSG \n'
225 >        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
226 >        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
227 >        txt += '    echo "middleware =$middleware" \n'
228 >        txt += 'else \n'
229 >        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
230 >        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
231 >        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
232 >        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
233 >        txt += '    rm -f $RUNTIME_AREA/$repo \n'
234 >        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
235 >        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
236 >        txt += '    exit 1 \n'
237 >        txt += 'fi \n'
238 >
239 >        txt += '# report first time to DashBoard \n'
240 >        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
241 >        txt += 'rm -f $RUNTIME_AREA/$repo \n'
242 >        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
243 >        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
244 >        
245 >        txt += '\n\n'
246 >
247 >        if int(self.copy_data) == 1:
248             if self.SE:
249                txt += 'export SE='+self.SE+'\n'
250                txt += 'echo "SE = $SE"\n'
# Line 123 | Line 252 | class SchedulerEdg(Scheduler):
252                if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
253                txt += 'export SE_PATH='+self.SE_PATH+'\n'
254                txt += 'echo "SE_PATH = $SE_PATH"\n'
255 <                                                                                                                                                            
256 <        if self.register_data:
255 >
256 >        txt += 'export VO='+self.VO+'\n'
257 >        ### FEDE: add some line for LFC catalog setting
258 >        txt += 'if [ $middleware == LCG ]; then \n'
259 >        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
260 >        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
261 >        txt += '    fi\n'
262 >        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
263 >        txt += '        export LFC_HOST='+self.lfc_host+'\n'
264 >        txt += '    fi\n'
265 >        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
266 >        txt += '        export LFC_HOME='+self.lfc_home+'\n'
267 >        txt += '    fi\n'
268 >        txt += 'elif [ $middleware == OSG ]; then\n'
269 >        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
270 >        txt += 'fi\n'
271 >        #####
272 >        if int(self.register_data) == 1:
273 >           txt += 'if [ $middleware == LCG ]; then \n'
274 >           txt += '    export LFN='+self.LFN+'\n'
275 >           txt += '    lfc-ls $LFN\n'
276 >           txt += '    result=$?\n'
277 >           txt += '    echo $result\n'
278 >           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
279 >           txt += '    if [ $result != 0 ]; then\n'
280 >           txt += '       lfc-mkdir $LFN\n'
281 >           txt += '       result=$?\n'
282 >           txt += '       echo $result\n'
283 >           txt += '    fi\n'
284 >           txt += 'elif [ $middleware == OSG ]; then\n'
285 >           txt += '    echo " Files registration to be implemented for OSG"\n'
286 >           txt += 'fi\n'
287 >           txt += '\n'
288 >
289             if self.VO:
290                txt += 'export VO='+self.VO+'\n'
291             if self.LFN:
292 <              txt += 'export LFN='+self.LFN+'\n'
292 >              txt += 'if [ $middleware == LCG ]; then \n'
293 >              txt += '    export LFN='+self.LFN+'\n'
294 >              txt += 'fi\n'
295                txt += '\n'
296 <        txt += 'CloseCEs=`edg-brokerinfo getCE`\n'
297 <        txt += 'echo "CloseCEs = $CloseCEs"\n'
298 <        txt += 'CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
299 <        txt += 'echo "CE = $CE"\n'
296 >
297 >        txt += 'if [ $middleware == LCG ]; then\n'
298 >        txt += '    CloseCEs=`edg-brokerinfo getCE`\n'
299 >        txt += '    echo "CloseCEs = $CloseCEs"\n'
300 >        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
301 >        txt += '    echo "CE = $CE"\n'
302 >        txt += 'elif [ $middleware == OSG ]; then \n'
303 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
304 >        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \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 >        except KeyError: self.copy_input_data = 0
327 >        if int(self.copy_input_data) == 1:
328 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
329 >           txt += 'if [ $middleware == OSG ]; then\n'
330 >           txt += '   #\n'
331 >           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
332 >           txt += '   #\n'
333 >           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
334 >           txt += 'elif [ $middleware == LCG ]; then \n'
335 >           txt += '   #\n'
336 >           txt += '   #   Copy Input Data from SE to this WN\n'
337 >           txt += '   #\n'
338 >           ### changed by georgia (put a loop copying more than one input files per jobs)          
339 >           txt += '   for input_file in $cur_file_list \n'
340 >           txt += '   do \n'
341 >           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
342 >           txt += '      copy_input_exit_status=$?\n'
343 >           txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
344 >           txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
345 >           txt += '         echo "Problems with copying to WN" \n'
346 >           txt += '      else \n'
347 >           txt += '         echo "input copied into WN" \n'
348 >           txt += '      fi \n'
349 >           txt += '   done \n'
350 >           ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
351 >           txt += '   for file in $cur_pu_list \n'
352 >           txt += '   do \n'
353 >           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
354 >           txt += '      copy_input_pu_exit_status=$?\n'
355 >           txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
356 >           txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
357 >           txt += '         echo "Problems with copying pu to WN" \n'
358 >           txt += '      else \n'
359 >           txt += '         echo "input pu files copied into WN" \n'
360 >           txt += '      fi \n'
361 >           txt += '   done \n'
362 >           txt += '   \n'
363 >           txt += '   ### Check SCRATCH space available on WN : \n'
364 >           txt += '   df -h \n'
365 >           txt += 'fi \n'
366 >          
367          return txt
368  
369      def wsCopyOutput(self):
# Line 142 | Line 372 | class SchedulerEdg(Scheduler):
372          to copy produced output into a storage element.
373          """
374          txt = ''
375 <        if self.copy_data:
146 <           copy = 'globus-url-copy file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file'
375 >        if int(self.copy_data) == 1:
376             txt += '#\n'
377             txt += '#   Copy output to SE = $SE\n'
378             txt += '#\n'
379 <           #### per orca l'exit_status non e' affidabile.....
380 <           #txt += 'if [ $executable_exit_status -eq 0 ]; then\n'
381 <           txt += 'if [ $exe_result -eq 0 ]; then\n'
382 <           txt += '  for out_file in $file_list ; do\n'
383 <           txt += '    echo "Trying to copy output file to $SE "\n'
384 <           txt += '    echo "'+copy+'"\n'
156 <           txt += '    '+copy+' 2>&1\n'
157 <           txt += '    copy_exit_status=$?\n'
158 <           txt += '    echo "COPY_EXIT_STATUS = $copy_exit_status"\n'
159 <           txt += '    echo "STAGE_OUT = $copy_exit_status"\n'
160 <           txt += '    if [ $copy_exit_status -ne 0 ]; then \n'
161 <           txt += '       echo "Problems with SE= $SE" \n'
162 <           txt += '    else \n'
163 <           txt += '       echo "output copied into $SE/$SE_PATH directory"\n'
379 >           txt += '    if [ $middleware == OSG ]; then\n'
380 >           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
381 >           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
382 >           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
383 >           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
384 >           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
385             txt += '    fi \n'
386 <           txt += '  done\n'
387 <           txt += 'fi \n'
386 >           txt += '    for out_file in $file_list ; do\n'
387 >           txt += '        echo "Trying to copy output file to $SE using lcg-cp"\n'
388 >           if common.logger.debugLevel() >= 5:
389 >               txt += '        echo "lcg-cp --vo $VO -t 2400 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
390 >               txt += '        exitstring=`lcg-cp --vo $VO -t 2400 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
391 >           else:
392 >               txt += '        echo "lcg-cp --vo $VO -t 2400 file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
393 >               txt += '        exitstring=`lcg-cp --vo $VO -t 2400 file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
394 >           txt += '        copy_exit_status=$?\n'
395 >           txt += '        echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
396 >           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
397 >           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
398 >           txt += '            echo "Possible problem with SE = $SE"\n'
399 >           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
400 >           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
401 >           txt += '            echo "lcg-cp failed.  For verbose lcg-cp output, use command line option -debug 5."\n'
402 >           txt += '            echo "lcg-cp failed, attempting srmcp"\n'
403 >           txt += '            echo "mkdir -p $HOME/.srmconfig"\n'
404 >           txt += '            mkdir -p $HOME/.srmconfig\n'
405 >           txt += '            if [ $middleware == LCG ]; then\n'
406 >           txt += '               echo "srmcp -retry_num 5 -retry_timeout 480000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
407 >           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 480000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
408 >           txt += '            elif [ $middleware == OSG ]; then\n'
409 >           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'
410 >           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'
411 >           txt += '            fi \n'
412 >           txt += '            copy_exit_status=$?\n'
413 >           txt += '            echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
414 >           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
415 >           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
416 >           txt += '               echo "Problems with SE = $SE"\n'
417 >           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
418 >           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
419 >           txt += '               echo "lcg-cp and srm failed"\n'
420 >           txt += '               echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
421 >           txt += '            else\n'
422 >           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
423 >           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
424 >           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
425 >           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
426 >           txt += '               echo "srmcp succeeded"\n'
427 >           txt += '            fi\n'
428 >           txt += '        else\n'
429 >           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
430 >           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
431 >           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
432 >           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
433 >           txt += '            echo "lcg-cp succeeded"\n'
434 >           txt += '         fi\n'
435 >           txt += '     done\n'
436          return txt
437  
438      def wsRegisterOutput(self):
# Line 172 | Line 441 | class SchedulerEdg(Scheduler):
441          """
442  
443          txt = ''
444 <        if self.register_data:
444 >        if int(self.register_data) == 1:
445 >        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
446 >           txt += 'if [ $middleware == OSG ]; then\n'
447 >           txt += '   #\n'
448 >           txt += '   #   Register output to LFC deactivated in OSG mode\n'
449 >           txt += '   #\n'
450 >           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
451 >           txt += 'elif [ $middleware == LCG ]; then \n'
452             txt += '#\n'
453 <           txt += '#  Register output to RLS\n'
453 >           txt += '#  Register output to LFC\n'
454             txt += '#\n'
455 <           ### analogo
456 <           #txt += 'if [[ $executable_exit_status -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
457 <           txt += 'if [[ $exe_result -eq 0 && $copy_exit_status -eq 0 ]]; then\n'
458 <           txt += '   for out_file in $file_list ; do\n'
459 <           txt += '      echo "Trying to register the output file into RLS"\n'
184 <           txt += '      echo "lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file"\n'
185 <           txt += '      lcg-rf -l $LFN/$out_file --vo $VO sfn://$SE$SE_PATH/$out_file 2>&1 \n'
186 <           txt += '      register_exit_status=$?\n'
187 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
188 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
189 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
190 <           txt += '         echo "Problems with the registration to RLS" \n'
191 <           txt += '         echo "Try with srm protocol" \n'
192 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file"\n'
193 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO srm://$SE$SE_PATH/$out_file 2>&1 \n'
455 >           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
456 >           txt += '      for out_file in $file_list ; do\n'
457 >           txt += '         echo "Trying to register the output file into LFC"\n'
458 >           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
459 >           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
460             txt += '         register_exit_status=$?\n'
461             txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
462             txt += '         echo "STAGE_OUT = $register_exit_status"\n'
463             txt += '         if [ $register_exit_status -ne 0 ]; then \n'
464 <           txt += '            echo "Problems with the registration into RLS" \n'
464 >           txt += '            echo "Problems with the registration to LFC" \n'
465 >           txt += '            echo "Try with srm protocol" \n'
466 >           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
467 >           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
468 >           txt += '            register_exit_status=$?\n'
469 >           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
470 >           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
471 >           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
472 >           txt += '               echo "Problems with the registration into LFC" \n'
473 >           txt += '            fi \n'
474 >           txt += '         else \n'
475 >           txt += '            echo "output registered to LFC"\n'
476             txt += '         fi \n'
477 <           txt += '      else \n'
478 <           txt += '         echo "output registered to RLS"\n'
479 <           txt += '      fi \n'
480 <           txt += '   done\n'
481 <           txt += 'elif [[ $exe_result -eq 0 && $copy_exit_status -ne 0 ]]; then \n'
482 <           txt += '   echo "Trying to copy output file to CloseSE"\n'
483 <           txt += '   CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
484 <           txt += '   for out_file in $file_list ; do\n'
485 <           txt += '      echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file" \n'
486 <           txt += '      lcg-cr -v -l lfn:${LFN}/$out_file -d $SE -P $LFN/$out_file --vo $VO file://`pwd`/$out_file 2>&1 \n'
487 <           txt += '      register_exit_status=$?\n'
488 <           txt += '      echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
489 <           txt += '      echo "STAGE_OUT = $register_exit_status"\n'
490 <           txt += '      if [ $register_exit_status -ne 0 ]; then \n'
491 <           txt += '         echo "Problems with CloseSE" \n'
492 <           txt += '      else \n'
493 <           txt += '         echo "The program was successfully executed"\n'
494 <           txt += '         echo "SE = $CLOSE_SE"\n'
495 <           txt += '         echo "LFN for the file is LFN=${LFN}/$out_file"\n'
496 <           txt += '      fi \n'
497 <           txt += '   done\n'
498 <           txt += 'else\n'
222 <           txt += '   echo "Problem with the executable"\n'
477 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
478 >           txt += '      done\n'
479 >           txt += '   else \n'
480 >           txt += '      echo "Trying to copy output file to CloseSE"\n'
481 >           txt += '      CLOSE_SE=`edg-brokerinfo getCloseSEs | head -1`\n'
482 >           txt += '      for out_file in $file_list ; do\n'
483 >           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'
484 >           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'
485 >           txt += '         register_exit_status=$?\n'
486 >           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
487 >           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
488 >           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
489 >           txt += '            echo "Problems with CloseSE or Catalog" \n'
490 >           txt += '         else \n'
491 >           txt += '            echo "The program was successfully executed"\n'
492 >           txt += '            echo "SE = $CLOSE_SE"\n'
493 >           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
494 >           txt += '         fi \n'
495 >           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
496 >           txt += '      done\n'
497 >           txt += '   fi \n'
498 >           txt += '   exit_status=$register_exit_status\n'
499             txt += 'fi \n'
500          return txt
225        #####################
501  
502      def loggingInfo(self, id):
503          """
504          retrieve the logging info from logging and bookkeeping and return it
505          """
506          self.checkProxy()
507 <      #  id = common.jobDB.jobId(nj)
508 <        cmd = 'edg-job-get-logging-info -v 2 ' + self.configOpt_() + id
507 >        cmd = 'edg-job-get-logging-info -v 2 ' + id
508 >        #cmd_out = os.popen(cmd)
509          cmd_out = runCommand(cmd)
510          return cmd_out
511  
237    def listMatch(self, nj):
238        """
239        Check the compatibility of available resources
240        """
241        self.checkProxy()
242        jdl = common.job_list[nj].jdlFilename()
243        cmd = 'edg-job-list-match ' + self.configOpt_() + jdl
244        cmd_out = runCommand(cmd)
245        return self.parseListMatch_(cmd_out, jdl)
246
247    def parseListMatch_(self, out, jdl):
248        reComment = re.compile( r'^\**$' )
249        reEmptyLine = re.compile( r'^$' )
250        reVO = re.compile( r'Selected Virtual Organisation name.*' )
251        reCE = re.compile( r'CEId.*\n((.*:.*)\n)*' )
252        reNO = re.compile( r'No Computing Element matching' )
253        reRB = re.compile( r'Connecting to host' )
254        next = 0
255        CEs=[]
256        Match=0
257
258        if reNO.match( out ):
259            common.logger.debug(5,out)
260            self.noMatchFound_(jdl)
261            Match=0
262            pass
263        if reVO.match( out ):
264            VO =reVO.match( out ).group()
265            common.logger.debug(5, 'VO           :'+VO)
266            pass
267
268        if reRB.match( out ):
269            RB =reRB.match(out).group()
270            common.logger.debug(5, 'Using RB     :'+RB)
271            pass
272
273        if reCE.search( out ):
274            groups=reCE.search(out).groups()
275            for CE in groups:
276                tmp = string.strip(CE)
277                CEs.append(tmp)
278                common.logger.debug(5, 'Matched CE   :'+tmp)
279                Match=Match+1
280            pass
281
282        return Match
283
284    def noMatchFound_(self, jdl):
285        reReq = re.compile( r'Requirements' )
286        reString = re.compile( r'"\S*"' )
287        f = file(jdl,'r')
288        for line in f.readlines():
289            line= line.strip()
290            if reReq.match(line):
291                for req in reString.findall(line):
292                    if re.search("VO",req):
293                        common.logger.message( "SW required: "+req)
294                        continue
295                    if re.search('"\d+',req):
296                        common.logger.message("Other req  : "+req)
297                        continue
298                    common.logger.message( "CE required: "+req)
299                break
300            pass
301        raise CrabException("No compatible resources found!")
302
303    def submit(self, nj):
304        """
305        Submit one EDG job.
306        """
307
308        self.checkProxy()
309        jid = None
310        jdl = common.job_list[nj].jdlFilename()
311
312        cmd = 'edg-job-submit ' + self.configOpt_() + jdl
313        cmd_out = runCommand(cmd)
314        if cmd_out != None:
315            reSid = re.compile( r'https.+' )
316            jid = reSid.search(cmd_out).group()
317            pass
318        return jid
319
512      def getExitStatus(self, id):
513          return self.getStatusAttribute_(id, 'exit_code')
514  
# Line 342 | Line 534 | class SchedulerEdg(Scheduler):
534          jobStat.getStatus(id, level)
535          err, apiMsg = jobStat.get_error()
536          if err:
537 <            print 'Error caught', apiMsg
346 <            common.log.message(apiMsg)
537 >            common.logger.debug(5,'Error caught' + apiMsg)
538              return None
539          else:
540              for i in range(len(self.states)):
541                  # Fill an hash table with all information retrieved from LB API
542                  hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
543 <            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
543 >            result = jobStat.loadStatus(st)[self.states.index(attr)]
544              return result
545  
546      def queryDetailedStatus(self, id):
# Line 358 | Line 549 | class SchedulerEdg(Scheduler):
549          cmd_out = runCommand(cmd)
550          return cmd_out
551  
552 <    def getOutput(self, id):
552 >    ##### FEDE ######        
553 >    def findSites_(self, n_tot_job):
554 >        itr4 = []
555 >       # print "n_tot_job = ", n_tot_job
556 >        for n in range(n_tot_job):
557 >            sites = common.jobDB.destination(n)
558 >            if len(sites)>0 and sites[0]=="Any": continue
559 >
560 >            #job = common.job_list[n]
561 >            #jbt = job.type()
562 >           # print "common.jobDB.destination(n) = ", common.jobDB.destination(n)
563 >           # print "sites = ", sites
564 >            itr = ''
565 >            if sites != [""]:#CarlosDaniele
566 >                for site in sites:
567 >                    #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
568 >                    itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
569 >                    pass
570 >                # remove last ||
571 >                itr = itr[0:-4]
572 >                itr4.append( itr )
573 >        # remove last ,
574 >       # print "itr4 = ", itr4
575 >        return itr4
576 >
577 >    def createXMLSchScript(self, nj, argsList):
578 >   # def createXMLSchScript(self, nj):
579 >        """
580 >        Create a XML-file for BOSS4.
581 >        """
582 >  #      job = common.job_list[nj]
583 >        """
584 >        INDY
585 >        [begin] da rivedere:
586 >        in particolare passerei il jobType ed eliminerei le dipendenze da job
587 >        """
588 >        index = nj - 1
589 >        job = common.job_list[index]
590 >        jbt = job.type()
591 >        
592 >        inp_sandbox = jbt.inputSandbox(index)
593 >        out_sandbox = jbt.outputSandbox(index)
594          """
595 <        Get output for a finished job with id.
364 <        Returns the name of directory with results.
595 >        [end] da rivedere
596          """
597  
598 <        self.checkProxy()
599 <        cmd = 'edg-job-get-output --dir ' + common.work_space.resDir() + ' ' + id
600 <        cmd_out = runCommand(cmd)
598 >        
599 >        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
600 >        jt_string = ''
601 >        
602 >        xml_fname = str(self.jobtypeName)+'.xml'
603 >        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
604  
605 <        # Determine the output directory name
606 <        dir = common.work_space.resDir()
607 <        dir += os.getlogin()
608 <        dir += '_' + os.path.basename(id)
609 <        return dir
605 >        #TaskName  
606 >        dir = string.split(common.work_space.topDir(), '/')
607 >        taskName = dir[len(dir)-2]
608 >  
609 >        to_writeReq = ''
610 >        to_write = ''
611 >
612 >        req=' '
613 >        req = req + jbt.getRequirements()
614 >
615 >
616 >        #sites = common.jobDB.destination(nj)
617 >        #if len(sites)>0 and sites[0]!="Any":
618 >        #    req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
619 >        #req = req    
620 >    
621 >        if self.EDG_requirements:
622 >            if (req == ' '):
623 >                req = req + self.EDG_requirements
624 >            else:
625 >                req = req +  ' && ' + self.EDG_requirements
626 >        if self.EDG_ce_white_list:
627 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
628 >            for i in range(len(ce_white_list)):
629 >                if i == 0:
630 >                    if (req == ' '):
631 >                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
632 >                    else:
633 >                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
634 >                    pass
635 >                else:
636 >                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
637 >            req = req + ')'
638 >        
639 >        if self.EDG_ce_black_list:
640 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
641 >            for ce in ce_black_list:
642 >                if (req == ' '):
643 >                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
644 >                else:
645 >                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
646 >                pass
647 >        if self.EDG_clock_time:
648 >            if (req == ' '):
649 >                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
650 >            else:
651 >                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
652  
653 <    def cancel(self, id):
654 <        """ Cancel the EDG job with id """
655 <        self.checkProxy()
656 <        cmd = 'edg-job-cancel --noint ' + id
657 <        cmd_out = runCommand(cmd)
658 <        return cmd_out
653 >        if self.EDG_cpu_time:
654 >            if (req == ' '):
655 >                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
656 >            else:
657 >                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
658 >                                                                                          
659 >        if ( self.EDG_retry_count ):              
660 >            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
661 >            pass
662  
663 <    def createSchScript(self, nj):
664 <        """
386 <        Create a JDL-file for EDG.
387 <        """
663 >        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
664 >        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
665  
666 <        job = common.job_list[nj]
667 <        jbt = job.type()
668 <        inp_sandbox = jbt.inputSandbox(nj)
669 <        out_sandbox = jbt.outputSandbox(nj)
670 <        inp_storage_subdir = ''
666 >
667 >        #TaskName  
668 >        dir = string.split(common.work_space.topDir(), '/')
669 >        taskName = dir[len(dir)-2]
670 >
671 >        xml.write(str(title))
672 >        xml.write('<task name="' +str(taskName)+'">\n')
673 >        xml.write(jt_string)
674 >
675 >        xml.write('<iterator>\n')
676 >        xml.write('\t<iteratorRule name="ITR1">\n')
677 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
678 >        xml.write('\t</iteratorRule>\n')
679 >        xml.write('\t<iteratorRule name="ITR2">\n')
680 >        for arg in argsList:
681 >            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
682 >            pass
683 >        xml.write('\t</iteratorRule>\n')
684 >        #print jobList
685 >        xml.write('\t<iteratorRule name="ITR3">\n')
686 >        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
687 >        xml.write('\t</iteratorRule>\n')
688 >
689 >        '''
690 >        indy: qui sotto ci sta itr4
691 >        '''
692          
693 <        title = '# This JDL was generated by '+\
694 <                common.prog_name+' (version '+common.prog_version_str+')\n'
695 <        jt_string = ''
693 >        itr4=self.findSites_(nj)
694 >        #print "--->>> itr4 = ", itr4
695 >        if (itr4 != []):
696 >            xml.write('\t<iteratorRule name="ITR4">\n')
697 >        #print argsList
698 >            for arg in itr4:
699 >                xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
700 >                pass
701 >            xml.write('\t</iteratorRule>\n')
702 >            req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
703 >            pass
704 >        #    print "--->>> req= ", req        
705 >        
706 >        if (to_write != ''):
707 >            xml.write('<extraTags\n')
708 >            xml.write(to_write)
709 >            xml.write('/>\n')
710 >            pass
711  
712 +        xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
713 +        xml.write(jt_string)
714  
715 <        
716 <        SPL = inp_storage_subdir
717 <        if ( SPL and SPL[-1] != '/' ) : SPL = SPL + '/'
715 >        if (req != ' '):
716 >            req = req + '\n'
717 >            xml.write('<extraTags>\n')
718 >            xml.write('<Requirements>\n')
719 >            xml.write('<![CDATA[\n')
720 >            xml.write(req)
721 >            xml.write(']]>\n')
722 >            xml.write('</Requirements>\n')
723 >            xml.write('</extraTags>\n')
724 >            pass
725  
726 <        jdl_fname = job.jdlFilename()
405 <        jdl = open(jdl_fname, 'w')
406 <        jdl.write(title)
726 >        #executable
727  
728 +        """
729 +        INDY
730 +        script dipende dal jobType: dovrebbe essere semplice tirarlo fuori in altro modo
731 +        """        
732          script = job.scriptFilename()
733 <        jdl.write('Executable = "' + os.path.basename(script) +'";\n')
734 <        jdl.write(jt_string)
735 <
733 >        xml.write('<program>\n')
734 >        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
735 >        xml.write(jt_string)
736 >    
737 >          
738          ### only one .sh  JDL has arguments:
739 <        firstEvent = common.jobDB.firstEvent(nj)
740 <        maxEvents = common.jobDB.maxEvents(nj)
741 <        jdl.write('Arguments = "' + str(nj+1)+' '+str(firstEvent)+' '+str(maxEvents)+'";\n')
742 <
743 <        inp_box = 'InputSandbox = { '
418 <        inp_box = inp_box + '"' + script + '",'
739 >        ### Fabio
740 > #        xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
741 >        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
742 >        xml.write('<program_types> crabjob </program_types>\n')
743 >        inp_box = script + ','
744  
745          if inp_sandbox != None:
746              for fl in inp_sandbox:
747 <                inp_box = inp_box + ' "' + fl + '",'
747 >                inp_box = inp_box + '' + fl + ','
748                  pass
749              pass
750  
751 <        #if common.use_jam:
752 <        #   inp_box = inp_box+' "'+common.bin_dir+'/'+common.run_jam+'",'
753 <
754 <        for addFile in jbt.additional_inbox_files:
755 <            addFile = os.path.abspath(addFile)
756 <            inp_box = inp_box+' "'+addFile+'",'
757 <            pass
751 >        inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
752 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
753 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
754 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
755 >                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
756 >
757 >        if (not jbt.additional_inbox_files == []):
758 >            inp_box = inp_box + ','
759 >            for addFile in jbt.additional_inbox_files:
760 >                addFile = os.path.abspath(addFile)
761 >                inp_box = inp_box+''+addFile+','
762 >                pass
763  
764          if inp_box[-1] == ',' : inp_box = inp_box[:-1]
765 <        inp_box = inp_box + ' };\n'
766 <        jdl.write(inp_box)
437 <
438 <        jdl.write('StdOutput     = "' + job.stdout() + '";\n')
439 <        jdl.write('StdError      = "' + job.stderr() + '";\n')
765 >        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
766 >        xml.write(inp_box)
767          
768 +        base = jbt.name()
769 +        stdout = base + '__ITR3_.stdout'
770 +        stderr = base + '__ITR3_.stderr'
771          
772 <        if job.stdout() == job.stderr():
773 <          out_box = 'OutputSandbox = { "' + \
774 <                    job.stdout() + '", ".BrokerInfo",'
775 <        else:
776 <          out_box = 'OutputSandbox = { "' + \
777 <                    job.stdout() + '", "' + \
448 <                    job.stderr() + '", ".BrokerInfo",'
772 >        xml.write('<stderr> ' + stderr + '</stderr>\n')
773 >        xml.write('<stdout> ' + stdout + '</stdout>\n')
774 >        
775 >
776 >        out_box = stdout + ',' + \
777 >                  stderr + ',.BrokerInfo,'
778  
779 <        if self.return_data :
779 >        """
780 >        if int(self.return_data) == 1:
781              if out_sandbox != None:
782                  for fl in out_sandbox:
783 <                    out_box = out_box + ' "' + fl + '",'
783 >                    out_box = out_box + '' + fl + ','
784                      pass
785                  pass
786              pass
787 <                                                                                                                                                            
458 <        if out_box[-1] == ',' : out_box = out_box[:-1]
459 <        out_box = out_box + ' };'
460 <        jdl.write(out_box+'\n')
787 >        """
788  
789 <        ### if at least a CE exists ...
790 <        if common.analisys_common_info['sites']:
791 <            if common.analisys_common_info['sw_version']:
792 <                req='Requirements = '
793 <                req=req + 'Member("VO-cms-' + \
794 <                     common.analisys_common_info['sw_version'] + \
795 <                     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
796 <            if len(common.analisys_common_info['sites'])>0:
797 <                req = req + ' && ('
471 <                for i in range(len(common.analisys_common_info['sites'])):
472 <                    req = req + 'other.GlueCEInfoHostName == "' \
473 <                         + common.analisys_common_info['sites'][i] + '"'
474 <                    if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
475 <                        req = req + ' || '
476 <            req = req + ')'
789 >        """
790 >        INDY
791 >        qualcosa del genere andrebbe fatta per gli infiles
792 >        """        
793 >        if int(self.return_data) == 1:
794 >            for fl in jbt.output_file:
795 >                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
796 >                pass
797 >            pass
798  
799 <            #### and USER REQUIREMENT
800 <            if self.EDG_requirements:
801 <                req = req +  ' && ' + self.EDG_requirements
802 <            if self.EDG_clock_time:
803 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
483 <            if self.EDG_cpu_time:
484 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
485 <            req = req + ';\n'
486 <            jdl.write(req)
487 <                                                                                                                                                            
488 <        jdl.write('VirtualOrganisation = "' + self.VO + '";\n')
799 >        if out_box[-1] == ',' : out_box = out_box[:-1]
800 >        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
801 >        xml.write(out_box)
802 >
803 >        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
804  
805 <        if ( self.EDG_retry_count ):              
806 <            jdl.write('RetryCount = '+self.EDG_retry_count+';\n')
807 <            pass
805 >        xml.write('</program>\n')
806 >        xml.write('</chain>\n')
807 >
808 >        xml.write('</iterator>\n')
809 >        xml.write('</task>\n')
810  
811 <        jdl.close()
811 >        xml.close()
812          return
813  
814      def checkProxy(self):
# Line 500 | Line 817 | class SchedulerEdg(Scheduler):
817          """
818          if (self.proxyValid): return
819          timeleft = -999
820 <        minTimeLeft=10 # in hours
821 <        cmd = 'grid-proxy-info -e -v '+str(minTimeLeft)+':00'
822 <        try: cmd_out = runCommand(cmd,0)
823 <        except: print cmd_out
824 <        if (cmd_out == None or cmd_out=='1'):
825 <            common.logger.message( "No valid proxy found or timeleft too short!\n Creating a user proxy with default length of 100h\n")
826 <            cmd = 'grid-proxy-init -valid 100:00'
820 >        minTimeLeft=10*3600 # in seconds
821 >
822 >        minTimeLeftServer = 100 # in hours
823 >
824 >        mustRenew = 0
825 >        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
826 >        timeLeftServer = -999
827 >        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
828 >            mustRenew = 1
829 >        else:
830 >            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
831 >            if not timeLeftServer or not isInt(timeLeftServer):
832 >                mustRenew = 1
833 >            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
834 >                mustRenew = 1
835 >            pass
836 >        pass
837 >
838 >        if mustRenew:
839 >            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")
840 >            cmd = 'voms-proxy-init -voms '+self.VO+' -valid 96:00'
841 >            if self.role:
842 >                cmd = 'voms-proxy-init -voms '+self.VO+':/'+self.VO+'/role='+self.role+' -valid 96:00'
843              try:
844 +                # SL as above: damn it!
845                  out = os.system(cmd)
846                  if (out>0): raise CrabException("Unable to create a valid proxy!\n")
847              except:
848                  msg = "Unable to create a valid proxy!\n"
849                  raise CrabException(msg)
516            cmd = 'grid-proxy-info -timeleft'
517            cmd_out = runCommand(cmd,0)
518            #print cmd_out, time.time()
519            #time.time(cms_out)
850              pass
851 +
852 +        ## now I do have a voms proxy valid, and I check the myproxy server
853 +        renewProxy = 0
854 +        cmd = 'myproxy-info -d -s '+self.proxyServer
855 +        cmd_out = runCommand(cmd,0,20)
856 +        if not cmd_out:
857 +            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
858 +            renewProxy = 1
859 +        else:
860 +            # if myproxy exist but not long enough, renew
861 +            reTime = re.compile( r'timeleft: (\d+)' )
862 +            #print "<"+str(reTime.search( cmd_out ).group(1))+">"
863 +            if reTime.match( cmd_out ):
864 +                time = reTime.search( line ).group(1)
865 +                if time < minTimeLeftServer:
866 +                    renewProxy = 1
867 +                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
868 +                pass
869 +            pass
870 +        
871 +        # if not, create one.
872 +        if renewProxy:
873 +            cmd = 'myproxy-init -d -n -s '+self.proxyServer
874 +            out = os.system(cmd)
875 +            if (out>0):
876 +                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
877 +            pass
878 +
879 +        # cache proxy validity
880          self.proxyValid=1
881          return
882 <    
882 >
883      def configOpt_(self):
884          edg_ui_cfg_opt = ' '
885          if self.edg_config:
886 <          edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
886 >            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
887          if self.edg_config_vo:
888 <          edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
888 >            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
889          return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines