MXS-1220: Implement /sessions/ resource
The /sessions/ resource was not implemented due to changes in the core polling mechanics. With the new worker thread messaging system, sessions can be listed in a safe manner.
This commit is contained in:

committed by
Markus Mäkelä

parent
cd6e0ab5e9
commit
690d592a94
@ -423,4 +423,13 @@ void session_clear_stmt(MXS_SESSION *session);
|
|||||||
*/
|
*/
|
||||||
json_t* session_to_json(const MXS_SESSION *session, const char* host);
|
json_t* session_to_json(const MXS_SESSION *session, const char* host);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert all sessions to JSON
|
||||||
|
*
|
||||||
|
* @param host Hostname of this server
|
||||||
|
*
|
||||||
|
* @return A JSON array with all sessions
|
||||||
|
*/
|
||||||
|
json_t* session_list_to_json(const char* host);
|
||||||
|
|
||||||
MXS_END_DECLS
|
MXS_END_DECLS
|
||||||
|
@ -228,8 +228,7 @@ HttpResponse cb_get_monitor(const HttpRequest& request)
|
|||||||
|
|
||||||
HttpResponse cb_all_sessions(const HttpRequest& request)
|
HttpResponse cb_all_sessions(const HttpRequest& request)
|
||||||
{
|
{
|
||||||
// TODO: Implement this
|
return HttpResponse(MHD_HTTP_OK, session_list_to_json(request.host()));
|
||||||
return HttpResponse(MHD_HTTP_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse cb_get_session(const HttpRequest& request)
|
HttpResponse cb_get_session(const HttpRequest& request)
|
||||||
|
@ -1059,3 +1059,23 @@ json_t* session_to_json(const MXS_SESSION *session, const char *host)
|
|||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SessionListData
|
||||||
|
{
|
||||||
|
json_t* json;
|
||||||
|
const char* host;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool seslist_cb(DCB* dcb, void* data)
|
||||||
|
{
|
||||||
|
SessionListData* d = (SessionListData*)data;
|
||||||
|
json_array_append_new(d->json, session_to_json(dcb->session, d->host));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_t* session_list_to_json(const char* host)
|
||||||
|
{
|
||||||
|
SessionListData data = {json_array(), host};
|
||||||
|
dcb_foreach(seslist_cb, &data);
|
||||||
|
return data.json;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user