diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-03 19:49:12 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-12 02:55:45 +0100 |
commit | 925ec7eb8ee709c0d6722227104df6dc89f307f0 (patch) | |
tree | a65777dda4504597c2df50b77c13ee8814d869c7 /documentapi | |
parent | 5a9f64253ca71c0923304c033d121d5f27dd69ad (diff) |
Avoid pulling in the config library everywhere.
Diffstat (limited to 'documentapi')
6 files changed, 120 insertions, 89 deletions
diff --git a/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt b/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt index 9be6458174a..9663a186ce6 100644 --- a/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt +++ b/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt @@ -2,5 +2,6 @@ vespa_add_library(documentapi_documentapiloadtypes OBJECT SOURCES loadtype.cpp + loadtypeset.cpp DEPENDS ) diff --git a/documentapi/src/vespa/documentapi/loadtypes/loadtype.h b/documentapi/src/vespa/documentapi/loadtypes/loadtype.h index e7ecaa3e40c..15d9c6f528b 100644 --- a/documentapi/src/vespa/documentapi/loadtypes/loadtype.h +++ b/documentapi/src/vespa/documentapi/loadtypes/loadtype.h @@ -13,13 +13,15 @@ #pragma once -#include <vespa/metrics/loadmetric.h> +#include <vespa/metrics/loadtype.h> #include <vespa/vespalib/util/linkedptr.h> #include <vespa/documentapi/messagebus/priority.h> -namespace documentapi { +namespace vespalib { + class asciistream; +} -class LoadTypeSet; +namespace documentapi { // Inherit metrics loadtype so it is easy to use load types in load metrics. class LoadType : public metrics::LoadType { @@ -37,5 +39,4 @@ private: void print(vespalib::asciistream & os) const; }; -} // documentapi - +} diff --git a/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.cpp b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.cpp new file mode 100644 index 00000000000..d992110513f --- /dev/null +++ b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.cpp @@ -0,0 +1,79 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "loadtypeset.h" +#include <vespa/config-load-type.h> +#include <vespa/config/config.h> + +namespace documentapi { + +void LoadTypeSet::configure(const LoadTypeConfig& config) { + // This configure does not support live reconfig + if (!_types.empty()) return; + + addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); + + for (uint32_t i=0; i<config.type.size(); ++i) { + addLoadType(config.type[i].id, config.type[i].name, Priority::getPriority(config.type[i].priority)); + } +} + +LoadTypeSet::LoadTypeSet() +{ + addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); +} + +LoadTypeSet::LoadTypeSet(const config::ConfigUri & configUri) +{ + std::unique_ptr<LoadTypeConfig> cfg = config::ConfigGetter<LoadTypeConfig>::getConfig(configUri.getConfigId(), configUri.getContext()); + configure(*cfg); +} + +LoadTypeSet::LoadTypeSet(const LoadTypeConfig& config) +{ + configure(config); +} + +LoadTypeSet::~LoadTypeSet() { } + +void +LoadTypeSet::addLoadType(uint32_t id, const string& name, Priority::Value priority) { + auto it(_types.find(id)); + if (it != _types.end()) { + throw config::InvalidConfigException("Load type identifiers need to be non-overlapping, 1+ and without gaps.\n", VESPA_STRLOC); + } + if (_nameMap.find(name) != _nameMap.end()) { + throw config::InvalidConfigException("Load type names need to be unique and different from the reserved name \"default\".", VESPA_STRLOC); + } + _types[id] = std::make_unique<LoadType>(id, name, priority); + _nameMap[name] = _types[id].get(); +} + +metrics::LoadTypeSet +LoadTypeSet::getMetricLoadTypes() const { + metrics::LoadTypeSet result; + for (const auto & entry : _types) { + result.push_back(metrics::LoadType(entry.first, entry.second->getName())); + } + return result; +} + +const LoadType& +LoadTypeSet::operator[](uint32_t id) const { + auto it(_types.find(id)); + return (it == _types.end() ? LoadType::DEFAULT : *it->second); +} + +const LoadType& +LoadTypeSet::operator[](const string& name) const { + auto it(_nameMap.find(name)); + + return (it == _nameMap.end() ? LoadType::DEFAULT : *it->second); +} + +const LoadType* +LoadTypeSet::findLoadType(const string& name) const { + auto it(_nameMap.find(name)); + return (it == _nameMap.end() ? 0 : it->second); +} + +} diff --git a/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h index 19b8ce61dbf..cdfc20591f3 100644 --- a/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h +++ b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h @@ -10,106 +10,59 @@ */ #pragma once -#include <vespa/config/config.h> -#include <vespa/documentapi/loadtypes/loadtype.h> -#include <vespa/metrics/loadmetric.h> -#include <vector> -#include <vespa/config-load-type.h> +#include "loadtype.h" #include <vespa/vespalib/stllike/hash_map.h> +#include <map> + +namespace config { + class ConfigUri; +} + +namespace vespa { +namespace config { +namespace content { +namespace internal { + class InternalLoadTypeType; +} +} +} +} namespace documentapi { class LoadTypeSet { - vespalib::hash_map<uint32_t, LoadType::LP> _types; - // Want order to be ~ alphabetical. + using LoadTypeConfig = const vespa::config::content::internal::InternalLoadTypeType; + vespalib::hash_map<uint32_t, std::unique_ptr<LoadType>> _types; + // Want order to be ~ alphabetical. std::map<string, LoadType*> _nameMap; - // This object cannot be copied - LoadTypeSet(const LoadTypeSet&); - LoadTypeSet& operator=(const LoadTypeSet&); - - void configure(const vespa::config::content::LoadTypeConfig& config) { - // This configure does not support live reconfig - if (!_types.empty()) return; - - addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); - - for (uint32_t i=0; i<config.type.size(); ++i) { - addLoadType(config.type[i].id, config.type[i].name, Priority::getPriority(config.type[i].priority)); - } - } - + void configure(const LoadTypeConfig& config); public: typedef std::unique_ptr<LoadTypeSet> UP; typedef std::shared_ptr<LoadTypeSet> SP; - LoadTypeSet() { - addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); - } - - LoadTypeSet(const config::ConfigUri & configUri) { - std::unique_ptr<vespa::config::content::LoadTypeConfig> cfg = - config::ConfigGetter<vespa::config::content::LoadTypeConfig>::getConfig(configUri.getConfigId(), configUri.getContext()); - configure(*cfg); - } - - LoadTypeSet(const vespa::config::content::LoadTypeConfig& config) { - configure(config); - } - - void addLoadType(uint32_t id, const string& name, Priority::Value priority) { - vespalib::hash_map<uint32_t, LoadType::LP>::iterator it( - _types.find(id)); - if (it != _types.end()) { - throw config::InvalidConfigException( - "Load type identifiers need to be non-overlapping, 1+ " - "and without gaps.\n", VESPA_STRLOC); - } - if (_nameMap.find(name) != _nameMap.end()) { - throw config::InvalidConfigException( - "Load type names need to be unique and different from " - "the reserved name \"default\".", VESPA_STRLOC); - } - _types[id] = LoadType::LP(new LoadType(id, name, priority)); - _nameMap[name] = _types[id].get(); - } + LoadTypeSet(const LoadTypeSet&) = delete; + LoadTypeSet& operator=(const LoadTypeSet&) = delete; - const std::map<string, LoadType*>& getLoadTypes() const - { return _nameMap; } - metrics::LoadTypeSet getMetricLoadTypes() const { - metrics::LoadTypeSet result; - for (vespalib::hash_map<uint32_t, LoadType::LP>::const_iterator it - = _types.begin(); it != _types.end(); ++it) - { - result.push_back(metrics::LoadType( - it->first, it->second->getName())); - } - return result; - } + LoadTypeSet(); + LoadTypeSet(const config::ConfigUri & configUri); + LoadTypeSet(const LoadTypeConfig& config); + ~LoadTypeSet(); - const LoadType& operator[](uint32_t id) const { - vespalib::hash_map<uint32_t, LoadType::LP>::const_iterator it( - _types.find(id)); - return (it == _types.end() ? LoadType::DEFAULT : *it->second); - } - const LoadType& operator[](const string& name) const { - std::map<string, LoadType*>::const_iterator it( - _nameMap.find(name)); + void addLoadType(uint32_t id, const string& name, Priority::Value priority); - return (it == _nameMap.end() ? LoadType::DEFAULT : *it->second); - } + const std::map<string, LoadType*>& getLoadTypes() const { return _nameMap; } + metrics::LoadTypeSet getMetricLoadTypes() const; + const LoadType& operator[](uint32_t id) const; + const LoadType& operator[](const string& name) const; uint32_t size() const { return uint32_t(_types.size()); } /** * Attempts to locate a load type with given name. Returns 0 if none found. */ - const LoadType* findLoadType(const string& name) const { - std::map<string, LoadType*>::const_iterator it( - _nameMap.find(name)); - return (it == _nameMap.end() ? 0 : it->second); - } + const LoadType* findLoadType(const string& name) const; }; } // documentapi diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp index def23cd9d78..97e6a1cdc4a 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp @@ -1,11 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "andpolicy.h" #include <vespa/messagebus/error.h> #include <vespa/messagebus/errorcode.h> #include <vespa/messagebus/emptyreply.h> #include <vespa/messagebus/routing/routingcontext.h> #include <vespa/documentapi/messagebus/documentprotocol.h> -#include <vespa/documentapi/messagebus/policies/andpolicy.h> namespace documentapi { diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp index f30a6522337..7a467e43b3d 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp @@ -1,12 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/documentapi/messagebus/policies/loadbalancerpolicy.h> +#include "loadbalancerpolicy.h" #include <vespa/messagebus/emptyreply.h> #include <vespa/messagebus/errorcode.h> #include <vespa/messagebus/routing/ihopdirective.h> #include <vespa/messagebus/routing/routingcontext.h> #include <vespa/messagebus/routing/verbatimdirective.h> -#include <vespa/documentapi/messagebus/documentprotocol.h> #include <vespa/log/log.h> LOG_SETUP(".loadbalancerpolicy"); |