MXS-2346 Exclude core parameters
Core parameters are not handled by the module but by the core and must hence be ignored when validating and configuring.
This commit is contained in:
@ -39,6 +39,11 @@ class Type;
|
|||||||
class Specification
|
class Specification
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum Kind
|
||||||
|
{
|
||||||
|
FILTER
|
||||||
|
};
|
||||||
|
|
||||||
using ParamsByName = std::map<std::string, Param*>;
|
using ParamsByName = std::map<std::string, Param*>;
|
||||||
using const_iterator = ParamsByName::const_iterator;
|
using const_iterator = ParamsByName::const_iterator;
|
||||||
using value_type = ParamsByName::value_type;
|
using value_type = ParamsByName::value_type;
|
||||||
@ -48,9 +53,14 @@ public:
|
|||||||
*
|
*
|
||||||
* @param zModule The the name of the module, e.g. "cachefilter".
|
* @param zModule The the name of the module, e.g. "cachefilter".
|
||||||
*/
|
*/
|
||||||
Specification(const char* zModule);
|
Specification(const char* zModule, Kind kind);
|
||||||
~Specification();
|
~Specification();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return What kind of specification.
|
||||||
|
*/
|
||||||
|
Kind kind() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The module name of this specification.
|
* @return The module name of this specification.
|
||||||
*/
|
*/
|
||||||
@ -133,6 +143,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_module;
|
std::string m_module;
|
||||||
|
Kind m_kind;
|
||||||
ParamsByName m_params;
|
ParamsByName m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,14 +16,60 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace config;
|
||||||
|
|
||||||
|
// TODO: Do not duplicate information from config.cc.
|
||||||
|
|
||||||
|
const char* pzCore_filter_params[] = {
|
||||||
|
CN_TYPE,
|
||||||
|
CN_MODULE,
|
||||||
|
nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_core_param(Specification::Kind kind, const std::string& param)
|
||||||
|
{
|
||||||
|
bool rv = false;
|
||||||
|
|
||||||
|
const char** pzCore_params = nullptr;
|
||||||
|
|
||||||
|
switch (kind)
|
||||||
|
{
|
||||||
|
case Specification::FILTER:
|
||||||
|
pzCore_params = pzCore_filter_params;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mxb_assert(!true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pzCore_params)
|
||||||
|
{
|
||||||
|
while (!rv && *pzCore_params)
|
||||||
|
{
|
||||||
|
const char* zCore_param = *pzCore_params;
|
||||||
|
|
||||||
|
rv = (param == zCore_param);
|
||||||
|
++pzCore_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace config
|
namespace config
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Specification
|
* class Specification
|
||||||
*/
|
*/
|
||||||
Specification::Specification(const char* zModule)
|
Specification::Specification(const char* zModule, Kind kind)
|
||||||
: m_module(zModule)
|
: m_module(zModule)
|
||||||
|
, m_kind(kind)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +114,17 @@ bool Specification::validate(const MXS_CONFIG_PARAMETER& params) const
|
|||||||
|
|
||||||
if (pParam)
|
if (pParam)
|
||||||
{
|
{
|
||||||
|
bool param_valid = true;
|
||||||
string message;
|
string message;
|
||||||
|
|
||||||
if (!pParam->validate(value.c_str(), &message))
|
if (!pParam->validate(value.c_str(), &message))
|
||||||
{
|
{
|
||||||
valid = false;
|
param_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.empty())
|
if (!message.empty())
|
||||||
{
|
{
|
||||||
if (valid)
|
if (param_valid)
|
||||||
{
|
{
|
||||||
MXS_WARNING("%s: %s", name.c_str(), message.c_str());
|
MXS_WARNING("%s: %s", name.c_str(), message.c_str());
|
||||||
}
|
}
|
||||||
@ -89,7 +136,7 @@ bool Specification::validate(const MXS_CONFIG_PARAMETER& params) const
|
|||||||
|
|
||||||
provided.insert(name);
|
provided.insert(name);
|
||||||
}
|
}
|
||||||
else
|
else if (!is_core_param(m_kind, name))
|
||||||
{
|
{
|
||||||
MXS_WARNING("%s: The parameter '%s' is unrecognized.", m_module.c_str(), name.c_str());
|
MXS_WARNING("%s: The parameter '%s' is unrecognized.", m_module.c_str(), name.c_str());
|
||||||
valid = false;
|
valid = false;
|
||||||
@ -121,6 +168,9 @@ bool Specification::configure(Configuration& configuration, const MXS_CONFIG_PAR
|
|||||||
for (const auto& param : params)
|
for (const auto& param : params)
|
||||||
{
|
{
|
||||||
const auto& name = param.first;
|
const auto& name = param.first;
|
||||||
|
|
||||||
|
if (!is_core_param(m_kind, name))
|
||||||
|
{
|
||||||
const auto& value = param.second;
|
const auto& value = param.second;
|
||||||
|
|
||||||
const Param* pParam = find_param(name.c_str());
|
const Param* pParam = find_param(name.c_str());
|
||||||
@ -143,6 +193,7 @@ bool Specification::configure(Configuration& configuration, const MXS_CONFIG_PAR
|
|||||||
configured = false;
|
configured = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (configured)
|
if (configured)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ inline ostream& operator << (ostream& out, const std::chrono::milliseconds& x)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
config::Specification specification("test_module");
|
config::Specification specification("test_module", config::Specification::FILTER);
|
||||||
|
|
||||||
config::ParamBool
|
config::ParamBool
|
||||||
param_bool(&specification,
|
param_bool(&specification,
|
||||||
|
2
server/modules/filter/cache/cacheconfig.cc
vendored
2
server/modules/filter/cache/cacheconfig.cc
vendored
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#define CACHE_ZDEFAULT_STORAGE "\"storage_inmemory\""
|
#define CACHE_ZDEFAULT_STORAGE "\"storage_inmemory\""
|
||||||
|
|
||||||
config::Specification CacheConfig::s_specification(MXS_MODULE_NAME);
|
config::Specification CacheConfig::s_specification(MXS_MODULE_NAME, config::Specification::FILTER);
|
||||||
|
|
||||||
config::ParamString CacheConfig::s_storage(
|
config::ParamString CacheConfig::s_storage(
|
||||||
&s_specification,
|
&s_specification,
|
||||||
|
Reference in New Issue
Block a user