MXS-1300: Add creation/deletion of listeners to cluster sync

New listeners are created and old ones removed. As listeners cannot yet be
altered via the REST API, differing listeners are not modified.
This commit is contained in:
Markus Mäkelä
2017-08-01 15:11:52 +03:00
parent 0dc53df32e
commit a3e9d5c327

View File

@ -145,7 +145,6 @@ exports.builder = function(yargs) {
})
.command('sync <target>', 'Synchronize the cluster with target MaxScale server.', {}, function(argv) {
maxctrl(argv, function(host) {
// TODO: Create new listeners
return getDiffs(argv.target, host)
.then(function(diffs) {
var promises = []
@ -198,6 +197,24 @@ exports.builder = function(yargs) {
})
return Promise.all(promises)
})
.then(function() {
// Add new and delete old listeners
var promises = []
var all_keys = _.concat(Object.keys(src), Object.keys(dest))
var unwanted_keys = _.concat(collections, endpoints)
var relevant_keys = _.uniq(_.difference(all_keys, unwanted_keys))
relevant_keys.forEach(function(i) {
getDifference(dest[i].data, src[i].data).forEach(function(j) {
promises.push(doAsyncRequest(host, i + '/' + j.id, null, {method: 'DELETE'}))
})
getDifference(src[i].data, dest[i].data).forEach(function(j) {
promises.push(doAsyncRequest(host, i, null, {method: 'POST', body: {data: j}}))
})
})
return Promise.all(promises)
})
.then(function() {
var promises = []
// PATCH all remaining resource collections in src from dest apart from the