1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "report-connectivity.h"
#include "connectivity.h"
#include <vespa/log/log.h>
LOG_SETUP(".report-connectivity");
using cloud::config::ModelConfig;
namespace config::sentinel {
SinglePing::~SinglePing() = default;
void SinglePing::returnStatus(bool ok) {
status = ok ? "ok" : "ping failed";
LOG(debug, "peer %s [port %d] -> %s", peerName.c_str(), peerPort, status.c_str());
parent.requestDone();
}
void SinglePing::startCheck(FRT_Supervisor &orb) {
check = std::make_unique<PeerCheck>(*this, peerName, peerPort, orb, 2500);
}
ReportConnectivity::ReportConnectivity(FRT_RPCRequest *req, FRT_Supervisor &orb)
: _parentRequest(req),
_orb(orb),
_result(),
_configFetcher()
{
_configFetcher.subscribe<ModelConfig>("admin/model", this);
_configFetcher.start();
}
ReportConnectivity::~ReportConnectivity() = default;
void ReportConnectivity::requestDone() {
{
std::lock_guard<std::mutex> guard(_lock);
if (--_remaining != 0) {
return;
}
}
finish();
}
void ReportConnectivity::configure(std::unique_ptr<ModelConfig> config) {
_configFetcher.close();
auto map = Connectivity::specsFrom(*config);
for (const auto & [ hostname, port ] : map) {
_result.emplace_back(*this, hostname, port);
}
LOG(debug, "making connectivity report for %zd peers", _result.size());
_remaining = _result.size();
for (auto & peer : _result) {
peer.startCheck(_orb);
}
}
void ReportConnectivity::finish() const {
FRT_Values *dst = _parentRequest->GetReturn();
FRT_StringValue *pt_hn = dst->AddStringArray(_result.size());
FRT_StringValue *pt_ss = dst->AddStringArray(_result.size());
for (const auto & peer : _result) {
dst->SetString(pt_hn++, peer.peerName.c_str());
dst->SetString(pt_ss++, peer.status.c_str());
}
_parentRequest->Return();
}
}
|