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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines