annotate commons/core/sql/JobAdaptator.py @ 16:6135c3075bc5

Deleted selected files
author m-zytnicki
date Mon, 22 Apr 2013 11:09:41 -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 import tempfile
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 import subprocess
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from commons.core.sql.Job import Job
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38
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 JobAdaptator(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 def __init__(self, lJob = [], table = "" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 self._lJobID = lJob
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 self._table = table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 self._acronym = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 ## Record a job
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 # @param job Job instance with the job informations
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 def recordJob(self, job):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 self._lJobID.append(job)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 ## Remove a job from the job table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 # @param job: job instance to remove
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 def removeJob(self, job):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 ## Set the jobid of a job with the id of SGE
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 # @param job job instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 # @param jobid integer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 def updateJobIdInDB(self, job, jobid):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 ## Get a job status
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 # @param job: a Job instance with the job informations
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 def getJobStatus(self, job):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 ## Change a job status
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 # @param job: a Job instance with the job informations
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 # @param status: the new status (waiting,finished,error)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 def changeJobStatus(self, job, status):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 ## Get the number of jobs belonging to the desired groupid with the desired status.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 # @param groupid string a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 # @param status string job status (waiting, running, finished, error)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 # @return int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 def getCountStatus(self, groupid, status):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 ## Clean all job from a job group
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 # @param groupid: a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 def cleanJobGroup(self, groupid):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 ## Check if there is unfinished job from a job group.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 # @param groupid string a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 def hasUnfinishedJob(self, groupid):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 def _getJobIDListFromQstat(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 lJobIDFromQstat = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 tmp = tempfile.NamedTemporaryFile(delete=False)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 cmd ="qstat | grep %s" % self._acronym
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 process = subprocess.Popen(cmd, shell=True,stdout=tmp)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 process.communicate()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 tmp.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 if process.returncode == 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 fileName = tmp.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 jobidFileHandler = open(fileName, "r")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 for line in jobidFileHandler:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 line2 = line.lstrip(" ")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 lJobIDFromQstat.append(line2.split(" ")[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 jobidFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 os.remove(fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 return lJobIDFromQstat
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 def _areJobsStillRunning(self,lJobID,lJobIDFromQstat):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 sorted(lJobID)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 sorted(lJobIDFromQstat)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 for i in lJobID:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 for j in lJobIDFromQstat:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 if int(i)== int(j):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 ## Wait job finished status from a job group.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 # Job are re-launched if error (max. 3 times)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 # @param groupid string a group identifier to record related job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 # @param checkInterval integer time laps in seconds between two checks (default = 5)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 # @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
141 # @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
142 # @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
143 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 def waitJobGroup(self, groupid, checkInterval=5, maxRelaunch=3, exitIfTooManyErrors=True, timeOutPerJob=60*60):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 time.sleep(checkInterval)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 lJobIDFromQstat = self._getJobIDListFromQstat()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 if self._areJobsStillRunning(self._lJobID, lJobIDFromQstat) == False:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 ## Submit a job to a queue and record it in job table.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 # @param job a job instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 # @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
156 # @param checkInterval integer time laps in seconds between two checks (default = 30)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 # @param verbose integer (default = 0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 def submitJob(self, job, verbose=0, maxNbWaitingJobs=10000, checkInterval=30):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 cmd = self._getQsubCommand(job)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 tmp = tempfile.NamedTemporaryFile(delete=False)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 process = subprocess.Popen(cmd, shell=True,stdout=tmp)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 process.communicate()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 tmp.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 if process.returncode == 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 fileName = tmp.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 jobidFileHandler = open(fileName, "r")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 jobid = self._getJobidFromJobManager(jobidFileHandler)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 if verbose > 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 print "job '%i %s' submitted" % (jobid, job.jobname)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 job.jobid = jobid
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 #newJob= Job(job.jobid, job.jobname, job.groupid, job.queue, job.command, job.launcher, job.node, job.lResources, job.parallelEnvironment)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 self._acronym = job.jobname.split("_")[0][:10]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 self.recordJob(job.jobid)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 jobidFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 os.remove(fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 return process.returncode
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 ## Get the list of nodes where jobs of one group were executed
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 # @param groupid string a group identifier of job series
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 # @return lNodes list of nodes names without redundancy
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 def getNodesListByGroupId(self, groupId):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 def checkJobTable(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 def close(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 def _getJobidAndNbJob(self, jobid) :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 tab = jobid.split(".")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 jobid = tab[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 tab = tab[1].split(":")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 nbJob = tab[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 return jobid, nbJob
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 class JobAdaptatorSGE(JobAdaptator):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 ## Check if a job is still handled by SGE
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 # @param jobid string job identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 # @param jobname string job name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 def isJobStillHandledBySge(self, jobid, jobname):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 isJobInQstat = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 tmp = tempfile.NamedTemporaryFile(delete=False)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 cmd = "qstat"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 process = subprocess.Popen(cmd, shell=True,stdout=tmp)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 process.communicate()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 tmp.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 qstatFile = tmp.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 if process.returncode != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 msg = "ERROR while launching 'qstat'"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 sys.stderr.write( "%s\n" % msg )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 qstatFileHandler = open(qstatFile, "r")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 lLines = qstatFileHandler.readlines()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 for line in lLines:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 tokens = line.split()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 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
226 isJobInQstat = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 qstatFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 os.remove(qstatFile)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 return isJobInQstat
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 def _getQsubCommand(self, job):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 cmd = "echo '%s' | " % job.launcher
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 prg = "qsub"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 cmd += prg
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 cmd += " -V"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 cmd += " -N %s" % job.jobname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 if job.queue != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 cmd += " -q %s" % job.queue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 cmd += " -cwd"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 if job.lResources != []:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 cmd += " -l \""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 cmd += " ".join(job.lResources)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 cmd += "\""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 if job.parallelEnvironment != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 cmd += " -pe " + job.parallelEnvironment
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 return cmd
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 def _getJobidFromJobManager(self, jobidFileHandler):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 return int(jobidFileHandler.readline().split(" ")[2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 class JobAdaptatorTorque(JobAdaptator):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 def _getQsubCommand(self, job):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 cmd = "echo '%s' | " % job.launcher
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 prg = "qsub"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 cmd += prg
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 cmd += " -V"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 cmd += " -d %s" % os.getcwd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 cmd += " -N %s" % job.jobname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 if job.queue != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 cmd += " -q %s" % job.queue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 if job.lResources != []:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 cmd += " -l \""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 cmd += " ".join(job.lResources).replace("mem_free","mem")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 cmd += "\""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268 return cmd
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 def _getJobidFromJobManager(self, jobidFileHandler):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 return int(jobidFileHandler.readline().split(".")[0])