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.4 by fanzago, Wed Oct 11 15:45:53 2006 UTC vs.
Revision 1.41 by spiga, Fri Mar 21 16:30:10 2008 UTC

# Line 1 | Line 1
1 < #from Scheduler import Scheduler
2 < from SchedulerEdg import SchedulerEdg
1 > from SchedulerGrid import SchedulerGrid
2   from crab_logger import Logger
3   from crab_exceptions import *
4   from crab_util import *
6 #from EdgConfig import *
5   from GliteConfig import *
6   import common
7  
8   import os, sys, time
9  
10 < class SchedulerGlite(SchedulerEdg):
11 <    def __init__(self):
12 <        SchedulerEdg.__init__(self)
10 > class SchedulerGlite(SchedulerGrid):
11 >    def __init__(self, name="GLITE"):
12 >        SchedulerGrid.__init__(self,name)
13 >
14 >    def configure(self,cfg_params):
15 >        SchedulerGrid.configure(self, cfg_params)
16 >        self.environment_unique_identifier = 'GLITE_WMS_JOBID'
17  
18      def rb_configure(self, RB):
19 <        self.glite_config = ''
20 <        self.rb_param_file = ''
19 >        if not RB: return None
20 >        glite_config = None
21 >        rb_param_file = None
22  
23          gliteConfig = GliteConfig(RB)
24 <        self.glite_config = gliteConfig.config()
24 >        glite_config = gliteConfig.config()
25  
26 <        if (self.glite_config != ''):
27 <            self.rb_param_file = 'WMSconfig = '+self.glite_config+';'
28 <            #print "rb_param_file = ", self.rb_param_file
26 <        return self.rb_param_file
26 >        if (glite_config ):
27 >            rb_param_file = glite_config
28 >        return rb_param_file
29  
30 <    def sched_parameter(self):
30 >    def ce_list(self):
31          """
32 <        Returns file with requirements and scheduler-specific parameters
32 >        Returns string with requirement CE related    
33          """
34 <        index = int(common.jobDB.nJobs()) - 1
33 <        job = common.job_list[index]
34 <        jbt = job.type()
35 <        
36 <        lastDest=''
37 <        first = []
38 <        last  = []
39 <        for n in range(common.jobDB.nJobs()):
40 <            currDest=common.jobDB.destination(n)
41 <            if (currDest!=lastDest):
42 <                lastDest = currDest
43 <                first.append(n)
44 <                if n != 0:last.append(n-1)
45 <        if len(first)>len(last) :last.append(common.jobDB.nJobs())
46 <  
47 <        req = ''
48 <        req = req + jbt.getRequirements()
49 <    
50 <        if self.EDG_requirements:
51 <            if (req == ' '):
52 <                req = req + self.EDG_requirements
53 <            else:
54 <                req = req +  ' && ' + self.EDG_requirements
34 >        req = ''  
35          if self.EDG_ce_white_list:
36 <            ce_white_list = string.split(self.EDG_ce_white_list,',')
37 <            for i in range(len(ce_white_list)):
38 <                if i == 0:
39 <                    if (req == ' '):
40 <                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
41 <                    else:
42 <                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
43 <                    pass
44 <                else:
45 <                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
46 <            req = req + ')'
47 <        
36 >            ce_white_list = self.EDG_ce_white_list
37 >            tmpCe=[]
38 >            concString = '&&'
39 >            for ce in ce_white_list:
40 >                tmpCe.append('RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId)')
41 >            if len(tmpCe) == 1:
42 >                req +=  " && (" + concString.join(tmpCe) + ") "
43 >            elif len(tmpCe) > 1:
44 >                firstCE = 0
45 >                for reqTemp in tmpCe:
46 >                    if firstCE == 0:
47 >                        req += " && ( (" + reqTemp + ") "
48 >                        firstCE = 1
49 >                    elif firstCE > 0:
50 >                        req += " || (" + reqTemp + ") "
51 >                if firstCE > 0:
52 >                    req += ") "
53 >
54          if self.EDG_ce_black_list:
55 <            ce_black_list = string.split(self.EDG_ce_black_list,',')
55 >            ce_black_list = self.EDG_ce_black_list
56 >            tmpCe=[]
57 >            concString = '&&'
58              for ce in ce_black_list:
59 <                if (req == ' '):
60 <                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
61 <                else:
62 <                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
63 <                pass
59 >                tmpCe.append('(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))')
60 >            if len(tmpCe): req += " && (" + concString.join(tmpCe) + ") "
61 >
62 >        # requirement added to skip gliteCE
63 >        req += '&& (!RegExp("blah", other.GlueCEUniqueId))'
64 >
65 >        return req,self.EDG_ce_white_list,self.EDG_ce_black_list
66 >
67 >    def se_list(self, id, dest):
68 >        """
69 >        Returns string with requirement SE related    
70 >        """  
71 >        hostList=self.findSites_(id,dest)
72 >        req=''
73 >        reqtmp=[]
74 >        concString = '||'
75 >
76 >        for arg in hostList:
77 >            reqtmp.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
78 >
79 >        if len(reqtmp): req += " && (" + concString.join(reqtmp) + ") "
80 >
81 >        return req
82 >
83 >    def jdlParam(self):
84 >        """
85 >        Returns
86 >        """
87 >        req=''
88 >        if self.EDG_addJdlParam:
89 >            if self.EDG_addJdlParam[-1] == '': self.EDG_addJdlParam= self.EDG_addJdlParam[:-1]
90 >            for p in self.EDG_addJdlParam:
91 >             #   param_file.write(string.strip(p)+';\n')
92 >                req+=string.strip(p)+';\n' ## BL--DS
93 >        return req
94 >
95 >    def specific_req(self):
96 >        """
97 >        Returns string with specific requirements
98 >        """
99 >        req=''
100          if self.EDG_clock_time:
101 <            if (req == ' '):
102 <                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
79 <            else:
80 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
101 >            if (not req == ' '): req = req + ' && '
102 >            req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
103  
104          if self.EDG_cpu_time:
105 <            if (req == ' '):
106 <                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
107 <            else:
108 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
109 <                
110 <        for i in range(len(first)): # Add loop DS
111 <            self.param='sched_param_'+str(i)+'.clad'
112 <            param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
113 <
114 <            itr4=self.findSites_(first[i])
115 <            req1=[]  
116 <            j = 0
117 <            concString = '||'
118 <            for arg in itr4:
119 <                #############
120 <                # MC Changed matching syntax to avoid gang matching
121 <                #############
122 <                req1.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
123 <            if len(req1): req = req + " && (" + concString.join(req1) + ')'
124 <            req = req + ';\n'
125 <            param_file.write('Requirements = ' + req )
104 <  
105 < #            if (self.edg_config and self.edg_config_vo != ''):
106 < #               param_file.write('RBconfig = "'+self.edg_config+'";\n')  
107 < #                param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
105 >            if (not req == ' '): req = req + ' && '
106 >            req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
107 >        
108 >        return req
109 >
110 >    def sched_fix_parameter(self):
111 >        """
112 >        Returns string with requirements and scheduler-specific parameters
113 >        """
114 >        index = int(common._db.nJobs())
115 >        job = common.job_list[index-1]
116 >        jbt = job.type()
117 >        req = ''
118 >        req = req + jbt.getRequirements()
119 >
120 >        if self.EDG_requirements:
121 >            if (not req == ' '): req = req +  ' && '
122 >            req = req + self.EDG_requirements
123 >
124 >        Task_Req={'jobType':req}## DS--BL
125 >        common._db.updateTask_(Task_Req)        
126  
127 <            if (self.rb_param_file != ''):
128 <                param_file.write(self.rb_param_file)  
127 >    def sched_parameter(self,i,task):
128 >        """
129 >        Returns string with requirements and scheduler-specific parameters
130 >        """
131 >        dest=  eval(task.jobs[i]['dlsDestination']) ## DS--BL
132  
133 +        req=''
134 +        req +=task['jobType']
135  
136 <            param_file.close()  
136 >        sched_param=''
137 >        sched_param+='Requirements = ' + req +self.specific_req() + self.se_list(i,dest) +\
138 >                                        self.ce_list()[0] +';\n' ## BL--DS
139 >        if self.EDG_addJdlParam: sched_param+=self.jdlParam() ## BL--DS
140 >        sched_param+='MyProxyServer = "' + self.proxyServer + '";\n'
141 >        sched_param+='VirtualOrganisation = "' + self.VO + '";\n'
142 >        sched_param+='RetryCount = '+str(self.EDG_retry_count)+';\n'
143 >        sched_param+='ShallowRetryCount = '+str(self.EDG_shallow_retry_count)+';\n'
144  
145 +        return sched_param
146 +  
147      def wsSetupEnvironment(self):
148          """
149          Returns part of a job script which does scheduler-specific work.
# Line 123 | Line 155 | class SchedulerGlite(SchedulerEdg):
155          txt += 'nargs=$#\n'
156          txt += 'shift $nargs\n'
157          txt += "# job number (first parameter for job wrapper)\n"
158 <        txt += "NJob=${args[0]}\n"
158 >        txt += "NJob=${args[0]}; export NJob\n"
159  
160          txt += '# job identification to DashBoard \n'
161 <        txt += 'MonitorJobID=`echo ${NJob}_$GLITE_WMS_JOBID`\n'
162 <        txt += 'SyncGridJobId=`echo $GLITE_WMS_JOBID`\n'
163 <        txt += 'MonitorID=`echo ' + self._taskId + '`\n'
164 <        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
165 <        txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
166 <        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
161 >        #txt += 'MonitorJobID=`echo ${NJob}_$GLITE_WMS_JOBID`\n'
162 >        #txt += 'SyncGridJobId=`echo $GLITE_WMS_JOBID`\n'
163 >        #txt += 'MonitorID=`echo ' + self._taskId + '`\n'
164 >        txt += 'MonitorJobID=${NJob}_$GLITE_WMS_JOBID \n'
165 >        txt += 'SyncGridJobId=$GLITE_WMS_JOBID \n'
166 >        txt += 'MonitorID='+self._taskId+' \n'
167 >        txt += 'echo "MonitorJobID=$MonitorJobID" > $RUNTIME_AREA/$repo \n'
168 >        txt += 'echo "SyncGridJobId=$SyncGridJobId" >> $RUNTIME_AREA/$repo \n'
169 >        txt += 'echo "MonitorID=$MonitorID" >> $RUNTIME_AREA/$repo\n'
170 >        #txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
171 >        #txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
172 >        #txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
173  
174 <        txt += 'echo "middleware discovery " \n'
174 >        #txt += 'echo "middleware discovery: " \n'
175 >        txt += 'echo ">>> GridFlavour discovery: " \n'
176          txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
177 <        txt += '    middleware=LCG \n'
178 <        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
179 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
180 <        txt += '    echo "middleware =$middleware" \n'
181 <        txt += 'elif [ $GRID3_APP_DIR ]; then\n'
182 <        txt += '    middleware=OSG \n'
144 <        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
145 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
146 <        txt += '    echo "middleware =$middleware" \n'
177 >        txt += '    middleware=LCG\n'
178 >        #txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
179 >        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" >> $RUNTIME_AREA/$repo \n'
180 >        #txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
181 >        txt += '    echo "GridFlavour=$middleware" | tee -a $RUNTIME_AREA/$repo \n'
182 >        #txt += '    echo ">>> middleware =$middleware" \n'
183          txt += 'elif [ $OSG_APP ]; then \n'
184          txt += '    middleware=OSG \n'
185 <        txt += '    echo "SyncCE=`echo $EDG_WL_LOG_DESTINATION`" | tee -a $RUNTIME_AREA/$repo \n'
186 <        txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
187 <        txt += '    echo "middleware =$middleware" \n'
185 >        txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
186 >        txt += '        SyncCE="$OSG_JOB_CONTACT"; \n'
187 >        #txt += '        echo "SyncCE=$SyncCE" | tee -a $RUNTIME_AREA/$repo ;\n'
188 >        txt += '        echo "SyncCE=$SyncCE" >> $RUNTIME_AREA/$repo ;\n'
189 >        txt += '    else\n'
190 >        txt += '        echo "not reporting SyncCE";\n'
191 >        txt += '    fi\n';
192 >        txt += '    echo "GridFlavour=$middleware" | tee -a $RUNTIME_AREA/$repo \n'
193 >        #txt += '    echo ">>> middleware =$middleware" \n'
194          txt += 'else \n'
195 <        txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
196 <        txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
197 <        txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
198 <        txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
199 <        txt += '    rm -f $RUNTIME_AREA/$repo \n'
200 <        txt += '    echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
201 <        txt += '    echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
202 <        txt += '    exit 1 \n'
195 >        txt += '    echo "ERROR ==> GridFlavour not identified" \n'
196 >        txt += '    job_exit_code=10030\n'
197 >        txt += '    func_exit \n'
198 >        #txt += '    echo "SET_CMS_ENV 10030 ==> middleware not identified" \n'
199 >        #txt += '    echo "JOB_EXIT_STATUS = 10030" \n'
200 >        #txt += '    echo "JobExitCode=10030" | tee -a $RUNTIME_AREA/$repo \n'
201 >        #txt += '    dumpStatus $RUNTIME_AREA/$repo \n'
202 >        #txt += '    exit 1 \n'
203          txt += 'fi \n'
204  
163        txt += '# report first time to DashBoard \n'
205          txt += 'dumpStatus $RUNTIME_AREA/$repo \n'
165        txt += 'rm -f $RUNTIME_AREA/$repo \n'
166        txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
167        txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
168        
169        txt += '\n\n'
206  
207 <        if int(self.copy_data) == 1:
172 <           if self.SE:
173 <              txt += 'export SE='+self.SE+'\n'
174 <              txt += 'echo "SE = $SE"\n'
175 <           if self.SE_PATH:
176 <              if ( self.SE_PATH[-1] != '/' ) : self.SE_PATH = self.SE_PATH + '/'
177 <              txt += 'export SE_PATH='+self.SE_PATH+'\n'
178 <              txt += 'echo "SE_PATH = $SE_PATH"\n'
207 >        txt += '\n\n'
208  
209          txt += 'export VO='+self.VO+'\n'
210 <        ### some line for LFC catalog setting
182 <        txt += 'if [ $middleware == LCG ]; then \n'
183 <        txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
184 <        txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
185 <        txt += '    fi\n'
186 <        txt += '    if [[ $LFC_HOST != \''+self.lfc_host+'\' ]]; then\n'
187 <        txt += '        export LFC_HOST='+self.lfc_host+'\n'
188 <        txt += '    fi\n'
189 <        txt += '    if [[ $LFC_HOME != \''+self.lfc_home+'\' ]]; then\n'
190 <        txt += '        export LFC_HOME='+self.lfc_home+'\n'
191 <        txt += '    fi\n'
192 <        txt += 'elif [ $middleware == OSG ]; then\n'
193 <        txt += '    echo "LFC catalog setting to be implemented for OSG"\n'
194 <        txt += 'fi\n'
195 <        #####
196 <        if int(self.register_data) == 1:
197 <           txt += 'if [ $middleware == LCG ]; then \n'
198 <           txt += '    export LFN='+self.LFN+'\n'
199 <           txt += '    lfc-ls $LFN\n'
200 <           txt += '    result=$?\n'
201 <           txt += '    echo $result\n'
202 <           ### creation of LFN dir in LFC catalog, under /grid/cms dir  
203 <           txt += '    if [ $result != 0 ]; then\n'
204 <           txt += '       lfc-mkdir $LFN\n'
205 <           txt += '       result=$?\n'
206 <           txt += '       echo $result\n'
207 <           txt += '    fi\n'
208 <           txt += 'elif [ $middleware == OSG ]; then\n'
209 <           txt += '    echo " Files registration to be implemented for OSG"\n'
210 <           txt += 'fi\n'
211 <           txt += '\n'
212 <
213 <           if self.VO:
214 <              txt += 'export VO='+self.VO+'\n'
215 <           if self.LFN:
216 <              txt += 'if [ $middleware == LCG ]; then \n'
217 <              txt += '    export LFN='+self.LFN+'\n'
218 <              txt += 'fi\n'
219 <              txt += '\n'
220 <
221 <        txt += 'if [ $middleware == LCG ]; then\n'
210 >        txt += 'if [ $middleware == LCG ]; then\n'
211          txt += '    CloseCEs=`glite-brokerinfo getCE`\n'
212          txt += '    echo "CloseCEs = $CloseCEs"\n'
213          txt += '    CE=`echo $CloseCEs | sed -e "s/:.*//"`\n'
# Line 227 | Line 216 | class SchedulerGlite(SchedulerEdg):
216          txt += '    if [ $OSG_JOB_CONTACT ]; then \n'
217          txt += '        CE=`echo $OSG_JOB_CONTACT | /usr/bin/awk -F\/ \'{print $1}\'` \n'
218          txt += '    else \n'
219 <        txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
220 <        txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
221 <        txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
222 <        txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
223 <        txt += '        rm -f $RUNTIME_AREA/$repo \n'
224 <        txt += '        echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
225 <        txt += '        echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
226 <        txt += '        exit 1 \n'
219 >        txt += '        echo "ERROR ==> OSG mode in setting CE name from OSG_JOB_CONTACT" \n'
220 >        txt += '        job_exit_code=10099\n'
221 >        txt += '        func_exit \n'
222 >        #txt += '        echo "SET_CMS_ENV 10099 ==> OSG mode: ERROR in setting CE name from OSG_JOB_CONTACT" \n'
223 >        #txt += '        echo "JOB_EXIT_STATUS = 10099" \n'
224 >        #txt += '        echo "JobExitCode=10099" | tee -a $RUNTIME_AREA/$repo \n'
225 >        #txt += '        dumpStatus $RUNTIME_AREA/$repo \n'
226 >        #txt += '        exit 1 \n'
227          txt += '    fi \n'
228 <        txt += 'fi \n'
228 >        txt += 'fi \n'
229  
230          return txt
231 <        
231 >
232      def loggingInfo(self, id):
233          """
234          retrieve the logging info from logging and bookkeeping and return it
235          """
236          self.checkProxy()
237 <        cmd = 'glite-job-logging-info -v 2 ' + id
237 >        cmd = 'glite-job-logging-info -v 3 ' + id
238          cmd_out = runCommand(cmd)
239          return cmd_out
240  
# Line 255 | Line 244 | class SchedulerGlite(SchedulerEdg):
244          cmd_out = runCommand(cmd)
245          return cmd_out
246  
247 <    def findSites_(self, n):
248 <        sites = common.jobDB.destination(n)
247 >    def findSites_(self, n, sites):
248 >        itr4 =[]
249          if len(sites)>0 and sites[0]=="":
250 <            return []
251 <        return sites
250 >            return itr4
251 >        if sites != [""]:
252 >            ##Addedd Daniele
253 >            replicas = self.blackWhiteListParser.checkBlackList(sites,n)
254 >            if len(replicas)!=0:
255 >                replicas = self.blackWhiteListParser.checkWhiteList(replicas,n)
256 >        
257 >            itr4 = replicas
258 >            #####
259 >        return itr4
260 >
261 >
262 >
263 >
264 >    def tOut(self, list):
265 >        return 180

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines