aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/connectivity.h
blob: 6fd2d3b96f6838d71acb747e7aa1e2f533a51b98 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "rpcserver.h"
#include "cc-result.h"
#include <vespa/config-sentinel.h>
#include <vespa/config-model.h>
#include <string>
#include <map>

using cloud::config::SentinelConfig;
using cloud::config::ModelConfig;

namespace config::sentinel {

/**
 * Utility class for running connectivity check.
 **/
class Connectivity {
public:
    using SpecMap = std::map<std::string, int>;
    using HostAndPort = SpecMap::value_type;

    Connectivity();
    ~Connectivity();
    void configure(const SentinelConfig::Connectivity &config,
                   const ModelConfig &model);
    bool checkConnectivity(RpcServer &rpcServer);
    static SpecMap specsFrom(const ModelConfig &model);
private:
    class Accumulator {
    private:
        size_t _numOk = 0;
        size_t _numBad = 0;
        size_t _numHandled = 0;
    public:
        void handleResult(CcResult value);
        bool enoughOk(const SentinelConfig::Connectivity &config) const;
    };
    SentinelConfig::Connectivity _config;
    SpecMap _checkSpecs;
    std::map<std::string, std::string> _detailsPerHost;
};

}