[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

extras-buildsys/server BuildJob.py, 1.10, 1.11 BuildMaster.py, 1.8, 1.9 UserInterface.py, 1.11, 1.12



Author: dcbw

Update of /cvs/fedora/extras-buildsys/server
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv28014/server

Modified Files:
	BuildJob.py BuildMaster.py UserInterface.py 
Log Message:
2005-06-29  Dan Williams <dcbw redhat com>

    * Implement job kill functionality




Index: BuildJob.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/BuildJob.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- BuildJob.py	26 Jun 2005 14:52:30 -0000	1.10
+++ BuildJob.py	29 Jun 2005 05:23:00 -0000	1.11
@@ -350,30 +350,44 @@
         if not self.no_cvs:
             shutil.rmtree(self.checkout_tmpdir, ignore_errors=True)
 
+    def is_done(self):
+        if self.curstage == 'needsign' or self.curstage == 'failed' or self.curstage == 'killed':
+            return True
+        return False
+
+    def die(self, username):
+        # Kill any building jobs
+        for job in self.sub_jobs.values():
+            job.die()
+        self.sub_jobs = {}
+        self.curstage = 'killed'
+        resultstring = "%s (%s): Build on target %s was killed by %s." % (self.uid, self.name, self.target, username)
+        self.email_result(resultstring)
+        self.bm.notify_job_done(self)
+
     def run(self):
-        while self.curstage != 'needsign' and self.curstage != 'failed':
+        while not self.is_done():
             # Advance to next stage based on current stage
             do_sleep = False
-            oldstage = self.curstage
-            if oldstage == 'initialize':
+            if self.curstage == 'initialize':
                 self._checkout()
-            elif oldstage == 'checkout':
+            elif self.curstage == 'checkout':
                 self._make_srpm()
-            elif oldstage == 'make_srpm':
+            elif self.curstage == 'make_srpm':
                 self._prep()
-            elif oldstage == 'prep' or oldstage == 'building':
+            elif self.curstage == 'prep' or self.curstage == 'building':
                 self._monitor()
                 do_sleep = True
-            elif oldstage == 'finished':
+            elif self.curstage == 'finished':
                 self._cleanup()
-            elif oldstage == 'cleanup':
+            elif self.curstage == 'cleanup':
                 if self.failed:
                     self._failed()
                 else:
                     self._add_to_repo()
-            elif oldstage == 'addtorepo':
+            elif self.curstage == 'addtorepo':
                 do_sleep = True
-            elif oldstage == 'repodone':
+            elif self.curstage == 'repodone':
                 self._succeeded()
 
             # Only some stages need to sleep because we stay in


Index: BuildMaster.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/BuildMaster.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BuildMaster.py	26 Jun 2005 14:52:30 -0000	1.8
+++ BuildMaster.py	29 Jun 2005 05:23:00 -0000	1.9
@@ -72,7 +72,6 @@
     def __init__(self, hostname, client_manager):
         self.bcm = client_manager
         self.hostname = hostname
-        self.building_jobs = []
         self.should_stop = False
         self.repos = {}
         for target in config_opts['targets'].keys():
@@ -90,6 +89,9 @@
         self._query_queue = []
         self._query_queue_lock = threading.Lock()
 
+        self._building_jobs = []
+        self._building_jobs_lock = threading.Lock()
+
         try:
             self.dbcx = sqlite.connect(CONFIG_LOCATION + "jobdb", encoding="utf-8", timeout=3)
         except sqlite.DatabaseError, e:
@@ -155,7 +157,9 @@
             curstage = job.get_cur_stage()
             self._write_status_to_db(job.get_uid(), curstage)
             print "%s (%s): Job finished." % (job.get_uid(), job.package)
-            self.building_jobs.remove(job)
+            self._building_jobs_lock.acquire()
+            self._building_jobs.remove(job)
+            self._building_jobs_lock.release()
 
         self._done_queue = []
         self._done_queue_lock.release()
@@ -220,7 +224,9 @@
             print "%s (%s): Starting tag '%s' on target '%s'" % (row['uid'], \
                     item['package'], locator, item['target'])
 
-            self.building_jobs.append(job)
+            self._building_jobs_lock.acquire()
+            self._building_jobs.append(job)
+            self._building_jobs_lock.release()
             job.start()
 
         self._new_queue = []
@@ -274,6 +280,16 @@
 
         return False
 
+    def get_job(self, jobid):
+        self._building_jobs_lock.acquire()
+        ret_job = None
+        for job in self._building_jobs:
+            if job.uid == jobid:
+                ret_job = job
+                break
+        self._building_jobs_lock.release()
+        return ret_job
+
     def run(self):
         while self.should_stop == False:
             # Write update status for jobs to the database


Index: UserInterface.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/UserInterface.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- UserInterface.py	26 Jun 2005 15:17:41 -0000	1.11
+++ UserInterface.py	29 Jun 2005 05:23:00 -0000	1.12
@@ -105,6 +105,13 @@
             self._bm.enqueue_srpm(email, package, srpm_file, target, buildreq, time.time())
         return (0, "Success: package has been queued.")
 
+    def _kill_job(self, email, job, jobid):
+        if not job:
+            return (-1, "Job %s does not exist." % jobid)
+        if job.is_done():
+            return (-1, "Job %s is already finished." % job.get_uid())
+        job.die(email)
+        return (0, "Success: job %s killed." % job.get_uid())
 
     def list_jobs(self, args_dict):
         sql = 'SELECT uid, username, package, cvs_tag, target, status FROM jobs'
@@ -167,6 +174,18 @@
         return UserInterface.enqueue_srpm(self, user.email, package, srpm_file, target, buildreq)
 
 
+    def kill_job(self, user, email, jobid):
+        if not user.own_jobs:
+            return (-1, "Insufficient privileges.")
+        if user.email != email:
+            return (-1, "Insufficient privileges.")
+        jobid = int(jobid)
+        job = self._bm.get_job(jobid)
+        if job and not user.kill_any_job and user.email != job.username:
+            return (-1, "Insufficient privileges.")
+        return self._kill_job(user.email, job, jobid)
+
+
     def list_jobs(self, user, args_dict):
         return UserInterface.list_jobs(self, args_dict)
 
@@ -187,3 +206,9 @@
     Allow all operations, NULL authentication
     """
 
+    def kill_job(self, email, jobid):
+        jobid = int(jobid)
+        job = self._bm.get_job(jobid)
+        return self._kill_job(self, email, job, jobid)
+
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]