MXS-1300: Fix deletion of monitors
The monitors should only be reused if they have the same name and they use the same module. This way the only difference is in configuration. Fixed MaxCtrl detection of bad options and altered monitor creation test to expect correct results. Also improved some of the error messages.
This commit is contained in:
parent
af847c29c3
commit
e133e758a6
@ -195,9 +195,9 @@ module.exports = function() {
|
||||
}
|
||||
}, function(err) {
|
||||
if (err.response && err.response.body) {
|
||||
return error('Server responded with an error to resource request `' + resource + '`:' + JSON.stringify(err.response.body, null, 4))
|
||||
return error('Server responded with status code ' + err.statusCode + ' to `' + err.response.request.method +' ' + resource + '`:' + JSON.stringify(err.response.body, null, 4))
|
||||
} else if (err.statusCode) {
|
||||
return error('Server responded with: ' + err.statusCode + 'to resource request `' + resource + '`')
|
||||
return error('Server responded with status code ' + err.statusCode + ' to `' + err.response.request.method +' ' + resource + '`')
|
||||
} else if (err.error) {
|
||||
return error(JSON.stringify(err.error, null, 4))
|
||||
} else {
|
||||
|
@ -19,6 +19,8 @@ const maxctrl_version = '1.0.0';
|
||||
program
|
||||
.version(maxctrl_version)
|
||||
.strict()
|
||||
.exitProcess(false)
|
||||
.showHelpOnFail(false)
|
||||
.group(['u', 'p', 'h', 's', 't', 'q', 'tsv'], 'Global Options:')
|
||||
.option('u', {
|
||||
alias:'user',
|
||||
@ -96,6 +98,10 @@ module.exports.execute = function(argv, opts) {
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
program
|
||||
.parse(argv, {resolve: resolve, reject: reject})
|
||||
.parse(argv, {resolve: resolve, reject: reject}, function(err, argv, output) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -7,16 +7,15 @@ describe("Create/Destroy Commands", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
it('create monitor', function() {
|
||||
return doCommand('create monitor my-monitor mysqlmon')
|
||||
.then(function() {
|
||||
return request.get(host + 'monitors/my-monitor', {json: true})
|
||||
.should.be.fulfilled
|
||||
})
|
||||
return verifyCommand('create monitor my-monitor mysqlmon', 'monitors/my-monitor')
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it('destroy monitor', function() {
|
||||
return doCommand('destroy monitor my-monitor')
|
||||
.should.be.fulfilled
|
||||
.then(() => doCommand('show monitor my-monitor'))
|
||||
.should.be.rejected
|
||||
})
|
||||
|
||||
it('destroy the same monitor again', function() {
|
||||
@ -40,15 +39,9 @@ describe("Create/Destroy Commands", function() {
|
||||
})
|
||||
|
||||
it('create monitor with options', function() {
|
||||
return stopMaxScale()
|
||||
.then(startMaxScale)
|
||||
.then(function() {
|
||||
return doCommand('unlink monitor MySQL-Monitor server4')
|
||||
})
|
||||
.then(function() {
|
||||
return verifyCommand('create monitor my-monitor mysqlmon --servers server4 --monitor-user maxuser --monitor-password maxpwd',
|
||||
'monitors/my-monitor')
|
||||
})
|
||||
return doCommand('unlink monitor MySQL-Monitor server4')
|
||||
.then(() => verifyCommand('create monitor my-monitor mysqlmon --servers server4 --monitor-user maxuser --monitor-password maxpwd',
|
||||
'monitors/my-monitor'))
|
||||
.then(function(res) {
|
||||
res.data.relationships.servers.data.length.should.equal(1)
|
||||
res.data.relationships.servers.data[0].id.should.equal("server4")
|
||||
|
@ -847,15 +847,15 @@ bool runtime_create_monitor(const char *name, const char *module)
|
||||
if (monitor_find(name) == NULL)
|
||||
{
|
||||
|
||||
MXS_MONITOR *monitor = monitor_find_destroyed(name);
|
||||
MXS_MONITOR *monitor = monitor_find_destroyed(name, module);
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
monitor->active = true;
|
||||
}
|
||||
else
|
||||
else if ((monitor = monitor_alloc(name, module)) == NULL)
|
||||
{
|
||||
monitor = monitor_alloc(name, module);
|
||||
runtime_error("Could not create monitor '%s' with module '%s'", name, module);
|
||||
}
|
||||
|
||||
if (monitor)
|
||||
@ -867,6 +867,10 @@ bool runtime_create_monitor(const char *name, const char *module)
|
||||
MXS_NOTICE("Created monitor '%s'", name);
|
||||
rval = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
runtime_error("Failed to serialize monitor '%s'", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -50,7 +50,7 @@ void monitorStopAll();
|
||||
void monitorStartAll();
|
||||
|
||||
MXS_MONITOR *monitor_find(const char *);
|
||||
MXS_MONITOR* monitor_find_destroyed(const char *name);
|
||||
MXS_MONITOR* monitor_find_destroyed(const char* name, const char* module);
|
||||
|
||||
void monitorShow(DCB *, MXS_MONITOR *);
|
||||
void monitorShowAll(DCB *);
|
||||
|
@ -574,7 +574,7 @@ monitor_find(const char *name)
|
||||
* @param name The name of the monitor
|
||||
* @return Pointer to the destroyed monitor or NULL if monitor is not found
|
||||
*/
|
||||
MXS_MONITOR* monitor_find_destroyed(const char *name)
|
||||
MXS_MONITOR* monitor_find_destroyed(const char* name, const char* module)
|
||||
{
|
||||
MXS_MONITOR* rval = NULL;
|
||||
|
||||
@ -582,7 +582,7 @@ MXS_MONITOR* monitor_find_destroyed(const char *name)
|
||||
|
||||
for (MXS_MONITOR *ptr = allMonitors; ptr; ptr = ptr->next)
|
||||
{
|
||||
if (!strcmp(ptr->name, name))
|
||||
if (strcmp(ptr->name, name) == 0 && strcmp(ptr->module_name, module) == 0)
|
||||
{
|
||||
rval = ptr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user