[CalendarServer-changes] [9667] CalendarServer/branches/users/glyph/q
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 11 01:55:38 PDT 2012
Revision: 9667
http://trac.macosforge.org/projects/calendarserver/changeset/9667
Author: glyph at apple.com
Date: 2012-08-11 01:55:37 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
run log messages over multiplexed socket
Modified Paths:
--------------
CalendarServer/branches/users/glyph/q/calendarserver/accesslog.py
CalendarServer/branches/users/glyph/q/calendarserver/tap/caldav.py
CalendarServer/branches/users/glyph/q/calendarserver/tap/test/test_caldav.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/q/
Modified: CalendarServer/branches/users/glyph/q/calendarserver/accesslog.py
===================================================================
--- CalendarServer/branches/users/glyph/q/calendarserver/accesslog.py 2012-08-11 08:55:36 UTC (rev 9666)
+++ CalendarServer/branches/users/glyph/q/calendarserver/accesslog.py 2012-08-11 08:55:37 UTC (rev 9667)
@@ -378,34 +378,25 @@
arguments = []
class AMPCommonAccessLoggingObserver(CommonAccessLoggingObserverExtensions):
- def __init__(self, mode, id):
- self.mode = mode
- self.id = id
+ def __init__(self):
self.protocol = None
self._buffer = []
+
def flushBuffer(self):
if self._buffer:
for msg in self._buffer:
self.logMessage(msg)
- def start(self):
- super(AMPCommonAccessLoggingObserver, self).start()
- from twisted.internet import reactor
+ def addClient(self, connectedClient):
+ """
+ An AMP client connected; hook it up to this observer.
+ """
+ self.protocol = connectedClient
+ self.flushBuffer()
- def _gotProtocol(proto):
- self.protocol = proto
- self.flushBuffer()
- self.client = protocol.ClientCreator(reactor, amp.AMP)
- if self.mode == "AF_UNIX":
- d = self.client.connectUNIX(self.id)
- else:
- d = self.client.connectTCP("localhost", self.id)
- d.addCallback(_gotProtocol)
-
-
def logMessage(self, message):
"""
Log a message to the remote AMP Protocol
@@ -420,6 +411,7 @@
else:
self._buffer.append(message)
+
def logGlobalHit(self):
"""
Log a server hit via the remote AMP Protocol
@@ -429,8 +421,10 @@
d = self.protocol.callRemote(LogGlobalHit)
d.addErrback(log.err)
else:
- log.msg("logGlobalHit() only works with an AMP Protocol")
+ log.msg("logGlobalHit() only works with an AMP Protocol")
+
+
class AMPLoggingProtocol(amp.AMP):
"""
A server side protocol for logging to the given observer.
@@ -453,15 +447,23 @@
LogGlobalHit.responder(logGlobalHit)
+
+
class AMPLoggingFactory(protocol.ServerFactory):
def __init__(self, observer):
self.observer = observer
+
def doStart(self):
self.observer.start()
+
def doStop(self):
self.observer.stop()
+
def buildProtocol(self, addr):
return AMPLoggingProtocol(self.observer)
+
+
+
Modified: CalendarServer/branches/users/glyph/q/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/q/calendarserver/tap/caldav.py 2012-08-11 08:55:36 UTC (rev 9666)
+++ CalendarServer/branches/users/glyph/q/calendarserver/tap/caldav.py 2012-08-11 08:55:37 UTC (rev 9667)
@@ -88,6 +88,11 @@
from calendarserver.tap.util import ConnectionDispenser
+from calendarserver.controlsocket import ControlSocket
+from twisted.internet.endpoints import UNIXClientEndpoint, TCP4ClientEndpoint
+
+from calendarserver.controlsocket import ControlSocketConnectingService
+from twisted.protocols.amp import AMP
from calendarserver.accesslog import AMPCommonAccessLoggingObserver
from calendarserver.accesslog import AMPLoggingFactory
from calendarserver.accesslog import RotatingFileAccessLoggingObserver
@@ -117,6 +122,13 @@
from twisted.python.util import uidFromString, gidFromString
+
+# Control socket message-routing constants.
+_LOG_ROUTE = "log"
+
+_CONTROL_SERVICE_NAME = "control"
+
+
def getid(uid, gid):
if uid is not None:
uid = uidFromString(uid)
@@ -762,22 +774,36 @@
#
self.log_info("Setting up service")
+ bonusServices = []
+
if config.ProcessType == "Slave":
+ logObserver = AMPCommonAccessLoggingObserver()
+
if config.ControlSocket:
- mode = "AF_UNIX"
id = config.ControlSocket
- self.log_info("Logging via AF_UNIX: %s" % (id,))
+ self.log_info("Control via AF_UNIX: %s" % (id,))
+ endpointFactory = lambda reactor: UNIXClientEndpoint(
+ reactor, id)
else:
- mode = "AF_INET"
id = int(config.ControlPort)
- self.log_info("Logging via AF_INET: %d" % (id,))
-
- logObserver = AMPCommonAccessLoggingObserver(mode, id)
-
+ self.log_info("Control via AF_INET: %d" % (id,))
+ endpointFactory = lambda reactor: TCP4ClientEndpoint(
+ reactor, "127.0.0.1", id)
+ controlSocketClient = ControlSocket()
+ class LogClient(AMP):
+ def connectionMade(self):
+ super(LogClient, self).connectionMade(self)
+ logObserver.addClient(self)
+ f = Factory()
+ f.protocol = LogClient
+ controlSocketClient.addFactory(_LOG_ROUTE, f)
+ controlClient = ControlSocketConnectingService(
+ endpointFactory, controlSocketClient
+ )
+ bonusServices.append(controlClient)
elif config.ProcessType == "Single":
# Make sure no old socket files are lying around.
self.deleteStaleSocketFiles()
-
logObserver = RotatingFileAccessLoggingObserver(
config.AccessLogFile,
)
@@ -785,18 +811,20 @@
self.log_info("Configuring access log observer: %s" % (logObserver,))
service = CalDAVService(logObserver)
+ for bonus in bonusServices:
+ bonus.setServiceParent(service)
rootResource = getRootResource(config, store, additional)
service.rootResource = rootResource
underlyingSite = Site(rootResource)
-
- # Need to cache SSL port info here so we can access it in a Request to deal with the
- # possibility of being behind an SSL decoder
+
+ # Need to cache SSL port info here so we can access it in a Request to
+ # deal with the possibility of being behind an SSL decoder
underlyingSite.EnableSSL = config.EnableSSL
underlyingSite.SSLPort = config.SSLPort
underlyingSite.BindSSLPorts = config.BindSSLPorts
-
+
requestFactory = underlyingSite
if config.RedirectHTTPToHTTPS:
@@ -1102,7 +1130,8 @@
try:
gid = getgrnam(config.GroupName).gr_gid
except KeyError:
- raise ConfigurationError("Invalid group name: %s" % (config.GroupName,))
+ raise ConfigurationError("Invalid group name: %s" %
+ (config.GroupName,))
else:
gid = os.getgid()
@@ -1110,20 +1139,24 @@
try:
uid = getpwnam(config.UserName).pw_uid
except KeyError:
- raise ConfigurationError("Invalid user name: %s" % (config.UserName,))
+ raise ConfigurationError("Invalid user name: %s" %
+ (config.UserName,))
else:
uid = os.getuid()
+
+ controlSocket = ControlSocket()
+ controlSocket.addFactory(_LOG_ROUTE, logger)
if config.ControlSocket:
- loggingService = GroupOwnedUNIXServer(
- gid, config.ControlSocket, logger, mode=0660
+ controlSocketService = GroupOwnedUNIXServer(
+ gid, config.ControlSocket, controlSocket, mode=0660
)
else:
- loggingService = ControlPortTCPServer(
- config.ControlPort, logger, interface="127.0.0.1"
+ controlSocketService = ControlPortTCPServer(
+ config.ControlPort, controlSocket, interface="127.0.0.1"
)
- loggingService.setName("logging")
- loggingService.setServiceParent(s)
+ controlSocketService.setName(_CONTROL_SERVICE_NAME)
+ controlSocketService.setServiceParent(s)
monitor = DelayedStartupProcessMonitor()
s.processMonitor = monitor
Modified: CalendarServer/branches/users/glyph/q/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/q/calendarserver/tap/test/test_caldav.py 2012-08-11 08:55:36 UTC (rev 9666)
+++ CalendarServer/branches/users/glyph/q/calendarserver/tap/test/test_caldav.py 2012-08-11 08:55:37 UTC (rev 9667)
@@ -57,7 +57,8 @@
from calendarserver.tap.caldav import (
CalDAVOptions, CalDAVServiceMaker, CalDAVService, GroupOwnedUNIXServer,
- DelayedStartupProcessMonitor, DelayedStartupLineLogger, TwistdSlaveProcess
+ DelayedStartupProcessMonitor, DelayedStartupLineLogger, TwistdSlaveProcess,
+ _CONTROL_SERVICE_NAME
)
from calendarserver.provision.root import RootResource
from StringIO import StringIO
@@ -460,7 +461,7 @@
self.config["ProcessType"] = "Combined"
self.writeConfig()
svc = self.makeService()
- for serviceName in ["logging"]:
+ for serviceName in [_CONTROL_SERVICE_NAME]:
socketService = svc.getServiceNamed(serviceName)
self.assertIsInstance(socketService, GroupOwnedUNIXServer)
m = socketService.kwargs.get("mode", 0666)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/d7375414/attachment-0001.html>
More information about the calendarserver-changes
mailing list