From 156abe81ee5dfd2e5d8c9346c6569ce882cd7ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 26 Mar 2019 13:37:37 +0200 Subject: [PATCH] Add type and module to default parameters When default parameters are loaded, the type and module name are added. This helps object serialization and allows all the code to expect that all the parameters needed to create an object are always present. --- server/core/config.cc | 10 +++++----- server/core/config_runtime.cc | 30 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/server/core/config.cc b/server/core/config.cc index 3f671ad6c..0620d0dd2 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -282,7 +282,7 @@ const MXS_MODULE_PARAM config_service_params[] = { CN_TYPE, MXS_MODULE_PARAM_STRING, - NULL, + CN_SERVICE, MXS_MODULE_OPT_REQUIRED }, { @@ -386,7 +386,7 @@ const MXS_MODULE_PARAM config_listener_params[] = { CN_TYPE, MXS_MODULE_PARAM_STRING, - NULL, + CN_LISTENER, MXS_MODULE_OPT_REQUIRED }, { @@ -473,7 +473,7 @@ const MXS_MODULE_PARAM config_monitor_params[] = { CN_TYPE, MXS_MODULE_PARAM_STRING, - NULL, + CN_MONITOR, MXS_MODULE_OPT_REQUIRED }, { @@ -560,7 +560,7 @@ const MXS_MODULE_PARAM config_filter_params[] = { { CN_TYPE, MXS_MODULE_PARAM_STRING, - NULL, + CN_FILTER, MXS_MODULE_OPT_REQUIRED }, { @@ -577,7 +577,7 @@ const MXS_MODULE_PARAM config_server_params[] = { CN_TYPE, MXS_MODULE_PARAM_STRING, - NULL, + CN_SERVER, MXS_MODULE_OPT_REQUIRED }, { diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 7b86e71b0..e6e77f8a3 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -106,6 +106,25 @@ static const MXS_MODULE_PARAM* get_type_parameters(const char* type) return NULL; } +std::string get_module_param_name(const std::string& type) +{ + if (type == CN_SERVICE) + { + return CN_ROUTER; + } + else if (type == CN_LISTENER || type == CN_SERVER) + { + return CN_PROTOCOL; + } + else if (type == CN_MONITOR || type == CN_FILTER) + { + return CN_MODULE; + } + + mxb_assert(!true); + return ""; +} + /** * @brief Load module default parameters * @@ -128,6 +147,7 @@ static std::pair load_defaults(const char* name, config_add_defaults(&ctx, get_type_parameters(object_type)); config_add_defaults(&ctx, mod->parameters); params = ctx.m_parameters; + params.set(get_module_param_name(object_type), name); rval = true; } else @@ -1284,12 +1304,6 @@ bool runtime_create_monitor(const char* name, const char* module, MXS_CONFIG_PAR final_params.set_multiple(*params); } - // Make sure the type and module parameters are in the parameter list. If this function is - // called from runtime_create_monitor_from_json, the assignment is redundant. Due to the fact - // that maxadmin is still supported, we must do this. - final_params.set(CN_TYPE, CN_MONITOR); - final_params.set(CN_MODULE, module); - Monitor* monitor = MonitorManager::create_monitor(name, module, &final_params); if (!monitor) @@ -2365,10 +2379,6 @@ Monitor* runtime_create_monitor_from_json(json_t* json) { auto params = extract_parameters(json); - // Make sure the type and module parameters are in the parameter list - params.set(CN_TYPE, CN_MONITOR); - params.set(CN_MODULE, module); - if (validate_param(config_monitor_params, mod->parameters, ¶ms) && server_relationship_to_parameter(json, ¶ms)) {