MXS-1220: Add missing relationships

The relationships from servers to services and monitors and filters to
services were not implemented. Now each server lists the services and
monitors that use it and each filter lists the services that use the
filter.

This enables the creation of a server and linking of that server to
services and monitors in one atomic operation.
This commit is contained in:
Markus Mäkelä
2017-04-19 11:08:07 +03:00
committed by Markus Mäkelä
parent b6add43bd2
commit 3d2219e8ef
6 changed files with 160 additions and 1 deletions

View File

@ -2502,3 +2502,61 @@ json_t* service_list_to_json(const char* host)
return rval;
}
static void add_service_relation(json_t* arr, const char* host, const SERVICE* service)
{
string svc = host;
svc += "/services/";
svc += service->name;
json_array_append_new(arr, json_string(svc.c_str()));
}
json_t* service_relations_to_filter(const MXS_FILTER_DEF* filter, const char* host)
{
json_t* arr = json_array();
spinlock_acquire(&service_spin);
for (SERVICE *service = allServices; service; service = service->next)
{
spinlock_acquire(&service->spin);
for (int i = 0; i < service->n_filters; i++)
{
if (service->filters[i] == filter)
{
add_service_relation(arr, host, service);
}
}
spinlock_release(&service->spin);
}
spinlock_release(&service_spin);
return arr;
}
json_t* service_relations_to_server(const SERVER* server, const char* host)
{
json_t* arr = json_array();
spinlock_acquire(&service_spin);
for (SERVICE *service = allServices; service; service = service->next)
{
spinlock_acquire(&service->spin);
for (SERVER_REF *ref = service->dbref; ref; ref = ref->next)
{
if (ref->server == server)
{
add_service_relation(arr, host, service);
}
}
spinlock_release(&service->spin);
}
spinlock_release(&service_spin);
return arr;
}