ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/JobDB.py
Revision: 1.17
Committed: Tue Jul 4 16:30:58 2006 UTC (18 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_2_1, CRAB_1_2_0, CRAB_1_2_0_pre9
Branch point for: CRAB_BOSS4
Changes since 1.16: +1 -15 lines
Log Message:
cosmetics

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 gutsche 1.13 self.arguments = [] ### Fabio: abstract job_type parameters
18 nsmirnov 1.1 return
19    
20 nsmirnov 1.2 def __str__(self):
21     txt = 'Status <' + self.status + '>; '
22 slacapra 1.8 if self.exitStatus!='':
23     txt += 'exitStatus <' + str(self.exitStatus) + '>\n'
24 nsmirnov 1.2 txt += 'Job Id <' + self.jid + '>\n'
25 gutsche 1.13 if self.arguments:
26     txt += 'Job Type Arguments <' + str(self.arguments) + '>\n'
27 slacapra 1.8 if self.collections:
28 slacapra 1.5 txt += 'Collections <' + str(self.collections) + '>\n'
29 slacapra 1.4
30 nsmirnov 1.1 return txt
31    
32     class JobDB:
33     def __init__(self):
34     self._dir = common.work_space.shareDir() + 'db/'
35     self._db_fname = 'jobs'
36     self._jobs = [] # list of dbEntry's
37     return
38    
39 nsmirnov 1.2 def __str__(self):
40 nsmirnov 1.1 njobs = self.nJobs()
41     if njobs == 1: plural = ''
42     else: plural = 's'
43     txt = 'Total of %d job%s:\n' % (njobs, plural)
44     for i in range(njobs):
45 nsmirnov 1.3 txt += ('Job %03d' % (i+1)) + ': '
46 nsmirnov 1.1 txt += str(self._jobs[i])
47     pass
48     return txt
49    
50 slacapra 1.4 def dump(self, jobs):
51     njobs = len(jobs)
52     if njobs == 1: plural = ''
53     else: plural = 's'
54     print 'Listing %d job%s:\n' % (njobs, plural)
55     for job in jobs:
56 slacapra 1.17 print ('Job %03d' % (job)) + ': ' + str(self._jobs[job-1])
57 slacapra 1.4 pass
58    
59 nsmirnov 1.1 def nJobs(self):
60     return len(self._jobs)
61    
62     def create(self, njobs):
63    
64     if os.path.exists(self._dir):
65     msg = 'Cannot create Job DB: already exists.'
66     raise CrabException(msg)
67    
68     os.mkdir(self._dir)
69    
70     for i in range(njobs):
71     self._jobs.append(dbEntry())
72     pass
73    
74 slacapra 1.4 common.logger.debug(5,'Created DB for '+str(njobs)+' jobs')
75    
76 nsmirnov 1.1 self.save()
77     return
78    
79     def save(self):
80     db_file = open(self._dir+self._db_fname, 'w')
81     for i in range(len(self._jobs)):
82     db_file.write(`(i+1)`+';')
83     db_file.write(self._jobs[i].status+';')
84 slacapra 1.8 db_file.write(self._jobs[i].exitStatus+';')
85 nsmirnov 1.1 db_file.write(self._jobs[i].jid+';')
86 fanzago 1.9 db_file.write(self._jobs[i].bossid+';')
87 slacapra 1.16 db_file.write(string.join(self._jobs[i].collections)+';')
88     db_file.write(string.join(self._jobs[i].inputSandbox)+';')
89     db_file.write(string.join(self._jobs[i].outputSandbox)+';')
90 corvo 1.10 db_file.write(str(self._jobs[i].taskId)+';')
91 slacapra 1.16 db_file.write(string.join(self._jobs[i].arguments)+';')
92 nsmirnov 1.1 db_file.write('\n')
93     pass
94     db_file.close()
95     return
96    
97     def load(self):
98     self._jobs = []
99 slacapra 1.6 try:
100     db_file = open(self._dir+self._db_fname, 'r')
101     except IOError:
102 slacapra 1.7 raise DBException("Something really serious! no JobDB is present!!!")
103 slacapra 1.6
104 nsmirnov 1.1 for line in db_file:
105 nsmirnov 1.2 db_entry = dbEntry()
106 gutsche 1.13 (n, db_entry.status, db_entry.exitStatus, db_entry.jid, db_entry.bossid, collectionsTMP, inputSandboxTMP , outputSandboxTMP , db_entry.taskId, argumentsTMP, rest) = string.split(line, ';')
107 slacapra 1.16 db_entry.collections = string.split(collectionsTMP)
108     db_entry.inputSandbox = string.split(inputSandboxTMP)
109     db_entry.outputSandbox = string.split(outputSandboxTMP)
110     db_entry.arguments = string.split(argumentsTMP)
111 nsmirnov 1.1 self._jobs.append(db_entry)
112     pass
113     db_file.close()
114     return
115    
116 slacapra 1.5
117 nsmirnov 1.1 def setStatus(self, nj, status):
118 gutsche 1.11 self._jobs[int(nj)].status = status
119 nsmirnov 1.1 return
120    
121     def status(self, nj):
122 gutsche 1.11 return self._jobs[int(nj)].status
123 nsmirnov 1.1
124 slacapra 1.8 def setExitStatus(self, nj, exitStatus):
125 gutsche 1.11 self._jobs[int(nj)].exitStatus = exitStatus
126 slacapra 1.8 return
127    
128     def exitStatus(self, nj):
129 gutsche 1.11 return self._jobs[int(nj)].exitStatus
130 slacapra 1.8
131 nsmirnov 1.1 def setJobId(self, nj, jid):
132 gutsche 1.11 self._jobs[int(nj)].jid = jid
133 nsmirnov 1.1 return
134    
135     def jobId(self, nj):
136 gutsche 1.11 return self._jobs[int(nj)].jid
137 slacapra 1.4
138 fanzago 1.9 def setBossId(self, nj, bossid):
139 gutsche 1.11 self._jobs[int(nj)].bossid = bossid
140 fanzago 1.9 return
141    
142     def bossId(self, nj):
143 gutsche 1.11 return self._jobs[int(nj)].bossid
144 fanzago 1.9
145 gutsche 1.13 def setArguments(self, nj, args):
146     self._jobs[int(nj)].arguments = args
147 slacapra 1.4 return
148    
149 gutsche 1.13 def arguments(self, nj):
150     return self._jobs[int(nj)].arguments
151 slacapra 1.4
152     def setCollections(self, nj, Collections):
153 gutsche 1.11 self._jobs[int(nj)].Collections = Collections
154 slacapra 1.4 return
155    
156     def collections(self, nj):
157 gutsche 1.11 return self._jobs[int(nj)].collections
158 slacapra 1.5
159     def setInputSandbox(self, nj, InputSandbox):
160 gutsche 1.11 self._jobs[int(nj)].inputSandbox = InputSandbox
161 slacapra 1.5 return
162    
163     def inputSandbox(self, nj):
164 gutsche 1.11 return self._jobs[int(nj)].inputSandbox
165 slacapra 1.5
166     def setOutputSandbox(self, nj, OutputSandbox):
167 gutsche 1.11 self._jobs[int(nj)].outputSandbox = OutputSandbox
168 slacapra 1.5 return
169    
170     def outputSandbox(self, nj):
171 gutsche 1.11 return self._jobs[int(nj)].outputSandbox
172 corvo 1.10
173     def setTaskId(self, nj, taskId):
174 gutsche 1.11 self._jobs[int(nj)].taskId = taskId