MXS-1220: Express relations in JSON API style
The JSON API (http://jsonapi.org/) specifies a way to express relations in a somewhat generic way. By moving towards a more generic schema for the resources, it will be easier to handle the modification of the relations between these resources.
This commit is contained in:
parent
5b9c276123
commit
b6add43bd2
@ -1553,6 +1553,8 @@ json_t* monitor_to_json(const MXS_MONITOR* monitor, const char* host)
|
||||
json_object_set_new(rval, "write_timeout", json_integer(monitor->write_timeout));
|
||||
json_object_set_new(rval, "connect_attempts", json_integer(monitor->connect_attempts));
|
||||
|
||||
json_t* rel = json_object();
|
||||
|
||||
if (monitor->databases)
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
@ -1565,9 +1567,10 @@ json_t* monitor_to_json(const MXS_MONITOR* monitor, const char* host)
|
||||
json_array_append_new(arr, json_string(s.c_str()));
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "servers", arr);
|
||||
json_object_set_new(rel, "servers", arr);
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "relationships", rel);
|
||||
|
||||
if (monitor->handle && monitor->module->diagnostics)
|
||||
{
|
||||
|
@ -2409,6 +2409,28 @@ json_t* service_to_json(const SERVICE* service, const char* host)
|
||||
json_object_set_new(rval, "started", json_string(timebuf));
|
||||
json_object_set_new(rval, "enable_root", json_boolean(service->enable_root));
|
||||
|
||||
if (service->weightby)
|
||||
{
|
||||
json_object_set_new(rval, "weightby", json_string(service->weightby));
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "total_connections", json_integer(service->stats.n_sessions));
|
||||
json_object_set_new(rval, "connections", json_integer(service->stats.n_current));
|
||||
|
||||
if (service->ports)
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
|
||||
for (SERV_LISTENER* p = service->ports; p; p = p->next)
|
||||
{
|
||||
json_array_append_new(arr, listener_to_json(p));
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "listeners", arr);
|
||||
}
|
||||
|
||||
json_t* rel = json_object();
|
||||
|
||||
if (service->n_filters)
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
@ -2421,19 +2443,7 @@ json_t* service_to_json(const SERVICE* service, const char* host)
|
||||
json_array_append_new(arr, json_string(filter.c_str()));
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "filters", arr);
|
||||
}
|
||||
|
||||
if (service->ports)
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
|
||||
for (SERV_LISTENER* p = service->ports; p; p = p->next)
|
||||
{
|
||||
json_array_append_new(arr, listener_to_json(p));
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "listeners", arr);
|
||||
json_object_set_new(rel, "filters", arr);
|
||||
}
|
||||
|
||||
bool active_servers = false;
|
||||
@ -2462,16 +2472,10 @@ json_t* service_to_json(const SERVICE* service, const char* host)
|
||||
}
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "servers", arr);
|
||||
json_object_set_new(rel, "servers", arr);
|
||||
}
|
||||
|
||||
if (service->weightby)
|
||||
{
|
||||
json_object_set_new(rval, "weightby", json_string(service->weightby));
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "total_connections", json_integer(service->stats.n_sessions));
|
||||
json_object_set_new(rval, "connections", json_integer(service->stats.n_current));
|
||||
json_object_set_new(rval, "relationships", rel);
|
||||
|
||||
spinlock_release(&service->spin);
|
||||
|
||||
|
@ -1010,10 +1010,16 @@ json_t* session_to_json(const MXS_SESSION *session, const char *host)
|
||||
json_object_set_new(rval, "id", json_integer(session->ses_id));
|
||||
json_object_set_new(rval, "state", json_string(session_state(session->state)));
|
||||
|
||||
json_t* rel = json_object();
|
||||
json_t* arr = json_array();
|
||||
|
||||
string svc = host;
|
||||
svc += "/services/";
|
||||
svc += session->service->name;
|
||||
json_object_set_new(rval, "service", json_string(svc.c_str()));
|
||||
|
||||
json_array_append(arr, json_string(svc.c_str()));
|
||||
json_object_set_new(rel, "services", arr);
|
||||
json_object_set_new(rval, "relationships", rel);
|
||||
|
||||
if (session->client_dcb->user)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user