ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/JobDB.py
Revision: 1.26
Committed: Mon Mar 3 18:56:39 2008 UTC (17 years, 2 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.25: +0 -0 lines
State: FILE REMOVED
Log Message:
jobdb and taskdb are obsolete with bosslite

File Contents

# User Rev Content
1 nsmirnov 1.1 from WorkSpace import WorkSpace
2     from crab_exceptions import *
3     import common
4    
5 nsmirnov 1.2 import os, string
6 nsmirnov 1.1
7     class dbEntry:
8     def __init__(self):
9 slacapra 1.5 self.status = 'X' # job status
10 slacapra 1.8 self.exitStatus = '' # job exit status
11 slacapra 1.5 self.jid = '' # scheduler job id
12 corvo 1.10 self.bossid = '' # BOSS job id
13 slacapra 1.5 self.collections = [] # EvCollection to be analyzed in this job
14     self.inputSandbox = [] # InputSandbox
15     self.outputSandbox = [] # OutputSandbox
16 corvo 1.10 self.taskId = '' # Task job belongs to
17 slacapra 1.22 self.block = '' # Task job belongs to
18     self.arguments = [] # abstract job_type parameters
19 gutsche 1.18 self.dest = [] # Destination for this job according to DLS
20 nsmirnov 1.1 return
21    
22 nsmirnov 1.2 def __str__(self):
23     txt = 'Status <' + self.status + '>; '
24 slacapra 1.8 if self.exitStatus!='':
25     txt += 'exitStatus <' + str(self.exitStatus) + '>\n'
26 slacapra 1.22 txt += 'Job Id <' + self.jid + '> Block <'+self.block+'>\n'
27 gutsche 1.13 if self.arguments:
28     txt += 'Job Type Arguments <' + str(self.arguments) + '>\n'
29 slacapra 1.19 if self.dest:
30     txt += 'Destination <' + str(self.dest) + '>\n'
31 slacapra 1.4
32 nsmirnov 1.1 return txt
33    
34     class JobDB:
35     def __init__(self):
36     self._dir = common.work_space.shareDir() + 'db/'
37     self._db_fname = 'jobs'
38     self._jobs = [] # list of dbEntry's
39     return
40    
41 nsmirnov 1.2 def __str__(self):
42 nsmirnov 1.1 njobs = self.nJobs()
43     if njobs == 1: plural = ''
44     else: plural = 's'
45     txt = 'Total of %d job%s:\n' % (njobs, plural)
46     for i in range(njobs):
47 nsmirnov 1.3 txt += ('Job %03d' % (i+1)) + ': '
48 nsmirnov 1.1 txt += str(self._jobs[i])
49     pass
50     return txt
51    
52 slacapra 1.4 def dump(self, jobs):
53     njobs = len(jobs)
54     if njobs == 1: plural = ''
55     else: plural = 's'
56     print 'Listing %d job%s:\n' % (njobs, plural)
57     for job in jobs:
58 slacapra 1.17 print ('Job %03d' % (job)) + ': ' + str(self._jobs[job-1])
59 slacapra 1.4 pass
60    
61 nsmirnov 1.1 def nJobs(self):
62     return len(self._jobs)
63    
64 corvo 1.23 def nSubmittedJobs(self):
65     n = 0
66     for i in range(self.nJobs()):
67 corvo 1.24 if self.status(i) in ['S', 'R']:
68 corvo 1.23 n += 1
69     return n
70    
71 nsmirnov 1.1 def create(self, njobs):
72    
73     if os.path.exists(self._dir):
74     msg = 'Cannot create Job DB: already exists.'
75     raise CrabException(msg)
76    
77     os.mkdir(self._dir)
78    
79     for i in range(njobs):
80     self._jobs.append(dbEntry())
81     pass
82    
83 slacapra 1.4 common.logger.debug(5,'Created DB for '+str(njobs)+' jobs')
84    
85 nsmirnov 1.1 self.save()
86     return
87    
88     def save(self):
89 slacapra 1.25 try:
90     db_file = open(self._dir+self._db_fname, 'w')
91     except IOError:
92     raise CrabException("Cannot open "+self._dir+self._db_fname+"\n")
93 nsmirnov 1.1 for i in range(len(self._jobs)):
94 gutsche 1.21 db_file.write(str(i)+'|')
95 slacapra 1.20 db_file.write(self._jobs[i].status+'|')
96     db_file.write(self._jobs[i].exitStatus+'|')
97     db_file.write(self._jobs[i].jid+'|')
98     db_file.write(self._jobs[i].bossid+'|')
99     db_file.write(string.join(self._jobs[i].collections)+'|')
100     db_file.write(string.join(self._jobs[i].inputSandbox)+'|')
101     db_file.write(string.join(self._jobs[i].outputSandbox)+'|')
102     db_file.write(str(self._jobs[i].taskId)+'|')
103 slacapra 1.22 db_file.write(str(self._jobs[i].block)+'|')
104 slacapra 1.20 db_file.write(string.join(self._jobs[i].arguments)+'|')
105     db_file.write(string.join(self._jobs[i].dest)+'|')
106 nsmirnov 1.1 db_file.write('\n')
107     pass
108     db_file.close()
109     return
110    
111     def load(self):
112     self._jobs = []
113 slacapra 1.6 try:
114     db_file = open(self._dir+self._db_fname, 'r')
115     except IOError:
116 slacapra 1.7 raise DBException("Something really serious! no JobDB is present!!!")
117 slacapra 1.6
118 nsmirnov 1.1 for line in db_file:
119 nsmirnov 1.2 db_entry = dbEntry()
120 slacapra 1.22 (n, db_entry.status, db_entry.exitStatus, db_entry.jid, db_entry.bossid, collectionsTMP, inputSandboxTMP , outputSandboxTMP , db_entry.taskId, db_entry.block, argumentsTMP, destTMP, rest) = string.split(line, '|')
121 slacapra 1.16 db_entry.collections = string.split(collectionsTMP)
122     db_entry.inputSandbox = string.split(inputSandboxTMP)
123     db_entry.outputSandbox = string.split(outputSandboxTMP)
124     db_entry.arguments = string.split(argumentsTMP)
125 gutsche 1.18 db_entry.dest = string.split(destTMP)
126 nsmirnov 1.1 self._jobs.append(db_entry)
127     pass
128     db_file.close()
129     return
130    
131 slacapra 1.5
132 nsmirnov 1.1 def setStatus(self, nj, status):
133 slacapra 1.20 self.check(nj)
134 gutsche 1.11 self._jobs[int(nj)].status = status
135 nsmirnov 1.1 return
136    
137     def status(self, nj):
138 gutsche 1.11 return self._jobs[int(nj)].status
139 nsmirnov 1.1
140 slacapra 1.8 def setExitStatus(self, nj, exitStatus):
141 slacapra 1.20 self.check(nj)
142 gutsche 1.11 self._jobs[int(nj)].exitStatus = exitStatus
143 slacapra 1.8 return
144    
145     def exitStatus(self, nj):
146 gutsche 1.11 return self._jobs[int(nj)].exitStatus
147 slacapra 1.8
148 nsmirnov 1.1 def setJobId(self, nj, jid):
149 slacapra 1.20 self.check(nj)
150 gutsche 1.11 self._jobs[int(nj)].jid = jid
151 nsmirnov 1.1 return
152    
153     def jobId(self, nj):
154 gutsche 1.11 return self._jobs[int(nj)].jid
155 slacapra 1.4
156 fanzago 1.9 def setBossId(self, nj, bossid):
157 slacapra 1.20 self.check(nj)
158 gutsche 1.11 self._jobs[int(nj)].bossid = bossid
159 fanzago 1.9 return
160    
161     def bossId(self, nj):
162 gutsche 1.11 return self._jobs[int(nj)].bossid
163 fanzago 1.9
164 gutsche 1.13 def setArguments(self, nj, args):
165 slacapra 1.20 self.check(nj)
166 gutsche 1.13 self._jobs[int(nj)].arguments = args
167 slacapra 1.4 return
168    
169 gutsche 1.13 def arguments(self, nj):
170     return self._jobs[int(nj)].arguments
171 slacapra 1.4
172     def setCollections(self, nj, Collections):
173 slacapra 1.20 self.check(nj)
174 gutsche 1.11 self._jobs[int(nj)].Collections = Collections
175 slacapra 1.4 return
176    
177     def collections(self, nj):
178 gutsche 1.11 return self._jobs[int(nj)].collections
179 slacapra 1.5
180     def setInputSandbox(self, nj, InputSandbox):
181 slacapra 1.20 self.check(nj)
182 gutsche 1.11 self._jobs[int(nj)].inputSandbox = InputSandbox
183 slacapra 1.5 return
184    
185     def inputSandbox(self, nj):
186 gutsche 1.11 return self._jobs[int(nj)].inputSandbox
187 slacapra 1.5
188     def setOutputSandbox(self, nj, OutputSandbox):
189 slacapra 1.20 self.check(nj)
190 gutsche 1.11 self._jobs[int(nj)].outputSandbox = OutputSandbox
191 slacapra 1.5 return
192    
193     def outputSandbox(self, nj):
194 gutsche 1.11 return self._jobs[int(nj)].outputSandbox
195 corvo 1.10
196     def setTaskId(self, nj, taskId):
197 slacapra 1.20 self.check(nj)
198 gutsche 1.11 self._jobs[int(nj)].taskId = taskId
199 gutsche 1.18
200 slacapra 1.22 def taskId(self, nj):
201 slacapra 1.20 return self._jobs[int(nj)].taskId
202    
203 slacapra 1.22 def setBlock(self, nj, block):
204     self.check(nj)
205     self._jobs[int(nj)].block = block
206    
207     def block(self, nj):
208     return self._jobs[int(nj)].block
209    
210 gutsche 1.18 def setDestination(self, nj, args):
211 slacapra 1.20 self.check(nj)
212 gutsche 1.18 self._jobs[int(nj)].dest = args
213     return
214    
215     def destination(self, nj):
216     return self._jobs[int(nj)].dest
217 slacapra 1.20
218     def check(self, nj):
219     """ Check if the job nj is already present in DB (first job is 0) and create it if not """
220     if (int(nj) >= self.nJobs()): self._jobs.append(dbEntry())