Package iceprod :: Package server :: Module dbqueue
[hide private]
[frames] | no frames]

Source Code for Module iceprod.server.dbqueue

 1  #!/bin/env python 
 2  # 
 3   
 4  """ 
 5   A basic wrapper for submitting and monitoring jobs to Condor.  
 6   This module implements only a small subset of Condor's many features.  
 7   (http://www.cs.wisc.edu/condor)    
 8   Inherits from i3Queue 
 9   
10   copyright  (c) 2005 the icecube collaboration 
11   
12   @version: $Revision: $ 
13   @date: $Date: $ 
14   @author: Juan Carlos Diaz Velez <juancarlos@icecube.wisc.edu> 
15   @todo: implement more functionality of condor. 
16  """ 
17   
18  import os 
19  import re 
20  import sys 
21  import math 
22  import dircache 
23  import time 
24  import string 
25  import shutil 
26  import ConfigParser 
27  from grid import iGrid 
28  import logging 
29  from iceprod.core import metadata 
30  from iceprod.core.dataclasses import Steering 
31  from iceprod.server.db import ConfigDB 
32   
33  logger = logging.getLogger('I3DBQueue') 
34   
35   
36 -class I3DBQueue(iGrid):
37 """ 38 This class represents a job or cluster on a condor system. 39 """ 40
41 - def __init__(self):
42 iGrid.__init__(self) 43 self.dataset_id = -1 44 self.cluster_id = -1 45 self.post = None 46 self.enqueue_cmd = "condor_submit" 47 self.checkqueue_cmd = "condor_q" 48 self.queue_rm_cmd = "condor_rm"
49
50 - def set_dataset_id(self,dataset_id):
53 54
55 - def WriteConfig(self,job,config_file):
56 """ 57 Write condor submit file to a file. 58 @param job: i3Job object 59 @param config_file: path to file were submit file will be written 60 """ 61 print "WriteConfig not implemented in this plugin"
62 63
64 - def CheckQ(self,db):
65 """ 66 Querie status of cluster or job on condor queue 67 """ 68 db.connect() 69 cursor = db.getcursor() 70 sql = " SELECT job.*,grid.* FROM job,grid " 71 sql += " WHERE job.grid_id=grid.grid_id and dataset_id = %d " % self.dataset_id 72 cursor.execute(sql) 73 format = " %(queue_id)04d | %(status)s | %(name)s | %(status_changed)s | %(host)s" 74 format += "| %(time_user)f | %(time_sys)f | %(time_real)f | %(nevents)s \n" 75 status = "queue_id | status | grid | last update | host" 76 status += "| user time | sys time | real time | events \n" 77 status += 100*"-"+"\n" 78 for item in cursor.fetchall(): 79 status += format % item 80 return status
81 82
83 - def QRemove(self,db):
84 """ 85 Remove cluster or job from condor queue 86 """ 87 db.connect() 88 cursor = db.getcursor() 89 sql = " DELETE FROM JOB WHERE dataset_id = %d " % self.dataset_id 90 cursor.execute(sql) 91 db.commit() 92 93 return "removed all jobs for dataset %d" % self.dataset_id
94