From fff727e0c2af9aa8bd2375009643ca014d4a854d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 15 Apr 2018 11:19:21 +0300 Subject: [PATCH] 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. --- maxctrl/lib/show.js | 174 ++++++++++++++++++++++++------------ maxctrl/test/diagnostics.js | 8 ++ 2 files changed, 125 insertions(+), 57 deletions(-) diff --git a/maxctrl/lib/show.js b/maxctrl/lib/show.js index 50b41ec25..5cb59a7d5 100644 --- a/maxctrl/lib/show.js +++ b/maxctrl/lib/show.js @@ -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 ' exports.desc = 'Show objects' exports.handler = function() {} @@ -26,21 +89,15 @@ exports.builder = function(yargs) { .usage('Usage: show 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 ', 'Show service', function(yargs) { @@ -51,17 +108,15 @@ exports.builder = function(yargs) { .usage('Usage: show 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 ', 'Show monitor', function(yargs) { @@ -72,13 +127,15 @@ exports.builder = function(yargs) { .usage('Usage: show 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 ', 'Show session', function(yargs) { @@ -89,15 +146,15 @@ exports.builder = function(yargs) { .usage('Usage: show 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 ', 'Show filter', function(yargs) { @@ -105,12 +162,15 @@ exports.builder = function(yargs) { .usage('Usage: show 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 ', 'Show loaded module', function(yargs) { @@ -119,15 +179,15 @@ exports.builder = function(yargs) { .usage('Usage: show 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) { diff --git a/maxctrl/test/diagnostics.js b/maxctrl/test/diagnostics.js index dc2822e92..e4abe7485 100644 --- a/maxctrl/test/diagnostics.js +++ b/maxctrl/test/diagnostics.js @@ -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',