Example #1
0
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,
    )
Example #2
0
async def group_nodes_by_scope(
        client: AdminAPI) -> Tuple[Tuple[NodeID, ...], ...]:
    (replication_info, nodes_config) = await asyncio.gather(
        admin_api.get_replication_info(client),
        admin_api.get_nodes_config(client))
    scope = replication_info.tolerable_failure_domains.domain
    ret = defaultdict(set)

    for node_config in nodes_config.nodes:
        # location_per_scope doesn't have NODE as a key, so we insert a
        # dummy value for the location, which is different for each node.
        # This is okay because we omit the name of the location from the
        # return value.
        if scope != LocationScope.NODE:
            location = node_config.location_per_scope[scope]
        else:
            location = node_config.node_index

        ret[location].add(
            NodeID(
                node_index=node_config.node_index,
                address=node_config.data_address,
                name=node_config.name,
            ))

    return tuple(
        sorted(
            (tuple(sorted(v, key=operator.attrgetter("node_index")))
             for k, v in ret.items()),
            key=lambda x: x[0].node_index,
        ))
Example #3
0
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
    }
Example #4
0
async def group_nodes_by_scope(
        client: AdminAPI) -> Tuple[Tuple[NodeID, ...], ...]:
    (replication_info, nodes_config) = await asyncio.gather(
        admin_api.get_replication_info(client),
        admin_api.get_nodes_config(client))
    scope = replication_info.tolerable_failure_domains.domain
    ret = defaultdict(set)

    for node_config in nodes_config.nodes:
        ret[node_config.location_per_scope[scope]].add(
            NodeID(
                node_index=node_config.node_index,
                address=node_config.data_address,
                name=node_config.name,
            ))

    return tuple(
        sorted(
            (tuple(sorted(v, key=operator.attrgetter("node_index")))
             for k, v in ret.items()),
            key=lambda x: x[0].node_index,
        ))