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

# Content
1 from WorkSpace import WorkSpace
2 from crab_exceptions import *
3 import common
4
5 import os, string
6
7 class dbEntry:
8 def __init__(self):
9 self.status = 'X' # job status
10 self.exitStatus = '' # job exit status
11 self.jid = '' # scheduler job id
12 self.bossid = '' # BOSS job id
13 self.collections = [] # EvCollection to be analyzed in this job
14 self.inputSandbox = [] # InputSandbox
15 self.outputSandbox = [] # OutputSandbox
16 self.taskId = '' # Task job belongs to
17 self.block = '' # Task job belongs to
18 self.arguments = [] # abstract job_type parameters
19 self.dest = [] # Destination for this job according to DLS
20 return
21
22 def __str__(self):
23 txt = 'Status <' + self.status + '>; '
24 if self.exitStatus!='':
25 txt += 'exitStatus <' + str(self.exitStatus) + '>\n'
26 txt += 'Job Id <' + self.jid + '> Block <'+self.block+'>\n'
27 if self.arguments:
28 txt += 'Job Type Arguments <' + str(self.arguments) + '>\n'
29 if self.dest:
30 txt += 'Destination <' + str(self.dest) + '>\n'
31
32 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 def __str__(self):
42 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 txt += ('Job %03d' % (i+1)) + ': '
48 txt += str(self._jobs[i])
49 pass
50 return txt
51
52 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 print ('Job %03d' % (job)) + ': ' + str(self._jobs[job-1])
59 pass
60
61 def nJobs(self):
62 return len(self._jobs)
63
64 def nSubmittedJobs(self):
65 n = 0
66 for i in range(self.nJobs()):
67 if self.status(i) in ['S', 'R']:
68 n += 1
69 return n
70
71 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 common.logger.debug(5,'Created DB for '+str(njobs)+' jobs')
84
85 self.save()
86 return
87
88 def save(self):
89 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 for i in range(len(self._jobs)):
94 db_file.write(str(i)+'|')
95 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 db_file.write(str(self._jobs[i].block)+'|')
104 db_file.write(string.join(self._jobs[i].arguments)+'|')
105 db_file.write(string.join(self._jobs[i].dest)+'|')
106 db_file.write('\n')
107 pass
108 db_file.close()
109 return
110
111 def load(self):
112 self._jobs = []
113 try:
114 db_file = open(self._dir+self._db_fname, 'r')
115 except IOError:
116 raise DBException("Something really serious! no JobDB is present!!!")
117
118 for line in db_file:
119 db_entry = dbEntry()
120 (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 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 db_entry.dest = string.split(destTMP)
126 self._jobs.append(db_entry)
127 pass
128 db_file.close()
129 return
130
131
132 def setStatus(self, nj, status):
133 self.check(nj)
134 self._jobs[int(nj)].status = status
135 return
136
137 def status(self, nj):
138 return self._jobs[int(nj)].status
139
140 def setExitStatus(self, nj, exitStatus):
141 self.check(nj)
142 self._jobs[int(nj)].exitStatus = exitStatus
143 return
144
145 def exitStatus(self, nj):
146 return self._jobs[int(nj)].exitStatus
147
148 def setJobId(self, nj, jid):
149 self.check(nj)
150 self._jobs[int(nj)].jid = jid
151 return
152
153 def jobId(self, nj):
154 return self._jobs[int(nj)].jid
155
156 def setBossId(self, nj, bossid):
157 self.check(nj)
158 self._jobs[int(nj)].bossid = bossid
159 return
160
161 def bossId(self, nj):
162 return self._jobs[int(nj)].bossid
163
164 def setArguments(self, nj, args):
165 self.check(nj)
166 self._jobs[int(nj)].arguments = args
167 return
168
169 def arguments(self, nj):
170 return self._jobs[int(nj)].arguments
171
172 def setCollections(self, nj, Collections):
173 self.check(nj)
174 self._jobs[int(nj)].Collections = Collections
175 return
176
177 def collections(self, nj):
178 return self._jobs[int(nj)].collections
179
180 def setInputSandbox(self, nj, InputSandbox):
181 self.check(nj)
182 self._jobs[int(nj)].inputSandbox = InputSandbox
183 return
184
185 def inputSandbox(self, nj):
186 return self._jobs[int(nj)].inputSandbox
187
188 def setOutputSandbox(self, nj, OutputSandbox):
189 self.check(nj)
190 self._jobs[int(nj)].outputSandbox = OutputSandbox
191 return
192
193 def outputSandbox(self, nj):
194 return self._jobs[int(nj)].outputSandbox
195
196 def setTaskId(self, nj, taskId):
197 self.check(nj)
198 self._jobs[int(nj)].taskId = taskId
199
200 def taskId(self, nj):
201 return self._jobs[int(nj)].taskId
202
203 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 def setDestination(self, nj, args):
211 self.check(nj)
212 self._jobs[int(nj)].dest = args
213 return
214
215 def destination(self, nj):
216 return self._jobs[int(nj)].dest
217
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())