diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index bd9a5f5b3..2606a0afb 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -1978,7 +1978,7 @@ bool server_to_object_relations(Server* server, json_t* old_json, json_t* new_js bool runtime_alter_server_from_json(Server* server, json_t* new_json) { bool rval = false; - std::unique_ptr old_json(server_to_json(server, "")); + std::unique_ptr old_json(server->to_json("")); mxb_assert(old_json.get()); if (is_valid_resource_body(new_json) @@ -2038,7 +2038,7 @@ static bool is_valid_relationship_body(json_t* json) bool runtime_alter_server_relationships_from_json(Server* server, const char* type, json_t* json) { bool rval = false; - std::unique_ptr old_json(server_to_json(server, "")); + std::unique_ptr old_json(server->to_json("")); mxb_assert(old_json.get()); if (is_valid_relationship_body(json)) diff --git a/server/core/internal/server.hh b/server/core/internal/server.hh index e7a75b80e..775c19c53 100644 --- a/server/core/internal/server.hh +++ b/server/core/internal/server.hh @@ -24,8 +24,6 @@ #include #include -std::unique_ptr serverGetList(); - // Private server implementation class Server : public SERVER { @@ -298,6 +296,16 @@ public: */ void printServer(); + static std::unique_ptr getList(); + + /** + * @brief Convert a server to JSON format + * + * @param host Hostname of this server as given in request + * @return JSON representation of server or NULL if an error occurred + */ + json_t* to_json(const char* host); + DCB** persistent = nullptr;/**< List of unused persistent connections to the server */ private: @@ -358,13 +366,3 @@ private: Settings m_settings; /**< Server settings */ VersionInfo info; /**< Server version and type information */ }; - -/** - * @brief Convert a server to JSON format - * - * @param server Server to convert - * @param host Hostname of this server - * - * @return JSON representation of server or NULL if an error occurred - */ -json_t* server_to_json(const Server* server, const char* host); diff --git a/server/core/resource.cc b/server/core/resource.cc index f55a21be9..1f088472f 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -550,7 +550,7 @@ HttpResponse cb_get_server(const HttpRequest& request) { auto server = Server::find_by_unique_name(request.uri_part(1)); mxb_assert(server); - return HttpResponse(MHD_HTTP_OK, server_to_json(server, request.host())); + return HttpResponse(MHD_HTTP_OK, server->to_json(request.host())); } HttpResponse cb_all_services(const HttpRequest& request) diff --git a/server/core/server.cc b/server/core/server.cc index 0ecc35543..f327daaa3 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -25,11 +25,10 @@ #include #include -#include #include #include #include -#include +#include #include #include @@ -47,7 +46,6 @@ #include #include #include -#include #include #include "internal/monitor.hh" @@ -770,7 +768,7 @@ string Server::get_custom_parameter(const string& name) const * * @return A Result set */ -std::unique_ptr serverGetList() +std::unique_ptr Server::getList() { std::unique_ptr set = ResultSet::create({"Server", "Address", "Port", "Connections", "Status"}); @@ -1139,11 +1137,11 @@ static json_t* server_to_json_data(const Server* server, const char* host) return rval; } -json_t* server_to_json(const Server* server, const char* host) +json_t* Server::to_json(const char* host) { string self = MXS_JSON_API_SERVERS; - self += server->name(); - return mxs_json_resource(host, self.c_str(), server_to_json_data(server, host)); + self += name(); + return mxs_json_resource(host, self.c_str(), server_to_json_data(this, host)); } json_t* Server::server_list_to_json(const char* host) diff --git a/server/modules/routing/maxinfo/maxinfo_exec.cc b/server/modules/routing/maxinfo/maxinfo_exec.cc index b4d3ee19d..d30fbdde7 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.cc +++ b/server/modules/routing/maxinfo/maxinfo_exec.cc @@ -164,7 +164,7 @@ static void exec_show_clients(DCB* dcb, MAXINFO_TREE* tree) */ static void exec_show_servers(DCB* dcb, MAXINFO_TREE* tree) { - serverGetList()->write(dcb); + Server::getList()->write(dcb); } /**