TNodesSet nodesListToSet(const TNodesList& list) {
    TNodesSet ret;

    for (auto i = list.begin(); i != list.end(); i++)
        ret.insert(*i);

    return ret;
}
TNodesSet buildNodeSet(const char* ids[], int cnt) {
    TNodesSet nodes;

    for (int i = 0; i < cnt; ++i) {
        GridClientNode node;
        GridClientNodeMarshallerHelper helper(node);

        helper.setNodeId(GridClientUuid(nodeUuids[i]));

        nodes.insert(node);
    }

    return nodes;
}
示例#3
0
void GridClientImpl::refreshTopology() {
    const GridClientConfiguration& clientCfg = sharedData->clientConfiguration();
    TGridClientSocketAddressList addrs = clientCfg.routers().size() > 0
            ? clientCfg.routers()
            : clientCfg.servers();

    if (addrs.empty()) {
        GG_LOG_DEBUG0("Skipping topology refresh (address list is empty).");

        return;
    }

    TGridClientCommandExecutorPtr exec = sharedData->executor();
    bool updated = false;

    GG_LOG_DEBUG0("Started refreshing the topology.");

    GridClientException last;

    for (auto it = addrs.begin(); !updated && it != addrs.end(); ++it) {
        try {
            GG_LOG_DEBUG("Refresh address: %s", it->host().c_str());

            GridTopologyRequestCommand topRqst;
            GridClientMessageTopologyResult rslt;
            TNodesSet nodes;

            // Fills the command by the default value.
            topRqst.setIncludeAttributes(false);
            topRqst.setIncludeMetrics(false);
            topRqst.setClientId(id().uuid());

            topRqst.setRequestId(topRqst.generateNewId());

            // Executes the topology command.
            exec->executeTopologyCmd(*it, topRqst, rslt);

            TNodesList nbns = rslt.getNodes();

            // Extract the actual list of nodes.
            nodes.insert(nbns.begin(), nbns.end());

            TNodesSet prevNodes = sharedData->topology()->nodes();

            // Update the topology.
            sharedData->topology()->update(nodes);

            fireTopologyEvents(nodes, prevNodes);

            GG_LOG_DEBUG("Topology size: %d", nodes.size());

            updated = true;
        }
        catch (GridClientException& e) {
        	last = e;
        }
    }

    if (!updated)
        GG_LOG_ERROR("Error refreshing the topology: %s", last.what());

    GG_LOG_DEBUG0("Finished refreshing the topology.");
}