ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerGlite.py
(Generate patch)

Comparing COMP/CRAB/python/SchedulerGlite.py (file contents):
Revision 1.2 by spiga, Fri Oct 6 16:29:12 2006 UTC vs.
Revision 1.75 by spiga, Sun Jan 17 19:01:08 2010 UTC

# Line 1 | Line 1
1 < #from Scheduler import Scheduler
2 < from SchedulerEdg import SchedulerEdg
3 < from crab_logger import Logger
1 > """
2 > CRAB interface to BossLite gLite Scheduler
3 > """
4 >
5 > __revision__ = "$Id$"
6 > __version__ = "$Revision$"
7 >
8 > from SchedulerGrid import SchedulerGrid
9   from crab_exceptions import *
10   from crab_util import *
11 < from EdgConfig import *
11 > import EdgLoggingInfo
12   import common
13 + from WMCore.SiteScreening.BlackWhiteListParser import CEBlackWhiteListParser
14  
15   import os, sys, time
16  
17 < class SchedulerGlite(SchedulerEdg):
18 <    def __init__(self):
19 <            SchedulerEdg.__init__(self)
20 <    def sched_parameter(self):
21 <        """
22 <        Returns file with requirements and scheduler-specific parameters
23 <        """
24 <        index = int(common.jobDB.nJobs()) - 1
25 <        job = common.job_list[index]
26 <        jbt = job.type()
27 <        
28 <        lastDest=''
29 <        first = []
30 <        last  = []
31 <        for n in range(common.jobDB.nJobs()):
32 <            currDest=common.jobDB.destination(n)
33 <            if (currDest!=lastDest):
34 <                lastDest = currDest
35 <                first.append(n)
36 <                if n != 0:last.append(n-1)
37 <        if len(first)>len(last) :last.append(common.jobDB.nJobs())
38 <  
17 > class SchedulerGlite(SchedulerGrid):
18 >    def __init__(self, name="GLITE"):
19 >        SchedulerGrid.__init__(self,name)
20 >
21 >        self.OSBsize = 55000000
22 >
23 >    def configure(self,cfg_params):
24 >        SchedulerGrid.configure(self, cfg_params)
25 >        self.environment_unique_identifier = '$GLITE_WMS_JOBID'
26 >
27 >    def realSchedParams(self,cfg_params):
28 >        """
29 >        Return dictionary with specific parameters, to use
30 >        with real scheduler
31 >        """
32 >        self.rb_param_file=''
33 >        if (not cfg_params.has_key('GRID.rb')):
34 >            cfg_params['GRID.rb']='CERN'
35 >        self.rb_param_file=common.scheduler.rb_configure(cfg_params.get("GRID.rb"))
36 >        self.wms_service=cfg_params.get("GRID.wms_service",'')
37 >        self.skipWMSAuth=cfg_params.get("GRID.skipwmsauth",1)
38 >        params = { 'service' : self.wms_service, \
39 >                   'config' : self.rb_param_file, \
40 >                   'skipWMSAuth' : self.skipWMSAuth
41 >                 }
42 >        return  params
43 >
44 >
45 >    def rb_configure(self, RB):
46 >        url ='http://cmsdoc.cern.ch/cms/LCG/crab/config/'
47 >        from Downloader import Downloader
48 >        common.logger.debug('Downloading config files for WMS: '+url)
49 >        ## 25-Jun-2009 SL: patch to use Cream enabled WMS
50 >        if ( self.cfg_params.get('GRID.use_cream',None) ):
51 >            RB='CREAM'
52 >        if not RB: return None
53 >        glite_config = None
54 >        rb_param_file = None
55 >        configFileName = 'glite_wms_'+str(RB)+'.conf'
56 >
57 >        results = Downloader(url, os.getcwd())
58 >        gliteConfig  = results.filePath(configFileName)
59 >
60 >        if (glite_config ):
61 >            rb_param_file = glite_config
62 >        return rb_param_file
63 >
64 >    def ce_list(self):
65 >        """
66 >        Returns string with requirement CE related
67 >        """
68 >        ceParser = CEBlackWhiteListParser(self.EDG_ce_white_list,
69 >                                          self.EDG_ce_black_list, common.logger())
70          req = ''
71 <        req = req + jbt.getRequirements()
72 <    
36 <        if self.EDG_requirements:
37 <            if (req == ' '):
38 <                req = req + self.EDG_requirements
39 <            else:
40 <                req = req +  ' && ' + self.EDG_requirements
71 >        ce_white_list = []
72 >        ce_black_list = []
73          if self.EDG_ce_white_list:
74 <            ce_white_list = string.split(self.EDG_ce_white_list,',')
75 <            for i in range(len(ce_white_list)):
76 <                if i == 0:
77 <                    if (req == ' '):
78 <                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
79 <                    else:
80 <                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
81 <                    pass
82 <                else:
83 <                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
84 <            req = req + ')'
85 <        
74 >            ce_white_list = ceParser.whiteList()
75 >            tmpCe=[]
76 >            concString = '&&'
77 >            for ce in ce_white_list:
78 >                tmpCe.append('RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId)')
79 >            if len(tmpCe) == 1:
80 >                req +=  " && (" + concString.join(tmpCe) + ") "
81 >            elif len(tmpCe) > 1:
82 >                firstCE = 0
83 >                for reqTemp in tmpCe:
84 >                    if firstCE == 0:
85 >                        req += " && ( (" + reqTemp + ") "
86 >                        firstCE = 1
87 >                    elif firstCE > 0:
88 >                        req += " || (" + reqTemp + ") "
89 >                if firstCE > 0:
90 >                    req += ") "
91 >
92          if self.EDG_ce_black_list:
93 <            ce_black_list = string.split(self.EDG_ce_black_list,',')
93 >            ce_black_list = ceParser.blackList()
94 >            tmpCe=[]
95 >            concString = '&&'
96              for ce in ce_black_list:
97 <                if (req == ' '):
98 <                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
99 <                else:
100 <                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
101 <                pass
97 >                tmpCe.append('(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))')
98 >            if len(tmpCe): req += " && (" + concString.join(tmpCe) + ") "
99 >
100 >        # requirement added to skip gliteCE
101 >        # not more needed
102 > #       req += '&& (!RegExp("blah", other.GlueCEUniqueId))'
103 >        retWL = ','.join(ce_white_list)
104 >        retBL = ','.join(ce_black_list)
105 >        if not retWL:
106 >            retWL = None
107 >        if not retBL:
108 >            retBL = None
109 >
110 >        return req, retWL, retBL
111 >
112 >    def se_list(self, dest):
113 >        """
114 >        Returns string with requirement SE related
115 >        """
116 >        hostList=self.findSites_(dest)
117 >        req=''
118 >        reqtmp=[]
119 >        concString = '||'
120 >
121 >        for arg in hostList:
122 >            reqtmp.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
123 >
124 >        if len(reqtmp): req += " && (" + concString.join(reqtmp) + ") "
125 >
126 >        return req
127 >
128 >    def jdlParam(self):
129 >        """
130 >        Returns
131 >        """
132 >        req=''
133 >        if self.EDG_addJdlParam:
134 >            if self.EDG_addJdlParam[-1] == '': self.EDG_addJdlParam= self.EDG_addJdlParam[:-1]
135 >            for p in self.EDG_addJdlParam:
136 >                req+=string.strip(p)+';\n'
137 >        return req
138 >
139 >    def specific_req(self):
140 >        """
141 >        Returns string with specific requirements
142 >        """
143 >        req=''
144          if self.EDG_clock_time:
145 <            if (req == ' '):
146 <                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
65 <            else:
66 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
145 >            if (not req == ' '): req = req + ' && '
146 >            req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
147  
148          if self.EDG_cpu_time:
149 <            if (req == ' '):
150 <                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
71 <            else:
72 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
73 <                
74 <        for i in range(len(first)): # Add loop DS
75 <            self.param='sched_param_'+str(i)+'.clad'
76 <            param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
77 <
78 <            itr4=self.findSites_(first[i])
79 <            if (itr4 != []):
80 <                req1=[]  
81 <                j = 0
82 <                concString = '||'
83 <                for arg in itr4:
84 <                    print "ITR: ", arg
85 <                    #############
86 <                    # MC Changed matching syntax to avoid gang matching
87 <                    #############
88 <                    req1.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
89 <            param_file.write('Requirements = ' + req + " && (" + concString.join(req1) + ');\n')  
90 <  
91 <            if (self.edg_config and self.edg_config_vo != ''):
92 <                param_file.write('RBconfig = "'+self.edg_config+'";\n')  
93 <                param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
94 <
95 <            param_file.close()  
96 <
97 <    def wsSetupEnvironment(self):
98 <        """
99 <        Returns part of a job script which does scheduler-specific work.
100 <        """
101 <        txt = ''
102 <        txt += '# strip arguments\n'
103 <        txt += 'echo "strip arguments"\n'
104 <        txt += 'args=("$@")\n'
105 <        txt += 'nargs=$#\n'
106 <        txt += 'shift $nargs\n'
107 <        txt += "# job number (first parameter for job wrapper)\n"
108 <        txt += "NJob=${args[0]}\n"
109 <
110 <        txt += '# job identification to DashBoard \n'
111 <        txt += 'MonitorJobID=`echo ${NJob}_$GLITE_WMS_JOBID`\n'
112 <        txt += 'SyncGridJobId=`echo $GLITE_WMS_JOBID`\n'
113 <        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
114 <        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
115 <        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
116 <        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
117 <
118 <        txt += 'echo "middleware discovery " \n'
119 <        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
120 <        txt += '    middleware=LCG \n'
121 <        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
122 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
123 <        txt += '    echo "middleware =$middleware" \n'
124 <        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
125 <        txt += '    middleware=OSG \n'
126 <        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
127 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
128 <        txt += '    echo "middleware =$middleware" \n'
129 <        txt += 'elif [ $OSG_APP ]; then \n'
130 <        txt += '    middleware=OSG \n'
131 <        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
132 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
133 <        txt += '    echo "middleware =$middleware" \n'
134 <        txt += 'else \n'
135 <        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
136 <        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
137 <        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
138 <        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
139 <        txt += '    rm -f $RUNTIME_AREA/$repo \n'
140 <        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
141 <        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
142 <        txt += '    exit 1 \n'
143 <        txt += 'fi \n'
144 <
145 <        txt += '# report first time to DashBoard \n'
146 <        txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
147 <        txt += 'rm -f $RUNTIME_AREA/$repo \n'
148 <        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
149 <        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
150 <        
151 <        txt += '\n\n'
152 <
153 <        if int(self.copy_data) == 1:
154 <           if self.SE:
155 <              txt += 'export SE='+self.SE+'\n'
156 <              txt += 'echo "SE = $SE"\n'
157 <           if self.SE_PATH:
158 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
159 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
160 <              txt += 'echo "SE_PATH = $SE_PATH"\n'
161 <
162 <        txt += 'export VO='+self.VO+'\n'
163 <        ### some line for LFC catalog setting
164 <        txt += 'if [ $middleware == LCG ]; then \n'
165 <        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
166 <        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
167 <        txt += '    fi\n'
168 <        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
169 <        txt += '        export LFC_HOST='+self.lfc_host+'\n'
170 <        txt += '    fi\n'
171 <        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
172 <        txt += '        export LFC_HOME='+self.lfc_home+'\n'
173 <        txt += '    fi\n'
174 <        txt += 'elif [ $middleware == OSG ]; then\n'
175 <        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
176 <        txt += 'fi\n'
177 <        #####
178 <        if int(self.register_data) == 1:
179 <           txt += 'if [ $middleware == LCG ]; then \n'
180 <           txt += '    export LFN='+self.LFN+'\n'
181 <           txt += '    lfc-ls $LFN\n'
182 <           txt += '    result=$?\n'
183 <           txt += '    echo $result\n'
184 <           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
185 <           txt += '    if [ $result != 0 ]; then\n'
186 <           txt += '       lfc-mkdir $LFN\n'
187 <           txt += '       result=$?\n'
188 <           txt += '       echo $result\n'
189 <           txt += '    fi\n'
190 <           txt += 'elif [ $middleware == OSG ]; then\n'
191 <           txt += '    echo " Files registration to be implemented for OSG"\n'
192 <           txt += 'fi\n'
193 <           txt += '\n'
194 <
195 <           if self.VO:
196 <              txt += 'export VO='+self.VO+'\n'
197 <           if self.LFN:
198 <              txt += 'if [ $middleware == LCG ]; then \n'
199 <              txt += '    export LFN='+self.LFN+'\n'
200 <              txt += 'fi\n'
201 <              txt += '\n'
202 <
203 <        txt += 'if [ $middleware == LCG ]; then\n'
204 <        txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
205 <        txt += '    echo "CloseCEs = $CloseCEs"\n'
206 <        txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
207 <        txt += '    echo "CE = $CE"\n'
208 <        txt += 'elif [ $middleware == OSG ]; then \n'
209 <        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
210 <        txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
211 <        txt += '    else \n'
212 <        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
213 <        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
214 <        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
215 <        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
216 <        txt += '        rm -f $RUNTIME_AREA/$repo \n'
217 <        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
218 <        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
219 <        txt += '        exit 1 \n'
220 <        txt += '    fi \n'
221 <        txt += 'fi \n'
149 >            if (not req == ' '): req = req + ' && '
150 >            req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
151  
152 <        return txt
153 <        
154 <    def loggingInfo(self, id):
152 >        return req
153 >
154 >    def sched_parameter(self,i,task):
155 >        """
156 >        Returns string with requirements and scheduler-specific parameters
157 >        """
158 >        dest=  task.jobs[i-1]['dlsDestination']
159 >
160 >        req=''
161 >        req +=task['jobType']
162 >
163 >        sched_param=''
164 >        sched_param+='Requirements = ' + req +self.specific_req() + self.se_list(dest) +\
165 >                                        self.ce_list()[0] +';\n'
166 >        if self.EDG_addJdlParam: sched_param+=self.jdlParam()
167 >        sched_param+='MyProxyServer = "' + self.proxyServer + '";\n'
168 >        sched_param+='VirtualOrganisation = "' + self.VO + '";\n'
169 >        sched_param+='RetryCount = '+str(self.EDG_retry_count)+';\n'
170 >        sched_param+='ShallowRetryCount = '+str(self.EDG_shallow_retry_count)+';\n'
171 >
172 >        return sched_param
173 >
174 >    def decodeLogInfo(self, file):
175          """
176 <        retrieve the logging info from logging and bookkeeping and return it
176 >        Parse logging info file and return main info
177          """
178 <        self.checkProxy()
179 <        cmd = 'glite-job-logging-info -v 2 ' + id
180 <        cmd_out = runCommand(cmd)
181 <        return cmd_out
182 <
183 <    def queryDetailedStatus(self, id):
184 <        """ Query a detailed status of the job with id """
236 <        cmd = 'glite-job-status '+id
237 <        cmd_out = runCommand(cmd)
238 <        return cmd_out
239 <
240 <    def findSites_(self, n):
241 <        itr4 =[]
242 <        sites = common.jobDB.destination(n)
243 <        if len(sites)>0 and sites[0]=="Any":
178 >        loggingInfo = EdgLoggingInfo.EdgLoggingInfo()
179 >        reason = loggingInfo.decodeReason(file)
180 >        return reason
181 >
182 >    def findSites_(self, sites):
183 >        itr4 =[]
184 >        if len(sites)>0 and sites[0]=="":
185              return itr4
186 <        if sites != [""]:
187 <            return sites
186 >        if sites != [""]:
187 >            replicas = self.blackWhiteListParser.checkBlackList(sites)
188 >            if len(replicas)!=0:
189 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas)
190 >
191 >            itr4 = replicas
192 >        return itr4
193 >
194 >    def delegateProxy(self):
195 >        self.boss().delegateProxy()  
196 >        return
197 >
198 >    def wsExitFunc(self):
199 >        """
200 >        """
201 >        txt = '\n'
202 >
203 >        txt += '#\n'
204 >        txt += '# EXECUTE THIS FUNCTION BEFORE EXIT \n'
205 >        txt += '#\n\n'
206 >
207 >        txt += 'func_exit() { \n'
208 >        txt += self.wsExitFunc_common()
209 >        ### specific Glite check for OSB
210 >        txt += '    tar zcvf ${out_files}.tgz  ${final_list}\n'
211 >        txt += '    tmp_size=`ls -gGrta ${out_files}.tgz | awk \'{ print $3 }\'`\n'
212 >        txt += '    rm ${out_files}.tgz\n'
213 >        txt += '    size=`expr $tmp_size`\n'
214 >        txt += '    echo "Total Output dimension: $size"\n'
215 >        txt += '    limit='+str(self.OSBsize) +' \n'
216 >        txt += '    echo "WARNING: output files size limit is set to: $limit"\n'
217 >        txt += '    if [ "$limit" -lt "$size" ]; then\n'
218 >        txt += '        exceed=1\n'
219 >        txt += '        job_exit_code=70000\n'
220 >        txt += '        echo "Output Sanbox too big. Produced output is lost "\n'
221 >        txt += '    else\n'
222 >        txt += '        exceed=0\n'
223 >        txt += '        echo "Total Output dimension $size is fine."\n'
224 >        txt += '    fi\n'
225 >
226 >        txt += '    echo "JOB_EXIT_STATUS = $job_exit_code"\n'
227 >        txt += '    echo "JobExitCode=$job_exit_code" >> $RUNTIME_AREA/$repo\n'
228 >        txt += '    dumpStatus $RUNTIME_AREA/$repo\n'
229 >        txt += '    if [ $exceed -ne 1 ]; then\n'
230 >        txt += '        tar zcvf ${out_files}.tgz  ${final_list}\n'
231 >        txt += '    else\n'
232 >        txt += '        tar zcvf ${out_files}.tgz CMSSW_${NJob}.stdout CMSSW_${NJob}.stderr\n'
233 >        txt += '    fi\n'
234 >        txt += '    python $RUNTIME_AREA/fillCrabFjr.py $RUNTIME_AREA/crab_fjr_$NJob.xml --errorcode $job_exit_code \n'
235 >        txt += '    exit $job_exit_code\n'
236 >
237 >        txt += '}\n'
238 >        return txt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines