async def get_cluster_view(client: AdminAPI) -> ClusterView: """ Returns ClusterView object """ (nodes_config_resp, nodes_state_resp, maintenances_resp) = await asyncio.gather( admin_api.get_nodes_config(client), admin_api.get_nodes_state(client), admin_api.get_maintenances(client), return_exceptions=True, ) if isinstance(maintenances_resp, NotSupported): # This exception can be raised from cluster which does not support # MaintenanceManager yet maintenances = [] elif isinstance(maintenances_resp, Exception): raise maintenances_resp else: # pyre-fixme[16]: `BaseException` has no attribute `maintenances`. maintenances = maintenances_resp.maintenances if isinstance(nodes_config_resp, Exception): raise nodes_config_resp if isinstance(nodes_state_resp, Exception): raise nodes_state_resp return ClusterView( # pyre-fixme[16]: `BaseException` has no attribute `nodes`. nodes_config=nodes_config_resp.nodes, # pyre-fixme[16]: `BaseException` has no attribute `states`. nodes_state=nodes_state_resp.states, maintenances=maintenances, )
async def get_nodes_state(client: AdminAPI) -> Dict[Node, NodeState]: """ Returns dict from Node to NodeState """ nodes_config_resp: NodesConfigResponse nodes_state_resp: NodesStateResponse (nodes_config_resp, nodes_state_resp) = await asyncio.gather( admin_api.get_nodes_config(client), admin_api.get_nodes_state(client)) node_index_to_node: Dict[int, Node] = { nc.node_index: _get_node_by_node_config(nc) for nc in nodes_config_resp.nodes } return { node_index_to_node[ns.node_index]: ns for ns in nodes_state_resp.states }