MXS-1929: Add direct filter relationship updates
The filters of a service can now be directly updated via the relationships endpoint.
This commit is contained in:
parent
f93658e487
commit
6661680c4e
@ -2120,7 +2120,7 @@ bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t*
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool runtime_alter_service_relationships_from_json(Service* service, json_t* json)
|
||||
bool runtime_alter_service_relationships_from_json(Service* service, const char* type, json_t* json)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::Closer<json_t*> old_json(service_to_json(service, ""));
|
||||
@ -2129,12 +2129,17 @@ bool runtime_alter_service_relationships_from_json(Service* service, json_t* jso
|
||||
if (is_valid_relationship_body(json))
|
||||
{
|
||||
mxs::Closer<json_t*> j(json_pack("{s: {s: {s: {s: O}}}}", "data",
|
||||
"relationships", "servers", "data",
|
||||
"relationships", type, "data",
|
||||
json_object_get(json, "data")));
|
||||
|
||||
if (object_to_server_relations(service->name, old_json.get(), j.get()))
|
||||
if (strcmp(type, CN_SERVERS) == 0)
|
||||
{
|
||||
rval = true;
|
||||
rval = object_to_server_relations(service->name, old_json.get(), j.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
ss_dassert(strcmp(type, CN_FILTERS) == 0);
|
||||
rval = service_to_filter_relations(service, old_json.get(), j.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,11 +342,12 @@ bool runtime_alter_service_from_json(Service* service, json_t* new_json);
|
||||
* @brief Alter service relationships
|
||||
*
|
||||
* @param service Service to alter
|
||||
* @param json JSON that defines the new relationships
|
||||
* @param type Type of relationship to alter
|
||||
* @param json JSON that defines the new relationships
|
||||
*
|
||||
* @return True if the relationships were successfully modified
|
||||
*/
|
||||
bool runtime_alter_service_relationships_from_json(Service* service, json_t* json);
|
||||
bool runtime_alter_service_relationships_from_json(Service* service, const char* type, json_t* json);
|
||||
|
||||
/**
|
||||
* @brief Create a listener from JSON
|
||||
|
@ -407,7 +407,20 @@ HttpResponse cb_alter_service_server_relationship(const HttpRequest& request)
|
||||
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||
ss_dassert(service && request.get_json());
|
||||
|
||||
if (runtime_alter_service_relationships_from_json(service, request.get_json()))
|
||||
if (runtime_alter_service_relationships_from_json(service, CN_SERVERS, request.get_json()))
|
||||
{
|
||||
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
return HttpResponse(MHD_HTTP_FORBIDDEN, runtime_get_json_error());
|
||||
}
|
||||
|
||||
HttpResponse cb_alter_service_filter_relationship(const HttpRequest& request)
|
||||
{
|
||||
Service* service = service_internal_find(request.uri_part(1).c_str());
|
||||
ss_dassert(service && request.get_json());
|
||||
|
||||
if (runtime_alter_service_relationships_from_json(service, CN_FILTERS, request.get_json()))
|
||||
{
|
||||
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||
}
|
||||
@ -966,6 +979,8 @@ public:
|
||||
"monitors", ":monitor", "relationships", "servers")));
|
||||
m_patch.push_back(SResource(new Resource(cb_alter_service_server_relationship, 4,
|
||||
"services", ":service", "relationships", "servers")));
|
||||
m_patch.push_back(SResource(new Resource(cb_alter_service_filter_relationship, 4,
|
||||
"services", ":service", "relationships", "filters")));
|
||||
|
||||
/** All patch resources require a request body */
|
||||
for (ResourceList::iterator it = m_patch.begin(); it != m_patch.end(); it++)
|
||||
|
@ -83,7 +83,7 @@ describe("Service", function() {
|
||||
.should.be.rejected
|
||||
})
|
||||
|
||||
it("remove service relationship via `relationships` endpoint", function() {
|
||||
it("remove service→server relationship via `relationships` endpoint", function() {
|
||||
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) => {
|
||||
@ -91,7 +91,7 @@ describe("Service", function() {
|
||||
})
|
||||
});
|
||||
|
||||
it("add service relationship via `relationships` endpoint", function() {
|
||||
it("add service→server relationship via `relationships` endpoint", function() {
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/servers",
|
||||
{ json: { data: [
|
||||
{id: "server1", type: "servers"},
|
||||
@ -105,6 +105,26 @@ describe("Service", function() {
|
||||
})
|
||||
});
|
||||
|
||||
it("add service→filter relationship via `relationships` endpoint", function() {
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/filters",
|
||||
{ json: { data: [
|
||||
{id: "QLA", type: "filters"},
|
||||
]}})
|
||||
.then(() => request.get(base_url + "/services/RW-Split-Router", { json: true}))
|
||||
.then((res) => {
|
||||
res.data.relationships.filters.data.should.have.lengthOf(1)
|
||||
})
|
||||
});
|
||||
|
||||
it("remove service→filter relationship via `relationships` endpoint", function() {
|
||||
return request.patch(base_url + "/services/RW-Split-Router/relationships/filters",
|
||||
{ json: { data: null}})
|
||||
.then(() => request.get(base_url + "/services/RW-Split-Router", { json: true}))
|
||||
.then((res) => {
|
||||
res.data.relationships.should.not.have.keys("filters")
|
||||
})
|
||||
});
|
||||
|
||||
const listener = {
|
||||
"links": {
|
||||
"self": "http://localhost:8989/v1/services/RW-Split-Router/listeners"
|
||||
|
Loading…
x
Reference in New Issue
Block a user