MXS-1220: Unify resource member naming

All resoures now use the `state` member to describe their internal
state. This includes servers, services and monitors. This means that the
`status` keyword can be reserved for something else and it can be removed
until it is needed again.

Changed the module maturity field to `maturity` to better describe its
purpose.
This commit is contained in:
Markus Mäkelä
2017-06-30 16:56:49 +03:00
parent a8bfdac49c
commit c7b9b7ac4a
13 changed files with 59 additions and 45 deletions

View File

@ -64,7 +64,7 @@ Status: 200 OK
"port": 3000, "port": 3000,
"protocol": "MySQLBackend" "protocol": "MySQLBackend"
}, },
"status": "Master, Running", // Server status string "state": "Master, Running", // Server state string
"version_string": "10.1.22-MariaDB", // Server version "version_string": "10.1.22-MariaDB", // Server version
"node_id": 3000, // Server node ID i.e. value of @@server_id "node_id": 3000, // Server node ID i.e. value of @@server_id
"master_id": -1, "master_id": -1,
@ -148,7 +148,7 @@ Status: 200 OK
"port": 3000, "port": 3000,
"protocol": "MySQLBackend" "protocol": "MySQLBackend"
}, },
"status": "Master, Running", "state": "Master, Running",
"version_string": "10.1.22-MariaDB", "version_string": "10.1.22-MariaDB",
"node_id": 3000, "node_id": 3000,
"master_id": -1, "master_id": -1,
@ -199,7 +199,7 @@ Status: 200 OK
"port": 3001, "port": 3001,
"protocol": "MySQLBackend" "protocol": "MySQLBackend"
}, },
"status": "Slave, Running", "state": "Slave, Running",
"version_string": "10.1.22-MariaDB", "version_string": "10.1.22-MariaDB",
"node_id": 3001, "node_id": 3001,
"master_id": 3000, "master_id": 3000,
@ -392,7 +392,7 @@ Response to `GET /v1/server/server1`:
"port": 3000, "port": 3000,
"protocol": "MySQLBackend" "protocol": "MySQLBackend"
}, },
"status": "Master, Running", "state": "Master, Running",
"version_string": "10.1.22-MariaDB", "version_string": "10.1.22-MariaDB",
"node_id": 3000, "node_id": 3000,
"master_id": -1, "master_id": -1,
@ -501,17 +501,17 @@ Server is in use:
Status: 403 Forbidden Status: 403 Forbidden
``` ```
### Set server status ### Set server state
``` ```
PUT /v1/servers/:name/set PUT /v1/servers/:name/set
``` ```
The _:name_ in the URI must map to a server name with all whitespace replaced The _:name_ in the URI must map to a server name with all whitespace replaced
with hyphens. This endpoint requires that the `status` parameter is passed with with hyphens. This endpoint requires that the `state` parameter is passed with
the request. The value of `status` must be one of the following values. the request. The value of `state` must be one of the following values.
|Value | Status Description | |Value | State Description |
|-----------|--------------------------------| |-----------|--------------------------------|
|master | Server is a Master | |master | Server is a Master |
|slave | Server is a Slave | |slave | Server is a Slave |
@ -525,7 +525,7 @@ For example, to set the server _db-server-1_ into maintenance mode, a request to
the following URL must be made: the following URL must be made:
``` ```
PUT /v1/servers/db-server-1/set?status=maintenance PUT /v1/servers/db-server-1/set?state=maintenance
``` ```
#### Response #### Response
@ -548,15 +548,15 @@ Missing or invalid parameter:
Status: 403 Forbidden Status: 403 Forbidden
``` ```
### Clear server status ### Clear server state
``` ```
POST /v1/servers/:name/clear POST /v1/servers/:name/clear
``` ```
The _:name_ in the URI must map to a server name with all whitespace replaced The _:name_ in the URI must map to a server name with all whitespace replaced
with hyphens. This endpoint requires that the `status` parameter is passed with with hyphens. This endpoint requires that the `state` parameter is passed with
the request. The value of `status` must be one of the values defined in the the request. The value of `state` must be one of the values defined in the
_set_ endpoint documentation. _set_ endpoint documentation.
#### Response #### Response

View File

@ -13,12 +13,12 @@
require('../common.js')() require('../common.js')()
exports.command = 'clear <command>' exports.command = 'clear <command>'
exports.desc = 'Clear object status' exports.desc = 'Clear object state'
exports.handler = function() {} exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('server <server> <status>', 'Clear server status', {}, function(argv) { .command('server <server> <state>', 'Clear server state', {}, function(argv) {
var target = 'servers/' + argv.server + '/clear?status=' + argv.status var target = 'servers/' + argv.server + '/clear?state=' + argv.state
doRequest(target, null, {method: 'POST'}) doRequest(target, null, {method: 'POST'})
}) })
.usage('Usage: clear <command>') .usage('Usage: clear <command>')

View File

@ -24,7 +24,7 @@ exports.builder = function(yargs) {
{'Address': 'attributes.parameters.address'}, {'Address': 'attributes.parameters.address'},
{'Port': 'attributes.parameters.port'}, {'Port': 'attributes.parameters.port'},
{'Connections': 'attributes.statistics.connections'}, {'Connections': 'attributes.statistics.connections'},
{'Status': 'attributes.status'} {'State': 'attributes.state'}
]) ])
}) })
.command('services', 'List services', {}, function() { .command('services', 'List services', {}, function() {
@ -39,7 +39,7 @@ exports.builder = function(yargs) {
.command('monitors', 'List monitors', {}, function() { .command('monitors', 'List monitors', {}, function() {
getCollection('monitors', [ getCollection('monitors', [
{'Monitor': 'id'}, {'Monitor': 'id'},
{'Status': 'attributes.state'}, {'State': 'attributes.state'},
{'Servers': 'relationships.servers.data[].id'} {'Servers': 'relationships.servers.data[].id'}
]) ])
}) })

View File

@ -13,12 +13,12 @@
require('../common.js')() require('../common.js')()
exports.command = 'set <command>' exports.command = 'set <command>'
exports.desc = 'Set object status' exports.desc = 'Set object state'
exports.handler = function() {} exports.handler = function() {}
exports.builder = function(yargs) { exports.builder = function(yargs) {
yargs yargs
.command('server <server> <status>', 'Set server status', {}, function(argv) { .command('server <server> <state>', 'Set server state', {}, function(argv) {
var target = 'servers/' + argv.server + '/set?status=' + argv.status var target = 'servers/' + argv.server + '/set?state=' + argv.state
doRequest(target, null, {method: 'POST'}) doRequest(target, null, {method: 'POST'})
}) })
.usage('Usage: set <command>') .usage('Usage: set <command>')

View File

@ -23,7 +23,7 @@ exports.builder = function(yargs) {
{'Server': 'id'}, {'Server': 'id'},
{'Address': 'attributes.parameters.address'}, {'Address': 'attributes.parameters.address'},
{'Port': 'attributes.parameters.port'}, {'Port': 'attributes.parameters.port'},
{'Status': 'attributes.status'}, {'State': 'attributes.state'},
{'Services': 'relationships.services.data[].id'}, {'Services': 'relationships.services.data[].id'},
{'Monitors': 'relationships.monitors.data[].id'}, {'Monitors': 'relationships.monitors.data[].id'},
{'Master ID': 'attributes.master_id'}, {'Master ID': 'attributes.master_id'},
@ -36,6 +36,7 @@ exports.builder = function(yargs) {
getResource('services/' + argv.service, [ getResource('services/' + argv.service, [
{'Service': 'id'}, {'Service': 'id'},
{'Router': 'attributes.router'}, {'Router': 'attributes.router'},
{'State': 'attributes.state'},
{'Started At': 'attributes.started'}, {'Started At': 'attributes.started'},
{'Current Connections': 'attributes.connections'}, {'Current Connections': 'attributes.connections'},
{'Total Connections': 'attributes.total_connections'}, {'Total Connections': 'attributes.total_connections'},
@ -47,7 +48,7 @@ exports.builder = function(yargs) {
.command('monitor <monitor>', 'Show monitor', {}, function(argv) { .command('monitor <monitor>', 'Show monitor', {}, function(argv) {
getResource('monitors/' + argv.monitor, [ getResource('monitors/' + argv.monitor, [
{'Monitor': 'id'}, {'Monitor': 'id'},
{'Status': 'attributes.state'}, {'State': 'attributes.state'},
{'Servers': 'relationships.servers.data[].id'}, {'Servers': 'relationships.servers.data[].id'},
{'Parameters': 'attributes.parameters'}, {'Parameters': 'attributes.parameters'},
{'Monitor Diagnostics': 'attributes.monitor_diagnostics'} {'Monitor Diagnostics': 'attributes.monitor_diagnostics'}
@ -57,7 +58,7 @@ exports.builder = function(yargs) {
getResource('sessions/' + argv.session, [ getResource('sessions/' + argv.session, [
{'Id': 'id'}, {'Id': 'id'},
{'Service': 'relationships.services.data[].id'}, {'Service': 'relationships.services.data[].id'},
{'Status': 'attributes.state'}, {'State': 'attributes.state'},
{'User': 'attributes.user'}, {'User': 'attributes.user'},
{'Host': 'attributes.remote'}, {'Host': 'attributes.remote'},
{'Connected': 'attributes.connected'}, {'Connected': 'attributes.connected'},
@ -77,7 +78,7 @@ exports.builder = function(yargs) {
{'Module': 'id'}, {'Module': 'id'},
{'Type': 'attributes.module_type'}, {'Type': 'attributes.module_type'},
{'Version': 'attributes.version'}, {'Version': 'attributes.version'},
{'Maturity': 'attributes.status'}, {'Maturity': 'attributes.maturity'},
{'Description': 'attributes.description'}, {'Description': 'attributes.description'},
{'Parameters': 'attributes.parameters'}, {'Parameters': 'attributes.parameters'},
{'Commands': 'attributes.commands'} {'Commands': 'attributes.commands'}

View File

@ -142,7 +142,6 @@ extern const char CN_SESSIONS[];
extern const char CN_SKIP_PERMISSION_CHECKS[]; extern const char CN_SKIP_PERMISSION_CHECKS[];
extern const char CN_SOCKET[]; extern const char CN_SOCKET[];
extern const char CN_STATE[]; extern const char CN_STATE[];
extern const char CN_STATUS[];
extern const char CN_SSL[]; extern const char CN_SSL[];
extern const char CN_SSL_CA_CERT[]; extern const char CN_SSL_CA_CERT[];
extern const char CN_SSL_CERT[]; extern const char CN_SSL_CERT[];

View File

@ -95,10 +95,11 @@ json_t* mxs_json_pointer(json_t* json, const char* json_ptr);
/** /**
* @brief Return a JSON formatted error * @brief Return a JSON formatted error
* *
* @param err Error description * @param format Format string
* @param ... Variable argument list
* *
* @return The error as JSON * @return The error as JSON
*/ */
json_t* mxs_json_error(const char* err); json_t* mxs_json_error(const char* format, ...);
MXS_END_DECLS MXS_END_DECLS

View File

@ -124,7 +124,6 @@ const char CN_SKIP_PERMISSION_CHECKS[] = "skip_permission_checks";
const char CN_SOCKET[] = "socket"; const char CN_SOCKET[] = "socket";
const char CN_SQL_MODE[] = "sql_mode"; const char CN_SQL_MODE[] = "sql_mode";
const char CN_STATE[] = "state"; const char CN_STATE[] = "state";
const char CN_STATUS[] = "status";
const char CN_SSL[] = "ssl"; const char CN_SSL[] = "ssl";
const char CN_SSL_CA_CERT[] = "ssl_ca_cert"; const char CN_SSL_CA_CERT[] = "ssl_ca_cert";
const char CN_SSL_CERT[] = "ssl_cert"; const char CN_SSL_CERT[] = "ssl_cert";

View File

@ -156,8 +156,19 @@ json_t* mxs_json_self_link(const char* host, const char* path, const char* id)
return links; return links;
} }
json_t* mxs_json_error(const char* message) json_t* mxs_json_error(const char* format, ...)
{ {
va_list args;
va_start(args, format);
int len = vsnprintf(NULL, 0, format, args);
va_end(args);
char message[len + 1];
va_start(args, format);
vsnprintf(message, sizeof(message), format, args);
va_end(args);
json_t* err = json_object(); json_t* err = json_object();
json_object_set_new(err, "detail", json_string(message)); json_object_set_new(err, "detail", json_string(message));

View File

@ -416,7 +416,7 @@ static json_t* module_json_data(const LOADED_MODULE *mod, const char* host)
json_object_set_new(attr, "version", json_string(mod->info->version)); json_object_set_new(attr, "version", json_string(mod->info->version));
json_object_set_new(attr, CN_DESCRIPTION, json_string(mod->info->description)); json_object_set_new(attr, CN_DESCRIPTION, json_string(mod->info->description));
json_object_set_new(attr, "api", json_string(mxs_module_api_to_string(mod->info->modapi))); json_object_set_new(attr, "api", json_string(mxs_module_api_to_string(mod->info->modapi)));
json_object_set_new(attr, CN_STATUS, json_string(mxs_module_status_to_string(mod->info->status))); json_object_set_new(attr, "maturity", json_string(mxs_module_status_to_string(mod->info->status)));
json_t* commands = json_array(); json_t* commands = json_array();
cb_param p = {commands, mod->module, host}; cb_param p = {commands, mod->module, host};

View File

@ -565,7 +565,7 @@ HttpResponse cb_delete_user(const HttpRequest& request)
HttpResponse cb_set_server(const HttpRequest& request) HttpResponse cb_set_server(const HttpRequest& request)
{ {
SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str()); SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str());
int opt = server_map_status(request.get_option("status").c_str()); int opt = server_map_status(request.get_option(CN_STATE).c_str());
if (opt) if (opt)
{ {
@ -573,13 +573,15 @@ HttpResponse cb_set_server(const HttpRequest& request)
return HttpResponse(MHD_HTTP_NO_CONTENT); return HttpResponse(MHD_HTTP_NO_CONTENT);
} }
return HttpResponse(MHD_HTTP_FORBIDDEN, mxs_json_error("Invalid or missing value for the `status` parameter")); return HttpResponse(MHD_HTTP_FORBIDDEN,
mxs_json_error("Invalid or missing value for the `%s` "
"parameter", CN_STATE));
} }
HttpResponse cb_clear_server(const HttpRequest& request) HttpResponse cb_clear_server(const HttpRequest& request)
{ {
SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str()); SERVER* server = server_find_by_unique_name(request.uri_part(1).c_str());
int opt = server_map_status(request.get_option("status").c_str()); int opt = server_map_status(request.get_option(CN_STATE).c_str());
if (opt) if (opt)
{ {
@ -587,7 +589,9 @@ HttpResponse cb_clear_server(const HttpRequest& request)
return HttpResponse(MHD_HTTP_NO_CONTENT); return HttpResponse(MHD_HTTP_NO_CONTENT);
} }
return HttpResponse(MHD_HTTP_FORBIDDEN, mxs_json_error("Invalid or missing value for the `status` parameter")); return HttpResponse(MHD_HTTP_FORBIDDEN,
mxs_json_error( "Invalid or missing value for the `%s` "
"parameter", CN_STATE));
} }
HttpResponse cb_modulecmd(const HttpRequest& request) HttpResponse cb_modulecmd(const HttpRequest& request)

View File

@ -1412,10 +1412,9 @@ static json_t* server_json_attributes(const SERVER* server)
json_object_set_new(attr, CN_PARAMETERS, params); json_object_set_new(attr, CN_PARAMETERS, params);
/** Store general information about the server state */ /** Store general information about the server state */
char* stat = server_status(server); char* stat = server_status(server);
json_object_set_new(attr, CN_STATUS, json_string(stat)); json_object_set_new(attr, CN_STATE, json_string(stat));
MXS_FREE(stat); MXS_FREE(stat);
json_object_set_new(attr, CN_VERSION_STRING, json_string(server->version_string)); json_object_set_new(attr, CN_VERSION_STRING, json_string(server->version_string));

View File

@ -81,7 +81,7 @@ describe("Server Relationships", function() {
after(stopMaxScale) after(stopMaxScale)
}); });
describe("Server Status", function() { describe("Server State", function() {
before(startMaxScale) before(startMaxScale)
it("create new server", function() { it("create new server", function() {
@ -90,34 +90,34 @@ describe("Server Status", function() {
}); });
it("set server into maintenance", function() { it("set server into maintenance", function() {
return request.put(base_url + "/servers/" + server.data.id + "/set?status=maintenance") return request.put(base_url + "/servers/" + server.data.id + "/set?state=maintenance")
.then(function(resp) { .then(function(resp) {
return request.get(base_url + "/servers/" + server.data.id) return request.get(base_url + "/servers/" + server.data.id)
}) })
.then(function(resp) { .then(function(resp) {
var srv = JSON.parse(resp) var srv = JSON.parse(resp)
srv.data.attributes.status.should.match(/Maintenance/) srv.data.attributes.state.should.match(/Maintenance/)
}) })
}); });
it("clear maintenance", function() { it("clear maintenance", function() {
return request.put(base_url + "/servers/" + server.data.id + "/clear?status=maintenance") return request.put(base_url + "/servers/" + server.data.id + "/clear?state=maintenance")
.then(function(resp) { .then(function(resp) {
return request.get(base_url + "/servers/" + server.data.id) return request.get(base_url + "/servers/" + server.data.id)
}) })
.then(function(resp) { .then(function(resp) {
var srv = JSON.parse(resp) var srv = JSON.parse(resp)
srv.data.attributes.status.should.not.match(/Maintenance/) srv.data.attributes.state.should.not.match(/Maintenance/)
}) })
}); });
it("set invalid status value", function() { it("set invalid state value", function() {
return request.put(base_url + "/servers/" + server.data.id + "/set?status=somethingstrange") return request.put(base_url + "/servers/" + server.data.id + "/set?state=somethingstrange")
.should.be.rejected .should.be.rejected
}); });
it("clear invalid status value", function() { it("clear invalid state value", function() {
return request.put(base_url + "/servers/" + server.data.id + "/clear?status=somethingstrange") return request.put(base_url + "/servers/" + server.data.id + "/clear?state=somethingstrange")
.should.be.rejected .should.be.rejected
}); });