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
|
// 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/config/common/exceptions.h>
#include <vespa/log/log.h>
#include <chrono>
LOG_SETUP(".sentinel.report-connectivity");
using cloud::config::ModelConfig;
using namespace std::chrono_literals;
namespace config::sentinel {
ReportConnectivity::ReportConnectivity(FRT_RPCRequest *req, int timeout_ms, FRT_Supervisor &orb, ModelOwner &modelOwner)
: _parentRequest(req),
_checks()
{
auto cfg = modelOwner.getModelConfig();
if (cfg.has_value()) {
auto map = Connectivity::specsFrom(cfg.value());
LOG(debug, "making connectivity report for %zd peers", map.size());
_remaining = map.size();
for (const auto & [ hostname, port ] : map) {
_checks.emplace_back(std::make_unique<PeerCheck>(*this, hostname, port, orb, timeout_ms));
timeout_ms += 20;
}
} else {
_parentRequest->SetError(FRTE_RPC_METHOD_FAILED, "failed getting model config");
_parentRequest->Return();
}
}
ReportConnectivity::~ReportConnectivity() = default;
void ReportConnectivity::returnStatus(bool) {
if (--_remaining == 0) {
finish();
}
}
void ReportConnectivity::finish() const {
FRT_Values *dst = _parentRequest->GetReturn();
FRT_StringValue *pt_hn = dst->AddStringArray(_checks.size());
FRT_StringValue *pt_ss = dst->AddStringArray(_checks.size());
for (const auto & peer : _checks) {
dst->SetString(pt_hn++, peer->getHostname().c_str());
dst->SetString(pt_ss++, peer->okStatus() ? "ok" : "ping failed");
}
_parentRequest->Return();
}
}
|