ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Submitter.py
Revision: 1.81
Committed: Fri Oct 5 12:09:51 2007 UTC (17 years, 7 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.80: +19 -1 lines
Log Message:
Added ce_white/black_list in glite list-match + bug fix ce_white_list

File Contents

# User Rev Content
1 nsmirnov 1.1 from Actor import *
2 nsmirnov 1.6 from crab_util import *
3 nsmirnov 1.2 import common
4 corvo 1.9 from ApmonIf import ApmonIf
5 spiga 1.10 import Statistic
6 slacapra 1.60 #from random import random
7 corvo 1.30 import time
8 slacapra 1.60 from ProgressBar import ProgressBar
9     from TerminalController import TerminalController
10 nsmirnov 1.1
11     class Submitter(Actor):
12 corvo 1.40 def __init__(self, cfg_params, nj_list):
13 nsmirnov 1.1 self.cfg_params = cfg_params
14 nsmirnov 1.4 self.nj_list = nj_list
15 gutsche 1.58
16     if common.scheduler.boss_scheduler_name == 'condor_g':
17     # create hash of cfg file
18     self.hash = makeCksum(common.work_space.cfgFileName())
19     else:
20     self.hash = ''
21 corvo 1.30
22 spiga 1.77 self.UseServer=0
23     try:
24     self.UseServer=int(self.cfg_params['CRAB.server_mode'])
25     except KeyError:
26     pass
27    
28 nsmirnov 1.1 return
29    
30     def run(self):
31 nsmirnov 1.2 """
32 slacapra 1.53 The main method of the class: submit jobs in range self.nj_list
33 nsmirnov 1.2 """
34     common.logger.debug(5, "Submitter::run() called")
35 slacapra 1.24
36 gutsche 1.42 totalCreatedJobs= 0
37 corvo 1.33 start = time.time()
38 slacapra 1.24 for nj in range(common.jobDB.nJobs()):
39 spiga 1.29 if (common.jobDB.status(nj)=='C') or (common.jobDB.status(nj)=='RC'): totalCreatedJobs +=1
40 slacapra 1.24 pass
41    
42     if (totalCreatedJobs==0):
43     common.logger.message("No jobs to be submitted: first create them")
44 slacapra 1.28 return
45 slacapra 1.60
46 gutsche 1.70 # submit pre DashBoard information
47     params = {'jobId':'TaskMeta'}
48    
49     fl = open(common.work_space.shareDir() + '/' + self.cfg_params['apmon'].fName, 'r')
50     for i in fl.readlines():
51     val = i.split(':')
52     params[val[0]] = string.strip(val[1])
53     fl.close()
54    
55     common.logger.debug(5,'Submission DashBoard Pre-Submission report: '+str(params))
56    
57     self.cfg_params['apmon'].sendToML(params)
58    
59 spiga 1.77 # modified to support server mode
60     # The boss declare step is performed here
61     # only if crab is used server mode
62     if (self.UseServer== 9999):
63     if not common.scheduler.taskDeclared( common.taskDB.dict('projectName') ): #os.path.basename(os.path.split(common.work_space.topDir())[0]) ):
64     common.logger.debug(5,'Declaring jobs to BOSS')
65     common.scheduler.declareJob_() #Add for BOSS4
66     else:
67     common.logger.debug(5,'Jobs already declared into BOSS')
68     common.jobDB.save()
69     common.taskDB.save()
70    
71     #########
72 fanzago 1.16 #########
73 nsmirnov 1.2 # Loop over jobs
74 nsmirnov 1.6 njs = 0
75 corvo 1.15 try:
76 slacapra 1.69 list=[]
77 spiga 1.66 list_of_list = []
78 slacapra 1.57 lastBlock=-1
79 spiga 1.66 count = 0
80 corvo 1.17 for nj in self.nj_list:
81 slacapra 1.53 same=0
82 slacapra 1.49 # first check that status of the job is suitable for submission
83 corvo 1.17 st = common.jobDB.status(nj)
84 slacapra 1.69 if st != 'C' and st != 'K' and st != 'A' and st != 'RC':
85 corvo 1.17 long_st = crabJobStatusToString(st)
86 slacapra 1.19 msg = "Job # %d not submitted: status %s"%(nj+1, long_st)
87 slacapra 1.18 common.logger.message(msg)
88 corvo 1.17 continue
89 corvo 1.72
90 slacapra 1.57 currBlock = common.jobDB.block(nj)
91     # SL perform listmatch only if block has changed
92     if (currBlock!=lastBlock):
93 gutsche 1.54 if common.scheduler.boss_scheduler_name != "condor_g" :
94 mcinquil 1.81 ### MATTY: patch for white-black list with the list-mathc in glite ###
95     whiteL = []
96     blackL = []
97     if 'EDG.ce_white_list' in self.cfg_params.keys():
98     print self.cfg_params['EDG.ce_white_list'].strip().split(",")
99     if self.cfg_params['EDG.ce_white_list'].strip() != "" and self.cfg_params['EDG.ce_white_list'] != None:
100     for ceW in self.cfg_params['EDG.ce_white_list'].strip().split(","):
101     if len(ceW.strip()) > 0 and ceW.strip() != None:
102     whiteL.append(ceW.strip())
103     #print "ADDING white ce = "+str(ceW.strip())
104     if 'EDG.ce_black_list' in self.cfg_params.keys():
105     print self.cfg_params['EDG.ce_black_list'].strip().split(",")
106     if self.cfg_params['EDG.ce_black_list'].strip() != "" and self.cfg_params['EDG.ce_black_list'] != None:
107     for ceB in self.cfg_params['EDG.ce_black_list'].strip().split(","):
108     if len(ceB.strip()) > 0 and ceB.strip() != None:
109     blackL.append(ceB.strip())
110     #print "ADDING ce = "+str(ceB.strip())
111     #######################################################################
112     match = common.scheduler.listMatch(nj, currBlock, whiteL, blackL)
113 gutsche 1.54 else :
114     match = "1"
115 slacapra 1.57 lastBlock = currBlock
116 mkirn 1.50 else:
117 slacapra 1.53 common.logger.debug(1,"Sites for job "+str(nj+1)+" the same as previous job")
118     same=1
119 corvo 1.72
120 slacapra 1.49 if match:
121 slacapra 1.53 if not same:
122     common.logger.message("Found "+str(match)+" compatible site(s) for job "+str(nj+1))
123     else:
124     common.logger.debug(1,"Found "+str(match)+" compatible site(s) for job "+str(nj+1))
125 slacapra 1.69 list.append(common.jobDB.bossId(nj))
126 corvo 1.72
127 slacapra 1.69 if nj == self.nj_list[-1]: # check that is not the last job in the list
128     list_of_list.append([currBlock,list])
129     else: # check if next job has same group
130     nextBlock = common.jobDB.block(nj+1)
131     if currBlock != nextBlock : # if not, close this group and reset
132 spiga 1.66 list_of_list.append([currBlock,list])
133 slacapra 1.69 list=[]
134 slacapra 1.49 else:
135 mkirn 1.50 common.logger.message("No compatible site found, will not submit job "+str(nj+1))
136 slacapra 1.49 continue
137 spiga 1.66 count += 1
138 gutsche 1.65 ### Progress Bar indicator, deactivate for debug
139     if not common.logger.debugLevel() :
140     term = TerminalController()
141 corvo 1.72
142 spiga 1.66 for ii in range(len(list_of_list)): # Add loop DS
143 slacapra 1.68 common.logger.debug(1,'Submitting jobs '+str(list_of_list[ii][1]))
144 corvo 1.74 if not common.logger.debugLevel() :
145     try: pbar = ProgressBar(term, 'Submitting '+str(len(list_of_list[ii][1]))+' jobs')
146     except: pbar = None
147 mcinquil 1.78
148 spiga 1.79 jidLista, bjidLista = common.scheduler.submit(list_of_list[ii])
149 slacapra 1.69 bjidLista = map(int, bjidLista) # cast all bjidLista to int
150 mcinquil 1.78
151 corvo 1.74 if not common.logger.debugLevel():
152     if pbar :
153     pbar.update(float(ii+1)/float(len(list_of_list)),'please wait')
154 corvo 1.72
155 corvo 1.67 for jj in bjidLista: # Add loop over SID returned from group submission DS
156 slacapra 1.69 tmpNj = jj - 1
157 mcinquil 1.78
158 corvo 1.67 jid=jidLista[bjidLista.index(jj)]
159 corvo 1.72 common.logger.debug(5,"Submitted job # "+ `(jj)`)
160 slacapra 1.69 common.jobDB.setStatus(tmpNj, 'S')
161     common.jobDB.setJobId(tmpNj, jid)
162     common.jobDB.setTaskId(tmpNj, self.cfg_params['taskId'])
163 mcinquil 1.78
164 spiga 1.56 njs += 1
165    
166 slacapra 1.69 ##### DashBoard report #####################
167 spiga 1.80 ## To distinguish if job is direct or through the server
168     if (self.UseServer == 0):
169     Sub_Type = 'Direct'
170     else:
171     Sub_Type = 'Server'
172    
173 slacapra 1.69 try:
174 spiga 1.56 resFlag = 0
175 slacapra 1.69 if st == 'RC': resFlag = 2
176 spiga 1.71 Statistic.Monitor('submit',resFlag,jid,'-----','dest')
177 spiga 1.56 except:
178     pass
179    
180     # OLI: JobID treatment, special for Condor-G scheduler
181     jobId = ''
182     if common.scheduler.boss_scheduler_name == 'condor_g':
183 corvo 1.72 jobId = str(jj) + '_' + self.hash + '_' + jid
184 spiga 1.56 common.logger.debug(5,'JobID for ML monitoring is created for CONDOR_G scheduler:'+jobId)
185     else:
186 corvo 1.72 jobId = str(jj) + '_' + jid
187 spiga 1.56 common.logger.debug(5,'JobID for ML monitoring is created for EDG scheduler'+jobId)
188    
189     if ( jid.find(":") != -1 ) :
190     rb = jid.split(':')[1]
191 slacapra 1.69 rb = rb.replace('//', '')
192 spiga 1.56 else :
193 slacapra 1.69 rb = 'OSG'
194 spiga 1.80
195     if len(common.jobDB.destination(tmpNj)) <= 2 :
196     T_SE=string.join((common.jobDB.destination(tmpNj)),",")
197     else :
198     T_SE=str(len(common.jobDB.destination(tmpNj)))+'_Selected_SE'
199 spiga 1.56 params = {'jobId': jobId, \
200 slacapra 1.69 'sid': jid, \
201     'broker': rb, \
202 corvo 1.72 'bossId': jj, \
203 spiga 1.80 'SubmissionType': Sub_Type, \
204     'TargetSE': T_SE,}
205     common.logger.debug(5,str(params))
206 spiga 1.56
207 slacapra 1.69 fl = open(common.work_space.shareDir() + '/' + self.cfg_params['apmon'].fName, 'r')
208 spiga 1.56 for i in fl.readlines():
209     val = i.split(':')
210     params[val[0]] = string.strip(val[1])
211 slacapra 1.69 fl.close()
212 corvo 1.72
213 gutsche 1.65 common.logger.debug(5,'Submission DashBoard report: '+str(params))
214    
215 spiga 1.56 self.cfg_params['apmon'].sendToML(params)
216 slacapra 1.69 pass
217     pass
218 corvo 1.17
219     except:
220 corvo 1.27 exctype, value = sys.exc_info()[:2]
221 corvo 1.30 print "Type: %s Value: %s"%(exctype, value)
222 corvo 1.27 common.logger.message("Submitter::run Exception raised: %s %s"%(exctype, value))
223 corvo 1.17 common.jobDB.save()
224 corvo 1.30
225     stop = time.time()
226 gutsche 1.47 common.logger.debug(1, "Submission Time: "+str(stop - start))
227 slacapra 1.60 common.logger.write("Submission time :"+str(stop - start))
228 corvo 1.17 common.jobDB.save()
229 corvo 1.15
230 nsmirnov 1.6 msg = '\nTotal of %d jobs submitted'%njs
231     if njs != len(self.nj_list) :
232     msg += ' (from %d requested).'%(len(self.nj_list))
233     pass
234     else:
235     msg += '.'
236     pass
237 nsmirnov 1.2 common.logger.message(msg)
238 slacapra 1.73 ## add some more verbose message in case submission is not complete
239     if (njs < len(self.nj_list)):
240     msg = 'Submission performed using the Requirements: \n'
241 slacapra 1.76 msg += common.taskDB.dict("jobtype")+' version: '+common.taskDB.dict("codeVersion")+'\n'
242 slacapra 1.73 try: msg += 'SE White List: '+self.cfg_params['EDG.se_white_list']+'\n'
243     except KeyError: pass
244     try: msg += 'SE Black List: '+self.cfg_params['EDG.se_black_list']+'\n'
245     except KeyError: pass
246     try: msg += 'CE White List: '+self.cfg_params['EDG.ce_white_list']+'\n'
247     except KeyError: pass
248     try: msg += 'CE Black List: '+self.cfg_params['EDG.ce_black_list']+'\n'
249     except KeyError: pass
250 slacapra 1.76 msg += '(Hint: please check if '+common.taskDB.dict("jobtype")+' is available at the Sites)\n'
251 slacapra 1.73
252     common.logger.message(msg)
253    
254 nsmirnov 1.1 return