Add Housekeeping to manage spare amphora and DB cleanup

Updating config file to include attributes for spare check and db cleanup
Validate the spare amphora count and create new ones when needed
Perform DB cleanup of the expired amphora

Implements: blueprint housekeeping-manager
Change-Id: I98990fbd3a3cb281a70e0eab97f256c960ca5dcb
This commit is contained in:
bharath
2015-07-16 16:14:36 -07:00
parent 539310db95
commit d74ef6b138
11 changed files with 369 additions and 31 deletions

View File

@@ -352,6 +352,17 @@ class AmphoraRepository(BaseRepository):
data_model_list = [model.to_data_model() for model in lb_list]
return data_model_list
def get_spare_amphora_count(self, session):
"""Get the count of the spare amphora.
:returns: Number of current spare amphora.
"""
with session.begin(subtransactions=True):
count = session.query(self.model_class).filter_by(
status=constants.AMPHORA_READY, load_balancer_id=None).count()
return count
class SNIRepository(BaseRepository):
model_class = models.SNI
@@ -379,18 +390,20 @@ class AmphoraHealthRepository(BaseRepository):
session.query(self.model_class).filter_by(
amphora_id=amphora_id).update(model_kwargs)
def check_amphora_expired(self, session, amphora_id, timestamp=None):
def check_amphora_expired(self, session, amphora_id, exp_age=None):
"""check if a specific amphora is expired
:param session: A Sql Alchemy database session.
:param amphora_id: id of an amphora object
:param timestamp: A standard datetime which is used to see if an
:param exp_age: A standard datetime which is used to see if an
amphora needs to be updated (default: now - 10s)
:returns: boolean
"""
if not timestamp:
if not exp_age:
timestamp = datetime.datetime.utcnow() - datetime.timedelta(
seconds=10)
else:
timestamp = datetime.datetime.utcnow() - exp_age
amphora_health = self.get(session, amphora_id=amphora_id)
return amphora_health.last_update < timestamp