aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/model-owner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'configd/src/apps/sentinel/model-owner.cpp')
-rw-r--r--configd/src/apps/sentinel/model-owner.cpp59
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);
+ }
+ }
+}
+
+}