7551 Commits

Author SHA1 Message Date
Markus Mäkelä
c30b817abc MXS-1220: Add warnings for invalid request JSON
Converted info level log messages to warnings and added a missing warning
to server creation.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
778631a860 MXS-1220: Add support for conditional HTTP requests
The REST API now supports the If-Modified-Since, If-Unmodified-Since,
If-Match and If-None-Match headers and returns the correct response if the
conditional fails.

Added tests for the date parsing and expanded the HTTP header tests in the
REST API test suite.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
3deb497394 MXS-1220: Add Last-Modified and ETag headers
The resource system now tracks both the time when a resource was last
modified and the revision number of the resource. This allows working
Last-Modified and ETag headers to be generated by the REST API.

The If-Modified-Since and If-None-Match request headers are not yet
processed and using them will always return the resource instead of a 304
Not Modified response.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
717f883839 Make service ports lock-free
The service port list is now iterated in a safe and lock-free manner. This
makes the handling of service ports somewhat simpler since once an item
has been added to the list it will never be removed. It also removes the
need to lock the service when checking whether a service listens on a port
which caused potential deadlocks.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
461cd6afd9 MXS-1220: Add creation of listeners via REST API
Listeners can now be created via the REST API by doing a POST request to
the service listener resource.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
3e1ff70d7d MXS-1220: Respond with 200 OK to root level requests
If a request to the `/` resource is made, the API responds with an 200
OK. This is done to make it possible to use the HTTP health check
mechanism found in many cloud load balancers.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
e3ff3b56bc MXS-1220: Add test for /maxscale/logs/ endpoint
The test alters logging options and flushes the logs.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
efc5461daa MXS-1220: Return 204 No Content for PUT and POST request
Returning 204 No Content removes the cost of always sending back the
modified resource. If the modified resource is required, a GET request
should be made to retrieve it.

Updated tests to account for this change.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
a384665141 MXS-1220: Allow modification of logging options
The logging options can now be modified with a PUT request.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
1cb2783106 MXS-1220: Implement /maxscale/logs resource
The /maxscale/logs resource exposes information about the state of logging
in MaxScale.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
d4212b9c78 MXS-1220: Add request option test
Currently only the `pretty=true` option is supported but it is also
tested.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
16e597d43e MXS-1220: Expand REST API test suite
Added tests for services and extended the monitor test suite to test
actions on monitors.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
0e57bec4ef MXS-1220: Add threads resource
The threads are now a REST API resource exposed via the /maxscale/threads
resource collection.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
ac21443529 MXS-1220: Make modules proper resources
The /maxscale/modules/ endpoint is now a resource collection and the
/maxscale/modules/:module endpoint exposes the individual resources.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
08dca8c273 MXS-1220: Treat service listeners as service sub-resources
The listeners under the /services/:service/listeners collection are now
fully JSON API compliant resources.

The listeners could also be exposed as a /listeners collection to easily
group all listener type resources in one place. This approach does has
some semantical and practical problems, namely the fact that each listener
has a many-to-one relationship with its service and listeners by
themselves can't exist alone.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
1d98b4b67b MXS-1220: Return 403 Forbidden for invalid requests
The JSON API specification suggests that the API returns the 403 Forbidden
error when the user does an invalid request. The 400 Bad Request isn't the
ideal error for cases where the syntax is correct but the action being
performed is wrong.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
798ee840a8 MXS-1220: Make /maxscale/ resource conform to JSON API
The /maxscale/ resource now conforms to the JSON API and a test checks
that it the returned JSON is valid.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
7ce20b75d7 MXS-1220: Extend and fix REST API tests
Fixed a few broken tests and extended the monitor tests.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
18b52adaeb MXS-1220: Fix minor bug in monitor creation
The JSON validation function wasn't using the JSON Pointer function for
all values.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
c1968aac2f MXS-1220: Migrate create/update monitor to JSON API format
The creation and modification of moitor now supports the JSON API
conforming format generated by the GET endpoints.

Also added tests for creating and altering monitors via the REST API.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
9495438f2b MXS-1220: Add server test
The test creates, alters and destroys servers.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
a3c683ab87 MXS-1220: Simplify test creation
The tests now automatically start MaxScale before each test block and stop
it and perform cleanup after the test. This is done by simply calling the
`before.sh` and `after.sh` scripts before each test block.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
6b0fabf834 MXS-1220: Make REST API locally testable
The `test_rest_api` make target creates a discardable installation of
MaxScale which is used to launch a local instance of MaxScale. This local
instance is then used to test the REST API.

This is definitely not an efficient way to test the MaxScale but it allows
local testing without virtual machines or containers.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
6c220a1151 MXS-1220: Migrate create/update server to JSON API format
The creation and modification of servers now supports the JSON API
conforming format generated by the GET endpoints.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
2f8db4ec1a MXS-1220: Add JSON Pointer support for json_t objects
Using the JSON Pointer syntax specified in RFC 6901
(https://tools.ietf.org/html/rfc6901) allows for a convenient way to
access values deep in a JSON object.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
432a6d6f28 MXS-1220: Reorganize filter resource
The filter resource now conforms to the JSON API schema. Added a test case
for the individual filter resource.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
b9a5d91fe6 MXS-1220: Reorganize monitor resource
The monitor resource now conforms to the JSON API schema. Added a test
case for the individual monitor resource.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
fb7f283316 MXS-1220: Reorganize service resource
The service resource now conforms to the JSON API schema. Added a test
case for individual resources and resource collections.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
ca62749f25 MXS-1220: Factor out common code from JSON object creation
The JSON objects that are created from the various core MaxScale objects
share a lot of common code. Moving this into a separate files removes the
redundant code.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
5ae9ff9663 MXS-1220: Add simple REST API validator
The validator uses Node.js to check that the REST API endpoints conform to
the specified schema.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
624434a6d4 MXS-1220: Compare headers case-insensitively
The header names are not case sensitive.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
49b45acd13 MXS-1220: Reorganize server resource
The server resource now conforms to the JSON API schema.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
dcf9c8dab6 MXS-1220: Reorganize sessions resource
The sessions resource now follows the JSON API specification:

    http://jsonapi.org/

This makes the API relatively easier to use as the specification and the
client libraries to consume this data exist.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
b2e94fc73c MXS-1220: Add versioned URLs
Added versioning to URLs. This should allow somewhat safe modification to
the API after it has been finished.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
0ea58ea6bc Add dependency on FLEX/BISON parts for dbfwfilter
The dbfwfilter didn't depend on the two targets which could cause
compilation problems when running a parallel build.
2017-05-09 15:31:58 +03:00
Markus Mäkelä
c7cffa0722 Add atomic compare-and-swap
The atomic compare-and-swap can be used to implement lock-free
structures. The planned use for this is to remove some of the locking done
in the services when listeners are being manipulated.
2017-05-09 15:28:04 +03:00
Markus Mäkelä
18ca4189f0 Fix testbinlogrouter
The test used service credentials directly instead of copying them.
2017-05-09 09:53:02 +03:00
Markus Mäkelä
c27b2a1805 Fix internal test header
The polling and message queue systems weren't initalized.
2017-05-09 09:53:02 +03:00
Markus Mäkelä
9e68726219 Fix internal test suite
Fixed minor problems in DCB and configuration tests.
2017-05-09 09:53:02 +03:00
Esa Korhonen
ee20191645 KILL [CONNECTION | QUERY] support, part2B
Various small changes to part2, as suggested by comments and otherwise.
Mostly renaming, working logic should not change.

Exception: session id changed to 64bit in the container and associated
functions. Another commit will change it to 64bit in the session itself.
2017-05-08 09:58:02 +03:00
Esa Korhonen
17f6e94cba KILL [CONNECTION | QUERY] support, part2
MySQL sessions are added to a hasmap when created, removed when closed.
MYSQL_COM_PROCESS_KILL is now detected, the thread_id is read and the kill
command sent to all worker threads to find the correct session. If found, a
fake hangup even is created for the client dcb.

As is, this function is of little use since the client could just disconnect
itself instead. Later on, additional commands of this nature will be  added.
2017-05-08 09:51:07 +03:00
Johan Wikman
f66620c89c Accept auto_ptr<T> where T is derived type
Without the member template it is not possible to pass an auto_ptr
instantiated with a derived type to post() or broadcast().

The reason is that the conversion constructor and conversion
operator of auto_ptr are equally good for that purpose, and hence
the compilation ends with an error.
2017-05-08 09:36:16 +03:00
Markus Mäkelä
5dc49a59be Fix build failures on CentOS 6
The older C++ compiler doesn't support struct initialization with explicit
values. In addition to this, fixed a few other warnings that caused
errors.
2017-05-05 19:59:36 +03:00
Johan Wikman
6c4a4a3ee0 Do not inherit WorkerDisposableTask from WorkerTask
WorkerDisposableTask is intended to be passed using auto_ptr, to
make it plain that the ownership is moved. If it's inherited from
WorkerTask it can be passed as a WorkerTask, which is confusing as
it in that case will not be disposed of.
2017-05-04 14:06:44 +03:00
Johan Wikman
5de5609692 Ensure messages are a multiple of 8
The compiler will anyway insert padding to ensure the size of the
structure is a multiple of 8. That will under Valgrind show up as
writes of uninitialized data when the messages are sent over the
pipe.

Rather than forcing the structure to be aligned on 4 byte boundary
we simply expand the id field to an 8 byte type.
2017-05-04 13:09:19 +03:00
Markus Mäkelä
bcbff5da1b MXS-1220: Add POST and DELETE documentation for servers
Added POST and DELETE documentation on the servers resource. Also cleaned
up formatting.
2017-05-04 09:17:54 +03:00
Markus Mäkelä
a3ae9d5401 MXS-1220: Add missing JSON fields to servers
Added missing `monitoruser` and `monitorpw` parameters to the JSON output
of a server.
2017-05-04 09:17:54 +03:00
Markus Mäkelä
c1a1f18d1a MXS-1220: Update server resource documentation
Updated server resource documentation with new output and updated
instructions on how to modify servers via the REST API.
2017-05-04 09:17:53 +03:00
Markus Mäkelä
301e3f0d19 MXS-1220: Fix parameter values that refer to objects
The parameters were validated with the correct object names but the actual
parameter values weren't converted to the new system. This caused a crash
when the service parameter validation was successful but the actual
retrieval of that parameter resulted in a NULL pointer.
2017-05-04 09:17:53 +03:00
Markus Mäkelä
dcbd91deee Fix filters parameter processing
The filter names for the service parameter `filters` weren't converted
into the new format. This caused a configuration error when a filter with
significant whitespace in its name was used in a service.
2017-05-04 09:17:53 +03:00