MXS-1220: Add simple functionality to resources
The resources now properly process parts of the uri. This allows, for example, certain sessions to be inspected. The current functionality is only intended for testing and provides no useful functionality. The actions taken by the resource manager are not done via the inter-thread messaging system. When the implementation of the messages and the JSON representation of the resources is done, the REST API resource can actually be used.
This commit is contained in:
parent
900bf2db5a
commit
b975518996
@ -16,6 +16,10 @@
|
||||
#include "maxscale/resource.hh"
|
||||
#include "maxscale/httprequest.hh"
|
||||
#include "maxscale/httpresponse.hh"
|
||||
#include "maxscale/session.h"
|
||||
#include "maxscale/filter.h"
|
||||
#include "maxscale/monitor.h"
|
||||
#include "maxscale/service.h"
|
||||
|
||||
using mxs::SpinLock;
|
||||
using mxs::SpinLockGuard;
|
||||
@ -37,7 +41,25 @@ class ServersResource: public Resource
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
if (request.uri_part_count() == 1)
|
||||
{
|
||||
// Show all servers
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str());
|
||||
|
||||
if (server)
|
||||
{
|
||||
// Show one server
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpResponse(HTTP_404_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -46,7 +68,25 @@ class ServicesResource: public Resource
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
if (request.uri_part_count() == 1)
|
||||
{
|
||||
// Show all services
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
SERVICE* service = service_find(request.uri_part(1).c_str());
|
||||
|
||||
if (service)
|
||||
{
|
||||
// Show one service
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpResponse(HTTP_404_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -55,12 +95,86 @@ class FiltersResource: public Resource
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
if (request.uri_part_count() == 1)
|
||||
{
|
||||
// Show all filters
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_FILTER_DEF* filter = filter_def_find(request.uri_part(1).c_str());
|
||||
|
||||
if (filter)
|
||||
{
|
||||
// Show one filter
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpResponse(HTTP_404_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class MonitorsResource: public Resource
|
||||
{
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
if (request.uri_part_count() == 1)
|
||||
{
|
||||
// Show all monitors
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_MONITOR* monitor = monitor_find(request.uri_part(1).c_str());
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
// Show one monitor
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpResponse(HTTP_404_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SessionsResource: public Resource
|
||||
{
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
if (request.uri_part_count() == 1)
|
||||
{
|
||||
// Show all sessions
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
int id = atoi(request.uri_part(1).c_str());
|
||||
MXS_SESSION* session = session_get_by_id(id);
|
||||
|
||||
if (session)
|
||||
{
|
||||
session_put_ref(session);
|
||||
// Show session statistics
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpResponse(HTTP_404_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class UsersResource: public Resource
|
||||
{
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
@ -73,24 +187,52 @@ class LogsResource : public Resource
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
if (request.uri_part(2) == "flush")
|
||||
{
|
||||
// Flush logs
|
||||
if (mxs_log_rotate() == 0)
|
||||
{
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HttpResponse(HTTP_500_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show log status
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SessionsResource: public Resource
|
||||
class ThreadsResource : public Resource
|
||||
{
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
// Show thread status
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
};
|
||||
|
||||
class UsersResource: public Resource
|
||||
class TasksResource : public Resource
|
||||
{
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
// Show housekeeper tasks
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
};
|
||||
|
||||
class ModulesResource : public Resource
|
||||
{
|
||||
protected:
|
||||
HttpResponse handle(HttpRequest& request)
|
||||
{
|
||||
// Show modules
|
||||
return HttpResponse(HTTP_200_OK);
|
||||
}
|
||||
};
|
||||
@ -101,6 +243,9 @@ public:
|
||||
CoreResource()
|
||||
{
|
||||
m_children["logs"] = SResource(new LogsResource());
|
||||
m_children["threads"] = SResource(new ThreadsResource());
|
||||
m_children["tasks"] = SResource(new TasksResource());
|
||||
m_children["modules"] = SResource(new ModulesResource());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -993,4 +993,4 @@ void session_clear_stmt(MXS_SESSION *session)
|
||||
uint32_t session_get_next_id()
|
||||
{
|
||||
return atomic_add_uint32(&next_session_id, 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user