int DiscoveryClient::DoCancel() const { pthread_once(&s_init_channel_once, InitChannel); Controller cntl; cntl.http_request().set_method(HTTP_METHOD_POST); cntl.http_request().uri() = "/discovery/cancel"; butil::IOBufBuilder os; os << "appid=" << _appid << "&hostname=" << _hostname << "&env=" << _env << "®ion=" << _region << "&zone=" << _zone; os.move_to(cntl.request_attachment()); s_discovery_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); if (cntl.Failed()) { LOG(ERROR) << "Fail to post /discovery/cancel: " << cntl.ErrorText(); return -1; } std::string error_text; if (ParseCommonResult(cntl.response_attachment(), &error_text) != 0) { LOG(ERROR) << "Fail to cancel " << _hostname << " in " << _appid << ": " << error_text; return -1; } return 0; }
int DiscoveryClient::DoRegister() const { Controller cntl; cntl.http_request().set_method(HTTP_METHOD_POST); cntl.http_request().uri() = "/discovery/register"; cntl.http_request().set_content_type("application/x-www-form-urlencoded"); butil::IOBufBuilder os; os << "appid=" << _appid << "&hostname=" << _hostname << "&addrs=" << _addrs << "&env=" << _env << "&zone=" << _zone << "®ion=" << _region << "&status=" << _status << "&version=" << _version << "&metadata=" << _metadata; os.move_to(cntl.request_attachment()); s_discovery_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); if (cntl.Failed()) { LOG(ERROR) << "Fail to register " << _appid << ": " << cntl.ErrorText(); return -1; } std::string error_text; if (ParseCommonResult(cntl.response_attachment(), &error_text) != 0) { LOG(ERROR) << "Fail to register " << _hostname << " to " << _appid << ": " << error_text; return -1; } return 0; }
int DiscoveryClient::Fetchs(const DiscoveryFetchsParam& req, std::vector<ServerNode>* servers) const { if (!req.IsValid()) { return false; } pthread_once(&s_init_channel_once, InitChannel); servers->clear(); Controller cntl; cntl.http_request().uri() = butil::string_printf( "/discovery/fetchs?appid=%s&env=%s&status=%s", req.appid.c_str(), req.env.c_str(), req.status.c_str()); s_discovery_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); if (cntl.Failed()) { LOG(ERROR) << "Fail to get /discovery/fetchs: " << cntl.ErrorText(); return -1; } return ParseFetchsResult(cntl.response_attachment(), req.appid.c_str(), servers); }