aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/outward-check.h
blob: 8e4858e972de37ec5e7211f65eb88570d5a8fb8a (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
47
48
49
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "cc-result.h"
#include <string>
#include <vespa/vespalib/util/count_down_latch.h>
#include <vespa/fnet/frt/supervisor.h>
#include <vespa/fnet/frt/invoker.h>
#include <vespa/fnet/frt/rpcrequest.h>
#include <vespa/fnet/frt/supervisor.h>
#include <vespa/fnet/frt/target.h>

namespace config::sentinel {

struct OutwardCheckContext {
    vespalib::CountDownLatch latch;
    std::string targetHostname;
    int targetPortnum;
    FRT_Supervisor &orb;
    OutwardCheckContext(size_t count,
                        const std::string &hostname,
                        int portnumber,
                        FRT_Supervisor &supervisor)
      : latch(count),
        targetHostname(hostname),
        targetPortnum(portnumber),
        orb(supervisor)
    {}
    ~OutwardCheckContext();
};

class OutwardCheck  : public FRT_IRequestWait {
private:
    CcResult _result = CcResult::UNKNOWN;
    FRT_Target *_target = nullptr;
    FRT_RPCRequest *_req = nullptr;
    std::string _spec;
    OutwardCheckContext &_context;
public:
    OutwardCheck(const std::string &spec, OutwardCheckContext &context, int ping_timeout);
    virtual ~OutwardCheck();
    void RequestDone(FRT_RPCRequest *req) override;
    bool ok() const { return _result == CcResult::ALL_OK; }
    CcResult result() const { return _result; }
    void classifyResult(CcResult value);
};

}