diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-06-11 13:24:18 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-06-11 13:24:51 +0000 |
commit | 714a924518bc5bef4f920899d3af96b56497eaf0 (patch) | |
tree | 6cea53d7a64aedeb4efda6680487dd5e9dc0f26c /configd/src/apps/sentinel/model-owner.cpp | |
parent | d32a461a49354922d81e55aabddbd13cc8902c30 (diff) |
keep naming convention
Diffstat (limited to 'configd/src/apps/sentinel/model-owner.cpp')
-rw-r--r-- | configd/src/apps/sentinel/model-owner.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/configd/src/apps/sentinel/model-owner.cpp b/configd/src/apps/sentinel/model-owner.cpp new file mode 100644 index 00000000000..601a57e16c9 --- /dev/null +++ b/configd/src/apps/sentinel/model-owner.cpp @@ -0,0 +1,59 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "model-owner.h" +#include <vespa/vespalib/util/exceptions.h> +#include <vespa/config/common/exceptions.h> +#include <string> +#include <chrono> +#include <vespa/log/log.h> + +LOG_SETUP(".sentinel.model-owner"); + +using namespace std::chrono_literals; + +namespace config::sentinel { + +std::optional<ModelConfig> ModelOwner::getModelConfig() { + checkForUpdates(); + if (_modelConfig) { + return ModelConfig(*_modelConfig); + } else { + return {}; + } +} + + +ModelOwner::ModelOwner(const std::string &configId) + : _configId(configId) +{} + +ModelOwner::~ModelOwner() = default; + +void +ModelOwner::start(std::chrono::milliseconds timeout) { + try { + _modelHandle =_subscriber.subscribe<ModelConfig>(_configId, timeout); + } catch (ConfigTimeoutException & ex) { + LOG(warning, "Timeout getting model config: %s [skipping connectivity checks]", ex.getMessage().c_str()); + } catch (InvalidConfigException& ex) { + LOG(warning, "Invalid model config: %s [skipping connectivity checks]", ex.getMessage().c_str()); + } catch (ConfigRuntimeException& ex) { + LOG(warning, "Runtime exception getting model config: %s [skipping connectivity checks]", ex.getMessage().c_str()); + } +} + +void +ModelOwner::checkForUpdates() { + if (! _modelHandle) { + start(5ms); + } + if (_modelHandle && _subscriber.nextGenerationNow()) { + if (auto newModel = _modelHandle->getConfig()) { + LOG(config, "Sentinel got model info [version %s] for %zd hosts [config generation %" PRId64 "]", + newModel->vespaVersion.c_str(), newModel->hosts.size(), _subscriber.getGeneration()); + _modelConfig = std::move(newModel); + } + } +} + +} |