[Checkins] SVN: zc.resumelb/trunk/src/zc/resumelb/ The status server provided when using ZooKeeper now listens on a

jim cvs-admin at zope.org
Mon Apr 23 21:34:23 UTC 2012


Log message for revision 125240:
  The status server provided when using ZooKeeper now listens on a
  unix-domain socket.
  

Changed:
  U   zc.resumelb/trunk/src/zc/resumelb/README.txt
  U   zc.resumelb/trunk/src/zc/resumelb/zk.py
  U   zc.resumelb/trunk/src/zc/resumelb/zk.test

-=-
Modified: zc.resumelb/trunk/src/zc/resumelb/README.txt
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/README.txt	2012-04-23 20:19:30 UTC (rev 125239)
+++ zc.resumelb/trunk/src/zc/resumelb/README.txt	2012-04-23 21:34:19 UTC (rev 125240)
@@ -256,6 +256,9 @@
   worker scrores chacking a maximum backlog, we subtract 1 from the
   worker's backlog if it's non-zero.
 
+- The status server provided when using ZooKeeper now listens on a
+  unix-domain socket.
+
 - The status server provided when using ZooKeeper now includes the
   start time of the oldest request for each worker, to be used for
   monitoring.

Modified: zc.resumelb/trunk/src/zc/resumelb/zk.py
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/zk.py	2012-04-23 20:19:30 UTC (rev 125239)
+++ zc.resumelb/trunk/src/zc/resumelb/zk.py	2012-04-23 21:34:19 UTC (rev 125240)
@@ -16,11 +16,13 @@
 import gevent
 import gevent.pool
 import gevent.server
+import gevent.socket
 import json
 import logging
 import os
 import re
 import signal
+import socket
 import sys
 import zc.parse_addr
 import zc.zk
@@ -108,7 +110,7 @@
     parser.add_option(
         '-s', '--status-server',
         help=("Run a status server for getting pool information. "
-              "The argument is an address to listen on."))
+              "The argument is a unix-domain socket path to listen on."))
     parser.add_option(
         '-L', '--logger-configuration',
         help=
@@ -230,12 +232,15 @@
                     ))+'\n')
             writer.close()
             socket.close()
-        status_server_address = zc.parse_addr.parse_addr(options.status_server)
-        status_server = gevent.server.StreamServer(
-            status_server_address, status)
+
+        status_server_address = options.status_server
+        if os.path.exists(status_server_address):
+            os.remove(status_server_address)
+        sock = gevent.socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        sock.bind(status_server_address)
+        sock.listen(5)
+        status_server = gevent.server.StreamServer(sock, status)
         status_server.start()
-        registration_data['status'] = "%s:%s" % (
-            status_server_address[0], status_server.server_port)
 
     zk.register_server(path+'/providers', (addr[0], server.server_port),
                        **registration_data)

Modified: zc.resumelb/trunk/src/zc/resumelb/zk.test
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/zk.test	2012-04-23 20:19:30 UTC (rev 125239)
+++ zc.resumelb/trunk/src/zc/resumelb/zk.test	2012-04-23 21:34:19 UTC (rev 125240)
@@ -194,8 +194,8 @@
                             connections.
       -s STATUS_SERVER, --status-server=STATUS_SERVER
                             Run a status server for getting pool
-                            information. The argument is an address to
-                            listen on.
+                            information. The argument is a unix-domain
+                            socket path to listen on.
       -L LOGGER_CONFIGURATION, --logger-configuration=LOGGER_CONFIGURATION
                             Read logger configuration from the given
                             configuration file path.  The configuration
@@ -215,7 +215,7 @@
 
     >>> gevent.signal.reset_mock()
     >>> lb, server = zc.resumelb.zk.lbmain(
-    ...     'zookeeper.example.com:2181 /test/lb -s :0')
+    ...     'zookeeper.example.com:2181 /test/lb -s status.sock')
 
     >>> sig, sighandler = gevent.signal.call_args[0]
 
@@ -271,12 +271,9 @@
 When we started the lb, we told it to create a status server.  The
 server is registered with ZooKeeper:
 
-    >>> status_addr = zc.parse_addr.parse_addr(
-    ...     zk.get_properties(
-    ...         '/test/lb/providers/' +
-    ...         zk.get_children('/test/lb/providers')[0])['status'])
-    >>> status_socket = gevent.socket.create_connection(
-    ...     ('127.0.0.1', status_addr[1]))
+    >>> import socket
+    >>> status_socket = gevent.socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+    >>> status_socket.connect('status.sock')
     >>> status_file = status_socket.makefile()
     >>> import json
     >>> status = json.loads(status_file.read())



More information about the checkins mailing list