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.4 by nsmirnov, Wed Jun 22 15:14:57 2005 UTC vs.
Revision 1.101 by slacapra, Tue Oct 17 09:52:57 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines