diff options
Diffstat (limited to 'configutil/src/lib')
-rw-r--r-- | configutil/src/lib/configstatus.cpp | 6 | ||||
-rw-r--r-- | configutil/src/lib/configstatus.h | 9 | ||||
-rw-r--r-- | configutil/src/lib/hostfilter.h | 49 |
3 files changed, 62 insertions, 2 deletions
diff --git a/configutil/src/lib/configstatus.cpp b/configutil/src/lib/configstatus.cpp index f889c436a97..76a1faec625 100644 --- a/configutil/src/lib/configstatus.cpp +++ b/configutil/src/lib/configstatus.cpp @@ -139,10 +139,14 @@ ConfigStatus::action() for (size_t i = 0; i < _cfg->hosts.size(); i++) { const cloud::config::ModelConfig::Hosts &hconf = _cfg->hosts[i]; + // TODO PERF: don't fetch entire model when we're only looking for + // a subset of hosts. + if (!_flags.host_filter.includes(hconf.name)) { + continue; + } for (size_t j = 0; j < hconf.services.size(); j++) { const cloud::config::ModelConfig::Hosts::Services &svc = hconf.services[j]; - if (svc.type == "configserver") { continue; } diff --git a/configutil/src/lib/configstatus.h b/configutil/src/lib/configstatus.h index 41e3d2fe782..0b168605d49 100644 --- a/configutil/src/lib/configstatus.h +++ b/configutil/src/lib/configstatus.h @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include "hostfilter.h" #include <vespa/config-model.h> #include <vespa/vespalib/stllike/string.h> #include <vespa/config/config.h> @@ -9,9 +10,15 @@ class ConfigStatus { public: struct Flags { + HostFilter host_filter; bool verbose; Flags() - : verbose(false) + : host_filter(), verbose(false) + {} + + explicit Flags(const HostFilter& filter) + : host_filter(filter), + verbose(false) {} }; diff --git a/configutil/src/lib/hostfilter.h b/configutil/src/lib/hostfilter.h new file mode 100644 index 00000000000..8c255c930cc --- /dev/null +++ b/configutil/src/lib/hostfilter.h @@ -0,0 +1,49 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <unordered_set> +#include <string> + +/** + * Simple host filter which in its default empty state implicitly includes all + * hosts, or only an explicit subset iff at least one host has been provided + * to the filter as part of construction. + */ +class HostFilter { +public: + using HostSet = std::unordered_set<std::string>; +private: + HostSet _hosts; +public: + /** + * Empty host filter; all hosts are implicitly included. + */ + HostFilter() : _hosts() {} + + /** + * Explicitly given host set; only the hosts whose name exactly match + * one of the provided names will pass the includes(name) check. + */ + explicit HostFilter(const std::unordered_set<std::string>& hosts) + : _hosts(hosts) + { + } + + explicit HostFilter(std::unordered_set<std::string>&& hosts) + : _hosts(std::move(hosts)) + { + } + + HostFilter(HostFilter&&) = default; + HostFilter& operator=(HostFilter&&) = default; + + HostFilter(const HostFilter&) = default; + HostFilter& operator=(const HostFilter&) = default; + + bool includes(const std::string& candidate) const { + if (_hosts.empty()) { + return true; + } + return (_hosts.find(candidate) != _hosts.end()); + } +}; |