7491 Commits

Author SHA1 Message Date
Markus Mäkelä
fdf279265a MXS-1220: Fix minor bugs
Destroyed servers were still shown as a part of the servers resource
collection.

If a parameter defined in persisted configurations was replaced, the value
would be appended to itself after it was replaced.

Return correct error codes for internal errors.

The server check was checking for old parameter locations.
2017-05-04 09:17:50 +03:00
Markus Mäkelä
d248c7e081 MXS-1220: Add PUT support for services
Service parameters can now be altered with a PUT request to the REST
API. This allows general level parameters to be altered.

Module specific parameters need to be altered with a different mechanism,
namely the module command system. This requires that a generic way to call
a function needs to be devised.
2017-05-04 09:17:49 +03:00
Markus Mäkelä
d282b14b36 Allow runtime changes to service parameters
General service parameters can now be altered at runtime.
2017-05-04 09:17:49 +03:00
Markus Mäkelä
f7fefad2e6 Improve persisted configuration handling
When a persisted configuration file is read, the values in it are
considered to be more up-to-date than the ones in the main configuration
file. This allows all objects to be persisted in a more complete form
making it easier to change configuration values at runtime.

This change is intended to help make runtime alterations to services
possible.
2017-05-04 09:17:49 +03:00
Markus Mäkelä
b736776c8f MXS-1220: Temporarily remove PATCH method
The PATCH method isn't supported in older versions of microhttpd. As this
functionality wasn't used, it can be removed until it is needed. The PUT
method already allows updates by defining complete resources so PATCH is
only an improvement, not a requirement.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
e62be5034a Use constant sized arrays for some service strings
The `user`, `password`, `version_string` and `weightby` values should be
allocated as a part of the service structure. This allows them to be
modified at runtime without having to worry about memory allocation
problems.

Although this removes the problem of reallocation, it still does not make
the updating of the strings thread-safe. This can cause invalid values to
be read from the service strings.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
b434c94563 Prevent monitor deadlocks with repeated restarts
If a monitor is started and stopped before the external monitoring thread
has had time to start, a deadlock will occur.

The first thing that the monitoring threads do is read the monitor handle
from the monitor object. This handle is given as the return value of
startMonitor and it is stored in the monitor object. As this can still be
NULL when the monitor thread starts, the threads use locks to prevent
this.

The correct way to prevent this is to pass the handle as the thread
parameter so that no locks are required.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
a4e361b5e5 Add atomic load/store operations on pointers
Added atomic operations on pointers. Also removed extra return statements
on void functions.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
1e1c4abcb7 MXS-1220: Add PUT support for monitors
Monitor resources can now be altered with a PUT request. The method allows
alterations on all parameters that the maxadmin `alter monitor` command
allows.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
690d592a94 MXS-1220: Implement /sessions/ resource
The /sessions/ resource was not implemented due to changes in the core
polling mechanics. With the new worker thread messaging system, sessions
can be listed in a safe manner.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
cd6e0ab5e9 MXS-1220: Show parameters for services, filters and monitors
The service, filter and monitor resources now have a "parameters" value
which contains a set of all configuration parameters for that object. This
set contains both standard and non-standard parameters.

Also fixed a mistake in the constant name definitions for the monitor
parameters "events" and "script".
2017-05-04 09:17:47 +03:00
Markus Mäkelä
722ca4c8d1 MXS-1220: Add service parameters to service resource
The service resource now exposes the parameters that were given to
it. This allows general service parameters to be changed at runtime
through the REST API.
2017-05-04 09:17:47 +03:00
Markus Mäkelä
fc887c7f5f MXS-1220: Add old router diagnostic interface
Added back the old diagnostic entry point to the router interface.
2017-05-04 09:17:42 +03:00
Markus Mäkelä
b1294f083c MXS-1220: Add old diagnostic interface for monitors and authenticators
Added back the old diagnostic entry point in the monitor and authenticator
interfaces.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
07175ed86b MXS-1220: Add old filter diagnostic interface
Added old diagnostic interface for filters.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
dd68069471 MXS-1220: Add back the old diagnostic entry point
This makes 2.2 maxadmin backwards compatible with 2.1.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
bab7957952 MXS-1220: Only process updated server parameters
The alteration function is only called when the value of a parameter
changes. This removes some of the redundant logging that was caused by
calling the alteration function with the same values.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
84d085ef39 MXS-1220: Only list active server references
The services listed disabled server references in their relationships.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
bcc3f11c4b MXS-1220: Fix upload data processing
The uploaded data is not a null-terminated string.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
50eafe19fe 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.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
ac7ec04af1 MXS-1220: Change default port to 8989
Port 8080 is commonly used as the alternative HTTP port. According to
Wikipedia, port 8989 isn't used by any well-known protocol:

    https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
2017-05-04 09:14:04 +03:00
Markus Mäkelä
99f25b1c31 MXS-1220: Add support for HEAD and OPTIONS methods
All resources now support HEAD and OPTIONS methods.

The HEAD response is generated by truncating a GET request on the same
resource. This does not work with other methods as they could require a
message body.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
47d819b008 MXS-1220: Make HTTP request handler parameters const
The HttpRequest can be const as the request itself will not be modified.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
043ed95bdf MXS-1220: Add PUT support for servers
The server can now be modified with a PUT request of a modified server
resource. The server resource was reorganized to have the parameters as a
separate entity from the other more general entities of the resource.

The PUT/POST functions return a more appropriate error message when no
request body is provided.

Moved some of the constant names used in server.cc into the config.h
header.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
1e55ee5b2f Add more common constants
Now all relevant and working core configuration parameters have constants
for their names. This removes some of the risk that comes with the
repetition of the same parameter name in more than place.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
695a4032ca Use common constants for monitor and server parameters
The parameter names for monitors and servers now use a set of constant
names. This removes some of the errors caused by spelling mistakes when
the same parameter name is repeated in multiple places.

The service, filter and listener parameters should also be converted to
constants. This allows for a consistent user experience.
2017-05-04 09:14:04 +03:00
Markus Mäkelä
9aa4138705 MXS-1220: Add POST handling for monitors
Doing a POST on the /monitors/ resource now creates a new monitor.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
076599ee5e MXS-1220: Make the parameters of the diagnostic entry points const
The diagnostic entry points should not modify the state of the object
being diagnosed.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
c17c451fb5 MXS-1220: Move header generation back to HttpResponse
The actual list of headers is not known when the request is first
generated. This prevents the headers from being generated in admin.cc
which handles things on a lower level.

The moving of the header generation is done with the OPTIONS method in
mind. This header needs to be generated inside the RootResource class
which manages the navigation of the resources.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
bc3cfe0221 MXS-1220: Fix memory leaks
Some of the JSON objects created in the diagnostic functions leaked
memory.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
ebc9e4bd3b MXS-1220: Clean up resource, request and response headers
Cleaned up various parts of the resource, request and response class
headers.

Moved `using` declarations into .cc files.

Made the Resource class non-copyable as it isn't really meant to be
copied.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
80104d6dad MXS-1220: Add POST handling for servers
New servers can now be created by POSTing a new server definition to the
/servers/ resource.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
46344b204a MXS-1220: Properly handle request with data
The data was not processed correctly and instead an error was sent to the
client as soon as the request arrived.

Created a class that somewhat abstracts the internals of the client
request processing.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
3d2219e8ef MXS-1220: Add missing relationships
The relationships from servers to services and monitors and filters to
services were not implemented. Now each server lists the services and
monitors that use it and each filter lists the services that use the
filter.

This enables the creation of a server and linking of that server to
services and monitors in one atomic operation.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
b6add43bd2 MXS-1220: Express relations in JSON API style
The JSON API (http://jsonapi.org/) specifies a way to express relations in
a somewhat generic way. By moving towards a more generic schema for the
resources, it will be easier to handle the modification of the relations
between these resources.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
5b9c276123 MXS-1220: Create corrent relation links
When a resource has a relation to another resource, it should be expressed
as a working link to the resource. By passing the hostname of the server
to the functions, we are able to generate working relation links.
2017-05-04 09:14:01 +03:00
Markus Mäkelä
978af12a91 MXS-1220: Simplify resource path handling
The resources are now declared by simply typing the path that they match
and providing a callback for that path. This makes it easier to add new
resources without having to create a new class for each added resource
endpoint. It also removes some of the pathname processing that was done
inside the child class handler functions.
2017-05-04 09:12:16 +03:00
Markus Mäkelä
52e075963e MXS-1220: Reorganize request and response processing
The standard response headers are now generated at a higher level. This
reduces the scope of the HttpResponse class making it a leaner wrapper
around a few simple variables, namely the JSON body of the response.

The HttpRequest now exposes the Host header that the client sent. This
allows resource relations to be real links that work without modification.
2017-05-04 09:12:16 +03:00
Markus Mäkelä
8c77e62872 MXS-1220: Make nested resources links
If a resource can be accessed from more than one place, it should be a
link. The previous change that duplicated the content for nested resources
wasn't a very clean solution. With links, the content is easier to browse
using a normal browser.
2017-05-04 09:12:16 +03:00
Markus Mäkelä
ec6f3d566b MXS-1220: Implement JSON diagnostics in binlogrouter
The binlogrouter now implements the JSON diagnistics entry point.
2017-05-04 09:12:16 +03:00
Markus Mäkelä
52e0cc8e16 MXS-1220: Add HTTP BA authentication
The admin interface now supports Basic Access authentication. This is not
a secure method of authentication and it should not be used without
unencrypted connections.

Made the admin interface port, authentication, username and password
configurable.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
d242203279 MXS-1220: Use libmicrohttpd for the HTTP handling
The HTTP side of the REST API is better handled with an actual
library. The libmicrohttpd library provides a convenient way of handling
the HTTP traffic between the clients and MaxScale.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
eb3ff1cc7b MXS-1220: Implement JSON diagnostics for most routers
All routers except the binlogrouter now fully implement the JSON
diagnostic entry point. The binlogrouter needs to be handled in a separate
commit as it produces a large amount of diagnostic output.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
25c8fb8556 MXS-1220: Implement JSON diagnostics entry point all filters
The second and final part of the filters now implement the JSON version of
the diagnostics function.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
12baa304e6 MXS-1220: Implement JSON diagnostics entry point in first part of filters
First part of the filters now implement the JSON version of the
diagnostics function. The rest are converted in a followup commit.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
4804c975ad MXS-1220: Implement JSON diagnostics entry point in autheticators
All autheticators now implement the JSON version of the diagnostics
function.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
5e679aa167 MXS-1220: Implement JSON diagnostics entry point in monitors
All monitors now implement the JSON version of the diagnostics function.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
9d108a58de MXS-1220: Use new diagnostics in avrorouter
The avrorouter now implements the new diagnostics API entry point.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
bbe0620944 MXS-1220: Add JSON return value to diagnostics entry points
The modules that implement a diagnostics entry point now return a JSON
type object. This removes the need to format data inside the modules.

The module implementations of these are not yet complete which means that
MaxScale will fail to compile.
2017-05-04 09:12:15 +03:00
Markus Mäkelä
94ebef0703 MXS-1220: Expand nested service and monitor resources
As a service is a collection of other resources, it makes sense to expand
those resources that were previously expressed as relative paths. This way
the API can be readily consumed without altering the pathnames to
links. The downside to this is the increased bandwidth consumption and
possible excess data.
2017-05-04 09:12:15 +03:00