in nodemanager/core/NamingClient.cpp [66:113]
void NamingClient::RequestForServiceLocation(const std::string& serviceName, std::string& serviceLocation, pplx::cancellation_token token)
{
int selected = rand() % this->namingServicesUri.size();
std::string uri;
int interval = this->intervalSeconds;
while (!token.is_canceled())
{
try
{
selected %= this->namingServicesUri.size();
uri = this->namingServicesUri[selected++] + serviceName;
Logger::Info("ResolveServiceLocation> Fetching from {0}", uri);
auto client = HttpHelper::GetHttpClient(uri);
auto request = HttpHelper::GetHttpRequest(methods::GET);
http_response response = client->request(*request, token).get();
if (response.status_code() == http::status_codes::OK)
{
serviceLocation = JsonHelper<std::string>::FromJson(response.extract_json().get());
Logger::Debug("ResolveServiceLocation> Fetched from {0} response code {1}, location {2}", uri, response.status_code(), serviceLocation);
return;
}
else
{
Logger::Debug("ResolveServiceLocation> Fetched from {0} response code {1}", uri, response.status_code());
}
}
catch (const http_exception& httpEx)
{
Logger::Warn("ResolveServiceLocation> HttpException occurred when fetching from {0}, ex {1}", uri, httpEx.what());
}
catch (const std::exception& ex)
{
Logger::Error("ResolveServiceLocation> Exception occurred when fetching from {0}, ex {1}", uri, ex.what());
}
catch (...)
{
Logger::Error("ResolveServiceLocation> Unknown error occurred when fetching from {0}", uri);
}
if (token.is_canceled()) break;
sleep(interval);
interval *= 2;
if (interval > 60) interval = 60;
}
}