MXS-2246 Remove duplicate info in SERVICE and Service

Both of them contained fields for the service and router names.
Now the names are in SERVICE and they must be accessed via member
function.
This commit is contained in:
Johan Wikman
2019-02-14 10:25:04 +02:00
parent 2528c5fa4d
commit 1fed465fdb
32 changed files with 294 additions and 278 deletions

View File

@ -3996,7 +3996,7 @@ int create_new_listener(CONFIG_CONTEXT* obj)
MXS_ERROR("Creation of listener '%s' for service '%s' failed, because "
"listener '%s' already listens on the %s %s.",
obj->object,
service->name,
service->name(),
l->name(),
socket ? "socket" : "port",
socket ? socket : port);

View File

@ -151,7 +151,7 @@ bool runtime_link_server(Server* server, const char* target)
else
{
config_runtime_error("Service '%s' already uses server '%s'",
service->name,
service->name(),
server->name());
}
}
@ -159,7 +159,7 @@ bool runtime_link_server(Server* server, const char* target)
{
config_runtime_error("The servers of the service '%s' are defined by the monitor '%s'. "
"Servers cannot explicitly be added to the service.",
service->name,
service->name(),
service->m_monitor->m_name);
}
}
@ -207,7 +207,7 @@ bool runtime_unlink_server(Server* server, const char* target)
{
config_runtime_error("The servers of the service '%s' are defined by the monitor '%s'. "
"Servers cannot explicitly be removed from the service.",
service->name,
service->name(),
service->m_monitor->m_name);
}
}
@ -704,7 +704,7 @@ bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value)
bool runtime_alter_service(Service* service, const char* zKey, const char* zValue)
{
const MXS_MODULE* mod = get_module(service->routerModule, MODULE_ROUTER);
const MXS_MODULE* mod = get_module(service->router_name(), MODULE_ROUTER);
std::string key(zKey);
std::string value(zValue);
@ -749,21 +749,21 @@ bool runtime_alter_service(Service* service, const char* zKey, const char* zValu
rval = false;
config_runtime_error("Reconfiguration of service '%s' failed. See log "
"file for more details.",
service->name);
service->name());
}
}
else
{
rval = false;
config_runtime_error("Router '%s' does not support reconfiguration.",
service->routerModule);
service->router_name());
}
}
if (rval)
{
service_serialize(service);
MXS_NOTICE("Updated service '%s': %s=%s", service->name, key.c_str(), value.c_str());
MXS_NOTICE("Updated service '%s': %s=%s", service->name(), key.c_str(), value.c_str());
}
return rval;
@ -1125,7 +1125,7 @@ bool runtime_create_listener(Service* service,
if (listener && listener_serialize(listener))
{
MXS_NOTICE("Created %slistener '%s' at %s:%s for service '%s'",
ssl ? "TLS encrypted " : "", name, print_addr, port, service->name);
ssl ? "TLS encrypted " : "", name, print_addr, port, service->name());
if (listener->listen())
{
@ -1181,8 +1181,8 @@ bool runtime_destroy_listener(Service* service, const char* name)
if (!service_remove_listener(service, name))
{
MXS_ERROR("Failed to destroy listener '%s' for service '%s'", name, service->name);
config_runtime_error("Failed to destroy listener '%s' for service '%s'", name, service->name);
MXS_ERROR("Failed to destroy listener '%s' for service '%s'", name, service->name());
config_runtime_error("Failed to destroy listener '%s' for service '%s'", name, service->name());
}
else
{
@ -1191,7 +1191,7 @@ bool runtime_destroy_listener(Service* service, const char* name)
"will be removed after the next restart of MaxScale or "
"when the associated service is destroyed.",
name,
service->name);
service->name());
}
return rval;
@ -1402,7 +1402,7 @@ bool runtime_destroy_service(Service* service)
{
config_runtime_error("Service '%s' cannot be destroyed: Remove all servers and "
"destroy all listeners first",
service->name);
service->name());
}
return rval;
@ -2397,7 +2397,7 @@ bool service_to_filter_relations(Service* service, json_t* old_json, json_t* new
}
else
{
config_runtime_error("Invalid object relations for '%s'", service->name);
config_runtime_error("Invalid object relations for '%s'", service->name());
}
return rval;
@ -2502,7 +2502,7 @@ bool runtime_alter_service_relationships_from_json(Service* service, const char*
if (strcmp(type, CN_SERVERS) == 0)
{
rval = object_to_server_relations(service->name, old_json.get(), j.get());
rval = object_to_server_relations(service->name(), old_json.get(), j.get());
}
else
{
@ -2534,7 +2534,7 @@ bool runtime_alter_service_from_json(Service* service, json_t* new_json)
mxb_assert(old_json.get());
if (is_valid_resource_body(new_json)
&& object_to_server_relations(service->name, old_json.get(), new_json)
&& object_to_server_relations(service->name(), old_json.get(), new_json)
&& service_to_filter_relations(service, old_json.get(), new_json))
{
rval = true;
@ -2555,7 +2555,7 @@ bool runtime_alter_service_from_json(Service* service, json_t* new_json)
}
}
const MXS_MODULE* mod = get_module(service->routerModule, MODULE_ROUTER);
const MXS_MODULE* mod = get_module(service->router_name(), MODULE_ROUTER);
for (int i = 0; mod->parameters[i].name; i++)
{

View File

@ -1374,7 +1374,7 @@ void dprintOneDCB(DCB* pdcb, DCB* dcb)
{
dcb_printf(pdcb,
"\tService: %s\n",
dcb->session->service->name);
dcb->session->service->name());
}
if (dcb->remote)
{
@ -1469,7 +1469,7 @@ static bool dlist_dcbs_cb(DCB* dcb, void* data)
" %-16p | %-26s | %-18s | %s\n",
dcb,
gw_dcb_state2string(dcb->state),
((dcb->session && dcb->session->service) ? dcb->session->service->name : ""),
((dcb->session && dcb->session->service) ? dcb->session->service->name() : ""),
(dcb->remote ? dcb->remote : ""));
return true;
}
@ -1505,7 +1505,7 @@ static bool dlist_clients_cb(DCB* dcb, void* data)
(dcb->remote ? dcb->remote : ""),
dcb,
(dcb->session->service ?
dcb->session->service->name : ""),
dcb->session->service->name() : ""),
dcb->session);
}
@ -1546,7 +1546,7 @@ void dprintDCB(DCB* pdcb, DCB* dcb)
{
dcb_printf(pdcb,
"\tService: %s\n",
dcb->session->service->name);
dcb->session->service->name());
}
if (dcb->remote)
{
@ -3069,8 +3069,8 @@ int poll_add_dcb(DCB* dcb)
if (dcb->role == DCB::Role::CLIENT)
{
if (strcasecmp(dcb->service->routerModule, "cli") == 0
|| strcasecmp(dcb->service->routerModule, "maxinfo") == 0)
if (strcasecmp(dcb->service->router_name(), "cli") == 0
|| strcasecmp(dcb->service->router_name(), "maxinfo") == 0)
{
// If the DCB refers to an accepted maxadmin/maxinfo socket, we force it
// to the main thread. That's done in order to prevent a deadlock

View File

@ -515,7 +515,7 @@ bool Listener::create_listener_config(const char* filename)
dprintf(file, "[%s]\n", m_name.c_str());
dprintf(file, "type=listener\n");
dprintf(file, "protocol=%s\n", m_protocol.c_str());
dprintf(file, "service=%s\n", m_service->name);
dprintf(file, "service=%s\n", m_service->name());
dprintf(file, "address=%s\n", m_address.c_str());
dprintf(file, "port=%u\n", m_port);
dprintf(file, "authenticator=%s\n", m_authenticator.c_str());
@ -970,7 +970,7 @@ bool Listener::listen_shared(std::string config_bind)
}
else
{
MXS_ERROR("[%s] Failed to listen on %s", m_service->name, config_bind.c_str());
MXS_ERROR("[%s] Failed to listen on %s", m_service->name(), config_bind.c_str());
}
return rval;
@ -987,12 +987,12 @@ bool Listener::listen()
{
case MXS_AUTH_LOADUSERS_FATAL:
MXS_ERROR("[%s] Fatal error when loading users for listener '%s', "
"service is not started.", m_service->name, name());
"service is not started.", m_service->name(), name());
return false;
case MXS_AUTH_LOADUSERS_ERROR:
MXS_WARNING("[%s] Failed to load users for listener '%s', authentication"
" might not work.", m_service->name, name());
" might not work.", m_service->name(), name());
break;
default:

View File

@ -276,7 +276,7 @@ static bool process_argument(const MODULECMD* cmd,
if ((arg->value.service = service_find((char*)value)))
{
if (MODULECMD_ALLOW_NAME_MISMATCH(type)
|| strcmp(cmd->domain, arg->value.service->routerModule) == 0)
|| strcmp(cmd->domain, arg->value.service->router_name()) == 0)
{
arg->type.type = MODULECMD_ARG_SERVICE;
rval = true;

View File

@ -114,7 +114,7 @@ Service* service_alloc(const char* name, const char* router, MXS_CONFIG_PARAMETE
if (service->router_instance == NULL)
{
MXS_ERROR("%s: Failed to create router instance. Service not started.", service->name);
MXS_ERROR("%s: Failed to create router instance. Service not started.", service->name());
service->active = false;
delete service;
return NULL;
@ -174,11 +174,10 @@ void service_remove_server(Monitor* pMonitor, SERVER* pServer)
}
}
Service::Service(const std::string& service_name,
Service::Service(const std::string& name,
const std::string& router_name,
MXS_CONFIG_PARAMETER* params)
: m_name(service_name)
, m_router_name(router_name)
: SERVICE(name, router_name)
, m_user(params->get_string(CN_USER))
, m_password(params->get_string(CN_PASSWORD))
, m_weightby(params->get_string(CN_WEIGHTBY))
@ -194,9 +193,6 @@ Service::Service(const std::string& service_name,
capabilities = module->module_capabilities;
client_count = 0;
n_dbref = 0;
// TODO: Remove once the name and router module are not directly visible to modules
name = m_name.c_str();
routerModule = m_router_name.c_str();
svc_config_param = NULL;
svc_config_version = 0;
stats.started = time(0);
@ -306,7 +302,7 @@ void service_destroy(Service* service)
sizeof(filename),
"%s/%s.cnf",
get_config_persistdir(),
service->name);
service->name());
if (unlink(filename) == -1 && errno != ENOENT)
{
@ -384,7 +380,7 @@ int serviceStartAllPorts(Service* service)
service->stats.n_failed_starts++;
int retry_after = MXS_MIN(service->stats.n_failed_starts * 10, service->max_retry_interval);
MXS_NOTICE("Failed to start service %s, retrying in %d seconds.",
service->name,
service->name(),
retry_after);
mxb::Worker* worker = mxb::Worker::get_current();
@ -397,7 +393,7 @@ int serviceStartAllPorts(Service* service)
}
else
{
MXS_WARNING("Service '%s' has no listeners defined.", service->name);
MXS_WARNING("Service '%s' has no listeners defined.", service->name());
listeners = 1; /** Set this to one to suppress errors */
}
@ -458,11 +454,11 @@ bool service_launch_all()
for (Service* service : this_unit.services)
{
n += (i = serviceInitialize(service));
MXS_NOTICE("Service '%s' started (%d/%d)", service->name, curr_svc++, num_svc);
MXS_NOTICE("Service '%s' started (%d/%d)", service->name(), curr_svc++, num_svc);
if (i == 0)
{
MXS_ERROR("Failed to start service '%s'.", service->name);
MXS_ERROR("Failed to start service '%s'.", service->name());
ok = false;
}
@ -781,7 +777,7 @@ bool Service::set_filters(const std::vector<std::string>& filters)
}
else
{
MXS_ERROR("Unable to find filter '%s' for service '%s'", f.c_str(), name);
MXS_ERROR("Unable to find filter '%s' for service '%s'", f.c_str(), name());
rval = false;
}
}
@ -839,7 +835,7 @@ Service* service_internal_find(const char* name)
for (Service* s : this_unit.services)
{
if (strcmp(s->name, name) == 0 && atomic_load_int(&s->active))
if (strcmp(s->name(), name) == 0 && atomic_load_int(&s->active))
{
return s;
}
@ -888,8 +884,8 @@ void dprintService(DCB* dcb, SERVICE* svc)
struct tm result;
char timebuf[30];
dcb_printf(dcb, "\tService: %s\n", service->name);
dcb_printf(dcb, "\tRouter: %s\n", service->routerModule);
dcb_printf(dcb, "\tService: %s\n", service->name());
dcb_printf(dcb, "\tRouter: %s\n", service->router_name());
switch (service->state)
{
case SERVICE_STATE_STARTED:
@ -986,8 +982,8 @@ void dListServices(DCB* dcb)
mxb_assert(service->stats.n_current >= 0);
dcb_printf(dcb,
"%-25s | %-17s | %6d | %14d | ",
service->name,
service->routerModule,
service->name(),
service->router_name(),
service->stats.n_current,
service->stats.n_sessions);
@ -1047,7 +1043,7 @@ void dListListeners(DCB* dcb)
dcb_printf(dcb,
"%-20s | %-19s | %-18s | %-15s | %5d | %s\n",
listener->name(),
service->name,
service->name(),
listener->protocol(),
(listener && *listener->address()) ? listener->address() : "*",
listener->port(),
@ -1224,7 +1220,7 @@ std::unique_ptr<ResultSet> serviceGetListenerList()
{
for (const auto& listener : listener_find_by_service(service))
{
set->add_row({service->name, listener->protocol(), listener->address(),
set->add_row({service->name(), listener->protocol(), listener->address(),
std::to_string(listener->port()), listener->state()});
}
}
@ -1245,7 +1241,7 @@ std::unique_ptr<ResultSet> serviceGetList()
for (Service* s : this_unit.services)
{
set->add_row({s->name, s->routerModule, std::to_string(s->stats.n_current),
set->add_row({s->name(), s->router_name(), std::to_string(s->stats.n_current),
std::to_string(s->stats.n_sessions)});
}
@ -1279,7 +1275,7 @@ bool service_all_services_have_listeners()
{
if (listener_find_by_service(service).empty())
{
MXS_ERROR("Service '%s' has no listeners.", service->name);
MXS_ERROR("Service '%s' has no listeners.", service->name());
rval = false;
}
}
@ -1318,7 +1314,7 @@ static void service_calculate_weights(SERVICE* service)
{
MXS_WARNING("Weighting parameters for service '%s' will be ignored as "
"no servers have (positive) values for the parameter '%s'.",
service->name,
service->name(),
weightby);
}
else
@ -1484,7 +1480,7 @@ bool service_serialize(const Service* service)
sizeof(filename),
"%s/%s.cnf.tmp",
get_config_persistdir(),
service->name);
service->name());
if (unlink(filename) == -1 && errno != ENOENT)
{
@ -1577,7 +1573,7 @@ json_t* service_parameters_to_json(const SERVICE* service)
{
json_t* rval = json_object();
const MXS_MODULE* mod = get_module(service->routerModule, MODULE_ROUTER);
const MXS_MODULE* mod = get_module(service->router_name(), MODULE_ROUTER);
config_add_module_params_json(service->svc_config_param,
{CN_TYPE, CN_ROUTER, CN_SERVERS, CN_FILTERS},
config_service_params,
@ -1628,7 +1624,7 @@ json_t* service_attributes(const SERVICE* service)
{
json_t* attr = json_object();
json_object_set_new(attr, CN_ROUTER, json_string(service->routerModule));
json_object_set_new(attr, CN_ROUTER, json_string(service->router_name()));
json_object_set_new(attr, CN_STATE, json_string(service_state_to_string(service->state)));
if (service->router && service->router_instance && service->router->diagnostics_json)
@ -1699,11 +1695,11 @@ json_t* service_json_data(const SERVICE* svc, const char* host)
json_t* rval = json_object();
LockGuard guard(service->lock);
json_object_set_new(rval, CN_ID, json_string(service->name));
json_object_set_new(rval, CN_ID, json_string(service->name()));
json_object_set_new(rval, CN_TYPE, json_string(CN_SERVICES));
json_object_set_new(rval, CN_ATTRIBUTES, service_attributes(service));
json_object_set_new(rval, CN_RELATIONSHIPS, service->json_relationships(host));
json_object_set_new(rval, CN_LINKS, mxs_json_self_link(host, CN_SERVICES, service->name));
json_object_set_new(rval, CN_LINKS, mxs_json_self_link(host, CN_SERVICES, service->name()));
return rval;
}
@ -1711,7 +1707,7 @@ json_t* service_json_data(const SERVICE* svc, const char* host)
json_t* service_to_json(const Service* service, const char* host)
{
string self = MXS_JSON_API_SERVICES;
self += service->name;
self += service->name();
return mxs_json_resource(host, self.c_str(), service_json_data(service, host));
}
@ -1720,7 +1716,7 @@ json_t* service_listener_list_to_json(const Service* service, const char* host)
/** This needs to be done here as the listeners are sort of sub-resources
* of the service. */
string self = MXS_JSON_API_SERVICES;
self += service->name;
self += service->name();
self += "/listeners";
return mxs_json_resource(host, self.c_str(), service_all_listeners_json_data(service));
@ -1731,7 +1727,7 @@ json_t* service_listener_to_json(const Service* service, const char* name, const
/** This needs to be done here as the listeners are sort of sub-resources
* of the service. */
string self = MXS_JSON_API_SERVICES;
self += service->name;
self += service->name();
self += "/listeners/";
self += name;
@ -1767,7 +1763,7 @@ json_t* service_relations_to_filter(const SFilterDef& filter, const char* host)
{
if (f == filter)
{
mxs_json_add_relation(rel, service->name, CN_SERVICES);
mxs_json_add_relation(rel, service->name(), CN_SERVICES);
}
}
}
@ -1789,7 +1785,7 @@ json_t* service_relations_to_server(const SERVER* server, const char* host)
{
if (ref->server == server && server_ref_is_active(ref))
{
names.push_back(service->name);
names.push_back(service->name());
}
}
}

View File

@ -120,7 +120,7 @@ bool session_start(MXS_SESSION* session)
{
session->state = SESSION_STATE_TO_BE_FREED;
MXS_ERROR("Failed to create new router session for service '%s'. "
"See previous errors for more details.", session->service->name);
"See previous errors for more details.", session->service->name());
return false;
}
@ -151,7 +151,7 @@ bool session_start(MXS_SESSION* session)
if (!session_setup_filters(session))
{
session->state = SESSION_STATE_TO_BE_FREED;
MXS_ERROR("Setting up filters failed. Terminating session %s.", session->service->name);
MXS_ERROR("Setting up filters failed. Terminating session %s.", session->service->name());
return false;
}
@ -160,7 +160,7 @@ bool session_start(MXS_SESSION* session)
mxb::atomic::add(&session->service->stats.n_current, 1, mxb::atomic::RELAXED);
MXS_INFO("Started %s client session [%" PRIu64 "] for '%s' from %s",
session->service->name, session->ses_id,
session->service->name(), session->ses_id,
session->client_dcb->user ? session->client_dcb->user : "<no user>",
session->client_dcb->remote);
@ -255,7 +255,7 @@ private:
*/
static void session_free(MXS_SESSION* session)
{
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id);
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name(), session->ses_id);
Service* service = static_cast<Service*>(session->service);
session_final_free(session);
@ -318,7 +318,7 @@ void printSession(MXS_SESSION* session)
printf("Session %p\n", session);
printf("\tState: %s\n", session_state_to_string(session->state));
printf("\tService: %s (%p)\n", session->service->name, session->service);
printf("\tService: %s (%p)\n", session->service->name(), session->service);
printf("\tClient DCB: %p\n", session->client_dcb);
printf("\tConnected: %s\n",
asctime_r(localtime_r(&session->stats.connect, &result), timebuf));
@ -387,7 +387,7 @@ void dprintSession(DCB* dcb, MXS_SESSION* print_session)
dcb_printf(dcb, "Session %" PRIu64 "\n", print_session->ses_id);
dcb_printf(dcb, "\tState: %s\n", session_state_to_string(print_session->state));
dcb_printf(dcb, "\tService: %s\n", print_session->service->name);
dcb_printf(dcb, "\tService: %s\n", print_session->service->name());
if (print_session->client_dcb && print_session->client_dcb->remote)
{
@ -427,8 +427,8 @@ bool dListSessions_cb(DCB* dcb, void* data)
session->ses_id,
session->client_dcb && session->client_dcb->remote ?
session->client_dcb->remote : "",
session->service && session->service->name ?
session->service->name : "",
session->service && session->service->name() ?
session->service->name() : "",
session_state_to_string(session->state));
}
@ -601,7 +601,7 @@ bool dcb_iter_cb(DCB* dcb, void* data)
char buf[20];
snprintf(buf, sizeof(buf), "%p", ses);
set->add_row({buf, ses->client_dcb->remote, ses->service->name, session_state_to_string(ses->state)});
set->add_row({buf, ses->client_dcb->remote, ses->service->name(), session_state_to_string(ses->state)});
}
return true;
@ -731,7 +731,7 @@ json_t* session_json_data(const Session* session, const char* host)
/** Service relationship (one-to-one) */
json_t* services = mxs_json_relationship(host, MXS_JSON_API_SERVICES);
mxs_json_add_relation(services, session->service->name, CN_SERVICES);
mxs_json_add_relation(services, session->service->name(), CN_SERVICES);
json_object_set_new(rel, CN_SERVICES, services);
/** Filter relationships (one-to-many) */
@ -1245,7 +1245,7 @@ bool Session::setup_filters(Service* service)
{
MXS_ERROR("Failed to create filter '%s' for service '%s'.\n",
filter_def_get_name(it->filter.get()),
service->name);
service->name());
return false;
}
@ -1263,7 +1263,7 @@ bool Session::setup_filters(Service* service)
{
MXS_ERROR("Failed to create filter '%s' for service '%s'.",
filter_def_get_name(it->filter.get()),
service->name);
service->name());
return false;
}

View File

@ -51,7 +51,7 @@ int ssl_authenticate_client(DCB* dcb, bool is_capable)
{
const char* user = dcb->user ? dcb->user : "";
const char* remote = dcb->remote ? dcb->remote : "";
const char* service = (dcb->service && dcb->service->name) ? dcb->service->name : "";
const char* service = (dcb->service && dcb->service->name()) ? dcb->service->name() : "";
if (NULL == dcb->session->listener || NULL == dcb->session->listener->ssl())
{

View File

@ -72,7 +72,7 @@ static int test1()
mxb_assert_message(NULL != service, "New service with valid router must not be null");
mxb_assert_message(0 != service_isvalid(service), "Service must be valid after creation");
mxb_assert_message(0 == strcmp("MyService", service->name), "Service must have given name");
mxb_assert_message(0 == strcmp("MyService", service->name()), "Service must have given name");
fprintf(stderr, "\t..done\nAdding protocol testprotocol.");
mxb_assert_message(Listener::create(service,
"TestProtocol",