From cbe58b5355ebbc737f76b2ef34eab33d891f46e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Aug 2017 14:43:14 +0300 Subject: [PATCH] MXS-620: Add start/stop maxscale to MaxCtrl The commands allow all services in MaxScale to be either stopped or started. --- maxctrl/lib/common.js | 6 +++++- maxctrl/lib/start.js | 14 ++++++++++++++ maxctrl/lib/stop.js | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/maxctrl/lib/common.js b/maxctrl/lib/common.js index 8ab16e147..fee2d51f8 100644 --- a/maxctrl/lib/common.js +++ b/maxctrl/lib/common.js @@ -174,6 +174,10 @@ module.exports = function() { return base + argv.user + ':' + argv.password + '@' + host + '/v1/' + endpoint } + this.OK = function() { + return Promise.resolve(colors.green('OK')) + } + // Helper for executing requests and handling their responses, returns a // promise that is fulfilled when all requests successfully complete. The // promise is rejected if any of the requests fails. @@ -190,7 +194,7 @@ module.exports = function() { return cb(res) } else { // Request OK, no data or data is ignored - return Promise.resolve(colors.green('OK')) + return OK() } }, function(err) { if (err.response && err.response.body) { diff --git a/maxctrl/lib/start.js b/maxctrl/lib/start.js index f54dd6ae4..e2c6f9fb4 100644 --- a/maxctrl/lib/start.js +++ b/maxctrl/lib/start.js @@ -27,6 +27,20 @@ exports.builder = function(yargs) { return doRequest(host, 'monitors/' + argv.name + '/start', null, {method: 'PUT'}) }) }) + .command('maxscale', 'Start MaxScale by starting all services', {}, function(argv) { + maxctrl(argv, function(host) { + return doRequest(host, 'services/', function(res) { + var promises = [] + + res.data.forEach(function(i) { + promises.push(doRequest(host, 'services/' + i.id + '/start', null, {method: 'PUT'})) + }) + + return Promise.all(promises) + .then(() => OK()) + }) + }) + }) .usage('Usage: start ') .help() .command('*', 'the default command', {}, function(argv) { diff --git a/maxctrl/lib/stop.js b/maxctrl/lib/stop.js index 7b0448732..28c1c3b95 100644 --- a/maxctrl/lib/stop.js +++ b/maxctrl/lib/stop.js @@ -27,6 +27,20 @@ exports.builder = function(yargs) { return doRequest(host, 'monitors/' + argv.name + '/stop', null, {method: 'PUT'}) }) }) + .command('maxscale', 'Stop MaxScale by stopping all services', {}, function(argv) { + maxctrl(argv, function(host) { + return doRequest(host, 'services/', function(res) { + var promises = [] + + res.data.forEach(function(i) { + promises.push(doRequest(host, 'services/' + i.id + '/stop', null, {method: 'PUT'})) + }) + + return Promise.all(promises) + .then(() => OK()) + }) + }) + }) .usage('Usage: stop ') .help() .command('*', 'the default command', {}, function(argv) {