Added basic REST interface to maxinfo plugin
This commit is contained in:
@ -34,10 +34,12 @@
|
||||
#include <time.h>
|
||||
#include <service.h>
|
||||
#include <session.h>
|
||||
#include <server.h>
|
||||
#include <router.h>
|
||||
#include <modules.h>
|
||||
#include <modinfo.h>
|
||||
#include <modutil.h>
|
||||
#include <monitor.h>
|
||||
#include <atomic.h>
|
||||
#include <spinlock.h>
|
||||
#include <dcb.h>
|
||||
@ -47,6 +49,7 @@
|
||||
#include <log_manager.h>
|
||||
#include <resultset.h>
|
||||
#include <version.h>
|
||||
#include <resultset.h>
|
||||
|
||||
|
||||
MODULE_INFO info = {
|
||||
@ -66,6 +69,7 @@ static char *version_str = "V1.0.0";
|
||||
static int maxinfo_statistics(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);
|
||||
static int maxinfo_ping(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);
|
||||
static int maxinfo_execute_query(INFO_INSTANCE *, INFO_SESSION *, char *);
|
||||
static int handle_url(INFO_INSTANCE *instance, INFO_SESSION *router_session, GWBUF *queue);
|
||||
|
||||
|
||||
/* The router entry points */
|
||||
@ -350,6 +354,10 @@ uint8_t *data;
|
||||
int length, len, residual;
|
||||
char *sql;
|
||||
|
||||
if (GWBUF_TYPE(queue) == GWBUF_TYPE_HTTP)
|
||||
{
|
||||
return handle_url(instance, session, queue);
|
||||
}
|
||||
if (session->queue)
|
||||
{
|
||||
queue = gwbuf_append(session->queue, queue);
|
||||
@ -655,3 +663,48 @@ PARSE_ERROR err;
|
||||
maxinfo_execute(session->dcb, tree);
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef RESULTSET *(*RESULTSETFUNC)();
|
||||
|
||||
static struct {
|
||||
char *uri;
|
||||
RESULTSETFUNC func
|
||||
} supported_uri[] = {
|
||||
{ "/services", serviceGetList },
|
||||
{ "/listeners", serviceGetListenerList },
|
||||
{ "/modules", moduleGetList },
|
||||
{ "/monitors", monitorGetList },
|
||||
{ "/sessions", sessionGetList },
|
||||
{ "/servers", serverGetList },
|
||||
{ "/variables", maxinfo_variables },
|
||||
{ "/status", maxinfo_status },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/**
|
||||
* We have data from the client, this is a HTTP URL
|
||||
*
|
||||
* @param instance The router instance
|
||||
* @param session The router session returned from the newSession call
|
||||
* @param queue The queue of data buffers to route
|
||||
* @return The number of bytes sent
|
||||
*/
|
||||
static int
|
||||
handle_url(INFO_INSTANCE *instance, INFO_SESSION *session, GWBUF *queue)
|
||||
{
|
||||
char *uri;
|
||||
int i;
|
||||
RESULTSET *set;
|
||||
|
||||
uri = (char *)GWBUF_DATA(queue);
|
||||
for (i = 0; supported_uri[i].uri; i++)
|
||||
{
|
||||
if (strcmp(uri, supported_uri[i].uri) == 0)
|
||||
{
|
||||
set = (*supported_uri[i].func)();
|
||||
resultset_stream_json(set, session->dcb);
|
||||
resultset_free(set);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -397,6 +397,29 @@ VARCONTEXT context;
|
||||
resultset_free(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the show variables output a a result set
|
||||
*
|
||||
* @return Variables as a result set
|
||||
*/
|
||||
RESULTSET *
|
||||
maxinfo_variables()
|
||||
{
|
||||
RESULTSET *result;
|
||||
static VARCONTEXT context;
|
||||
|
||||
context.like = NULL;
|
||||
context.index = 0;
|
||||
|
||||
if ((result = resultset_create(variable_row, &context)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR);
|
||||
resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Variables that may be sent in a show variables
|
||||
*/
|
||||
@ -486,6 +509,29 @@ VARCONTEXT context;
|
||||
resultset_free(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the show status data as a result set
|
||||
*
|
||||
* @return The show status data as a result set
|
||||
*/
|
||||
RESULTSET *
|
||||
maxinfo_status()
|
||||
{
|
||||
RESULTSET *result;
|
||||
static VARCONTEXT context;
|
||||
|
||||
context.like = NULL;
|
||||
context.index = 0;
|
||||
|
||||
if ((result = resultset_create(status_row, &context)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
resultset_add_column(result, "Variable_name", 40, COL_TYPE_VARCHAR);
|
||||
resultset_add_column(result, "Value", 40, COL_TYPE_VARCHAR);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute a select command parse tree and return the result set
|
||||
|
Reference in New Issue
Block a user