Add support for multiple runtime error messages
Storing all the runtime errors makes it possible to return all of them them via the REST API. MaxAdmin will still only show the latest error but MaxCtrl will now show all errors if more than one error occurs.
This commit is contained in:
parent
74eeb64fba
commit
203bba0e1d
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2022-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file Helper functions for creating JSON API conforming objects
|
||||
*
|
||||
* @see http://jsonapi.org/format/
|
||||
*/
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <maxbase/jansson.h>
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
/** Resource endpoints */
|
||||
#define MXS_JSON_API_SERVERS "/servers/"
|
||||
#define MXS_JSON_API_SERVICES "/services/"
|
||||
#define MXS_JSON_API_FILTERS "/filters/"
|
||||
#define MXS_JSON_API_MONITORS "/monitors/"
|
||||
#define MXS_JSON_API_SESSIONS "/sessions/"
|
||||
#define MXS_JSON_API_MAXSCALE "/maxscale/"
|
||||
#define MXS_JSON_API_THREADS "/maxscale/threads/"
|
||||
#define MXS_JSON_API_LOGS "/maxscale/logs/"
|
||||
#define MXS_JSON_API_TASKS "/maxscale/tasks/"
|
||||
#define MXS_JSON_API_MODULES "/maxscale/modules/"
|
||||
#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_USERS "/users/"
|
||||
|
||||
/**
|
||||
* @brief Create a JSON object
|
||||
*
|
||||
* @param host Hostname of this server
|
||||
* @param self Endpoint of this resource
|
||||
* @param data The JSON data, either an array or an object, stored in
|
||||
* the `data` field of the returned object
|
||||
*
|
||||
* @return A valid top-level JSON API object
|
||||
*/
|
||||
json_t* mxs_json_resource(const char* host, const char* self, json_t* data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a JSON metadata object
|
||||
*
|
||||
* This should be used to transport non-standard data to the client.
|
||||
*
|
||||
* @param host Hostname of this server
|
||||
* @param self Endpoint of this resource
|
||||
* @param data The JSON data, either an array or an object, stored in
|
||||
* the `meta` field of the returned object
|
||||
*
|
||||
* @return A valid top-level JSON API object
|
||||
*/
|
||||
json_t* mxs_json_metadata(const char* host, const char* self, json_t* data);
|
||||
|
||||
/**
|
||||
* @brief Create an empty relationship object
|
||||
*
|
||||
* @param host Hostname of this server
|
||||
* @param endpoint The endpoint for the resource's collection
|
||||
*
|
||||
* @return New relationship object
|
||||
*/
|
||||
json_t* mxs_json_relationship(const char* host, const char* endpoint);
|
||||
|
||||
/**
|
||||
* @brief Add an item to a relationship object
|
||||
*
|
||||
* @param rel Relationship created with mxs_json_relationship
|
||||
* @param id The resource identifier
|
||||
* @param type The resource type
|
||||
*/
|
||||
void mxs_json_add_relation(json_t* rel, const char* id, const char* type);
|
||||
|
||||
/**
|
||||
* @brief Create self link object
|
||||
*
|
||||
* The self link points to the object itself.
|
||||
*
|
||||
* @param host Hostname of this server
|
||||
* @param path Base path to the resource collection
|
||||
* @param id The identified of this resource
|
||||
*
|
||||
* @return New self link object
|
||||
*/
|
||||
json_t* mxs_json_self_link(const char* host, const char* path, const char* id);
|
||||
|
||||
/**
|
||||
* @brief Return value at provided JSON Pointer
|
||||
*
|
||||
* @param json JSON object
|
||||
* @param json_ptr JSON Pointer to object
|
||||
*
|
||||
* @return Pointed value or NULL if no value is found
|
||||
*/
|
||||
json_t* mxs_json_pointer(json_t* json, const char* json_ptr);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return a JSON formatted error
|
||||
*
|
||||
* @param format Format string
|
||||
* @param ... Variable argument list
|
||||
*
|
||||
* @return The error as JSON
|
||||
*/
|
||||
json_t* mxs_json_error(const char* format, ...);
|
||||
|
||||
/**
|
||||
* @brief Append error to existing JSON object.
|
||||
*
|
||||
* @param object Existing json error object, or NULL.
|
||||
* @param format Format string
|
||||
* @param ... Variable argument list
|
||||
*
|
||||
* @return The error added to 'errors' array of the JSON object.
|
||||
*/
|
||||
json_t* mxs_json_error_append(json_t* object, const char* format, ...) mxb_attribute((format (printf, 2, 3)));
|
||||
|
||||
MXS_END_DECLS
|
@ -26,7 +26,7 @@
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/adminusers.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
/**
|
||||
* @file adminusers.c - Administration user account management
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <maxscale/http.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/limits.h>
|
||||
#include <maxscale/maxscale.h>
|
||||
#include <maxscale/maxadmin.h>
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <maxbase/atomic.h>
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/jansson.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/router.hh>
|
||||
#include <maxscale/users.h>
|
||||
@ -50,23 +50,31 @@ using maxscale::Monitor;
|
||||
static std::mutex crt_lock;
|
||||
|
||||
#define RUNTIME_ERRMSG_BUFSIZE 512
|
||||
thread_local char runtime_errmsg[RUNTIME_ERRMSG_BUFSIZE];
|
||||
thread_local std::vector<std::string> runtime_errmsg;
|
||||
|
||||
typedef std::function<bool (const std::string&, const std::string&)> JsonValidator;
|
||||
typedef std::pair<const char*, JsonValidator> Relationship;
|
||||
|
||||
void config_runtime_error(const char* fmt, ...)
|
||||
{
|
||||
char errmsg[RUNTIME_ERRMSG_BUFSIZE];
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
vsnprintf(runtime_errmsg, sizeof(runtime_errmsg), fmt, list);
|
||||
vsnprintf(errmsg, sizeof(errmsg), fmt, list);
|
||||
va_end(list);
|
||||
runtime_errmsg.push_back(errmsg);
|
||||
}
|
||||
|
||||
static std::string runtime_get_error()
|
||||
{
|
||||
std::string rval(runtime_errmsg);
|
||||
runtime_errmsg[0] = '\0';
|
||||
std::string rval;
|
||||
|
||||
if (!runtime_errmsg.empty())
|
||||
{
|
||||
rval = runtime_errmsg.back();
|
||||
runtime_errmsg.clear();
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
@ -2779,11 +2787,11 @@ bool runtime_create_listener_from_json(Service* service, json_t* json)
|
||||
json_t* runtime_get_json_error()
|
||||
{
|
||||
json_t* obj = NULL;
|
||||
std::string errmsg = runtime_get_error();
|
||||
|
||||
if (errmsg.length())
|
||||
if (!runtime_errmsg.empty())
|
||||
{
|
||||
obj = mxs_json_error(errmsg.c_str());
|
||||
obj = mxs_json_error(runtime_errmsg);
|
||||
runtime_errmsg.clear();
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <maxscale/session.hh>
|
||||
#include <maxscale/service.hh>
|
||||
#include <maxscale/filter.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
#include "internal/config.hh"
|
||||
#include "internal/modules.hh"
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/config.hh>
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/query_classifier.hh>
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -207,6 +207,24 @@ json_t* mxs_json_error(const char* format, ...)
|
||||
return json_error(message);
|
||||
}
|
||||
|
||||
json_t* mxs_json_error(const std::vector<std::string>& errors)
|
||||
{
|
||||
json_t* rval = nullptr;
|
||||
|
||||
if (!errors.empty())
|
||||
{
|
||||
auto it = errors.begin();
|
||||
rval = json_error(it->c_str());
|
||||
|
||||
for (it = std::next(it); it != errors.end(); ++it)
|
||||
{
|
||||
rval = mxs_json_error_append(rval, it->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
static json_t* json_error_append(json_t* obj, const char* message)
|
||||
{
|
||||
json_t* err = json_error_detail(message);
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <maxscale/version.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/modulecmd.hh>
|
||||
#include <maxscale/protocol.hh>
|
||||
#include <maxscale/router.hh>
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <maxbase/logger.hh>
|
||||
|
||||
#include <maxscale/config.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/session.hh>
|
||||
|
||||
namespace
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxbase/atomic.hh>
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/mariadb.hh>
|
||||
#include <maxscale/mysql_utils.hh>
|
||||
#include <maxscale/paths.h>
|
||||
@ -40,7 +40,7 @@
|
||||
#include <maxscale/routingworker.hh>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <mysqld_error.h>
|
||||
|
||||
#include "internal/config.hh"
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <maxbase/atomic.h>
|
||||
#include <maxbase/format.hh>
|
||||
#include <maxscale/config.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/modutil.hh>
|
||||
#include <maxscale/pcre2.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <maxscale/http.hh>
|
||||
#include <maxscale/jansson.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/modulecmd.hh>
|
||||
#include <maxscale/routingworker.hh>
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <maxscale/config.hh>
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/limits.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <maxscale/statistics.hh>
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/http.hh>
|
||||
#include <maxscale/maxscale.h>
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <maxscale/version.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/routingworker.hh>
|
||||
#include <maxscale/routingworker.hh>
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/dcb.hh>
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/modutil.hh>
|
||||
#include <maxscale/poll.hh>
|
||||
#include <maxscale/router.hh>
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <string>
|
||||
|
||||
#include <maxscale/jansson.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
using std::string;
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/modulecmd.hh>
|
||||
#include <maxscale/session.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
#include "../internal/monitor.hh"
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define MXS_MODULE_NAME "masking"
|
||||
#include "maskingfilter.hh"
|
||||
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/modulecmd.hh>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <maxscale/mysql_utils.hh>
|
||||
#include <maxscale/pcre2.hh>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
using std::auto_ptr;
|
||||
using std::string;
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <maxscale/service.hh>
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/modulecmd.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -100,7 +100,6 @@ void print_string_replace_newlines(const char* sql_string, size_t sql_str_len,
|
||||
const char* rep_newline, std::stringstream* output);
|
||||
|
||||
bool check_replace_file(const string& filename, FILE** ppFile);
|
||||
|
||||
}
|
||||
|
||||
QlaInstance::QlaInstance(const string& name, MXS_CONFIG_PARAMETER* params)
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <maxscale/ccdefs.hh>
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include <maxscale/jansson.hh>
|
||||
|
||||
#include "throttlefilter.hh"
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "clustrixmonitor.hh"
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
#include "../../../core/internal/config_runtime.hh"
|
||||
#include "../../../core/internal/service.hh"
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <maxscale/ccdefs.hh>
|
||||
|
||||
#include <string>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/json_api.hh>
|
||||
|
||||
/** Utility macros for printing both MXS_ERROR and json error */
|
||||
#define PRINT_MXS_JSON_ERROR(err_out, format, ...) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user