From 498395cd3d206d7a0bd6dba311dcb9f782950eba Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 22 Nov 2016 16:06:18 +0200 Subject: [PATCH] Add monitor alteration to config_runtime.h Moved the monitor alteration to config_runtime.c. --- include/maxscale/config_runtime.h | 10 +++ server/core/config_runtime.c | 77 ++++++++++++++++++++++ server/modules/routing/debugcli/debugcmd.c | 77 +--------------------- 3 files changed, 88 insertions(+), 76 deletions(-) diff --git a/include/maxscale/config_runtime.h b/include/maxscale/config_runtime.h index db8674493..acb56bba8 100644 --- a/include/maxscale/config_runtime.h +++ b/include/maxscale/config_runtime.h @@ -106,3 +106,13 @@ bool runtime_alter_server(SERVER *server, char *key, char *value); */ bool runtime_enable_server_ssl(SERVER *server, const char *key, const char *cert, const char *ca, const char *version, const char *depth); + +/** + * @brief Alter monitor parameters + * + * @param monitor Monitor to aler + * @param key Key to modify + * @param value New value + * @return True if @c key was one of the supported parameters + */ +bool runtime_alter_monitor(MONITOR *monitor, char *key, char *value); diff --git a/server/core/config_runtime.c b/server/core/config_runtime.c index 2fa5fabc0..854be86be 100644 --- a/server/core/config_runtime.c +++ b/server/core/config_runtime.c @@ -258,3 +258,80 @@ bool runtime_alter_server(SERVER *server, char *key, char *value) spinlock_release(&crt_lock); return valid; } + +/** + * @brief Convert a string value to a positive integer + * + * If the value is not a positive integer, an error is printed to @c dcb. + * + * @param value String value + * @return 0 on error, otherwise a positive integer + */ +static long get_positive_int(const char *value) +{ + char *endptr; + long ival = strtol(value, &endptr, 10); + + if (*endptr == '\0' && ival > 0) + { + return ival; + } + + return 0; +} + +bool runtime_alter_monitor(MONITOR *monitor, char *key, char *value) +{ + spinlock_acquire(&crt_lock); + bool valid = false; + + if (strcmp(key, "user") == 0) + { + valid = true; + monitorAddUser(monitor, value, monitor->password); + } + else if (strcmp(key, "password") == 0) + { + valid = true; + monitorAddUser(monitor, monitor->user, value); + } + else if (strcmp(key, "monitor_interval") == 0) + { + long ival = get_positive_int(value); + if (ival) + { + valid = true; + monitorSetInterval(monitor, ival); + } + } + else if (strcmp(key, "backend_connect_timeout") == 0) + { + long ival = get_positive_int(value); + if (ival) + { + valid = true; + monitorSetNetworkTimeout(monitor, MONITOR_CONNECT_TIMEOUT, ival); + } + } + else if (strcmp(key, "backend_write_timeout") == 0) + { + long ival = get_positive_int(value); + if (ival) + { + valid = true; + monitorSetNetworkTimeout(monitor, MONITOR_WRITE_TIMEOUT, ival); + } + } + else if (strcmp(key, "backend_read_timeout") == 0) + { + long ival = get_positive_int(value); + if (ival) + { + valid = true; + monitorSetNetworkTimeout(monitor, MONITOR_READ_TIMEOUT, ival); + } + } + + spinlock_release(&crt_lock); + return valid; +} diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index 2f215733c..492ebc741 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -1169,81 +1169,6 @@ static void alterServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3, } } -/** - * @brief Convert a string value to a positive integer - * - * If the value is not a positive integer, an error is printed to @c dcb. - * - * @param value String value - * @return 0 on error, otherwise a positive integer - */ -static long get_positive_int(const char *value) -{ - char *endptr; - long ival = strtol(value, &endptr, 10); - - if (*endptr == '\0' && ival > 0) - { - return ival; - } - - return 0; -} - -static bool handle_alter_monitor(MONITOR *monitor, char *key, char *value) -{ - bool valid = false; - - if (strcmp(key, "user") == 0) - { - valid = true; - monitorAddUser(monitor, value, monitor->password); - } - else if (strcmp(key, "password") == 0) - { - valid = true; - monitorAddUser(monitor, monitor->user, value); - } - else if (strcmp(key, "monitor_interval") == 0) - { - long ival = get_positive_int(value); - if (ival) - { - valid = true; - monitorSetInterval(monitor, ival); - } - } - else if (strcmp(key, "backend_connect_timeout") == 0) - { - long ival = get_positive_int(value); - if (ival) - { - valid = true; - monitorSetNetworkTimeout(monitor, MONITOR_CONNECT_TIMEOUT, ival); - } - } - else if (strcmp(key, "backend_write_timeout") == 0) - { - long ival = get_positive_int(value); - if (ival) - { - valid = true; - monitorSetNetworkTimeout(monitor, MONITOR_WRITE_TIMEOUT, ival); - } - } - else if (strcmp(key, "backend_read_timeout") == 0) - { - long ival = get_positive_int(value); - if (ival) - { - valid = true; - monitorSetNetworkTimeout(monitor, MONITOR_READ_TIMEOUT, ival); - } - } - - return valid; -} - static void alterMonitor(DCB *dcb, MONITOR *monitor, char *v1, char *v2, char *v3, char *v4, char *v5, char *v6, char *v7, char *v8, char *v9, char *v10, char *v11) @@ -1260,7 +1185,7 @@ static void alterMonitor(DCB *dcb, MONITOR *monitor, char *v1, char *v2, char *v { *value++ = '\0'; - if (!handle_alter_monitor(monitor, key, value)) + if (!runtime_alter_monitor(monitor, key, value)) { dcb_printf(dcb, "Error: Bad key-value parameter: %s=%s\n", key, value); }