MXS-1220: Add self links to all resources
A self link to the resource itself provides a convenient way for the client to request a resource, modify it and call the self link to update it. This removes some of the burden on the client to keep track of the resource links by placing these in the resource itself.
This commit is contained in:

committed by
Markus Mäkelä

parent
ac7ec04af1
commit
50eafe19fe
@ -85,6 +85,7 @@ extern const char CN_REQUIRED[];
|
|||||||
extern const char CN_RETRY_ON_FAILURE[];
|
extern const char CN_RETRY_ON_FAILURE[];
|
||||||
extern const char CN_ROUTER[];
|
extern const char CN_ROUTER[];
|
||||||
extern const char CN_ROUTER_OPTIONS[];
|
extern const char CN_ROUTER_OPTIONS[];
|
||||||
|
extern const char CN_SELF[];
|
||||||
extern const char CN_SERVERS[];
|
extern const char CN_SERVERS[];
|
||||||
extern const char CN_SERVER[];
|
extern const char CN_SERVER[];
|
||||||
extern const char CN_SERVICES[];
|
extern const char CN_SERVICES[];
|
||||||
|
@ -96,6 +96,7 @@ const char CN_REQUIRED[] = "required";
|
|||||||
const char CN_RETRY_ON_FAILURE[] = "retry_on_failure";
|
const char CN_RETRY_ON_FAILURE[] = "retry_on_failure";
|
||||||
const char CN_ROUTER[] = "router";
|
const char CN_ROUTER[] = "router";
|
||||||
const char CN_ROUTER_OPTIONS[] = "router_options";
|
const char CN_ROUTER_OPTIONS[] = "router_options";
|
||||||
|
const char CN_SELF[] = "self";
|
||||||
const char CN_SERVERS[] = "servers";
|
const char CN_SERVERS[] = "servers";
|
||||||
const char CN_SERVER[] = "server";
|
const char CN_SERVER[] = "server";
|
||||||
const char CN_SERVICES[] = "services";
|
const char CN_SERVICES[] = "services";
|
||||||
|
@ -14,22 +14,27 @@
|
|||||||
/**
|
/**
|
||||||
* @file filter.c - A representation of a filter within MaxScale.
|
* @file filter.c - A representation of a filter within MaxScale.
|
||||||
*/
|
*/
|
||||||
#include <maxscale/filter.h>
|
|
||||||
#include <maxscale/filter.hh>
|
#include "maxscale/filter.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <maxscale/alloc.h>
|
#include <maxscale/alloc.h>
|
||||||
#include <maxscale/log_manager.h>
|
#include <maxscale/log_manager.h>
|
||||||
#include <maxscale/session.h>
|
#include <maxscale/session.h>
|
||||||
#include <maxscale/spinlock.h>
|
#include <maxscale/spinlock.h>
|
||||||
#include <maxscale/service.h>
|
#include <maxscale/service.h>
|
||||||
|
#include <maxscale/filter.hh>
|
||||||
|
|
||||||
#include "maxscale/filter.h"
|
|
||||||
#include "maxscale/config.h"
|
#include "maxscale/config.h"
|
||||||
#include "maxscale/modules.h"
|
#include "maxscale/modules.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */
|
static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */
|
||||||
static MXS_FILTER_DEF *allFilters = NULL; /**< 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();
|
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);
|
json_t* arr = service_relations_to_filter(filter, host);
|
||||||
|
|
||||||
if (json_array_size(arr) > 0)
|
if (json_array_size(arr) > 0)
|
||||||
|
@ -19,6 +19,11 @@
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::deque;
|
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 */
|
/** TODO: Move this to a C++ string utility header */
|
||||||
namespace maxscale
|
namespace maxscale
|
||||||
{
|
{
|
||||||
@ -93,7 +98,9 @@ HttpRequest::HttpRequest(struct MHD_Connection *connection, string url, string m
|
|||||||
m_connection(connection)
|
m_connection(connection)
|
||||||
{
|
{
|
||||||
process_uri(url, m_resource_parts);
|
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()
|
HttpRequest::~HttpRequest()
|
||||||
|
@ -162,6 +162,10 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/** Constants */
|
||||||
|
static const std::string HTTP_PREFIX;
|
||||||
|
static const std::string HTTPS_PREFIX;
|
||||||
|
|
||||||
std::map<std::string, std::string> m_options; /**< Request options */
|
std::map<std::string, std::string> m_options; /**< Request options */
|
||||||
mxs::Closer<json_t*> m_json; /**< Request body */
|
mxs::Closer<json_t*> m_json; /**< Request body */
|
||||||
std::string m_json_string; /**< String version of @c m_json */
|
std::string m_json_string; /**< String version of @c m_json */
|
||||||
|
@ -13,19 +13,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file monitor.c - The monitor module management routines
|
* @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 <maxscale/monitor.h>
|
#include <maxscale/monitor.h>
|
||||||
|
|
||||||
@ -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)));
|
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();
|
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)
|
if (monitor->databases)
|
||||||
{
|
{
|
||||||
json_t* arr = json_array();
|
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);
|
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;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <maxscale/config.h>
|
#include <maxscale/config.h>
|
||||||
#include <maxscale/service.h>
|
#include <maxscale/service.h>
|
||||||
@ -45,6 +46,8 @@ using maxscale::Semaphore;
|
|||||||
using maxscale::Worker;
|
using maxscale::Worker;
|
||||||
using maxscale::WorkerTask;
|
using maxscale::WorkerTask;
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
/** The latin1 charset */
|
/** The latin1 charset */
|
||||||
#define SERVER_DEFAULT_CHARSET 0x08
|
#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);
|
json_object_set_new(rval, "statictics", stats);
|
||||||
|
|
||||||
/** Store server relations to other objects */
|
/** Store relationships to other objects */
|
||||||
json_t* rel = json_object();
|
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);
|
json_t* arr = service_relations_to_server(server, host);
|
||||||
|
|
||||||
if (json_array_size(arr) > 0)
|
if (json_array_size(arr) > 0)
|
||||||
|
@ -12,31 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file service.c - A representation of the service within the gateway.
|
* @file service.c - A representation of a service within MaxScale
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <maxscale/cppdefs.hh>
|
#include <maxscale/cppdefs.hh>
|
||||||
@ -2429,8 +2405,14 @@ json_t* service_to_json(const SERVICE* service, const char* host)
|
|||||||
json_object_set_new(rval, "listeners", arr);
|
json_object_set_new(rval, "listeners", arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Store relationships to other objects */
|
||||||
json_t* rel = json_object();
|
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)
|
if (service->n_filters)
|
||||||
{
|
{
|
||||||
json_t* arr = json_array();
|
json_t* arr = json_array();
|
||||||
|
Reference in New Issue
Block a user