Changeset 0ea11af for fedd/fedd.py
- Timestamp:
- Oct 9, 2008 2:08:28 PM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- 0b466d1
- Parents:
- 11a08b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd.py
r11a08b0 r0ea11af 21 21 from signal import signal, pause, SIGINT, SIGTERM 22 22 from select import select 23 from time import sleep 23 24 import logging 24 25 … … 30 31 31 32 class fedd_server(ThreadingSSLServer): 33 """ 34 Interface the fedd services to the XMLRPC and SOAP interfaces 35 """ 32 36 def __init__(self, ME, handler, ssl_ctx, impl): 37 """ 38 Create an SSL server that handles the transport in handler using the 39 credentials in ssl_ctx, and interfacing to the implementation of fedd 40 services in fedd. ME is the host port pair on which to bind. 41 """ 33 42 ThreadingSSLServer.__init__(self, ME, handler, ssl_ctx) 34 43 self.impl = impl … … 37 46 38 47 class fedd_soap_handler(BaseHTTPRequestHandler): 48 """ 49 Standard connection between SOAP and the fedd services in impl. 50 51 Much of this is boilerplate from 52 http://www.xml.com/pub/a/ws/2004/01/20/salz.html 53 """ 39 54 server_version = "ZSI/2.0 fedd/0.1 " + BaseHTTPRequestHandler.server_version 40 55 … … 99 114 100 115 def soap_dispatch(self, method, req, fid): 116 """ 117 The connection to the implementation, using the method maps 118 119 The implementation provides a mapping from SOAP method name to the 120 method in the implementation that provides the service. 121 """ 101 122 if self.server.soap_methods.has_key(method): 102 123 try: … … 118 139 119 140 class fedd_xmlrpc_handler(BaseHTTPRequestHandler): 141 """ 142 Standard connection between XMLRPC and the fedd services in impl. 143 144 Much of this is boilerplate from 145 http://www.xml.com/pub/a/ws/2004/01/20/salz.html 146 """ 120 147 server_version = "ZSI/2.0 fedd/0.1 " + BaseHTTPRequestHandler.server_version 121 148 … … 157 184 158 185 def xmlrpc_dispatch(self, method, req, fid): 186 """ 187 The connection to the implementation, using the method maps 188 189 The implementation provides a mapping from XMLRPC method name to the 190 method in the implementation that provides the service. 191 """ 159 192 if self.server.xmlrpc_methods.has_key(method): 160 193 try: … … 193 226 const=sys.stderr, help="Print SOAP exchange to stderr") 194 227 195 servers_active = True 196 197 log_params = {\ 198 'format': "%(asctime)s %(levelname)-8s %(message)s",\ 199 'datefmt': '%a, %d %b %Y %H:%M:%S'\ 200 } 228 servers_active = True # Sub-servers run while this is True 229 services = [ ] # Service descriptions 230 servers = [ ] # fedd_server instances instantiated from services 231 servers_lock = Lock() # Lock to manipulate servers from sub-server threads 201 232 202 233 def shutdown(sig, frame): 234 """ 235 On a signal, stop running sub-servers. 236 237 This is connected to signals below 238 """ 203 239 global servers_active, flog 204 240 servers_active = False … … 206 242 207 243 def run_server(s): 244 """ 245 Operate a subserver, shutting down when servers_active is false. 246 247 Each server (that is host/port/transport triple) has a thread running this 248 function, so each can handle requests independently. They all call in to 249 the same implementation, which must manage its own synchronization. 250 """ 208 251 global servers_active # Not strictly needed: servers_active is only read 209 210 if s: 211 while servers_active: 212 i, o, e = select((s,), (), (), 5.0) 213 if s in i: 214 s.handle_request() 215 216 services = [ ] 217 servers = [ ] 252 global servers # List of active servers 253 global servers_lock # Lock to manipulate servers 254 255 while servers_active: 256 i, o, e = select((s,), (), (), 5.0) 257 if s in i: s.handle_request() 258 259 # Done. Remove us from the list 260 servers_lock.acquire() 261 servers.remove(s) 262 servers_lock.release() 218 263 219 264 opts, args = fedd_opts().parse_args() 220 265 266 # Logging setup 221 267 flog = logging.getLogger("fedd") 222 ffmt = logging.Formatter("%(asctime)s %( levelname)-8s %(message)s",223 '% a, %d %b %Y%H:%M:%S')268 ffmt = logging.Formatter("%(asctime)s %(name)s %(message)s", 269 '%d %b %y %H:%M:%S') 224 270 225 271 if opts.logfile: fh = logging.FileHandler(opts.logfile) … … 236 282 flog.addHandler(fh) 237 283 238 284 # Initialize the implementation 239 285 if opts.configfile != None: 240 286 try: … … 247 293 sys.exit("--configfile is required") 248 294 249 SOAP_port = (opts.host, opts.port)250 251 295 if impl.cert_file == None: 252 296 sys.exit("Must supply certificate file (probably in config)") 253 297 298 # Create the SSL credentials 254 299 ctx = None 255 300 while ctx == None: … … 261 306 raise 262 307 308 # Walk through the service descriptions and pack them into the services list. 309 # That list has the form (transport (host, port)). 263 310 if opts.services: 264 311 for s in opts.services: … … 275 322 services.append((opts.transport, (opts.host, opts.port))) 276 323 324 # Create the servers and put them into a list 277 325 for s in services: 278 326 if s[0] == "soap": … … 282 330 else: flog.warning("Unknown transport: %s" % s[0]) 283 331 332 # Make sure that there are no malformed servers in the list 333 services = [ s for s in services if s ] 334 335 # Catch signals 284 336 signal(SIGINT, shutdown) 285 337 signal(SIGTERM, shutdown) 286 338 339 # Start the servers 287 340 for s in servers: 288 if s: 289 t = Thread(target=run_server, args=(s,)) 290 t.start() 291 292 pause() 341 Thread(target=run_server, args=(s,)).start() 342 343 # Main thread waits for signals 344 while servers_active: 345 pause() 346 347 #Once shutdown starts wait for all the servers to terminate. 348 while True: 349 servers_lock.acquire() 350 if len(servers) == 0: 351 servers_lock.release() 352 flog.info("All servers exited. Terminating") 353 sys.exit(0) 354 servers_lock.release() 355 sleep(1) 356
Note: See TracChangeset
for help on using the changeset viewer.