MXS-1782: Take getCollectionAsResource into use

Each `show` type command that takes a resource name now also has a version
that prints all resources of that type.

Added test cases for newly added commands.
This commit is contained in:
Markus Mäkelä 2018-04-15 11:19:21 +03:00
parent 87ce1f6dab
commit fff727e0c2
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 125 additions and 57 deletions

View File

@ -13,6 +13,69 @@
require('./common.js')()
const server_fields = [
{'Server': 'id'},
{'Address': 'attributes.parameters.address'},
{'Port': 'attributes.parameters.port'},
{'State': 'attributes.state'},
{'Last Event': 'attributes.last_event'},
{'Triggered At': 'attributes.triggered_at'},
{'Services': 'relationships.services.data[].id'},
{'Monitors': 'relationships.monitors.data[].id'},
{'Master ID': 'attributes.master_id'},
{'Node ID': 'attributes.node_id'},
{'Slave Server IDs': 'attributes.slaves'},
{'Statistics': 'attributes.statistics'},
{'Parameters': 'attributes.parameters'}
]
const service_fields = [
{'Service': 'id'},
{'Router': 'attributes.router'},
{'State': 'attributes.state'},
{'Started At': 'attributes.started'},
{'Current Connections': 'attributes.connections'},
{'Total Connections': 'attributes.total_connections'},
{'Servers': 'relationships.servers.data[].id'},
{'Parameters': 'attributes.parameters'},
{'Router Diagnostics': 'attributes.router_diagnostics'}
]
const monitor_fields = [
{'Monitor': 'id'},
{'State': 'attributes.state'},
{'Servers': 'relationships.servers.data[].id'},
{'Parameters': 'attributes.parameters'},
{'Monitor Diagnostics': 'attributes.monitor_diagnostics'}
]
const session_fields = [
{'Id': 'id'},
{'Service': 'relationships.services.data[].id'},
{'State': 'attributes.state'},
{'User': 'attributes.user'},
{'Host': 'attributes.remote'},
{'Connected': 'attributes.connected'},
{'Idle': 'attributes.idle'}
]
const filter_fields = [
{'Filter': 'id'},
{'Module': 'attributes.module'},
{'Services': 'relationships.services.data[].id'},
{'Parameters': 'attributes.parameters'}
]
const module_fields = [
{'Module': 'id'},
{'Type': 'attributes.module_type'},
{'Version': 'attributes.version'},
{'Maturity': 'attributes.maturity'},
{'Description': 'attributes.description'},
{'Parameters': 'attributes.parameters'},
{'Commands': 'attributes.commands'}
]
exports.command = 'show <command>'
exports.desc = 'Show objects'
exports.handler = function() {}
@ -26,21 +89,15 @@ exports.builder = function(yargs) {
.usage('Usage: show server <server>')
}, function(argv) {
maxctrl(argv, function(host) {
return getResource(host, 'servers/' + argv.server, [
{'Server': 'id'},
{'Address': 'attributes.parameters.address'},
{'Port': 'attributes.parameters.port'},
{'State': 'attributes.state'},
{'Last Event': 'attributes.last_event'},
{'Triggered At': 'attributes.triggered_at'},
{'Services': 'relationships.services.data[].id'},
{'Monitors': 'relationships.monitors.data[].id'},
{'Master ID': 'attributes.master_id'},
{'Node ID': 'attributes.node_id'},
{'Slave Server IDs': 'attributes.slaves'},
{'Statistics': 'attributes.statistics'},
{'Parameters': 'attributes.parameters'}
])
return getResource(host, 'servers/' + argv.server, server_fields)
})
})
.command('servers', 'Show all servers', function(yargs) {
return yargs.epilog('Show detailed information about all servers.')
.usage('Usage: show servers')
}, function(argv) {
maxctrl(argv, function(host) {
return getCollectionAsResource(host, 'servers/', server_fields)
})
})
.command('service <service>', 'Show service', function(yargs) {
@ -51,17 +108,15 @@ exports.builder = function(yargs) {
.usage('Usage: show service <service>')
}, function(argv) {
maxctrl(argv, function(host) {
return getResource(host, 'services/' + argv.service, [
{'Service': 'id'},
{'Router': 'attributes.router'},
{'State': 'attributes.state'},
{'Started At': 'attributes.started'},
{'Current Connections': 'attributes.connections'},
{'Total Connections': 'attributes.total_connections'},
{'Servers': 'relationships.servers.data[].id'},
{'Parameters': 'attributes.parameters'},
{'Router Diagnostics': 'attributes.router_diagnostics'}
])
return getResource(host, 'services/' + argv.service, service_fields)
})
})
.command('services', 'Show all services', function(yargs) {
return yargs.epilog('Show detailed information about all services.')
.usage('Usage: show services')
}, function(argv) {
maxctrl(argv, function(host) {
return getCollectionAsResource(host, 'services/', service_fields)
})
})
.command('monitor <monitor>', 'Show monitor', function(yargs) {
@ -72,13 +127,15 @@ exports.builder = function(yargs) {
.usage('Usage: show monitor <monitor>')
}, function(argv) {
maxctrl(argv, function(host) {
return getResource(host, 'monitors/' + argv.monitor, [
{'Monitor': 'id'},
{'State': 'attributes.state'},
{'Servers': 'relationships.servers.data[].id'},
{'Parameters': 'attributes.parameters'},
{'Monitor Diagnostics': 'attributes.monitor_diagnostics'}
])
return getResource(host, 'monitors/' + argv.monitor, monitor_fields)
})
})
.command('monitors', 'Show all monitors', function(yargs) {
return yargs.epilog('Show detailed information about all monitors.')
.usage('Usage: show monitors')
}, function(argv) {
maxctrl(argv, function(host) {
return getCollectionAsResource(host, 'monitors/', monitor_fields)
})
})
.command('session <session>', 'Show session', function(yargs) {
@ -89,15 +146,15 @@ exports.builder = function(yargs) {
.usage('Usage: show session <session>')
}, function(argv) {
maxctrl(argv, function(host) {
return getResource(host, 'sessions/' + argv.session, [
{'Id': 'id'},
{'Service': 'relationships.services.data[].id'},
{'State': 'attributes.state'},
{'User': 'attributes.user'},
{'Host': 'attributes.remote'},
{'Connected': 'attributes.connected'},
{'Idle': 'attributes.idle'}
])
return getResource(host, 'sessions/' + argv.session, session_fields)
})
})
.command('sessions', 'Show all sessions', function(yargs) {
return yargs.epilog('Show detailed information about all sessions.')
.usage('Usage: show sessions')
}, function(argv) {
maxctrl(argv, function(host) {
return getCollectionAsResource(host, 'sessions/', session_fields)
})
})
.command('filter <filter>', 'Show filter', function(yargs) {
@ -105,12 +162,15 @@ exports.builder = function(yargs) {
.usage('Usage: show filter <filter>')
}, function(argv) {
maxctrl(argv, function(host) {
return getResource(host, 'filters/' + argv.filter, [
{'Filter': 'id'},
{'Module': 'attributes.module'},
{'Services': 'relationships.services.data[].id'},
{'Parameters': 'attributes.parameters'}
])
return getResource(host, 'filters/' + argv.filter, filter_fields)
})
})
.command('filters', 'Show all filters', function(yargs) {
return yargs.epilog('Show detailed information of all filters.')
.usage('Usage: show filters')
}, function(argv) {
maxctrl(argv, function(host) {
return getCollectionAsResource(host, 'filters/', filter_fields)
})
})
.command('module <module>', 'Show loaded module', function(yargs) {
@ -119,15 +179,15 @@ exports.builder = function(yargs) {
.usage('Usage: show module <module>')
}, function(argv) {
maxctrl(argv, function(host) {
return getResource(host, 'maxscale/modules/' + argv.module, [
{'Module': 'id'},
{'Type': 'attributes.module_type'},
{'Version': 'attributes.version'},
{'Maturity': 'attributes.maturity'},
{'Description': 'attributes.description'},
{'Parameters': 'attributes.parameters'},
{'Commands': 'attributes.commands'}
])
return getResource(host, 'maxscale/modules/' + argv.module, module_fields)
})
})
.command('modules', 'Show all loaded modules', function(yargs) {
return yargs.epilog('Displays detailed information about all modules.')
.usage('Usage: show modules')
}, function(argv) {
maxctrl(argv, function(host) {
return getCollectionAsResource(host, 'maxscale/modules/', module_fields)
})
})
.command('maxscale', 'Show MaxScale information', function(yargs) {

View File

@ -10,6 +10,14 @@ var tests = [
'list modules',
'list users',
'list commands',
'show servers',
'show services',
'show monitors',
'show sessions',
'show filters',
'show modules',
'show maxscale',
'show logging',
'show server server1',
'show service RW-Split-Router',
'show monitor MariaDB-Monitor',