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; }
void GridClientProtobufMarshaller::unwrap(const ObjectWrapper& objWrapper, GridClientMessageTopologyResult& topRslt) { ProtoResponse resp; unwrapResponse(objWrapper, resp); fillResponseHeader(resp, topRslt); std::vector<GridClientNode> nodes; if (resp.has_resultbean()) { if (resp.resultbean().type() == NODE_BEAN) { GridClientNode nodeBean; ::unwrap(resp.resultbean(), nodeBean); nodes.push_back(nodeBean); } else { assert(resp.resultbean().type() == COLLECTION); std::string binary = resp.resultbean().binary(); ::Collection coll; unmarshalMsg((int8_t*) binary.c_str(), binary.size(), coll); unwrapCollection(coll.item(), nodes); assert(nodes.size() == (size_t) coll.item().size()); } } topRslt.setNodes(nodes); }
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."); }