diff --git a/include/maxscale/config.h b/include/maxscale/config.h index 7ea18424f..a876d8281 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -85,6 +85,7 @@ extern const char CN_REQUIRED[]; extern const char CN_RETRY_ON_FAILURE[]; extern const char CN_ROUTER[]; extern const char CN_ROUTER_OPTIONS[]; +extern const char CN_SELF[]; extern const char CN_SERVERS[]; extern const char CN_SERVER[]; extern const char CN_SERVICES[]; diff --git a/server/core/config.cc b/server/core/config.cc index 09abeb260..7a2dafabf 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -96,6 +96,7 @@ const char CN_REQUIRED[] = "required"; const char CN_RETRY_ON_FAILURE[] = "retry_on_failure"; const char CN_ROUTER[] = "router"; const char CN_ROUTER_OPTIONS[] = "router_options"; +const char CN_SELF[] = "self"; const char CN_SERVERS[] = "servers"; const char CN_SERVER[] = "server"; const char CN_SERVICES[] = "services"; diff --git a/server/core/filter.cc b/server/core/filter.cc index d225f45ba..d46fc007e 100644 --- a/server/core/filter.cc +++ b/server/core/filter.cc @@ -14,22 +14,27 @@ /** * @file filter.c - A representation of a filter within MaxScale. */ -#include -#include + +#include "maxscale/filter.h" + #include #include #include #include +#include + #include #include #include #include #include +#include -#include "maxscale/filter.h" #include "maxscale/config.h" #include "maxscale/modules.h" +using std::string; + static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */ static MXS_FILTER_DEF *allFilters = NULL; /**< The list of all filters */ @@ -506,8 +511,14 @@ json_t* filter_to_json(const MXS_FILTER_DEF* filter, const char* host) } } + /** Store relationships to other objects */ json_t* rel = json_object(); + string self = host; + self += "/filters/"; + self += filter->name; + json_object_set_new(rel, CN_SELF, json_string(self.c_str())); + json_t* arr = service_relations_to_filter(filter, host); if (json_array_size(arr) > 0) diff --git a/server/core/httprequest.cc b/server/core/httprequest.cc index 833f13f2a..b5a444203 100644 --- a/server/core/httprequest.cc +++ b/server/core/httprequest.cc @@ -19,6 +19,11 @@ using std::string; using std::deque; +#define HTTP_HOST_HEADER "Host" + +const std::string HttpRequest::HTTP_PREFIX = "http://"; +const std::string HttpRequest::HTTPS_PREFIX = "https://"; + /** TODO: Move this to a C++ string utility header */ namespace maxscale { @@ -93,7 +98,9 @@ HttpRequest::HttpRequest(struct MHD_Connection *connection, string url, string m m_connection(connection) { process_uri(url, m_resource_parts); - m_hostname = get_header("Host"); + // TODO: Add https support + m_hostname = HttpRequest::HTTP_PREFIX; + m_hostname += get_header(HTTP_HOST_HEADER); } HttpRequest::~HttpRequest() diff --git a/server/core/maxscale/httprequest.hh b/server/core/maxscale/httprequest.hh index 7863dc002..6986d676a 100644 --- a/server/core/maxscale/httprequest.hh +++ b/server/core/maxscale/httprequest.hh @@ -162,6 +162,10 @@ public: } private: + /** Constants */ + static const std::string HTTP_PREFIX; + static const std::string HTTPS_PREFIX; + std::map m_options; /**< Request options */ mxs::Closer m_json; /**< Request body */ std::string m_json_string; /**< String version of @c m_json */ diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 72543c190..ce93fa519 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -13,19 +13,6 @@ /** * @file monitor.c - The monitor module management routines - * - * @verbatim - * Revision History - * - * Date Who Description - * 08/07/13 Mark Riddoch Initial implementation - * 23/05/14 Massimiliano Pinto Addition of monitor_interval parameter - * and monitor id - * 30/10/14 Massimiliano Pinto Addition of disable_master_failback parameter - * 07/11/14 Massimiliano Pinto Addition of monitor network timeouts - * 08/05/15 Markus Makela Moved common monitor variables to MONITOR struct - * - * @endverbatim */ #include @@ -1561,8 +1548,24 @@ json_t* monitor_to_json(const MXS_MONITOR* monitor, const char* host) json_object_set_new(rval, "state", json_string(monitor_state_to_string(monitor->state))); + if (monitor->handle && monitor->module->diagnostics) + { + json_t* diag = monitor->module->diagnostics(monitor); + + if (diag) + { + json_object_set_new(rval, "monitor_diagnostics", diag); + } + } + json_t* rel = json_object(); + /** Store relationships to other objects */ + string self = host; + self += "/monitors/"; + self += monitor->name; + json_object_set_new(rel, CN_SELF, json_string(self.c_str())); + if (monitor->databases) { json_t* arr = json_array(); @@ -1580,16 +1583,6 @@ json_t* monitor_to_json(const MXS_MONITOR* monitor, const char* host) json_object_set_new(rval, "relationships", rel); - if (monitor->handle && monitor->module->diagnostics) - { - json_t* diag = monitor->module->diagnostics(monitor); - - if (diag) - { - json_object_set_new(rval, "monitor_diagnostics", diag); - } - } - return rval; } diff --git a/server/core/server.cc b/server/core/server.cc index 4cb9daa4b..cdb5cd926 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,8 @@ using maxscale::Semaphore; using maxscale::Worker; using maxscale::WorkerTask; +using std::string; + /** The latin1 charset */ #define SERVER_DEFAULT_CHARSET 0x08 @@ -1456,9 +1459,14 @@ json_t* server_to_json(const SERVER* server, const char* host) json_object_set_new(rval, "statictics", stats); - /** Store server relations to other objects */ + /** Store relationships to other objects */ json_t* rel = json_object(); + string self = host; + self += "/servers/"; + self += server->unique_name; + json_object_set_new(rel, CN_SELF, json_string(self.c_str())); + json_t* arr = service_relations_to_server(server, host); if (json_array_size(arr) > 0) diff --git a/server/core/service.cc b/server/core/service.cc index c6fe5c19d..f8342cd86 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -12,31 +12,7 @@ */ /** - * @file service.c - A representation of the service within the gateway. - * - * @verbatim - * Revision History - * - * Date Who Description - * 18/06/13 Mark Riddoch Initial implementation - * 24/06/13 Massimiliano Pinto Added: Loading users from mysql backend in serviceStart - * 06/02/14 Massimiliano Pinto Added: serviceEnableRootUser routine - * 25/02/14 Massimiliano Pinto Added: service refresh limit feature - * 28/02/14 Massimiliano Pinto users_alloc moved from service_alloc to - * serviceStartPort (generic hashable for services) - * 07/05/14 Massimiliano Pinto Added: version_string initialized to NULL - * 23/05/14 Mark Riddoch Addition of service validation call - * 29/05/14 Mark Riddoch Filter API implementation - * 09/09/14 Massimiliano Pinto Added service option for localhost authentication - * 13/10/14 Massimiliano Pinto Added hashtable for resources (i.e database names for MySQL services) - * 06/02/15 Mark Riddoch Added caching of authentication data - * 18/02/15 Mark Riddoch Added result set management - * 03/03/15 Massimiliano Pinto Added config_enable_feedback_task() call in serviceStartAll - * 19/06/15 Martin Brampton More meaningful names for temp variables - * 31/05/16 Martin Brampton Implement connection throttling - * 08/11/16 Massimiliano Pinto Added: service_shutdown() calls destroyInstance() hoosk for routers - * - * @endverbatim + * @file service.c - A representation of a service within MaxScale */ #include @@ -2429,8 +2405,14 @@ json_t* service_to_json(const SERVICE* service, const char* host) json_object_set_new(rval, "listeners", arr); } + /** Store relationships to other objects */ json_t* rel = json_object(); + string self = host; + self += "/services/"; + self += service->name; + json_object_set_new(rel, CN_SELF, json_string(self.c_str())); + if (service->n_filters) { json_t* arr = json_array();