MXS-1929: Combine service creation and configuration

The servers and filters are taken into use immediately after the service
is created. This removes the need for a second configuration step.
This commit is contained in:
Markus Mäkelä
2018-08-01 08:16:22 +03:00
parent c01840ffb3
commit ea8b522c8a

View File

@ -221,7 +221,6 @@ int create_new_server(CONFIG_CONTEXT *obj);
int create_new_monitor(CONFIG_CONTEXT *obj, std::set<std::string>& monitored_servers); int create_new_monitor(CONFIG_CONTEXT *obj, std::set<std::string>& monitored_servers);
int create_new_listener(CONFIG_CONTEXT *obj); int create_new_listener(CONFIG_CONTEXT *obj);
int create_new_filter(CONFIG_CONTEXT *obj); int create_new_filter(CONFIG_CONTEXT *obj);
int configure_new_service(CONFIG_CONTEXT *obj);
void config_fix_param(const MXS_MODULE_PARAM *params, MXS_CONFIG_PARAMETER *p); void config_fix_param(const MXS_MODULE_PARAM *params, MXS_CONFIG_PARAMETER *p);
static const char *config_file = NULL; static const char *config_file = NULL;
@ -1505,6 +1504,8 @@ process_config_context(CONFIG_CONTEXT *context)
return false; return false;
} }
std::set<std::string> monitored_servers;
/** /**
* Process the data and create the services defined in the data. * Process the data and create the services defined in the data.
*/ */
@ -1521,27 +1522,6 @@ process_config_context(CONFIG_CONTEXT *context)
{ {
error_count += create_new_filter(obj); error_count += create_new_filter(obj);
} }
}
if (error_count == 0)
{
/*
* Now we have created the services, servers and filters and we can add the
* servers and filters to the services. Monitors are also created at this point
* because they require a set of servers to monitor.
*/
std::set<std::string> monitored_servers;
for (CONFIG_CONTEXT* obj : objects)
{
std::string type = config_get_string(obj->parameters, CN_TYPE);
ss_dassert(!type.empty());
if (type == CN_SERVICE)
{
error_count += configure_new_service(obj);
}
else if (type == CN_LISTENER) else if (type == CN_LISTENER)
{ {
error_count += create_new_listener(obj); error_count += create_new_listener(obj);
@ -1551,7 +1531,6 @@ process_config_context(CONFIG_CONTEXT *context)
error_count += create_new_monitor(obj, monitored_servers); error_count += create_new_monitor(obj, monitored_servers);
} }
} }
}
if (error_count) if (error_count)
{ {
@ -3404,12 +3383,46 @@ int create_new_service(CONFIG_CONTEXT *obj)
Service* service = service_alloc(obj->object, router, obj->parameters); Service* service = service_alloc(obj->object, router, obj->parameters);
if (service) if (service)
{
int error_count = 0;
for (auto&& a : mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
{
fix_object_name(a);
if (SERVER * s = server_find_by_unique_name(a.c_str()))
{
serviceAddBackend(service, s);
}
else
{
MXS_ERROR("Unable to find server '%s' that is configured as part "
"of service '%s'.", a.c_str(), obj->object);
error_count++;
}
}
if (char* filters = config_get_value(obj->parameters, CN_FILTERS))
{
if (!service_set_filters(service, filters))
{
error_count++;
}
}
if (error_count == 0)
{ {
obj->element = service; obj->element = service;
} }
else else
{ {
MXS_ERROR("Service creation failed."); service_free(service);
service = nullptr;
}
}
else
{
MXS_ERROR("Service '%s' creation failed.", obj->object);
} }
return service ? 0 : 1; return service ? 0 : 1;
@ -3488,46 +3501,6 @@ int create_new_server(CONFIG_CONTEXT *obj)
return error; return error;
} }
/**
* Configure a new service after all objects have been created
*
* @param obj The service configuration context
*
* @return Number of errors
*/
int configure_new_service(CONFIG_CONTEXT *obj)
{
int error_count = 0;
Service *service = static_cast<Service*>(obj->element);
ss_dassert(service);
for (auto&& a : mxs::strtok(config_get_string(obj->parameters, CN_SERVERS), ","))
{
fix_object_name(a);
if (SERVER* s = server_find_by_unique_name(a.c_str()))
{
serviceAddBackend(service, s);
}
else
{
MXS_ERROR("Unable to find server '%s' that is configured as part "
"of service '%s'.", a.c_str(), obj->object);
error_count++;
}
}
if (char* filters = config_get_value(obj->parameters, CN_FILTERS))
{
if (!service_set_filters(service, filters))
{
error_count++;
}
}
return error_count;
}
/** /**
* Create a new monitor * Create a new monitor
* *