Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Change calling of commands to use their String command name rather th… #17

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

## [2.3.0] - 2019-11-07
### Changed
- Update to framework 6.3.0
- All commands are now called using their String command name to allow for new commands to be
added without needing to update the dependency on framework

## [2.2.4] - 2019-10-31
### Changed
- Update to framework 6.2.3
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<cpp.repo.name>framework-jmx-command-client</cpp.repo.name>

<framework-api.version>4.1.0</framework-api.version>
<framework.version>6.2.3</framework.version>
<framework.version>6.3.0</framework.version>
<maven-common-bom.version>2.4.0</maven-common-bom.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion runSystemCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
################################################

FRAMEWORK_JMX_COMMAND_CLIENT_VERSION=2.2.2-SNAPSHOT
FRAMEWORK_JMX_COMMAND_CLIENT_VERSION=2.3.1-SNAPSHOT
mapingo marked this conversation as resolved.
Show resolved Hide resolved
CONTEXT_NAME="people"
USER_NAME="admin"
PASSWORD="admin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import uk.gov.justice.framework.command.client.io.CommandPrinter;
import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.framework.command.client.jmx.SystemCommandInvoker;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;

import java.util.List;
import java.util.Optional;

import javax.inject.Inject;

Expand All @@ -18,32 +17,19 @@ public class CommandExecutor {
@Inject
private SystemCommandInvoker systemCommandInvoker;

@Inject
private CommandLocator commandLocator;

@Inject
private ToConsolePrinter toConsolePrinter;

@Inject
private CommandPrinter commandPrinter;

public void executeCommand(
final CommandLine commandLine,
final JmxParameters jmxParameters,
final List<SystemCommand> systemCommands) {
final List<SystemCommandDetails> systemCommandDetails) {

if (commandLine.hasOption("list")) {
commandPrinter.printSystemCommands(systemCommands);
commandPrinter.printSystemCommands(systemCommandDetails);
} else {
final String commandName = commandLine.getOptionValue("command");
final Optional<SystemCommand> command = commandLocator.lookupCommand(commandName, systemCommands);

if (command.isPresent()) {
systemCommandInvoker.runSystemCommand(command.get(), jmxParameters);
} else {
toConsolePrinter.printf("No command found with name '%s'", commandName);
commandPrinter.printSystemCommands(systemCommands);
}
systemCommandInvoker.runSystemCommand(commandName, jmxParameters);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uk.gov.justice.framework.command.client.jmx.ListCommandsInvoker;
import uk.gov.justice.framework.command.client.startup.CommandLineArgumentParser;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;

import java.util.List;
Expand Down Expand Up @@ -51,7 +52,7 @@ public ReturnCode run(final String[] args) {

try {

final Optional<List<SystemCommand>> systemCommandsOptional = listCommandsInvoker.listSystemCommands(jmxParameters);
final Optional<List<SystemCommandDetails>> systemCommandsOptional = listCommandsInvoker.listSystemCommands(jmxParameters);
systemCommandsOptional.ifPresent(systemCommands -> commandExecutor.executeCommand(commandLine, jmxParameters, systemCommands));

} catch (final RuntimeException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package uk.gov.justice.framework.command.client.io;

import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;

import java.util.List;

Expand All @@ -11,19 +11,19 @@ public class CommandPrinter {
@Inject
private ToConsolePrinter toConsolePrinter;

public void printSystemCommands(final List<SystemCommand> commands) {
public void printSystemCommands(final List<SystemCommandDetails> systemCommandDetails) {

if (commands.isEmpty()) {
if (systemCommandDetails.isEmpty()) {
toConsolePrinter.println("This instance of wildfly does not support any system commands");
}

toConsolePrinter.printf("This instance of wildfly supports the following %d commands:", commands.size());
commands.forEach(this::printCommand);
toConsolePrinter.printf("This instance of wildfly supports the following %d commands:", systemCommandDetails.size());
systemCommandDetails.forEach(this::printCommand);
}

private void printCommand(final SystemCommand systemCommand) {
private void printCommand(final SystemCommandDetails systemCommandDetails) {

final String commandName = systemCommand.getName() + ":";
toConsolePrinter.printf("\t- %-20s%s", commandName, systemCommand.getDescription());
final String commandName = systemCommandDetails.getName() + ":";
toConsolePrinter.printf("\t- %-20s%s", commandName, systemCommandDetails.getDescription());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CommandPoller {
@Inject
private ToConsolePrinter toConsolePrinter;

public void runUntilComplete(final SystemCommanderMBean systemCommanderMBean, final UUID commandId, final SystemCommand systemCommand) {
public void runUntilComplete(final SystemCommanderMBean systemCommanderMBean, final UUID commandId, final String commandName) {

final ZonedDateTime startTime = clock.now();

Expand All @@ -39,7 +39,7 @@ public void runUntilComplete(final SystemCommanderMBean systemCommanderMBean, fi

if (count % 10 == 0) {
final long seconds = between(startTime, clock.now()).getSeconds();
toConsolePrinter.println(format("%s running for %d seconds", systemCommand.getName(), seconds));
toConsolePrinter.println(format("%s running for %d seconds", commandName, seconds));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory;
Expand All @@ -24,7 +25,7 @@ public class ListCommandsInvoker {
@Inject
private ToConsolePrinter toConsolePrinter;

public Optional<List<SystemCommand>> listSystemCommands(final JmxParameters jmxParameters) {
public Optional<List<SystemCommandDetails>> listSystemCommands(final JmxParameters jmxParameters) {

final String contextName = jmxParameters.getContextName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public class SystemCommandInvoker {
@Inject
private ToConsolePrinter toConsolePrinter;

public void runSystemCommand(final SystemCommand systemCommand, final JmxParameters jmxParameters) {
public void runSystemCommand(final String commandName, final JmxParameters jmxParameters) {

final String commandName = systemCommand.getName();
final String contextName = jmxParameters.getContextName();

toConsolePrinter.printf("Running system command '%s'", commandName);
Expand All @@ -41,9 +40,9 @@ public void runSystemCommand(final SystemCommand systemCommand, final JmxParamet
toConsolePrinter.printf("Connected to %s context", contextName);

final SystemCommanderMBean systemCommanderMBean = systemCommanderClient.getRemote(contextName);
final UUID commandId = systemCommanderMBean.call(systemCommand);
final UUID commandId = systemCommanderMBean.call(commandName);
toConsolePrinter.printf("System command '%s' with id '%s' successfully sent to %s", commandName, commandId, contextName);
commandPoller.runUntilComplete(systemCommanderMBean, commandId, systemCommand);
commandPoller.runUntilComplete(systemCommanderMBean, commandId, commandName);

} catch (final UnrunnableSystemCommandException e) {
toConsolePrinter.printf("The command '%s' is not supported on this %s context", commandName, contextName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.framework.command.client.jmx.SystemCommandInvoker;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;

import java.util.List;
Expand All @@ -30,9 +31,6 @@ public class CommandExecutorTest {
@Mock
private SystemCommandInvoker systemCommandInvoker;

@Mock
private CommandLocator commandLocator;

@Mock
private ToConsolePrinter toConsolePrinter;

Expand All @@ -47,54 +45,30 @@ public void shouldLookupSystemCommandByNameAndExecute() throws Exception {

final String commandName = "CATCHUP";

final SystemCommand systemCommand_1 = mock(SystemCommand.class);
final SystemCommand systemCommand_2 = mock(SystemCommand.class);
final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class);
final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class);

final CommandLine commandLine = mock(CommandLine.class);
final JmxParameters jmxParameters = mock(JmxParameters.class);
final List<SystemCommand> systemCommands = asList(systemCommand_1, systemCommand_2);
final List<SystemCommandDetails> systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2);

when(commandLine.hasOption("list")).thenReturn(false);
when(commandLine.getOptionValue("command")).thenReturn(commandName);
when(commandLocator.lookupCommand(commandName, systemCommands)).thenReturn(of(systemCommand_2));

commandExecutor.executeCommand(commandLine, jmxParameters, systemCommands);

verify(systemCommandInvoker).runSystemCommand(systemCommand_2, jmxParameters);
}

@Test
public void shouldPrintErrorAndListOfSystemCommandsIfTheNoCommandFound() throws Exception {

final String commandName = "CATCHUP";

final SystemCommand systemCommand_1 = mock(SystemCommand.class);
final SystemCommand systemCommand_2 = mock(SystemCommand.class);

final CommandLine commandLine = mock(CommandLine.class);
final JmxParameters jmxParameters = mock(JmxParameters.class);
final List<SystemCommand> systemCommands = asList(systemCommand_1, systemCommand_2);

when(commandLine.hasOption("list")).thenReturn(false);
when(commandLine.getOptionValue("command")).thenReturn(commandName);
when(commandLocator.lookupCommand(commandName, systemCommands)).thenReturn(empty());

commandExecutor.executeCommand(commandLine, jmxParameters, systemCommands);

verify(toConsolePrinter).printf("No command found with name '%s'", commandName);
verify(commandPrinter).printSystemCommands(systemCommands);
verifyZeroInteractions(systemCommandInvoker);
verify(systemCommandInvoker).runSystemCommand(commandName, jmxParameters);
}

@Test
public void shouldListSystemCommandsIfCommandLineOptionIsList() throws Exception {

final SystemCommand systemCommand_1 = mock(SystemCommand.class);
final SystemCommand systemCommand_2 = mock(SystemCommand.class);
final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class);
final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class);

final CommandLine commandLine = mock(CommandLine.class);
final JmxParameters jmxParameters = mock(JmxParameters.class);
final List<SystemCommand> systemCommands = asList(systemCommand_1, systemCommand_2);
final List<SystemCommandDetails> systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2);

when(commandLine.hasOption("list")).thenReturn(true);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import uk.gov.justice.framework.command.client.jmx.ListCommandsInvoker;
import uk.gov.justice.framework.command.client.startup.CommandLineArgumentParser;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommandDetails;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;

import java.util.List;
Expand Down Expand Up @@ -65,10 +66,10 @@ public void shouldLookupTheCorrectCommandAndInvokeIt() throws Exception {
final JmxParameters jmxParameters = mock(JmxParameters.class);

final CommandLine commandLine = mock(CommandLine.class);
final SystemCommand systemCommand_1 = mock(SystemCommand.class);
final SystemCommand systemCommand_2 = mock(SystemCommand.class);
final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class);
final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class);

final List<SystemCommand> systemCommands = asList(systemCommand_1, systemCommand_2);
final List<SystemCommandDetails> systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2);

when(commandLineArgumentParser.parse(args)).thenReturn(of(commandLine));
when(jmxParametersFactory.createFrom(commandLine)).thenReturn(jmxParameters);
Expand Down
Loading