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.8 by slacapra, Tue Aug 23 10:38:09 2005 UTC vs.
Revision 1.102 by slacapra, Tue Oct 17 13:28:03 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines