summaryrefslogtreecommitdiffstats
path: root/configutil/src/lib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2016-07-12 21:16:06 +0200
committerVegard Sjonfjell <vegardsjo@gmail.com>2016-07-12 21:16:06 +0200
commitfc7a2cdb64ca870cf00fa2d7dc723d91f56e5561 (patch)
tree3924b7e47689cf9c7936d0f3e84b20ca4517955a /configutil/src/lib
parent99de121a82da5b20ef5b8324706f272973879b9b (diff)
Add host filtering option to config status util (#350)
* Let vespa-config-status take in an optional host filter set If the argument is not specified, services on all hosts in the model will be queried as before. Iff the filter argument is specified, only services on the hosts explicitly given will be queried. * Make variable name easier on the eyes
Diffstat (limited to 'configutil/src/lib')
-rw-r--r--configutil/src/lib/configstatus.cpp6
-rw-r--r--configutil/src/lib/configstatus.h9
-rw-r--r--configutil/src/lib/hostfilter.h49
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());
+ }
+};