Allow servers to be removed from multiple objects

Since servers can be added to multiple objects, it only makes sense to be
able to remove them from multiple objects.
This commit is contained in:
Markus Makela
2016-11-15 23:36:59 +02:00
parent ae339f174c
commit 696d103ed0

View File

@ -802,12 +802,17 @@ struct subcommand addoptions[] =
static void telnetdRemoveUser(DCB *, char *user, char *password); static void telnetdRemoveUser(DCB *, char *user, char *password);
static void cmd_RemoveServer(DCB *dcb, void *a, void *b) static void cmd_RemoveServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3,
char *v4, char *v5, char *v6, char *v7, char *v8, char *v9,
char *v10, char *v11)
{ {
SERVER *server = (SERVER*)a; char *values[11] = {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11};
char *name = (char*)b; const int items = sizeof(values) / sizeof(values[0]);
SERVICE *service = service_find(name);
MONITOR *monitor = monitor_find(name); for (int i = 0; i < items && values[i]; i++)
{
SERVICE *service = service_find(values[i]);
MONITOR *monitor = monitor_find(values[i]);
if (service || monitor) if (service || monitor)
{ {
@ -825,12 +830,13 @@ static void cmd_RemoveServer(DCB *dcb, void *a, void *b)
} }
const char *target = service ? "service" : "monitor"; const char *target = service ? "service" : "monitor";
MXS_NOTICE("Removed server '%s' from %s '%s'", server->unique_name, target, name); MXS_NOTICE("Removed server '%s' from %s '%s'", server->unique_name, target, values[i]);
dcb_printf(dcb, "Removed server '%s' from %s '%s'\n", server->unique_name, target, name); dcb_printf(dcb, "Removed server '%s' from %s '%s'\n", server->unique_name, target, values[i]);
} }
else else
{ {
dcb_printf(dcb, "No service or monitor with the name '%s'\n", name); dcb_printf(dcb, "No service or monitor with the name '%s'\n", values[i]);
}
} }
} }
@ -849,11 +855,15 @@ struct subcommand removeoptions[] =
{ARG_TYPE_STRING, ARG_TYPE_STRING} {ARG_TYPE_STRING, ARG_TYPE_STRING}
}, },
{ {
"server", 2, 2, cmd_RemoveServer, "server", 2, 12, cmd_RemoveServer,
"Remove a server from a service or a monitor", "Remove a server from a service or a monitor",
"Usage: remove server SERVER TARGET\n" "Usage: remove server SERVER TARGET...\n"
"The TARGET must be either a service or a monitor", "The TARGET must be a list of service and monitor names\n"
{ARG_TYPE_SERVER, ARG_TYPE_STRING} "e.g. remove server my-db my-service 'Cluster Monitor'\n"
"A server can be removed from a maximum of 11 objects in one command",
{ARG_TYPE_SERVER, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING,
ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING,
ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING}
}, },
{ {
EMPTY_OPTION EMPTY_OPTION
@ -1125,9 +1135,7 @@ static void alterServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3,
const int items = sizeof(values) / sizeof(values[0]); const int items = sizeof(values) / sizeof(values[0]);
CONFIG_CONTEXT *obj = NULL; CONFIG_CONTEXT *obj = NULL;
for (int i = 0; i < items; i++) for (int i = 0; i < items && values[i]; i++)
{
if (values[i])
{ {
char *key = values[i]; char *key = values[i];
char *value = strchr(key, '='); char *value = strchr(key, '=');
@ -1160,7 +1168,6 @@ static void alterServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3,
dcb_printf(dcb, "Error: not a key-value parameter: %s\n", values[i]); dcb_printf(dcb, "Error: not a key-value parameter: %s\n", values[i]);
} }
} }
}
if (obj) if (obj)
{ {
@ -1252,9 +1259,7 @@ static void alterMonitor(DCB *dcb, MONITOR *monitor, char *v1, char *v2, char *v
char *values[11] = {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11}; char *values[11] = {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11};
const int items = sizeof(values) / sizeof(values[0]); const int items = sizeof(values) / sizeof(values[0]);
for (int i = 0; i < items; i++) for (int i = 0; i < items && values[i]; i++)
{
if (values[i])
{ {
char *key = values[i]; char *key = values[i];
char *value = strchr(key, '='); char *value = strchr(key, '=');
@ -1273,7 +1278,6 @@ static void alterMonitor(DCB *dcb, MONITOR *monitor, char *v1, char *v2, char *v
dcb_printf(dcb, "Error: not a key-value parameter: %s\n", values[i]); dcb_printf(dcb, "Error: not a key-value parameter: %s\n", values[i]);
} }
} }
}
} }