Merge branch '2.2' into develop
This commit is contained in:
@ -23,6 +23,7 @@
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <maxscale/atomic.h>
|
||||
#include <maxscale/clock.h>
|
||||
@ -1316,6 +1317,28 @@ static bool is_valid_resource_body(json_t* json)
|
||||
runtime_error("No '%s' field defined", MXS_JSON_PTR_DATA);
|
||||
rval = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check that the relationship JSON is well-formed
|
||||
const std::vector<const char*> relations =
|
||||
{
|
||||
MXS_JSON_PTR_RELATIONSHIPS "/servers",
|
||||
MXS_JSON_PTR_RELATIONSHIPS "/services",
|
||||
MXS_JSON_PTR_RELATIONSHIPS "/monitors",
|
||||
MXS_JSON_PTR_RELATIONSHIPS "/filters",
|
||||
};
|
||||
|
||||
for (auto it = relations.begin(); it != relations.end(); it++)
|
||||
{
|
||||
json_t* j = mxs_json_pointer(json, *it);
|
||||
|
||||
if (j && !json_is_object(j))
|
||||
{
|
||||
runtime_error("Relationship '%s' is not an object",*it);
|
||||
rval = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
@ -1555,7 +1578,8 @@ SERVER* runtime_create_server_from_json(json_t* json)
|
||||
|
||||
bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_json)
|
||||
{
|
||||
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS) == NULL)
|
||||
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVICES) == NULL &&
|
||||
mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_MONITORS) == NULL)
|
||||
{
|
||||
/** No change to relationships */
|
||||
return true;
|
||||
@ -1661,9 +1685,9 @@ static bool is_valid_relationship_body(json_t* json)
|
||||
runtime_error("Field '%s' is not defined", MXS_JSON_PTR_DATA);
|
||||
rval = false;
|
||||
}
|
||||
else if (!json_is_array(obj))
|
||||
else if (!json_is_array(obj) && !json_is_null(obj))
|
||||
{
|
||||
runtime_error("Field '%s' is not an array", MXS_JSON_PTR_DATA);
|
||||
runtime_error("Field '%s' is not an array or null", MXS_JSON_PTR_DATA);
|
||||
rval = false;
|
||||
}
|
||||
|
||||
@ -1886,7 +1910,7 @@ Service* runtime_create_service_from_json(json_t* json)
|
||||
|
||||
bool object_to_server_relations(const char* target, json_t* old_json, json_t* new_json)
|
||||
{
|
||||
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS) == NULL)
|
||||
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVERS) == NULL)
|
||||
{
|
||||
/** No change to relationships */
|
||||
return true;
|
||||
|
@ -47,11 +47,27 @@ describe("Monitor Relationships", function() {
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("remove with malformed relationships", function() {
|
||||
var mon = {data: {relationships: {servers: null}}}
|
||||
return request.patch(base_url + "/monitors/MariaDB-Monitor", {json: mon})
|
||||
.should.be.rejected
|
||||
.then(() => request.get(base_url + "/monitors/MariaDB-Monitor", { json: true }))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.have.keys("servers")
|
||||
})
|
||||
});
|
||||
|
||||
it("missing relationships are not removed", function() {
|
||||
var mon = {data: {relationships: {}}}
|
||||
return request.patch(base_url + "/monitors/MariaDB-Monitor", {json: mon})
|
||||
.then(() => request.get(base_url + "/monitors/MariaDB-Monitor", { json: true }))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.have.keys("servers")
|
||||
})
|
||||
});
|
||||
|
||||
it("remove relationships from old monitor", function() {
|
||||
var mon = { data: {
|
||||
relationships: {
|
||||
servers: null
|
||||
}}}
|
||||
var mon = {data: {relationships: {servers: {data: null}}}}
|
||||
return request.patch(base_url + "/monitors/MariaDB-Monitor", {json: mon})
|
||||
.then(() => request.get(base_url + "/monitors/MariaDB-Monitor", { json: true }))
|
||||
.then((res) => {
|
||||
@ -79,7 +95,7 @@ describe("Monitor Relationships", function() {
|
||||
});
|
||||
|
||||
it("move relationships back to old monitor", function() {
|
||||
var mon = {data: {relationships: {servers: null}}}
|
||||
var mon = {data: {relationships: {servers: {data: null}}}}
|
||||
return request.patch(base_url + "/monitors/" + monitor.data.id, {json: mon})
|
||||
.then(() => request.get(base_url + "/monitors/" + monitor.data.id, { json: true }))
|
||||
.then((res) => {
|
||||
@ -125,7 +141,7 @@ describe("Monitor Relationships", function() {
|
||||
});
|
||||
|
||||
it("bad request body with `relationships` endpoint should be rejected", function() {
|
||||
return request.patch(base_url + "/monitors/" + monitor.data.id + "/relationships/servers", {json: {data: null}})
|
||||
return request.patch(base_url + "/monitors/" + monitor.data.id + "/relationships/servers", {json: {servers: null}})
|
||||
.should.be.rejected
|
||||
})
|
||||
|
||||
@ -137,7 +153,7 @@ describe("Monitor Relationships", function() {
|
||||
{ id: "server4", type: "servers" }
|
||||
]}
|
||||
|
||||
return request.patch(base_url + "/monitors/" + monitor.data.id + "/relationships/servers", {json: {data: []}})
|
||||
return request.patch(base_url + "/monitors/" + monitor.data.id + "/relationships/servers", {json: {data: null}})
|
||||
.then(() => request.patch(base_url + "/monitors/MariaDB-Monitor/relationships/servers", {json: old}))
|
||||
.then(() => request.get(base_url + "/monitors/MariaDB-Monitor", { json: true }))
|
||||
.then((res) => {
|
||||
|
@ -80,13 +80,13 @@ describe("Server Relationships", function() {
|
||||
});
|
||||
|
||||
it("bad request body with `relationships` endpoint should be rejected", function() {
|
||||
var body = {data: null}
|
||||
var body = {monitors: null}
|
||||
return request.patch(base_url + "/servers/" + rel_server.data.id + "/relationships/monitors", { json: body })
|
||||
.should.be.rejected
|
||||
});
|
||||
|
||||
it("remove relationships with `relationships` endpoint", function() {
|
||||
var body = {data: []}
|
||||
var body = {data: null}
|
||||
return request.patch(base_url + "/servers/" + rel_server.data.id + "/relationships/monitors", { json: body })
|
||||
.then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true}))
|
||||
.then((res) => {
|
||||
@ -96,11 +96,37 @@ describe("Server Relationships", function() {
|
||||
})
|
||||
});
|
||||
|
||||
it("remove relationships", function() {
|
||||
it("remove with malformed relationships", function() {
|
||||
rel_server.data.relationships["services"] = null
|
||||
rel_server.data.relationships["monitors"] = null
|
||||
return request.patch(base_url + "/servers/" + rel_server.data.id, {json: rel_server})
|
||||
.should.be.rejected
|
||||
.then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true}))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.have.keys("services")
|
||||
})
|
||||
});
|
||||
|
||||
it("missing relationships are not removed", function() {
|
||||
rel_server.data.relationships = {}
|
||||
return request.patch(base_url + "/servers/" + rel_server.data.id, {json: rel_server})
|
||||
.should.be.fulfilled
|
||||
.then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true}))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.have.keys("services")
|
||||
})
|
||||
});
|
||||
|
||||
it("remove relationships", function() {
|
||||
rel_server.data.relationships["services"] = {data: null}
|
||||
rel_server.data.relationships["monitors"] = {data: null}
|
||||
return request.patch(base_url + "/servers/" + rel_server.data.id, {json: rel_server})
|
||||
.should.be.fulfilled
|
||||
.then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true}))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.not.have.keys("services")
|
||||
res.data.relationships.should.not.have.keys("monitors")
|
||||
})
|
||||
});
|
||||
|
||||
it("destroy server", function() {
|
||||
|
@ -20,12 +20,27 @@ describe("Service", function() {
|
||||
});
|
||||
|
||||
|
||||
it("remove service relationship", function() {
|
||||
it("missing relationships are not removed", function() {
|
||||
return request.get(base_url + "/services/RW-Split-Router")
|
||||
.then(function(resp) {
|
||||
var svc = JSON.parse(resp)
|
||||
delete svc.data.relationships["servers"]
|
||||
delete svc.data.relationships["servers"]
|
||||
return request.patch(base_url + "/services/RW-Split-Router", {json: svc})
|
||||
})
|
||||
.then(function(resp) {
|
||||
return request.get(base_url + "/services/RW-Split-Router")
|
||||
})
|
||||
.then(function(resp) {
|
||||
var svc = JSON.parse(resp)
|
||||
svc.data.relationships.should.not.be.empty
|
||||
})
|
||||
});
|
||||
|
||||
it("remove service relationship", function() {
|
||||
return request.get(base_url + "/services/RW-Split-Router")
|
||||
.then(function(resp) {
|
||||
var svc = JSON.parse(resp)
|
||||
svc.data.relationships.servers.data = null
|
||||
return request.patch(base_url + "/services/RW-Split-Router", {json: svc})
|
||||
})
|
||||
.then(function(resp) {
|
||||
@ -64,12 +79,12 @@ describe("Service", function() {
|
||||
});
|
||||
|
||||
it("bad request body with `relationships` endpoint should be rejected", function() {
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/servers", {json: {data: null}})
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/servers", {json: {servers: null}})
|
||||
.should.be.rejected
|
||||
})
|
||||
|
||||
it("remove service relationship via `relationships` endpoint", function() {
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/servers", { json: {data: []}})
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/servers", { json: {data: null}})
|
||||
.then(() => request.get(base_url + "/services/RW-Split-Router", { json: true }))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.not.have.keys("servers")
|
||||
|
Reference in New Issue
Block a user