annotate commons/core/sql/RepetJob.py @ 12:5a054da77808

Updated CompareOverlappingSmallRef.xml
author m-zytnicki
date Thu, 14 Mar 2013 05:37:35 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 # Copyright INRA (Institut National de la Recherche Agronomique)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # http://www.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # http://urgi.versailles.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import time
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from commons.core.sql.DbMySql import DbMySql
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from commons.core.sql.TableJobAdaptatorFactory import TableJobAdaptatorFactory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 #TODO: to remove... => replace all RepetJob() by TableJobAdaptator()...
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 ## Methods for Job persistence
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 class RepetJob( DbMySql ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 ## Record a job
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 # @param job Job instance with the job informations
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 def recordJob( self, job ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 self.removeJob( job )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 sqlCmd = "INSERT INTO %s" % ( job.tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 sqlCmd += " VALUES ("
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 sqlCmd += " \"%s\"," % ( job.jobid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 sqlCmd += " \"%s\"," % ( job.jobname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 sqlCmd += " \"%s\"," % ( job.groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 sqlCmd += " \"%s\"," % ( job.command.replace("\"","\'") )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 sqlCmd += " \"%s\"," % ( job.launcher )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 sqlCmd += " \"%s\"," % ( job.queue )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 sqlCmd += " \"waiting\","
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 sqlCmd += " \"%s\"," % ( time.strftime( "%Y-%m-%d %H:%M:%S" ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 sqlCmd += " \"?\" );"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 self.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 ## Remove a job from the job table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 # @param job: job instance to remove
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 def removeJob( self, job ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 qry = "DELETE FROM %s" % ( job.tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 qry += " WHERE groupid='%s'" % ( job.groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 qry += " AND jobname='%s'" % ( job.jobname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 qry += " AND queue='%s';" % ( job.queue )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 ## Set the jobid of a job with the id of SGE
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 # @param job job instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 # @param jobid integer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 def setJobIdFromSge( self, job, jobid ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 qry = "UPDATE %s" % ( job.tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 qry += " SET jobid='%i'" % ( int(jobid) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 qry += " WHERE jobname='%s'" % ( job.jobname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 qry += " AND groupid='%s'" % ( job.groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 qry += " AND queue='%s';" % ( job.queue )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 ## Get a job status
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 # @param job: a Job instance with the job informations
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 def getJobStatus( self, job ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 if job.jobid != 0 and job.jobname == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 job.jobname = job.jobid
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 job.jobid = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 qry = "SELECT status FROM %s" % ( job.tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 qry += " WHERE groupid='%s'" % ( job.groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 qry += " AND jobname='%s'" % ( job.jobname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 qry += " AND queue='%s';" % ( job.queue )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 res = self.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 if len(res) > 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 msg = "ERROR while getting job status: non-unique jobs"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 sys.stderr.write( "%s\n" % msg )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 sys.stderr.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 if res == None or len(res) == 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 return "unknown"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 return res[0][0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 ## Change a job status
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 # @param job: a Job instance with the job informations
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 # @param status: the new status (waiting,finished,error)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 # @param method: db or file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 def changeJobStatus( self, job, status, method=""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 sqlCmd = "UPDATE %s" % ( job.tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 sqlCmd += " SET status='%s'" % ( status )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 sqlCmd += ",node='%s'" % ( job.node )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 sqlCmd += " WHERE groupid='%s'" % ( job.groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 sqlCmd += " AND jobname='%s'" % ( job.jobname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 sqlCmd += " AND queue='%s';" % ( job.queue )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 self.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 ## Get the number of jobs belonging to the desired groupid with the desired status.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 # @param tablename string table name to record the jobs
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 # @param groupid string a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 # @param status string job status (waiting, running, finished, error)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 # @return int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 def getCountStatus( self, tablename, groupid, status ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 qry = "SELECT count(jobname) FROM %s" % ( tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 qry += " WHERE groupid='%s'" % ( groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 qry += " AND status='%s';" % ( status )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 res = self.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 return int( res[0][0] )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 ## Clean all job from a job group
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 # @param tablename table name to record the jobs
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 # @param groupid: a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 def cleanJobGroup( self, tablename, groupid ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 if self.doesTableExist( tablename ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 qry = "DELETE FROM %s WHERE groupid='%s';" % ( tablename, groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 ## Check if there is unfinished job from a job group.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 # @param tablename string table name to record the jobs
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 # @param groupid string a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 def hasUnfinishedJob( self, tablename, groupid ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 if not self.doesTableExist( tablename ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 qry = "SELECT * FROM %s" % ( tablename )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 qry += " WHERE groupid='%s'" % ( groupid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 qry += " and status!='finished';"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 res = self.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 if len(res) == 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 ## Check if a job is still handled by SGE
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 # @param jobid string job identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 # @param jobname string job name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 def isJobStillHandledBySge( self, jobid, jobname ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 isJobInQstat = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 qstatFile = "qstat_stdout"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 cmd = "qstat > %s" % ( qstatFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 returnStatus = os.system( cmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 if returnStatus != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 msg = "ERROR while launching 'qstat'"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 sys.stderr.write( "%s\n" % msg )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 qstatFileHandler = open( qstatFile, "r" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 lLines = qstatFileHandler.readlines()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 for line in lLines:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 tokens = line.split()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 if len(tokens) > 3 and tokens[0] == str(jobid) and tokens[2] == jobname[0:len(tokens[2])]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 isJobInQstat = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 qstatFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 os.remove( qstatFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 return isJobInQstat
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 ## Wait job finished status from a job group.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 # Job are re-launched if error (max. 3 times)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 # @param tableName string table name to record the jobs
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 # @param groupid string a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 # @param checkInterval integer time laps in seconds between two checks (default = 5)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 # @param maxRelaunch integer max nb of times a job in error is relaunch before exiting (default = 3)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 # @param exitIfTooManyErrors boolean exit if a job is still in error above maxRelaunch (default = True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 # @param timeOutPerJob integer max nb of seconds after which one tests if a job is still in SGE or not (default = 60*60=1h)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 def waitJobGroup(self, tableName, groupid, checkInterval=5, maxRelaunch=3, exitIfTooManyErrors=True, timeOutPerJob=60*60):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 iTJA = TableJobAdaptatorFactory.createInstance(self, tableName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 iTJA.waitJobGroup(groupid, checkInterval, maxRelaunch, exitIfTooManyErrors, timeOutPerJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 ## Submit a job to a queue and record it in job table.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 # @param job a job instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 # @param maxNbWaitingJobs integer max nb of waiting jobs before submitting a new one (default = 10000)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 # @param checkInterval integer time laps in seconds between two checks (default = 30)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 # @param verbose integer (default = 0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 def submitJob( self, job, verbose=0, maxNbWaitingJobs=10000, checkInterval=30 ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 iTJA = TableJobAdaptatorFactory.createInstance(self, job.tablename)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 return iTJA.submitJob(job, verbose, maxNbWaitingJobs, checkInterval)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 ## Get the list of nodes where jobs of one group were executed
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 # @param tablename string table name where jobs are recored
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 # @param groupid string a group identifier of job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 # @return lNodes list of nodes names
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 def getNodesListByGroupId( self, tableName, groupId ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 qry = "SELECT node FROM %s" % tableName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 qry += " WHERE groupid='%s'" % groupId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 self.execute( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 res = self.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 lNodes = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 for resTuple in res:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 lNodes.append(resTuple[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 return lNodes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 def getDbName(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 return "DbMySql"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 def _getJobidAndNbJob(self, jobid) :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 tab = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 tab = jobid.split(".")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 jobid = tab[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 tab = tab[1].split(":")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 nbJob = tab[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 return jobid, nbJob