Skip to content
Snippets Groups Projects
Commit 97a5ee90 authored by Martin Blanchard's avatar Martin Blanchard
Browse files

bots/service.py: Calculate bot counts

parent 53615a07
No related branches found
No related tags found
Loading
......@@ -36,16 +36,21 @@ class BotsService(bots_pb2_grpc.BotsServicer):
def __init__(self, server, monitor=True):
self.__logger = logging.getLogger(__name__)
self.__bots_by_status = {}
self.__bots_by_instance = {}
self.__bots = {}
self.__bots_by_status = None
self.__bots_by_instance = None
self.__bots = None
self._instances = {}
self._is_monitored = True
bots_pb2_grpc.add_BotsServicer_to_server(self, server)
self._is_monitored = monitor
if self._is_monitored:
self.__bots_by_status = {}
self.__bots_by_instance = {}
self.__bots = {}
self.__bots_by_status[BotStatus.OK] = set()
self.__bots_by_status[BotStatus.UNHEALTHY] = set()
self.__bots_by_status[BotStatus.HOST_REBOOTING] = set()
......
......@@ -157,6 +157,21 @@ class ExecutionService(remote_execution_pb2_grpc.ExecutionServicer):
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
yield operations_pb2.Operation()
# --- Public API: Monitoring ---
@property
def is_monitored(self):
return self._is_monitored
def query_n_clients(self):
return len(self.__peers)
def query_n_clients_for_instance(self, instance_name):
try:
return len(self.__peers_by_instance[instance_name])
except KeyError:
return 0
# --- Private API ---
def _rpc_termination_callback(self, peer, instance_name, job_name, message_queue):
......@@ -177,18 +192,3 @@ class ExecutionService(remote_execution_pb2_grpc.ExecutionServicer):
except KeyError:
raise InvalidArgumentError("Instance doesn't exist on server: [{}]".format(name))
# --- Public API: Monitoring ---
@property
def is_monitored(self):
return self._is_monitored
def query_n_clients(self):
return len(self.__peers)
def query_n_clients_for_instance(self, instance_name):
try:
return len(self.__peers_by_instance[instance_name])
except KeyError:
return 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment