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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines