1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 from __future__ import absolute_import, print_function
6 from future import standard_library
14 _logger = logging.getLogger('status.Handler')
17 class Server(socketserver.ThreadingMixIn, http.server.HTTPServer, object):
18 def __init__(self, config):
19 port = config.getint('Manage', 'port')
20 self.enabled = port >= 0
22 _logger.warning("Management server disabled. "+
23 "Use [Manage] config section to enable.")
26 self._tracker = tracker
27 super(Server, self).__init__(
28 (config.get('Manage', 'address'), port), Handler)
29 self._thread = threading.Thread(target=self.serve_forever)
30 self._thread.daemon = True
37 class Handler(http.server.BaseHTTPRequestHandler, object):
39 if self.path == '/status.json':
40 self.send_response(200)
41 self.send_header('Content-type', 'application/json')
43 self.wfile.write(tracker.get_json())
45 self.send_response(404)
47 def log_message(self, fmt, *args, **kwargs):
48 _logger.info(fmt, *args, **kwargs)
51 class Tracker(object):
53 self._mtx = threading.Lock()
58 return json.dumps(self._latest)
62 return self._latest.keys()
64 def update(self, updates):
66 self._latest.update(updates)