TGridClientNodeList GridClientComputeProjectionImpl::refreshTopology(GridTopologyRequestCommand& cmd) { class RefreshTopologyProjectionClosure: public ClientMessageProjectionClosure { public: RefreshTopologyProjectionClosure(std::string clientId, GridTopologyRequestCommand& topReqCmd, GridClientMessageTopologyResult& rslt) : ClientMessageProjectionClosure(clientId), cmd(topReqCmd), topRslt(rslt) { } virtual void apply(TGridClientNodePtr node, GridSocketAddress connParams, GridClientCommandExecutor& cmdExecutor) { fillRequestHeader(cmd, node); cmdExecutor.executeTopologyCmd(connParams, cmd, topRslt); } private: GridTopologyRequestCommand& cmd; GridClientMessageTopologyResult& topRslt; }; GridClientMessageTopologyResult topRslt; RefreshTopologyProjectionClosure topClosure(clientUniqueId(), cmd, topRslt); TGridClientNodeList nodes; withReconnectHandling(topClosure); TNodesList nodesList = topRslt.getNodes(); for (auto iter = nodesList.begin(); iter != nodesList.end(); ++iter) nodes.push_back(TGridClientNodePtr(new GridClientNode(*iter))); return nodes; }
TNodesSet nodesListToSet(const TNodesList& list) { TNodesSet ret; for (auto i = list.begin(); i != list.end(); i++) ret.insert(*i); return ret; }
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."); }