Detect duplicate objects
Creating a monitor or a listener twice is now detected and the proper error is printed.
This commit is contained in:
@ -242,6 +242,26 @@ SERVICE* service_find(const char *name);
|
|||||||
// TODO: Change binlogrouter to use the functions in config_runtime.h
|
// TODO: Change binlogrouter to use the functions in config_runtime.h
|
||||||
void serviceAddBackend(SERVICE *service, SERVER *server);
|
void serviceAddBackend(SERVICE *service, SERVER *server);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a service uses a server
|
||||||
|
* @param service Service to check
|
||||||
|
* @param server Server being used
|
||||||
|
* @return True if service uses the server
|
||||||
|
*/
|
||||||
|
bool serviceHasBackend(SERVICE *service, SERVER *server);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a service has a listener
|
||||||
|
*
|
||||||
|
* @param service Service to check
|
||||||
|
* @param protocol Listener protocol
|
||||||
|
* @param address Listener address
|
||||||
|
* @param port Listener port
|
||||||
|
* @return True if service has the listener
|
||||||
|
*/
|
||||||
|
bool serviceHasListener(SERVICE *service, const char *protocol,
|
||||||
|
const char* address, unsigned short port);
|
||||||
|
|
||||||
int serviceGetUser(SERVICE *service, char **user, char **auth);
|
int serviceGetUser(SERVICE *service, char **user, char **auth);
|
||||||
int serviceSetUser(SERVICE *service, char *user, char *auth);
|
int serviceSetUser(SERVICE *service, char *user, char *auth);
|
||||||
bool serviceSetFilters(SERVICE *service, char *filters);
|
bool serviceSetFilters(SERVICE *service, char *filters);
|
||||||
|
|||||||
@ -3110,7 +3110,7 @@ int create_new_listener(CONFIG_CONTEXT *obj)
|
|||||||
SSL_LISTENER *ssl_info = make_ssl_structure(obj, true, &error_count);
|
SSL_LISTENER *ssl_info = make_ssl_structure(obj, true, &error_count);
|
||||||
if (socket)
|
if (socket)
|
||||||
{
|
{
|
||||||
if (serviceHasProtocol(service, protocol, address, 0))
|
if (serviceHasListener(service, protocol, address, 0))
|
||||||
{
|
{
|
||||||
MXS_ERROR("Listener '%s' for service '%s' already has a socket at '%s.",
|
MXS_ERROR("Listener '%s' for service '%s' already has a socket at '%s.",
|
||||||
obj->object, service_name, socket);
|
obj->object, service_name, socket);
|
||||||
@ -3125,7 +3125,7 @@ int create_new_listener(CONFIG_CONTEXT *obj)
|
|||||||
|
|
||||||
if (port)
|
if (port)
|
||||||
{
|
{
|
||||||
if (serviceHasProtocol(service, protocol, address, atoi(port)))
|
if (serviceHasListener(service, protocol, address, atoi(port)))
|
||||||
{
|
{
|
||||||
MXS_ERROR("Listener '%s', for service '%s', already have port %s.",
|
MXS_ERROR("Listener '%s', for service '%s', already have port %s.",
|
||||||
obj->object,
|
obj->object,
|
||||||
|
|||||||
@ -396,8 +396,6 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add
|
|||||||
const char *ssl_cert, const char *ssl_ca,
|
const char *ssl_cert, const char *ssl_ca,
|
||||||
const char *ssl_version, const char *ssl_depth)
|
const char *ssl_version, const char *ssl_depth)
|
||||||
{
|
{
|
||||||
SSL_LISTENER *ssl = NULL;
|
|
||||||
bool rval = true;
|
|
||||||
|
|
||||||
if (addr == NULL || strcasecmp(addr, "default") == 0)
|
if (addr == NULL || strcasecmp(addr, "default") == 0)
|
||||||
{
|
{
|
||||||
@ -426,34 +424,42 @@ bool runtime_create_listener(SERVICE *service, const char *name, const char *add
|
|||||||
|
|
||||||
unsigned short u_port = atoi(port);
|
unsigned short u_port = atoi(port);
|
||||||
|
|
||||||
if (ssl_key && ssl_cert && ssl_ca)
|
|
||||||
{
|
|
||||||
ssl = create_ssl(name, ssl_key, ssl_cert, ssl_ca, ssl_version, ssl_depth);
|
|
||||||
|
|
||||||
if (ssl == NULL)
|
|
||||||
{
|
|
||||||
MXS_ERROR("SSL initialization for listener '%s' failed.", name);
|
|
||||||
rval = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spinlock_acquire(&crt_lock);
|
spinlock_acquire(&crt_lock);
|
||||||
|
|
||||||
if (rval)
|
SSL_LISTENER *ssl = NULL;
|
||||||
{
|
bool rval = false;
|
||||||
const char *print_addr = addr ? addr : "0.0.0.0";
|
|
||||||
SERV_LISTENER *listener = serviceCreateListener(service, name, proto, addr,
|
|
||||||
u_port, auth, auth_opt, ssl);
|
|
||||||
|
|
||||||
if (listener && listener_serialize(listener) && serviceLaunchListener(service, listener))
|
if (!serviceHasListener(service, proto, addr, u_port))
|
||||||
|
{
|
||||||
|
rval = true;
|
||||||
|
|
||||||
|
if (ssl_key && ssl_cert && ssl_ca)
|
||||||
{
|
{
|
||||||
MXS_NOTICE("Listener '%s' at %s:%s for service '%s' created",
|
ssl = create_ssl(name, ssl_key, ssl_cert, ssl_ca, ssl_version, ssl_depth);
|
||||||
name, print_addr, port, service->name);
|
|
||||||
|
if (ssl == NULL)
|
||||||
|
{
|
||||||
|
MXS_ERROR("SSL initialization for listener '%s' failed.", name);
|
||||||
|
rval = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (rval)
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to start listener '%s' at %s:%s.", name, print_addr, port);
|
const char *print_addr = addr ? addr : "0.0.0.0";
|
||||||
rval = false;
|
SERV_LISTENER *listener = serviceCreateListener(service, name, proto, addr,
|
||||||
|
u_port, auth, auth_opt, ssl);
|
||||||
|
|
||||||
|
if (listener && listener_serialize(listener) && serviceLaunchListener(service, listener))
|
||||||
|
{
|
||||||
|
MXS_NOTICE("Listener '%s' at %s:%s for service '%s' created",
|
||||||
|
name, print_addr, port, service->name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MXS_ERROR("Failed to start listener '%s' at %s:%s.", name, print_addr, port);
|
||||||
|
rval = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,16 +520,20 @@ bool runtime_create_monitor(const char *name, const char *module)
|
|||||||
{
|
{
|
||||||
spinlock_acquire(&crt_lock);
|
spinlock_acquire(&crt_lock);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
MONITOR *monitor = monitor_alloc((char*)name, (char*)module);
|
|
||||||
|
|
||||||
if (monitor)
|
if (monitor_find(name) == NULL)
|
||||||
{
|
{
|
||||||
/** Mark that this monitor was created after MaxScale was started */
|
MONITOR *monitor = monitor_alloc((char*)name, (char*)module);
|
||||||
monitor->created_online = true;
|
|
||||||
|
|
||||||
if (monitor_serialize(monitor))
|
if (monitor)
|
||||||
{
|
{
|
||||||
rval = true;
|
/** Mark that this monitor was created after MaxScale was started */
|
||||||
|
monitor->created_online = true;
|
||||||
|
|
||||||
|
if (monitor_serialize(monitor))
|
||||||
|
{
|
||||||
|
rval = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,10 +68,8 @@ SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name,
|
|||||||
const char *protocol, const char *address,
|
const char *protocol, const char *address,
|
||||||
unsigned short port, const char *authenticator,
|
unsigned short port, const char *authenticator,
|
||||||
const char *options, SSL_LISTENER *ssl);
|
const char *options, SSL_LISTENER *ssl);
|
||||||
int serviceHasProtocol(SERVICE *service, const char *protocol,
|
|
||||||
const char* address, unsigned short port);
|
|
||||||
void serviceRemoveBackend(SERVICE *service, const SERVER *server);
|
void serviceRemoveBackend(SERVICE *service, const SERVER *server);
|
||||||
bool serviceHasBackend(SERVICE *service, SERVER *server);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Serialize a service to a file
|
* @brief Serialize a service to a file
|
||||||
|
|||||||
@ -708,9 +708,9 @@ SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name, const c
|
|||||||
* @param protocol The name of the protocol module
|
* @param protocol The name of the protocol module
|
||||||
* @param address The address to listen on
|
* @param address The address to listen on
|
||||||
* @param port The port to listen on
|
* @param port The port to listen on
|
||||||
* @return TRUE if the protocol/port is already part of the service
|
* @return True if the protocol/port is already part of the service
|
||||||
*/
|
*/
|
||||||
int serviceHasProtocol(SERVICE *service, const char *protocol,
|
bool serviceHasListener(SERVICE *service, const char *protocol,
|
||||||
const char* address, unsigned short port)
|
const char* address, unsigned short port)
|
||||||
{
|
{
|
||||||
SERV_LISTENER *proto;
|
SERV_LISTENER *proto;
|
||||||
|
|||||||
@ -72,7 +72,7 @@ test1()
|
|||||||
ss_info_dassert(serviceCreateListener(service, "TestProtocol", "testprotocol",
|
ss_info_dassert(serviceCreateListener(service, "TestProtocol", "testprotocol",
|
||||||
"localhost", 9876, "MySQLAuth", NULL, NULL),
|
"localhost", 9876, "MySQLAuth", NULL, NULL),
|
||||||
"Add Protocol should succeed");
|
"Add Protocol should succeed");
|
||||||
ss_info_dassert(0 != serviceHasProtocol(service, "testprotocol", "localhost", 9876),
|
ss_info_dassert(0 != serviceHasListener(service, "testprotocol", "localhost", 9876),
|
||||||
"Service should have new protocol as requested");
|
"Service should have new protocol as requested");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -1085,7 +1085,11 @@ static void createListener(DCB *dcb, SERVICE *service, char *name, char *address
|
|||||||
|
|
||||||
static void createMonitor(DCB *dcb, const char *name, const char *module)
|
static void createMonitor(DCB *dcb, const char *name, const char *module)
|
||||||
{
|
{
|
||||||
if (runtime_create_monitor(name, module))
|
if (monitor_find(name))
|
||||||
|
{
|
||||||
|
dcb_printf(dcb, "Monitor '%s' already exists\n", name);
|
||||||
|
}
|
||||||
|
else if (runtime_create_monitor(name, module))
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "Created monitor '%s'\n", name);
|
dcb_printf(dcb, "Created monitor '%s'\n", name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user