Author: nunofsantos
Date: 2008-12-02 11:52:14 -0500 (Tue, 02 Dec 2008)
New Revision: 2903
Modified:
mgmt/trunk/cumin/python/cumin/__init__.py
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/mint/python/mint/__init__.py
mgmt/trunk/mint/python/mint/dbexpire.py
mgmt/trunk/mint/python/mint/sql.py
mgmt/trunk/mint/python/mint/tools.py
Log:
make the expiration of db records configurable via two params (in cumin.conf and/or in
command line): dbexpire-frequency and dbexpire-threshold
Modified: mgmt/trunk/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/__init__.py 2008-12-01 21:00:26 UTC (rev 2902)
+++ mgmt/trunk/cumin/python/cumin/__init__.py 2008-12-02 16:52:14 UTC (rev 2903)
@@ -37,7 +37,7 @@
self.add_resource_dir(os.path.join(self.home, "resources-wooly"))
self.add_resource_dir(os.path.join(self.home, "resources"))
- self.model = CuminModel(self, self.config.data, self.config.spec)
+ self.model = CuminModel(self, self.config.data)
self.main_page = MainPage(self, "index.html")
self.add_page(self.main_page)
@@ -167,6 +167,12 @@
param = ConfigParameter(self, "user", str)
+ param = ConfigParameter(self, "dbexpire-frequency", int)
+ param.default = 600 # 10 minutes
+
+ param = ConfigParameter(self, "dbexpire-threshold", int)
+ param.default = 24 * 3600 # 1 day
+
def init(self):
super(CuminConfig, self).init()
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-12-01 21:00:26 UTC (rev 2902)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-12-02 16:52:14 UTC (rev 2903)
@@ -18,9 +18,10 @@
log = logging.getLogger("cumin.model")
class CuminModel(object):
- def __init__(self, app, data_uri, spec_path):
+ def __init__(self, app, data_uri):
self.app = app
- self.data = MintModel(data_uri, spec_path, debug=False)
+ self.data = MintModel(data_uri, dbExpireFrequency=app.config.dbexpire_frequency,
\
+ dbExpireThreshold=app.config.dbexpire_threshold, debug=False)
self.classes = list()
self.invocations = set()
Modified: mgmt/trunk/mint/python/mint/__init__.py
===================================================================
--- mgmt/trunk/mint/python/mint/__init__.py 2008-12-01 21:00:26 UTC (rev 2902)
+++ mgmt/trunk/mint/python/mint/__init__.py 2008-12-02 16:52:14 UTC (rev 2903)
@@ -313,7 +313,7 @@
class MintModel(qmf.console.Console):
staticInstance = None
- def __init__(self, dataUri, specPath="", debug=False):
+ def __init__(self, dataUri, dbExpireFrequency, dbExpireThreshold, debug=False):
self.dataUri = dataUri
self.debug = debug
@@ -325,7 +325,7 @@
self.__lock = RLock()
self.dbConn = None
- self.dbExpireThread = dbexpire.DBExpireThread(self)
+ self.dbExpireThread = dbexpire.DBExpireThread(self, frequency=dbExpireFrequency,
threshold=dbExpireThreshold)
self.updateThread = update.ModelUpdateThread(self)
self.mgmtSession = qmf.console.Session(self, manageConnections=True)
self.outstandingMethodCalls = dict()
Modified: mgmt/trunk/mint/python/mint/dbexpire.py
===================================================================
--- mgmt/trunk/mint/python/mint/dbexpire.py 2008-12-01 21:00:26 UTC (rev 2902)
+++ mgmt/trunk/mint/python/mint/dbexpire.py 2008-12-02 16:52:14 UTC (rev 2903)
@@ -8,20 +8,20 @@
log = logging.getLogger("mint.dbexpire")
class DBExpireThread(Thread):
- def __init__(self, model, frequency=600, expiration=24*3600, keepCurrStats=False):
+ def __init__(self, model, frequency, threshold, keepCurrStats=False):
super(DBExpireThread, self).__init__()
self.model = model
self.setDaemon(False)
self.stopRequested = False
self.frequency = frequency
- self.expiration = expiration
+ self.threshold = threshold
self.keepCurrStats = keepCurrStats
frequency_out, frequency_unit = self.convertTimeUnits(frequency)
- expiration_out, expiration_unit = self.convertTimeUnits(expiration)
+ threshold_out, threshold_unit = self.convertTimeUnits(threshold)
log.debug("Expiring database records older than %d %s, every %d %s" \
- % (expiration_out, expiration_unit, frequency_out, frequency_unit))
+ % (threshold_out, threshold_unit, frequency_out, frequency_unit))
def run(self):
ops = []
@@ -30,7 +30,7 @@
ops.append(SqlExpire(Job, self.keepCurrStats))
attrs = dict()
- attrs["expiration"] = self.expiration
+ attrs["threshold"] = self.threshold
conn = self.model.dbConn.getConnection()
Modified: mgmt/trunk/mint/python/mint/sql.py
===================================================================
--- mgmt/trunk/mint/python/mint/sql.py 2008-12-01 21:00:26 UTC (rev 2902)
+++ mgmt/trunk/mint/python/mint/sql.py 2008-12-02 16:52:14 UTC (rev 2903)
@@ -152,14 +152,14 @@
parent_table = table[0:table.find("_stats")]
sql = """
delete from %s
- where qmf_update_time < now() - interval '%%(expiration)s seconds'
+ where qmf_update_time < now() - interval '%%(threshold)s seconds'
""" % (table)
if self.keepCurrStats:
sql += " and id not in (select stats_curr_id from %s)" %
(parent_table)
else:
sql = """
delete from %s
- where qmf_create_time < now() - interval '%%(expiration)s seconds'
+ where qmf_create_time < now() - interval '%%(threshold)s seconds'
""" % (table)
return sql
Modified: mgmt/trunk/mint/python/mint/tools.py
===================================================================
--- mgmt/trunk/mint/python/mint/tools.py 2008-12-01 21:00:26 UTC (rev 2902)
+++ mgmt/trunk/mint/python/mint/tools.py 2008-12-02 16:52:14 UTC (rev 2903)
@@ -26,6 +26,14 @@
opt = CommandOption(self, "debug")
opt.description = "Enable debugging; print logging to console"
+ opt = CommandOption(self, "dbexpire-frequency")
+ opt.argument = "FREQUENCY"
+ opt.description = "Frequency (in seconds) of the database expiration
thread"
+
+ opt = CommandOption(self, "dbexpire-threshold")
+ opt.argument = "THRESHOLD"
+ opt.description = "Threshold (in seconds) of the age of database records
before they're expired"
+
def check(self):
if os.getuid() not in (os.stat(__file__).st_uid, 0):
print "Error: You have insufficient privileges"
@@ -70,8 +78,14 @@
def do_run(self, opts, args):
ddef = "postgresql://cumin@localhost/cumin"
- model = MintModel(opts.get("data", ddef), debug=True)
+ freqDefault = 600 # 10 minutes
+ thresholdDefault = 24 * 3600 # 1 day
+ model = MintModel(opts.get("data", ddef),
opts.get("dbexpire-frequency", freqDefault), \
+ opts.get("dbexpire-threshold", thresholdDefault),
debug=True)
+ print opts.get("dbexpire-frequency", freqDefault)
+ print opts.get("dbexpire-threshold", thresholdDefault)
+
model.check()
model.init()
model.start()