[sldev-commits] r101 - trunk/certified_http

which.linden at svn.secondlife.com which.linden at svn.secondlife.com
Fri Dec 7 19:54:01 PST 2007


Author: which.linden
Date: 2007-12-07 21:54:01 -0600 (Fri, 07 Dec 2007)
New Revision: 101

Modified:
   trunk/certified_http/oplog.py
   trunk/certified_http/oplog_test.py
Trac: http://svn.secondlife.com/trac/certified_http/changeset/101
Log:
Added REST API for looking at the existing oplogs.  It's very little code, but it is rather simple.  Left the html-based monitor around.

Modified: trunk/certified_http/oplog.py
===================================================================
--- trunk/certified_http/oplog.py	2007-12-07 01:28:39 UTC (rev 100)
+++ trunk/certified_http/oplog.py	2007-12-08 03:54:01 UTC (rev 101)
@@ -23,7 +23,8 @@
 import uuid
 import weakref
 
-from mulib import mu
+from mulib import mu, stacked
+from mulib.mu import tags
 from certified_http import fault_injector
 
 # "long time" 15 days
@@ -37,10 +38,26 @@
 class ConcurrentReplayError(Exception):
     pass
 
+def dict_standin(op):
+    return {
+        'id':op._persister._id,
+        'created':op.created(),
+        'replay_count':op.replays()[1],
+        'replayed':op.replays()[0],
+        'restore_times':op._restore_times,
+        'version': op.version(),
+        'tombstoned': op.tombstoned()}
+
 class Monitor(mu.Resource):
     def __init__(self,persist):
         self._persist = persist
 
+    def child_oplogs(self, req, childName):
+        # make a deep dict copy of the active oplogs for rendering by stacked
+        return dict([(id, dict_standin(op))
+                     for id,op in self._persist._active_oplogs.items()
+                     if op])
+
     def fmtrow(self,tag,*cols):
         return "<TR><"+tag+">" + (("</"+tag+"><"+tag+">").join(list(cols))) + "</"+tag+"></TR>"
 
@@ -381,7 +398,6 @@
         """ Returns true if the oplog has been tombstoned. """
         return self._persister.tombstoned()
 
-
 def _test():
     import doctest
     doctest.testmod()

Modified: trunk/certified_http/oplog_test.py
===================================================================
--- trunk/certified_http/oplog_test.py	2007-12-07 01:28:39 UTC (rev 100)
+++ trunk/certified_http/oplog_test.py	2007-12-08 03:54:01 UTC (rev 101)
@@ -27,9 +27,11 @@
 import unittest
 import uuid
 
-from eventlet import api
+from eventlet import api, util
 from certified_http import file_persist, fault_injector, oplog, mysql_persist
 
+util.wrap_socket_with_coroutine_socket()
+
 def test_append(op, l):
     l.append('app')
     return l
@@ -204,6 +206,27 @@
         self.assert_(last_time0 < last_time1)
         self.assert_(last_time1 < last_time2)
 
+    def test_monitoring_interface(self):
+        from eventlet import httpd, jsonhttp, httpc
+        from mulib import mu
+        from cStringIO import StringIO
+        logfile = StringIO()
+        killer = api.spawn(
+            httpd.server, api.tcp_listener(('0.0.0.0', 2009)),
+            mu.SiteMap(self.persister.get_monitor()), log=logfile)
+        try:
+            c = self.persister.get_oplog(mid='ohnoes')
+            result = jsonhttp.get('http://localhost:2009/oplogs')
+            self.assertEquals(len(result.items()), 1)
+            self.assertEquals(jsonhttp.get('http://localhost:2009/oplogs/ohnoes/id'), 'ohnoes')
+            self.persister.tombstone(c)
+            self.assert_(jsonhttp.get('http://localhost:2009/oplogs/ohnoes/tombstoned'))
+            del c
+            result = jsonhttp.get('http://localhost:2009/oplogs')
+            self.assertEquals(len(result.items()), 0)
+        finally:
+            api.kill(killer)
+
     def test_faults_in_exceptions(self):
         fault_injector.use()
         # only fault inside test_raising_exception



More information about the sldev-commits mailing list