Author: croberts
Date: 2012-05-23 18:06:45 +0000 (Wed, 23 May 2012)
New Revision: 5390
Modified:
trunk/cumin/model/plumage/rosemary.xml
trunk/mint/python/mint/plumage/session.py
trunk/rosemary/python/rosemary/model.py
Log:
Refactoring code to load plumage data so that the loading method can be defined in
rosemary.xml, at runtime, we grab that name and use it as the method to call to perform
the customized loading operations.
Modified: trunk/cumin/model/plumage/rosemary.xml
===================================================================
--- trunk/cumin/model/plumage/rosemary.xml 2012-05-23 17:00:00 UTC (rev 5389)
+++ trunk/cumin/model/plumage/rosemary.xml 2012-05-23 18:06:45 UTC (rev 5390)
@@ -1,6 +1,10 @@
<model>
<package name="com.redhat.grid.plumage"
persistent="timestamp">
<class name="OSUtil">
+ <loading_class>
+ <name>OSUtilLoader</name>
+ </loading_class>
+
<source>
<database>condor_stats</database>
<collection>samples.machine</collection>
Modified: trunk/mint/python/mint/plumage/session.py
===================================================================
--- trunk/mint/python/mint/plumage/session.py 2012-05-23 17:00:00 UTC (rev 5389)
+++ trunk/mint/python/mint/plumage/session.py 2012-05-23 18:06:45 UTC (rev 5390)
@@ -49,22 +49,13 @@
if cls._package._name in self.app.package_filter:
black_list.add(cls)
else:
- # We're going to have a thread for this...
- self.threads.append(CatchUpPlumageSessionThread(
- self.app,
- self.server_host,
- self.server_port,
- cls))
- self.threads.append(PlumageSessionThread(
- self.app,
- self.server_host,
- self.server_port,
- cls))
- self.threads.append(CurrentPlumageSessionThread(
- self.app,
- self.server_host,
- self.server_port,
- cls))
+ try:
+ loaders = ClassLoaders()
+ # Here we grab the name of the method to use (should be in
rosemary.xml package/class/loading_class)
+ func = getattr(loaders, cls.loading_class, None)
+ func(self, cls)
+ except Exception, e:
+ log.error("No loading function for class %s (%s). Be sure
that the method exists and is defined in rosemary.xml" % (cls._name, str(e)))
# Update our list, minus the black_list
self.app.classes.difference_update(black_list)
@@ -75,22 +66,14 @@
for pkg in self.app.model._packages:
if pkg._name not in self.app.package_filter:
self.app.packages.add(pkg)
+ loaders = ClassLoaders()
for cls in pkg._classes:
- self.threads.append(CatchUpPlumageSessionThread(
- self.app,
- self.server_host,
- self.server_port,
- cls))
- self.threads.append(PlumageSessionThread(
- self.app,
- self.server_host,
- self.server_port,
- cls))
- self.threads.append(CurrentPlumageSessionThread(
- self.app,
- self.server_host,
- self.server_port,
- cls))
+ try:
+ # Here we grab the name of the method to use (should be in
rosemary.xml package/class/loading_class)
+ func = getattr(loaders, cls.loading_class, None)
+ func(self, cls)
+ except Exception, e:
+ log.error("No loading function for class %s (%s). Be
sure that the method exists and is defined in rosemary.xml" % (cls._name, str(e)))
def start(self):
log.info("Starting %s", self)
if not imports_ok:
@@ -107,6 +90,25 @@
def __repr__(self):
return "%s(%s:%s)" % (self.__class__.__name__, self.server_host,
self.server_port)
+class ClassLoaders(object):
+ ''' method for loading the com.redhat.grid.plumage.OSUtil data from
plumage, name is found in rosemary.xml under package/class/loading_class '''
+ def OSUtilLoader(self, obj, cls):
+ obj.threads.append(CatchUpPlumageSessionThread(
+ obj.app,
+ obj.server_host,
+ obj.server_port,
+ cls))
+ obj.threads.append(PlumageSessionThread(
+ obj.app,
+ obj.server_host,
+ obj.server_port,
+ cls))
+ obj.threads.append(CurrentPlumageSessionThread(
+ obj.app,
+ obj.server_host,
+ obj.server_port,
+ cls))
+
class PlumageSessionThread(MintDaemonThread):
def __init__(self, app, server_host, server_port, cls):
super(PlumageSessionThread, self).__init__(app)
Modified: trunk/rosemary/python/rosemary/model.py
===================================================================
--- trunk/rosemary/python/rosemary/model.py 2012-05-23 17:00:00 UTC (rev 5389)
+++ trunk/rosemary/python/rosemary/model.py 2012-05-23 18:06:45 UTC (rev 5390)
@@ -759,6 +759,7 @@
self.source = ""
self.database = ""
self.collection = ""
+ self.loading_class = ""
def init(self):
super(Generic_class, self).init()
@@ -787,6 +788,7 @@
self.source = elem.findtext("source")
self.database = elem.findtext("source/database")
self.collection = elem.findtext("source/collection")
+ self.loading_class = elem.findtext("loading_class/name")
def load_class_components(self, elem):
for child in elem.findall("property"):