mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
[CORDA-1552]: Log commands executed by the Shell.
This commit is contained in:
@ -10,9 +10,12 @@ import org.crsh.cli.*;
|
|||||||
import org.crsh.command.*;
|
import org.crsh.command.*;
|
||||||
import org.crsh.text.*;
|
import org.crsh.text.*;
|
||||||
import org.crsh.text.ui.TableElement;
|
import org.crsh.text.ui.TableElement;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.*;
|
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.runFlowByNameFragment;
|
||||||
import static net.corda.tools.shell.InteractiveShell.runStateMachinesView;
|
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."
|
"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 {
|
public class FlowShellCommand extends InteractiveShellCommand {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(FlowShellCommand.class);
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
@Usage("Start a (work)flow on the node. This is how you can change the ledger.")
|
@Usage("Start a (work)flow on the node. This is how you can change the ledger.")
|
||||||
public void start(
|
public void start(
|
||||||
@Usage("The class name of the flow to run, or an unambiguous substring") @Argument String name,
|
@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
|
@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());
|
startFlow(name, input, out, ops(), ansiProgressRenderer(), objectMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +44,7 @@ public class FlowShellCommand extends InteractiveShellCommand {
|
|||||||
@Command
|
@Command
|
||||||
@Usage("watch information about state machines running on the node with result information")
|
@Usage("watch information about state machines running on the node with result information")
|
||||||
public void watch(InvocationContext<TableElement> context) throws Exception {
|
public void watch(InvocationContext<TableElement> context) throws Exception {
|
||||||
|
logger.info("Executing command \"flow watch\".");
|
||||||
runStateMachinesView(out, ops());
|
runStateMachinesView(out, ops());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +65,7 @@ public class FlowShellCommand extends InteractiveShellCommand {
|
|||||||
@Command
|
@Command
|
||||||
@Usage("list flows that user can start")
|
@Usage("list flows that user can start")
|
||||||
public void list(InvocationContext<String> context) throws Exception {
|
public void list(InvocationContext<String> context) throws Exception {
|
||||||
|
logger.info("Executing command \"flow list\".");
|
||||||
for (String name : ops().registeredFlows()) {
|
for (String name : ops().registeredFlows()) {
|
||||||
context.provide(name + System.lineSeparator());
|
context.provide(name + System.lineSeparator());
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import org.crsh.cli.Man;
|
|||||||
import org.crsh.cli.Usage;
|
import org.crsh.cli.Usage;
|
||||||
import org.crsh.command.InvocationContext;
|
import org.crsh.command.InvocationContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,11 +19,15 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static java.util.Comparator.comparing;
|
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
|
// 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.
|
// is the closest you can get in Kotlin to raw types.
|
||||||
|
|
||||||
public class RunShellCommand extends InteractiveShellCommand {
|
public class RunShellCommand extends InteractiveShellCommand {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(RunShellCommand.class);
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
@Man(
|
@Man(
|
||||||
"Runs a method from the CordaRPCOps interface, which is the same interface exposed to RPC clients.\n\n" +
|
"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"
|
"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.")
|
@Usage("runs a method from the CordaRPCOps interface on the node.")
|
||||||
public Object main(
|
public Object main(InvocationContext<Map> context, @Usage("The command to run") @Argument(unquote = false) List<String> command) {
|
||||||
InvocationContext<Map> context,
|
logger.info("Executing command \"run {}\",", command.stream().collect(joining(" ")));
|
||||||
@Usage("The command to run") @Argument(unquote = false) List<String> command
|
|
||||||
) {
|
|
||||||
StringToMethodCallParser<CordaRPCOps> parser = new StringToMethodCallParser<>(CordaRPCOps.class, objectMapper());
|
StringToMethodCallParser<CordaRPCOps> parser = new StringToMethodCallParser<>(CordaRPCOps.class, objectMapper());
|
||||||
|
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
|
@ -5,14 +5,23 @@ package net.corda.tools.shell;
|
|||||||
import net.corda.tools.shell.utlities.ANSIProgressRenderer;
|
import net.corda.tools.shell.utlities.ANSIProgressRenderer;
|
||||||
import net.corda.tools.shell.utlities.CRaSHANSIProgressRenderer;
|
import net.corda.tools.shell.utlities.CRaSHANSIProgressRenderer;
|
||||||
import org.crsh.cli.*;
|
import org.crsh.cli.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
public class StartShellCommand extends InteractiveShellCommand {
|
public class StartShellCommand extends InteractiveShellCommand {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(StartShellCommand.class);
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
@Man("An alias for 'flow start'. Example: \"start Yo target: Some other company\"")
|
@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,
|
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) {
|
@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();
|
ANSIProgressRenderer ansiProgressRenderer = ansiProgressRenderer();
|
||||||
FlowShellCommand.startFlow(name, input, out, ops(), ansiProgressRenderer != null ? ansiProgressRenderer : new CRaSHANSIProgressRenderer(out), objectMapper());
|
FlowShellCommand.startFlow(name, input, out, ops(), ansiProgressRenderer != null ? ansiProgressRenderer : new CRaSHANSIProgressRenderer(out), objectMapper());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user