Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(716)

Side by Side Diff: testing/legion/discovery_server.py

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/legion/common_lib.py ('k') | testing/legion/examples/hello_world/client_test.isolate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """The registration server used to register tasks. 5 """The discovery server used to register clients.
6 6
7 The registration server is started by the test controller and allows the tasks 7 The discovery server is started by the host controller and allows the clients
8 to register themselves when they start. Authentication of the tasks controllers 8 to register themselves when they start. Authentication of the client controllers
9 is based on an OTP passed to the run_task binary on startup. 9 is based on an OTP passed to the client controller binary on startup.
10 """ 10 """
11 11
12 import logging 12 import logging
13 import threading 13 import threading
14 import xmlrpclib 14 import xmlrpclib
15 import SimpleXMLRPCServer 15 import SimpleXMLRPCServer
16 16
17 #pylint: disable=relative-import 17 #pylint: disable=relative-import
18 import common_lib 18 import common_lib
19 19
20 20
21 class TaskRegistrationServer(object): 21 class DiscoveryServer(object):
22 """Discovery server run on the host.""" 22 """Discovery server run on the host."""
23 23
24 def __init__(self): 24 def __init__(self):
25 self._expected_tasks = {} 25 self._expected_clients = {}
26 self._rpc_server = None 26 self._rpc_server = None
27 self._thread = None 27 self._thread = None
28 28
29 def _RegisterTaskRPC(self, otp, ip): 29 def _RegisterClientRPC(self, otp, ip):
30 """The RPC used by a task to register with the registration server.""" 30 """The RPC used by a client to register with the discovery server."""
31 assert otp in self._expected_tasks 31 assert otp in self._expected_clients
32 cb = self._expected_tasks.pop(otp) 32 cb = self._expected_clients.pop(otp)
33 cb(ip) 33 cb(ip)
34 34
35 def RegisterTaskCallback(self, otp, callback): 35 def RegisterClientCallback(self, otp, callback):
36 """Registers a callback associated with an OTP.""" 36 """Registers a callback associated with an OTP."""
37 assert callable(callback) 37 assert callable(callback)
38 self._expected_tasks[otp] = callback 38 self._expected_clients[otp] = callback
39 39
40 def Start(self): 40 def Start(self):
41 """Starts the registration server.""" 41 """Starts the discovery server."""
42 logging.debug('Starting task registration server') 42 logging.debug('Starting discovery server')
43 self._rpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( 43 self._rpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer(
44 (common_lib.SERVER_ADDRESS, common_lib.SERVER_PORT), 44 (common_lib.SERVER_ADDRESS, common_lib.SERVER_PORT),
45 allow_none=True, logRequests=False) 45 allow_none=True, logRequests=False)
46 self._rpc_server.register_function( 46 self._rpc_server.register_function(
47 self._RegisterTaskRPC, 'RegisterTask') 47 self._RegisterClientRPC, 'RegisterClient')
48 self._thread = threading.Thread(target=self._rpc_server.serve_forever) 48 self._thread = threading.Thread(target=self._rpc_server.serve_forever)
49 self._thread.start() 49 self._thread.start()
50 50
51 def Shutdown(self): 51 def Shutdown(self):
52 """Shuts the discovery server down.""" 52 """Shuts the discovery server down."""
53 if self._thread and self._thread.is_alive(): 53 if self._thread and self._thread.is_alive():
54 logging.debug('Shutting down task registration server') 54 logging.debug('Shutting down discovery server')
55 self._rpc_server.shutdown() 55 self._rpc_server.shutdown()
OLDNEW
« no previous file with comments | « testing/legion/common_lib.py ('k') | testing/legion/examples/hello_world/client_test.isolate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698