aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/config-owner.cpp
blob: 0d6040b7035c46d89eb8f2d40c45e7a4bb028b27 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "config-owner.h"
#include <vespa/config/subscription/configsubscriber.hpp>
#include <cinttypes>

#include <vespa/log/log.h>
LOG_SETUP(".sentinel.config-owner");

namespace config::sentinel {

ConfigOwner::ConfigOwner() = default;
ConfigOwner::~ConfigOwner() = default;

void
ConfigOwner::subscribe(const std::string & configId, std::chrono::milliseconds timeout) {
    _sentinelHandle = _subscriber.subscribe<SentinelConfig>(configId, timeout);
}

void
ConfigOwner::doConfigure()
{
    _currConfig = _sentinelHandle->getConfig();
    LOG_ASSERT(_currConfig);
    _currGeneration = _subscriber.getGeneration();
    const SentinelConfig& config(*_currConfig);
    const auto & app = config.application;
    LOG(config, "Sentinel got %zd service elements [tenant(%s), application(%s), instance(%s)] for config generation %" PRId64,
        config.service.size(), app.tenant.c_str(), app.name.c_str(), app.instance.c_str(), _currGeneration);
}


// Return true if there was a config generation change
bool
ConfigOwner::checkForConfigUpdate() {
    if (_subscriber.nextGenerationNow()) {
        doConfigure();
        return true;
    }
    return false;
}

}