MXS-2363 Skeleton of /v1/maxscale/query_classifier/cache

URL routing in place, callback exists, but no actual information.
This commit is contained in:
Johan Wikman 2019-03-27 13:29:27 +02:00
parent 1a81371346
commit 9ec82932cf
6 changed files with 31 additions and 0 deletions

View File

@ -105,6 +105,7 @@ extern const char CN_AUTH_CONNECT_TIMEOUT[];
extern const char CN_AUTH_READ_TIMEOUT[];
extern const char CN_AUTH_WRITE_TIMEOUT[];
extern const char CN_AUTO[];
extern const char CN_CACHE[];
extern const char CN_CACHE_SIZE[];
extern const char CN_CLASSIFY[];
extern const char CN_CONNECTION_TIMEOUT[];

View File

@ -36,6 +36,7 @@
#define MXS_JSON_API_QC_STATS "/maxscale/qc_stats/"
#define MXS_JSON_API_QC "/maxscale/query_classifier/"
#define MXS_JSON_API_QC_CLASSIFY "/maxscale/query_classifier/classify"
#define MXS_JSON_API_QC_CACHE "/maxscale/query_classifier/cache"
#define MXS_JSON_API_USERS "/users/"
/**

View File

@ -92,6 +92,7 @@ const char CN_AUTH_CONNECT_TIMEOUT[] = "auth_connect_timeout";
const char CN_AUTH_READ_TIMEOUT[] = "auth_read_timeout";
const char CN_AUTH_WRITE_TIMEOUT[] = "auth_write_timeout";
const char CN_AUTO[] = "auto";
const char CN_CACHE[] = "cache";
const char CN_CACHE_SIZE[] = "cache_size";
const char CN_CLASSIFY[] = "classify";
const char CN_CLUSTER[] = "cluster";

View File

@ -66,4 +66,13 @@ bool qc_alter_from_json(json_t* pJson);
*/
std::unique_ptr<json_t> qc_classify_as_json(const char* zHost, const std::string& statement);
/**
* Return query classifier cache content.
*
* @param zHost The MaxScale host.
*
* @return A json object containing information about the query classifier cache.
*/
std::unique_ptr<json_t> qc_cache_as_json(const char* zHost);
MXS_END_DECLS

View File

@ -1504,3 +1504,15 @@ std::unique_ptr<json_t> qc_classify_as_json(const char* zHost, const std::string
return std::unique_ptr<json_t>(mxs_json_resource(zHost, MXS_JSON_API_QC_CLASSIFY, pSelf));
}
std::unique_ptr<json_t> qc_cache_as_json(const char* zHost)
{
json_t* pAttributes = json_object();
json_t* pSelf = json_object();
json_object_set_new(pSelf, CN_ID, json_string(CN_CACHE));
json_object_set_new(pSelf, CN_TYPE, json_string(CN_CACHE));
json_object_set_new(pSelf, CN_ATTRIBUTES, pAttributes);
return std::unique_ptr<json_t>(mxs_json_resource(zHost, MXS_JSON_API_QC_CACHE, pSelf));
}

View File

@ -691,6 +691,11 @@ HttpResponse cb_qc_classify(const HttpRequest& request)
return HttpResponse(MHD_HTTP_OK, qc_classify_as_json(request.host(), sql).release());
}
HttpResponse cb_qc_cache(const HttpRequest& request)
{
return HttpResponse(MHD_HTTP_OK, qc_cache_as_json(request.host()).release());
}
HttpResponse cb_thread(const HttpRequest& request)
{
int id = atoi(request.last_uri_part().c_str());
@ -969,6 +974,8 @@ public:
m_get.push_back(SResource(new Resource(cb_qc, 2, "maxscale", "query_classifier")));
m_get.push_back(SResource(new Resource(cb_qc_classify, 3,
"maxscale", "query_classifier", "classify")));
m_get.push_back(SResource(new Resource(cb_qc_cache, 3,
"maxscale", "query_classifier", "cache")));
m_get.push_back(SResource(new Resource(cb_all_threads, 2, "maxscale", "threads")));
m_get.push_back(SResource(new Resource(cb_thread, 3, "maxscale", "threads", ":thread")));
m_get.push_back(SResource(new Resource(cb_logs, 2, "maxscale", "logs")));