On Tue, 2008-04-22 at 07:59 -0600, Matt Ryan wrote:
> On Tue, 2008-04-22 at 05:27 -0500, Carlo Marcelo Arenas Belon wrote:
> > On Mon, Apr 21, 2008 at 11:48:35AM -0600, Matt Ryan wrote:
> > > 
> > > Attached is a patch for this bug.  The problem was that with no data
> > > sources providing data to gmetad (since the gmond used as a cluster
> > > collector is down) the internal data structure was empty, and the code
> > > was trying to navigate an empty data structure, hence the 'NoneType'
> > > exception.
> > >
> > > The patch checks for that and does not try to navigate the data
> > > structure if the root node is None.  This results in an empty XML
> > > document - the DTD is printed but no other information.  Is that
> > > behavior correct?
> > 
> > no, an XML with no body is invalid
> > 
> > > If not, let me know what the correct behavior should
> > > be on the XML port if there is no data being collected, and I will
> > > revise.
> > 
> > stable gmetad returns an XML with an empty GRID (which I suspect is not
> > correct either) but that the web frontend relies on.
> > 
> > <GANGLIA_XML VERSION="3.0.7" SOURCE="gmetad">
> > <GRID NAME="unspecified" AUTHORITY="http://dell/ganglia/";
> > LOCALTIME="1208858522">
> > </GRID>
> > </GANGLIA_XML>
> > 
> > an empty GANGLIA_XML (no GRID) makes more sense and is valid, but might 
> > break
> > the frontend, and so will require further patches
> 
> 
> Thanks for the clarification, will submit another patch today
> (hopefully) to fix.

Patch attached to fix the XML output when no data is being collected.



--- gmetad_gmondReader.py       2008-04-22 11:34:11.000000000 -0600
+++ gmetad_gmondReader.py.new   2008-04-22 09:00:15.000000000 -0600
@@ -4,7 +4,7 @@
 import time
 import logging
 
-from gmetad_config import GmetadConfig
+from gmetad_config import GmetadConfig, getConfig
 from gmetad_random import getRandomInterval
 from gmetad_data import DataStore, Element
 
@@ -19,9 +19,10 @@
         e = Element(tag, attrs)
         if 'GANGLIA_XML' == tag:
             ds.lock.acquire()
-            self._elemStack.append(ds.setNode(e))
+            self._elemStack.append(ds.getNode()) # Fetch the root node.  It 
has already been set into the tree.
             self._elemStackLen += 1
-            cfg = GmetadConfig()
+            cfg = getConfig()
+            # We'll go ahead and update any existing GRID tag with a new one 
(new time) even if one already exists.
             e = Element('GRID', {'NAME':cfg[GmetadConfig.GRIDNAME], 
'AUTHORITY':cfg[GmetadConfig.AUTHORITY], 'LOCALTIME':'%d' % time.time()})
         self._elemStack.append(ds.setNode(e, 
self._elemStack[self._elemStackLen-1]))
         self._elemStackLen += 1
--- gmetad_data.py      2008-04-22 11:34:11.000000000 -0600
+++ gmetad_data.py.new  2008-04-22 08:57:58.000000000 -0600
@@ -1,5 +1,8 @@
 import thread
 import logging
+import time
+
+from gmetad_config import getConfig, GmetadConfig
 
 class DataStore:
     _shared_state = {}
@@ -10,7 +13,16 @@
         self.__dict__ = DataStore._shared_state
         if not DataStore._initialized:
             self.lock = thread.allocate_lock()
+            self.lock.acquire()
             self.rootElement = None
+            # Initialize the data store with the GANGLIA_XML and GRID tags.
+            # Data store should never be completely empty.  Even if there are
+            # no reporting data sources the web front end depends on having
+            # at least a GANGLIA_XML tag and a nested GRID tag.
+            self.setNode(Element('GANGLIA_XML', {}))
+            cfg = getConfig()
+            self.setNode(Element('GRID', {'NAME':cfg[GmetadConfig.GRIDNAME], 
'AUTHORITY':cfg[GmetadConfig.AUTHORITY], 'LOCALTIME':'%d' % time.time()}), 
self.rootElement)
+            self.lock.release()
             DataStore._initialized = True
             
     def setNode(self, node, parent=None):
@@ -22,7 +34,9 @@
         parent[str(node)] = node
         return parent[str(node)]
         
-    def getNode(self, ancestry):
+    def getNode(self, ancestry=[]):
+        if not len(ancestry):
+            return self.rootElement
         node = None
         while ancestry:
             nodeId = ancestry.pop(0)
--- gmetad_xmlWriter.py 2008-04-22 11:34:11.000000000 -0600
+++ gmetad_xmlWriter.py.new     2008-04-22 08:27:37.000000000 -0600
@@ -118,6 +118,8 @@
         
     def _getXmlImpl(self, element, filterList=None, queryargs=None):
         rbuf = '<%s' % element.id
+        if 'GRID' == element.id:
+            element.localtime = '%d' % time.time()
         foundName = False
         try:
             rbuf += ' NAME="%s"' % element.name
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Ganglia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to