[CORDA-1552]: Log commands executed by the Shell.

This commit is contained in:
sollecitom 2018-05-30 13:28:05 +01:00
parent 3535633d45
commit 6f0363258e
3 changed files with 27 additions and 5 deletions

View File

@ -10,9 +10,12 @@ import org.crsh.cli.*;
import org.crsh.command.*;
import org.crsh.text.*;
import org.crsh.text.ui.TableElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import static java.util.stream.Collectors.joining;
import static net.corda.tools.shell.InteractiveShell.runFlowByNameFragment;
import static net.corda.tools.shell.InteractiveShell.runStateMachinesView;
@ -24,12 +27,16 @@ import static net.corda.tools.shell.InteractiveShell.runStateMachinesView;
"flow constructors (the right one is picked automatically) are then specified using the same syntax as for the run command."
)
public class FlowShellCommand extends InteractiveShellCommand {
private static Logger logger = LoggerFactory.getLogger(FlowShellCommand.class);
@Command
@Usage("Start a (work)flow on the node. This is how you can change the ledger.")
public void start(
@Usage("The class name of the flow to run, or an unambiguous substring") @Argument String name,
@Usage("The data to pass as input") @Argument(unquote = false) List<String> input
) {
logger.info("Executing command \"flow start {} {}\",", name, input.stream().collect(joining(" ")));
startFlow(name, input, out, ops(), ansiProgressRenderer(), objectMapper());
}
@ -37,6 +44,7 @@ public class FlowShellCommand extends InteractiveShellCommand {
@Command
@Usage("watch information about state machines running on the node with result information")
public void watch(InvocationContext<TableElement> context) throws Exception {
logger.info("Executing command \"flow watch\".");
runStateMachinesView(out, ops());
}
@ -57,6 +65,7 @@ public class FlowShellCommand extends InteractiveShellCommand {
@Command
@Usage("list flows that user can start")
public void list(InvocationContext<String> context) throws Exception {
logger.info("Executing command \"flow list\".");
for (String name : ops().registeredFlows()) {
context.provide(name + System.lineSeparator());
}

View File

@ -10,6 +10,8 @@ import org.crsh.cli.Man;
import org.crsh.cli.Usage;
import org.crsh.command.InvocationContext;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@ -17,11 +19,15 @@ import java.util.Map;
import java.util.Set;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.joining;
// Note that this class cannot be converted to Kotlin because CRaSH does not understand InvocationContext<Map<?, ?>> which
// is the closest you can get in Kotlin to raw types.
public class RunShellCommand extends InteractiveShellCommand {
private static Logger logger = LoggerFactory.getLogger(RunShellCommand.class);
@Command
@Man(
"Runs a method from the CordaRPCOps interface, which is the same interface exposed to RPC clients.\n\n" +
@ -30,10 +36,8 @@ public class RunShellCommand extends InteractiveShellCommand {
"consulting the developer guide at https://docs.corda.net/api/kotlin/corda/net.corda.core.messaging/-corda-r-p-c-ops/index.html"
)
@Usage("runs a method from the CordaRPCOps interface on the node.")
public Object main(
InvocationContext<Map> context,
@Usage("The command to run") @Argument(unquote = false) List<String> command
) {
public Object main(InvocationContext<Map> context, @Usage("The command to run") @Argument(unquote = false) List<String> command) {
logger.info("Executing command \"run {}\",", command.stream().collect(joining(" ")));
StringToMethodCallParser<CordaRPCOps> parser = new StringToMethodCallParser<>(CordaRPCOps.class, objectMapper());
if (command == null) {

View File

@ -5,15 +5,24 @@ package net.corda.tools.shell;
import net.corda.tools.shell.utlities.ANSIProgressRenderer;
import net.corda.tools.shell.utlities.CRaSHANSIProgressRenderer;
import org.crsh.cli.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import static java.util.stream.Collectors.joining;
public class StartShellCommand extends InteractiveShellCommand {
private static Logger logger = LoggerFactory.getLogger(StartShellCommand.class);
@Command
@Man("An alias for 'flow start'. Example: \"start Yo target: Some other company\"")
public void main(@Usage("The class name of the flow to run, or an unambiguous substring") @Argument String name,
@Usage("The data to pass as input") @Argument(unquote = false) List<String> input) {
logger.info("Executing command \"start {} {}\",", name, input.stream().collect(joining(" ")));
ANSIProgressRenderer ansiProgressRenderer = ansiProgressRenderer();
FlowShellCommand.startFlow(name, input, out, ops(), ansiProgressRenderer != null ? ansiProgressRenderer : new CRaSHANSIProgressRenderer(out), objectMapper());
}
}
}