MXS-2220 Use private Server class in config_runtime

Required for further changes.
This commit is contained in:
Esa Korhonen
2018-12-12 18:45:17 +02:00
parent 31ceee6d22
commit 383f5304d9
3 changed files with 23 additions and 24 deletions

View File

@ -131,7 +131,7 @@ static std::pair<bool, MXS_CONFIG_PARAMETER*> load_defaults(const char* name,
return {rval, params}; return {rval, params};
} }
bool runtime_link_server(SERVER* server, const char* target) bool runtime_link_server(Server* server, const char* target)
{ {
std::lock_guard<std::mutex> guard(crt_lock); std::lock_guard<std::mutex> guard(crt_lock);
@ -175,7 +175,7 @@ bool runtime_link_server(SERVER* server, const char* target)
return rval; return rval;
} }
bool runtime_unlink_server(SERVER* server, const char* target) bool runtime_unlink_server(Server* server, const char* target)
{ {
std::lock_guard<std::mutex> guard(crt_lock); std::lock_guard<std::mutex> guard(crt_lock);
@ -272,7 +272,7 @@ bool runtime_create_server(const char* name,
return rval; return rval;
} }
bool runtime_destroy_server(SERVER* server) bool runtime_destroy_server(Server* server)
{ {
std::lock_guard<std::mutex> guard(crt_lock); std::lock_guard<std::mutex> guard(crt_lock);
bool rval = false; bool rval = false;
@ -358,7 +358,7 @@ static SSL_LISTENER* create_ssl(const char* name,
return rval; return rval;
} }
bool runtime_enable_server_ssl(SERVER* server, bool runtime_enable_server_ssl(Server* server,
const char* key, const char* key,
const char* cert, const char* cert,
const char* ca, const char* ca,
@ -1626,7 +1626,7 @@ static bool service_to_filter_relation_is_valid(const std::string& type, const s
return type == CN_FILTERS && filter_find(value.c_str()); return type == CN_FILTERS && filter_find(value.c_str());
} }
static bool unlink_server_from_objects(SERVER* server, StringSet& relations) static bool unlink_server_from_objects(Server* server, StringSet& relations)
{ {
bool rval = true; bool rval = true;
@ -1641,7 +1641,7 @@ static bool unlink_server_from_objects(SERVER* server, StringSet& relations)
return rval; return rval;
} }
static bool link_server_to_objects(SERVER* server, StringSet& relations) static bool link_server_to_objects(Server* server, StringSet& relations)
{ {
bool rval = true; bool rval = true;
@ -1735,7 +1735,7 @@ static bool validate_ssl_json(json_t* params, object_type type)
return rval; return rval;
} }
static bool process_ssl_parameters(SERVER* server, json_t* params) static bool process_ssl_parameters(Server* server, json_t* params)
{ {
mxb_assert(server->server_ssl == NULL); mxb_assert(server->server_ssl == NULL);
bool rval = true; bool rval = true;
@ -1785,9 +1785,9 @@ static bool process_ssl_parameters(SERVER* server, json_t* params)
return rval; return rval;
} }
SERVER* runtime_create_server_from_json(json_t* json) Server* runtime_create_server_from_json(json_t* json)
{ {
SERVER* rval = NULL; Server* rval = NULL;
if (is_valid_resource_body(json) if (is_valid_resource_body(json)
&& server_contains_required_fields(json)) && server_contains_required_fields(json))
@ -1812,12 +1812,11 @@ SERVER* runtime_create_server_from_json(json_t* json)
{ {
if (runtime_create_server(name, address, port.c_str(), protocol, authenticator)) if (runtime_create_server(name, address, port.c_str(), protocol, authenticator))
{ {
rval = server_find_by_unique_name(name); rval = Server::find_by_unique_name(name);
mxb_assert(rval); mxb_assert(rval);
json_t* param = mxs_json_pointer(json, MXS_JSON_PTR_PARAMETERS); json_t* param = mxs_json_pointer(json, MXS_JSON_PTR_PARAMETERS);
if (!process_ssl_parameters(rval, param) if (!process_ssl_parameters(rval, param) || !link_server_to_objects(rval, relations))
|| !link_server_to_objects(rval, relations))
{ {
runtime_destroy_server(rval); runtime_destroy_server(rval);
rval = NULL; rval = NULL;
@ -1833,7 +1832,7 @@ SERVER* runtime_create_server_from_json(json_t* json)
return rval; return rval;
} }
bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_json) bool server_to_object_relations(Server* server, json_t* old_json, json_t* new_json)
{ {
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVICES) == NULL if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVICES) == NULL
&& mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_MONITORS) == NULL) && mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_MONITORS) == NULL)
@ -1961,7 +1960,7 @@ static bool is_valid_relationship_body(json_t* json)
return rval; return rval;
} }
bool runtime_alter_server_relationships_from_json(SERVER* server, const char* type, json_t* json) bool runtime_alter_server_relationships_from_json(Server* server, const char* type, json_t* json)
{ {
bool rval = false; bool rval = false;
std::unique_ptr<json_t> old_json(server_to_json(server, "")); std::unique_ptr<json_t> old_json(server_to_json(server, ""));
@ -2076,7 +2075,7 @@ static bool unlink_object_from_servers(const char* target, StringSet& relations)
for (StringSet::iterator it = relations.begin(); it != relations.end(); it++) for (StringSet::iterator it = relations.begin(); it != relations.end(); it++)
{ {
SERVER* server = server_find_by_unique_name(it->c_str()); auto server = Server::find_by_unique_name(*it);
if (!server || !runtime_unlink_server(server, target)) if (!server || !runtime_unlink_server(server, target))
{ {
@ -2094,7 +2093,7 @@ static bool link_object_to_servers(const char* target, StringSet& relations)
for (StringSet::iterator it = relations.begin(); it != relations.end(); it++) for (StringSet::iterator it = relations.begin(); it != relations.end(); it++)
{ {
SERVER* server = server_find_by_unique_name(it->c_str()); auto server = Server::find_by_unique_name(*it);
if (!server || !runtime_link_server(server, target)) if (!server || !runtime_link_server(server, target))
{ {

View File

@ -68,7 +68,7 @@ bool runtime_create_server(const char* name,
* @param server Server to destroy * @param server Server to destroy
* @return True if server was destroyed * @return True if server was destroyed
*/ */
bool runtime_destroy_server(SERVER* server); bool runtime_destroy_server(Server* server);
/** /**
* @brief Link a server to an object * @brief Link a server to an object
@ -81,7 +81,7 @@ bool runtime_destroy_server(SERVER* server);
* @return True if the object was found and the server was linked to it, false * @return True if the object was found and the server was linked to it, false
* if no object matching @c target was found * if no object matching @c target was found
*/ */
bool runtime_link_server(SERVER* server, const char* target); bool runtime_link_server(Server* server, const char* target);
/** /**
* @brief Unlink a server from an object * @brief Unlink a server from an object
@ -94,7 +94,7 @@ bool runtime_link_server(SERVER* server, const char* target);
* @return True if the object was found and the server was unlinked from it, false * @return True if the object was found and the server was unlinked from it, false
* if no object matching @c target was found * if no object matching @c target was found
*/ */
bool runtime_unlink_server(SERVER* server, const char* target); bool runtime_unlink_server(Server* server, const char* target);
/** /**
* @brief Alter server parameters * @brief Alter server parameters
@ -124,7 +124,7 @@ bool runtime_alter_server(Server* server, const char* key, const char* value);
* *
* @return True if SSL was successfully enabled * @return True if SSL was successfully enabled
*/ */
bool runtime_enable_server_ssl(SERVER* server, bool runtime_enable_server_ssl(Server* server,
const char* key, const char* key,
const char* cert, const char* cert,
const char* ca, const char* ca,
@ -271,7 +271,7 @@ bool runtime_destroy_service(Service* service);
* *
* @return Created server or NULL on error * @return Created server or NULL on error
*/ */
SERVER* runtime_create_server_from_json(json_t* json); Server* runtime_create_server_from_json(json_t* json);
/** /**
* @brief Alter a server using JSON * @brief Alter a server using JSON
@ -292,7 +292,7 @@ bool runtime_alter_server_from_json(Server* server, json_t* new_json);
* *
* @return True if the relationships were successfully modified * @return True if the relationships were successfully modified
*/ */
bool runtime_alter_server_relationships_from_json(SERVER* server, const char* type, json_t* json); bool runtime_alter_server_relationships_from_json(Server* server, const char* type, json_t* json);
/** /**
* @brief Create a new monitor from JSON * @brief Create a new monitor from JSON

View File

@ -312,7 +312,7 @@ HttpResponse cb_alter_server(const HttpRequest& request)
HttpResponse do_alter_server_relationship(const HttpRequest& request, const char* type) HttpResponse do_alter_server_relationship(const HttpRequest& request, const char* type)
{ {
SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str()); auto server = Server::find_by_unique_name(request.uri_part(1));
mxb_assert(server && request.get_json()); mxb_assert(server && request.get_json());
if (runtime_alter_server_relationships_from_json(server, type, request.get_json())) if (runtime_alter_server_relationships_from_json(server, type, request.get_json()))
@ -473,7 +473,7 @@ HttpResponse cb_alter_qc(const HttpRequest& request)
HttpResponse cb_delete_server(const HttpRequest& request) HttpResponse cb_delete_server(const HttpRequest& request)
{ {
SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str()); auto server = Server::find_by_unique_name(request.uri_part(1).c_str());
mxb_assert(server); mxb_assert(server);
if (runtime_destroy_server(server)) if (runtime_destroy_server(server))