From: Brian Warner Date: Thu, 13 Dec 2007 03:31:01 +0000 (-0700) Subject: remove logpublisher, use the Foolscap version now that this functionality has been... X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri//%22%22?a=commitdiff_plain;h=69b65b6b015482fd43b2912d1fcc15e5ec9eb5f1;p=tahoe-lafs%2Ftahoe-lafs.git remove logpublisher, use the Foolscap version now that this functionality has been moved into Foolscap-0.2.2 --- diff --git a/src/allmydata/logpublisher.py b/src/allmydata/logpublisher.py deleted file mode 100644 index 0718dcf7..00000000 --- a/src/allmydata/logpublisher.py +++ /dev/null @@ -1,86 +0,0 @@ - -import os.path -from zope.interface import implements -from twisted.application import service -from twisted.python import log -from foolscap import Referenceable, RemoteInterface -from foolscap.schema import DictOf, Any -from allmydata import get_package_versions - -class RILogObserver(RemoteInterface): - def msg(logmsg=DictOf(str, Any())): - return None -class RISubscription(RemoteInterface): - pass - -class RILogPublisher(RemoteInterface): - def get_versions(): - return DictOf(str, str) - def subscribe_to_all(observer=RILogObserver): - return RISubscription - def unsubscribe(subscription=Any()): - # I don't know how to get the constraint right: unsubscribe() should - # accept return value of subscribe_to_all() - return None - -class RILogGatherer(RemoteInterface): - def logport(nodeid=str, logport=RILogPublisher): - return None - -class Subscription(Referenceable): - implements(RISubscription) - -class LogPublisher(Referenceable, service.MultiService): - implements(RILogPublisher) - name = "log_publisher" - - def __init__(self): - service.MultiService.__init__(self) - self._subscribers = {} - self._notifyOnDisconnectors = {} - - def startService(self): - service.MultiService.startService(self) - furlfile = os.path.join(self.parent.basedir, "logport.furl") - self.parent.tub.registerReference(self, furlFile=furlfile) - os.chmod(furlfile, 0600) - - log.addObserver(self._twisted_log_observer) - - def stopService(self): - log.removeObserver(self._twisted_log_observer) - return service.MultiService.stopService(self) - - def _twisted_log_observer(self, d): - # Twisted will remove this for us if it fails. - - # keys: - # ['message']: *args - # ['time']: float - # ['isError']: bool, usually False - # ['system']: string - - for o in self._subscribers.values(): - o.callRemoteOnly("msg", d) - - #f = open("/tmp/f.out", "a") - #print >>f, d['message'] - #f.close() - - def remote_get_versions(self): - # Convert all the version instances to strings. - return dict([(k,str(v)) - for k,v in get_package_versions().iteritems()]) - - def remote_subscribe_to_all(self, observer): - s = Subscription() - self._subscribers[s] = observer - c = observer.notifyOnDisconnect(self.remote_unsubscribe, s) - self._notifyOnDisconnectors[s] = c - return s - - def remote_unsubscribe(self, s): - observer = self._subscribers.pop(s) - c = self._notifyOnDisconnectors.pop(s) - observer.dontNotifyOnDisconnect(c) - diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 53281229..e955849c 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -10,7 +10,18 @@ from allmydata import get_package_versions_string from allmydata.util import log as tahoe_log from allmydata.util import iputil, observer, humanreadable from allmydata.util.assertutil import precondition -from allmydata.logpublisher import LogPublisher + +# Just to get their versions: +import allmydata, pycryptopp, zfec + +from foolscap.logging.publish import LogPublisher +# Add our application versions to the data that Foolscap's +# LogPublisher reports. Our __version__ attributes are actually +# instances of allmydata.util.version_class.Version, so convert them +# into strings first. +LogPublisher.versions['allmydata'] = str(allmydata.__version__) +LogPublisher.versions['zfec'] = str(zfec.__version__) +LogPublisher.versions['pycryptopp'] = str(pycryptopp.__version__) # group 1 will be addr (dotted quad string), group 3 if any will be portnum (string) ADDR_RE=re.compile("^([1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*)(:([1-9][0-9]*))?$") @@ -177,6 +188,11 @@ class Node(service.MultiService): ob.formatTime = newmeth # TODO: twisted >2.5.0 offers maxRotatedFiles=50 + self.tub.setOption("logport-furlfile", + os.path.join(self.basedir, "logport.furl")) + self.tub.setOption("log-gatherer-furlfile", + os.path.join(self.basedir, "log_gatherer.furl")) + def log(self, msg, src="", args=(), **kw): if src: logsrc = src @@ -222,17 +238,7 @@ class Node(service.MultiService): def tub_ready(self): # called when the Tub is available for registerReference - self.setup_log_publisher() - - def setup_log_publisher(self): - self.add_service(LogPublisher()) - log_gatherer_furl = self.get_config("log_gatherer.furl") - if log_gatherer_furl: - self.tub.connectTo(log_gatherer_furl, self._log_gatherer_connected) - - def _log_gatherer_connected(self, rref): - rref.callRemote("logport", - self.nodeid, self.getServiceNamed("log_publisher")) + pass def when_tub_ready(self): return self._tub_ready_observerlist.when_fired() diff --git a/src/allmydata/test/test_node.py b/src/allmydata/test/test_node.py index dc354cf2..352ae6ba 100644 --- a/src/allmydata/test/test_node.py +++ b/src/allmydata/test/test_node.py @@ -1,17 +1,13 @@ import os, time -from zope.interface import implements from twisted.trial import unittest from twisted.internet import defer from twisted.python import log -from foolscap import Tub, Referenceable -from foolscap.eventual import fireEventually, flushEventualQueue +from foolscap.eventual import flushEventualQueue from twisted.application import service -import allmydata from allmydata.node import Node, formatTimeTahoeStyle from allmydata.util import testutil, fileutil -from allmydata import logpublisher class LoggingMultiService(service.MultiService): def log(self, msg, **kw): @@ -59,16 +55,3 @@ class TestCase(unittest.TestCase, testutil.SignalMixin): self.failUnless("Z" in t) t2 = formatTimeTahoeStyle("ignored", int(time.time())) self.failUnless("Z" in t2) - -class Gatherer(Referenceable): - implements(logpublisher.RILogGatherer) - def remote_logport(self, nodeid, logport): - d = logport.callRemote("get_versions") - d.addCallback(self.d.callback) - -class LogObserver(Referenceable): - implements(logpublisher.RILogObserver) - def __init__(self): - self.messages = [] - def remote_msg(self, d): - self.messages.append(d) diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index ac51e023..284bf5e5 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -4,10 +4,8 @@ def foo(): pass # keep the line number constant import os from twisted.trial import unittest -from twisted.python import failure -from twisted.python import log as twisted_log from allmydata.util import bencode, idlib, humanreadable, mathutil -from allmydata.util import assertutil, fileutil, testutil, log +from allmydata.util import assertutil, fileutil, testutil class IDLib(unittest.TestCase):