summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Reports/reports
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2010-09-24 03:44:21 +0000
committerSol Jerome <sol.jerome@gmail.com>2010-09-26 15:27:08 -0500
commit202a61db37490b84a256674a6fb95b88edbeafbd (patch)
tree10c6753ae878d5f5653a3bcb8ee2b73707195bee /src/lib/Server/Reports/reports
parent14f43b5b4abc3c5c0afcda055bb13d375ca949ab (diff)
downloadbcfg2-202a61db37490b84a256674a6fb95b88edbeafbd.tar.gz
bcfg2-202a61db37490b84a256674a6fb95b88edbeafbd.tar.bz2
bcfg2-202a61db37490b84a256674a6fb95b88edbeafbd.zip
DBStats: Purge historic data and expired clients
Adds a purge command to bcfg2-admin reports to permanently remove interactions and clients. Extends bcfg2-admin scrub to remove orphaned Reason and Entries objects. git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@6070 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Reports/reports')
-rw-r--r--src/lib/Server/Reports/reports/models.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/Server/Reports/reports/models.py b/src/lib/Server/Reports/reports/models.py
index 709e7aa1c..5468420f6 100644
--- a/src/lib/Server/Reports/reports/models.py
+++ b/src/lib/Server/Reports/reports/models.py
@@ -1,5 +1,6 @@
"""Django models for Bcfg2 reports."""
from django.db import models
+from django.db import connection, transaction
from django.db.models import Q
from datetime import datetime, timedelta
from time import strptime
@@ -163,6 +164,14 @@ class Interaction(models.Model):
self.client.current_interaction = self.client.interactions.latest()
self.client.save()#save again post update
+ def delete(self):
+ '''Override the default delete. Allows us to remove Performance items'''
+ pitems = list(self.performance_items.all())
+ super(Interaction, self).delete()
+ for perf in pitems:
+ if perf.interaction.count() == 0:
+ perf.delete()
+
def badcount(self):
return self.totalcount - self.goodcount
@@ -226,6 +235,15 @@ class Reason(models.Model):
def _str_(self):
return "Reason"
+ @staticmethod
+ @transaction.commit_on_success
+ def prune_orphans():
+ '''Prune oprhaned rows... no good way to use the ORM'''
+ cursor = connection.cursor()
+ cursor.execute('delete from reports_reason where not exists (select rei.id from reports_entries_interactions rei where rei.reason_id = reports_reason.id)')
+ transaction.set_dirty()
+
+
class Entries(models.Model):
"""Contains all the entries feed by the client."""
name = models.CharField(max_length=128, db_index=True)
@@ -234,6 +252,14 @@ class Entries(models.Model):
def __str__(self):
return self.name
+ @staticmethod
+ @transaction.commit_on_success
+ def prune_orphans():
+ '''Prune oprhaned rows... no good way to use the ORM'''
+ cursor = connection.cursor()
+ cursor.execute('delete from reports_entries where not exists (select rei.id from reports_entries_interactions rei where rei.entry_id = reports_entries.id)')
+ transaction.set_dirty()
+
class Entries_interactions(models.Model):
"""Define the relation between the reason, the interaction and the entry."""
entry = models.ForeignKey(Entries)
@@ -284,6 +310,14 @@ class Performance(models.Model):
value = models.DecimalField(max_digits=32, decimal_places=16)
def __str__(self):
return self.metric
+
+ @staticmethod
+ @transaction.commit_on_success
+ def prune_orphans():
+ '''Prune oprhaned rows... no good way to use the ORM'''
+ cursor = connection.cursor()
+ cursor.execute('delete from reports_performance where not exists (select ri.id from reports_performance_interaction ri where ri.performance_id = reports_performance.id)')
+ transaction.set_dirty()
objects = PerformanceManager()