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
2 changed files with 125 additions and 57 deletions

View File

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

View File

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