MXS-1300: Use native promises for requests
The request-promise-native package adds support for request with native promises. This is a convenient way to synchronize multiple HTTP requests. The functions are changed to use promises to make testing easier. With promises, the testing code can use the chai-as-promised library. There are a few cases where doRequest is called with a callback that again calls doAsyncRequest. With multiple hosts, this causes each command to be propagated to all servers. This is a design flaw of the current multi-host mode and needs to be changed. Changed maxctrl.js to wait on the promises to silence some warnings if the promise rejections are ignored.
This commit is contained in:
@ -32,11 +32,11 @@ exports.builder = function(yargs) {
|
||||
}
|
||||
})
|
||||
|
||||
maxctrl
|
||||
.doRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
console.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
return maxctrl
|
||||
.doAsyncRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
console.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
})
|
||||
})
|
||||
.usage('Usage: call <command>')
|
||||
|
||||
@ -30,7 +30,7 @@ exports.builder = function(yargs) {
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, false)
|
||||
} else {
|
||||
maxctrl(argv)
|
||||
.logError('Invalid log priority: ' + argv.log);
|
||||
.error('Invalid log priority: ' + argv.log);
|
||||
}
|
||||
})
|
||||
.command('maxlog', 'Disable MaxScale logging', {}, function(argv) {
|
||||
|
||||
@ -30,7 +30,7 @@ exports.builder = function(yargs) {
|
||||
.updateValue('maxscale/logs', 'data.attributes.parameters.log_' + argv.log, true)
|
||||
} else {
|
||||
maxctrl(argv)
|
||||
.logError('Invalid log priority: ' + argv.log);
|
||||
.error('Invalid log priority: ' + argv.log);
|
||||
}
|
||||
})
|
||||
.command('maxlog', 'Enable MaxScale logging', {}, function(argv) {
|
||||
|
||||
@ -25,8 +25,8 @@ function addServer(argv, path, targets) {
|
||||
_.set(res, 'data.relationships.servers.data', servers)
|
||||
delete res.data.attributes
|
||||
|
||||
maxctrl(argv)
|
||||
.doRequest(path, null, {method: 'PATCH', body: res})
|
||||
return maxctrl(argv)
|
||||
.doAsyncRequest(path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -25,8 +25,8 @@ function removeServer(argv, path, targets) {
|
||||
_.set(res, 'data.relationships.servers.data', servers)
|
||||
delete res.data.attributes
|
||||
|
||||
maxctrl(argv)
|
||||
.doRequest(path, null, {method: 'PATCH', body: res})
|
||||
return maxctrl(argv)
|
||||
.doAsyncRequest(path, null, {method: 'PATCH', body: res})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user