MXS-2556 Make config::Configuration aware of its object
The name of the object (i.e. the section name from the configuration file), is now stored in the configuration object for that object. That way, more contextual and hence morfe user friendly errors and warnings can be generated.
This commit is contained in:
parent
df5377f135
commit
04fdaf1fdb
@ -815,9 +815,15 @@ public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name The object (i.e. section name) of this configuration.
|
||||
* @param pSpecification The specification this instance is a configuration of.
|
||||
*/
|
||||
Configuration(const Specification* pSpecification);
|
||||
Configuration(const std::string& name, const Specification* pSpecification);
|
||||
|
||||
/**
|
||||
* @return The The object (i.e. section name) of this configuration.
|
||||
*/
|
||||
const std::string& name() const;
|
||||
|
||||
/**
|
||||
* @return The specification of this configuration.
|
||||
@ -880,6 +886,7 @@ private:
|
||||
void remove(Type* pValue);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
const Specification& m_specification;
|
||||
ValuesByName m_values;
|
||||
};
|
||||
|
@ -385,11 +385,17 @@ void Param::populate(MXS_MODULE_PARAM& param) const
|
||||
/**
|
||||
* class Configuration
|
||||
*/
|
||||
Configuration::Configuration(const config::Specification* pSpecification)
|
||||
: m_specification(*pSpecification)
|
||||
Configuration::Configuration(const std::string& name, const config::Specification* pSpecification)
|
||||
: m_name(name)
|
||||
, m_specification(*pSpecification)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& Configuration::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const config::Specification& Configuration::specification() const
|
||||
{
|
||||
return m_specification;
|
||||
|
@ -338,7 +338,7 @@ int main()
|
||||
|
||||
specification.document(cout);
|
||||
|
||||
config::Configuration configuration(&specification);
|
||||
config::Configuration configuration("test", &specification);
|
||||
|
||||
int nErrors = 0;
|
||||
|
||||
|
4
server/modules/filter/cache/cacheconfig.cc
vendored
4
server/modules/filter/cache/cacheconfig.cc
vendored
@ -146,8 +146,8 @@ config::ParamBool CacheConfig::s_enabled(
|
||||
true
|
||||
);
|
||||
|
||||
CacheConfig::CacheConfig()
|
||||
: config::Configuration(&s_specification)
|
||||
CacheConfig::CacheConfig(const std::string& name)
|
||||
: config::Configuration(name, &s_specification)
|
||||
, storage(this, &s_storage)
|
||||
, storage_options(this, &s_storage_options)
|
||||
, hard_ttl(this, &s_hard_ttl)
|
||||
|
2
server/modules/filter/cache/cacheconfig.hh
vendored
2
server/modules/filter/cache/cacheconfig.hh
vendored
@ -38,7 +38,7 @@ const cache_thread_model CACHE_DEFAULT_THREAD_MODEL = CACHE_THREAD_MODEL_ST;
|
||||
class CacheConfig : public config::Configuration
|
||||
{
|
||||
public:
|
||||
CacheConfig();
|
||||
CacheConfig(const std::string& name);
|
||||
~CacheConfig();
|
||||
|
||||
CacheConfig(const CacheConfig&) = delete;
|
||||
|
5
server/modules/filter/cache/cachefilter.cc
vendored
5
server/modules/filter/cache/cachefilter.cc
vendored
@ -144,7 +144,8 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
// CacheFilter
|
||||
//
|
||||
|
||||
CacheFilter::CacheFilter()
|
||||
CacheFilter::CacheFilter(const std::string& name)
|
||||
: m_config(name)
|
||||
{
|
||||
}
|
||||
|
||||
@ -155,7 +156,7 @@ CacheFilter::~CacheFilter()
|
||||
// static
|
||||
CacheFilter* CacheFilter::create(const char* zName, MXS_CONFIG_PARAMETER* ppParams)
|
||||
{
|
||||
CacheFilter* pFilter = new CacheFilter;
|
||||
CacheFilter* pFilter = new CacheFilter(zName);
|
||||
|
||||
if (pFilter)
|
||||
{
|
||||
|
2
server/modules/filter/cache/cachefilter.hh
vendored
2
server/modules/filter/cache/cachefilter.hh
vendored
@ -49,7 +49,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
CacheFilter();
|
||||
CacheFilter(const std::string& name);
|
||||
|
||||
CacheFilter(const CacheFilter&);
|
||||
CacheFilter& operator=(const CacheFilter&);
|
||||
|
@ -190,8 +190,8 @@ sqlite3* open_or_create_db(const std::string& path)
|
||||
}
|
||||
}
|
||||
|
||||
ClustrixMonitor::Config::Config()
|
||||
: m_configuration(&clustrixmon::specification)
|
||||
ClustrixMonitor::Config::Config(const std::string& name)
|
||||
: m_configuration(name, &clustrixmon::specification)
|
||||
, m_cluster_monitor_interval(&m_configuration, &clustrixmon::cluster_monitor_interval)
|
||||
, m_health_check_threshold(&m_configuration, &clustrixmon::health_check_threshold)
|
||||
, m_dynamic_node_detection(&m_configuration, &clustrixmon::dynamic_node_detection)
|
||||
@ -212,6 +212,7 @@ bool ClustrixMonitor::Config::configure(const MXS_CONFIG_PARAMETER& params)
|
||||
|
||||
ClustrixMonitor::ClustrixMonitor(const string& name, const string& module, sqlite3* pDb)
|
||||
: MonitorWorker(name, module)
|
||||
, m_config(name)
|
||||
, m_pDb(pDb)
|
||||
{
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
Config();
|
||||
Config(const std::string& name);
|
||||
|
||||
static void populate(MXS_MODULE& module);
|
||||
|
||||
|
@ -65,8 +65,8 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
return &info;
|
||||
}
|
||||
|
||||
SmartRouter::Config::Config()
|
||||
: config::Configuration(&smartquery::specification)
|
||||
SmartRouter::Config::Config(const std::string& name)
|
||||
: config::Configuration(name, &smartquery::specification)
|
||||
, m_master(this, &smartquery::master)
|
||||
{
|
||||
}
|
||||
@ -100,10 +100,10 @@ bool SmartRouter::Config::post_configure(const MXS_CONFIG_PARAMETER& params)
|
||||
{
|
||||
if (strcmp(pServer->address, "127.0.0.1") == 0 || strcmp(pServer->address, "localhost"))
|
||||
{
|
||||
MXS_WARNING("The server %s, used by the smartrouter, is currently accessed "
|
||||
MXS_WARNING("The server %s, used by the smartrouter %s, is currently accessed "
|
||||
"using a TCP/IP socket (%s:%d). For better performance, a Unix "
|
||||
"domain socket should be used. See the 'socket' argument.",
|
||||
pServer->name(), pServer->address, pServer->port);
|
||||
pServer->name(), name().c_str(), pServer->address, pServer->port);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,8 +124,9 @@ bool SmartRouter::Config::post_configure(const MXS_CONFIG_PARAMETER& params)
|
||||
s += server->name();
|
||||
}
|
||||
|
||||
MXS_ERROR("The master server %s, is not one of the servers (%s) of the service.",
|
||||
m_master.get()->name(), s.c_str());
|
||||
MXS_ERROR("The master server %s of the smartrouter %s, is not one of the "
|
||||
"servers (%s) of the service.",
|
||||
m_master.get()->name(), name().c_str(), s.c_str());
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -149,6 +150,7 @@ SERVICE* SmartRouter::service() const
|
||||
|
||||
SmartRouter::SmartRouter(SERVICE* service)
|
||||
: mxs::Router<SmartRouter, SmartRouterSession>(service)
|
||||
, m_config(service->name())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
class Config : public config::Configuration
|
||||
{
|
||||
public:
|
||||
Config();
|
||||
Config(const std::string& name);
|
||||
|
||||
Config(const Config&) = delete;
|
||||
Config& operator=(const Config&) = delete;
|
||||
|
Loading…
x
Reference in New Issue
Block a user