2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
10 from . import clientactor
15 class ArvadosNodeListMonitorActor(clientactor.RemotePollLoopActor):
16 """Actor to poll the Arvados node list.
18 This actor regularly polls the list of Arvados node records, and
19 sends it to subscribers.
22 def is_common_error(self, exception):
23 return isinstance(exception, config.ARVADOS_ERRORS)
25 def _item_key(self, node):
28 def _send_request(self):
29 nodelist = arvados.util.list_all(self._client.nodes().list)
31 # node hostname, state
32 sinfo_out = subprocess.check_output(["sinfo", "--noheader", "--format=%n %t"])
34 for out in sinfo_out.splitlines():
36 nodename, state = out.split(" ", 2)
37 if state in ('alloc', 'alloc*',
41 nodestates[nodename] = 'busy'
43 nodestates[nodename] = 'idle'
45 nodestates[nodename] = 'down'
50 if n["slot_number"] and n["hostname"] and n["hostname"] in nodestates:
51 n["crunch_worker_state"] = nodestates[n["hostname"]]
53 n["crunch_worker_state"] = 'down'
57 class CloudNodeListMonitorActor(clientactor.RemotePollLoopActor):
58 """Actor to poll the cloud node list.
60 This actor regularly polls the cloud to get a list of running compute
61 nodes, and sends it to subscribers.
64 def __init__(self, client, timer_actor, server_calc, *args, **kwargs):
65 super(CloudNodeListMonitorActor, self).__init__(
66 client, timer_actor, *args, **kwargs)
67 self._calculator = server_calc
69 def is_common_error(self, exception):
70 return isinstance(exception, config.CLOUD_ERRORS)
72 def _item_key(self, node):
75 def _send_request(self):
76 nodes = self._client.list_nodes()
78 # Replace with libcloud NodeSize object with compatible
79 # CloudSizeWrapper object which merges the size info reported from
80 # the cloud with size information from the configuration file.
81 n.size = self._calculator.find_size(n.size.id)