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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines