MXS-1992 Move QC json "parsing" to query_classifier.cc
This commit is contained in:
parent
2188090742
commit
1b521b16a9
@ -108,6 +108,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_SIZE[];
|
||||
extern const char CN_CONNECTION_TIMEOUT[];
|
||||
extern const char CN_DUMP_LAST_STATEMENTS[];
|
||||
extern const char CN_DATA[];
|
||||
|
@ -87,6 +87,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_SIZE[] = "cache_size";
|
||||
const char CN_CONNECTION_TIMEOUT[] = "connection_timeout";
|
||||
const char CN_DATA[] = "data";
|
||||
const char CN_DEFAULT[] = "default";
|
||||
|
@ -2541,39 +2541,7 @@ bool runtime_alter_maxscale_from_json(json_t* new_json)
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool validate_qc_json(json_t* json)
|
||||
{
|
||||
json_t* param = mxs_json_pointer(json, MXS_JSON_PTR_PARAMETERS);
|
||||
bool rval = false;
|
||||
|
||||
if (param && json_is_object(param))
|
||||
{
|
||||
rval = runtime_is_count_or_null(param, "cache_size");
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
// TODO: Expose everything needed so that this function could be
|
||||
// TODO: part of the query classifier API.
|
||||
bool runtime_alter_qc_from_json(json_t* json)
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
if (validate_qc_json(json))
|
||||
{
|
||||
rval = true;
|
||||
|
||||
json_t* param = mxs_json_pointer(json, MXS_JSON_PTR_PARAMETERS);
|
||||
json_t* value;
|
||||
|
||||
if ((value = mxs_json_pointer(param, "cache_size")))
|
||||
{
|
||||
QC_CACHE_PROPERTIES cache_properties = { json_integer_value(value) };
|
||||
|
||||
qc_set_cache_properties(&cache_properties);
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
return qc_alter_from_json(json);
|
||||
}
|
||||
|
@ -38,12 +38,22 @@ typedef enum qc_trx_parse_using
|
||||
uint32_t qc_get_trx_type_mask_using(GWBUF* stmt, qc_trx_parse_using_t use);
|
||||
|
||||
/**
|
||||
* Generic query classifier information.
|
||||
* Common query classifier properties as JSON.
|
||||
*
|
||||
* @param zHost The MaxScale host.
|
||||
*
|
||||
* @return A json object containing information.
|
||||
* @return A json object containing properties.
|
||||
*/
|
||||
std::unique_ptr<json_t> qc_as_json(const char* zHost);
|
||||
|
||||
/**
|
||||
* Alter common query classifier properties.
|
||||
*
|
||||
* @param pJson A JSON object.
|
||||
*
|
||||
* @return True, if the object was valid and parameters could be changed,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool qc_alter_from_json(json_t* pJson);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <maxscale/platform.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
#include "internal/config_runtime.h"
|
||||
#include "internal/modules.h"
|
||||
#include "internal/trxboundaryparser.hh"
|
||||
|
||||
@ -1258,15 +1259,54 @@ json_t* qc_get_cache_stats_as_json()
|
||||
std::unique_ptr<json_t> qc_as_json(const char* zHost)
|
||||
{
|
||||
json_t* pParams = json_object();
|
||||
json_object_set_new(pParams, "cache_size", json_integer(this_unit.cache_max_size()));
|
||||
json_object_set_new(pParams, CN_CACHE_SIZE, json_integer(this_unit.cache_max_size()));
|
||||
|
||||
json_t* pAttributes = json_object();
|
||||
json_object_set_new(pAttributes, CN_PARAMETERS, pParams);
|
||||
|
||||
json_t* pSelf = json_object();
|
||||
json_object_set_new(pSelf, CN_ID, json_string("query_classifier"));
|
||||
json_object_set_new(pSelf, CN_TYPE, json_string("query_classifier"));
|
||||
json_object_set_new(pSelf, CN_ID, json_string(CN_QUERY_CLASSIFIER));
|
||||
json_object_set_new(pSelf, CN_TYPE, json_string(CN_QUERY_CLASSIFIER));
|
||||
json_object_set_new(pSelf, CN_ATTRIBUTES, pAttributes);
|
||||
|
||||
return std::unique_ptr<json_t>(mxs_json_resource(zHost, MXS_JSON_API_QC, pSelf));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
json_t* get_params(json_t* pJson)
|
||||
{
|
||||
json_t* pParams = mxs_json_pointer(pJson, MXS_JSON_PTR_PARAMETERS);
|
||||
|
||||
if (pParams && json_is_object(pParams))
|
||||
{
|
||||
if (!runtime_is_count_or_null(pParams, CN_CACHE_SIZE))
|
||||
{
|
||||
pParams = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return pParams;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool qc_alter_from_json(json_t* pJson)
|
||||
{
|
||||
json_t* pParams = get_params(pJson);
|
||||
|
||||
if (pParams)
|
||||
{
|
||||
json_t* pValue;
|
||||
|
||||
if ((pValue = mxs_json_pointer(pParams, CN_CACHE_SIZE)))
|
||||
{
|
||||
QC_CACHE_PROPERTIES cache_properties = { json_integer_value(pValue) };
|
||||
|
||||
qc_set_cache_properties(&cache_properties);
|
||||
}
|
||||
}
|
||||
|
||||
return pParams != nullptr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user