HDDS-11838. Top-level shell to allow access to admin/debug/sh commands#10134
HDDS-11838. Top-level shell to allow access to admin/debug/sh commands#10134will-sh wants to merge 3 commits intoapache:masterfrom
Conversation
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks a lot @will-sh for the patch.
In addition to inline comments, please also add the new command to ozone help here:
ozone/hadoop-ozone/dist/src/shell/ozone/ozone
Lines 62 to 64 in de379b4
| if (cmd.getOut() != null) { | ||
| cmd.getOut().println("Command executed with exit code: " + exitCode); | ||
| } |
There was a problem hiding this comment.
This looks like extra output, why is this added?
| OZONE_RUN_ARTIFACT_NAME="ozone-cli-shell" | ||
| OZONE_OPTS="${OZONE_OPTS} ${RATIS_OPTS} ${OZONE_MODULE_ACCESS_ARGS}" | ||
| # Add all CLI classpaths to support all subcommands dynamically | ||
| for cp_file in "ozone-cli-admin" "ozone-cli-debug" "ozone-cli-repair" "ozone-tools"; do | ||
| if [[ -f "${OZONE_HOME}/share/ozone/classpath/${cp_file}.classpath" ]]; then | ||
| ozone_add_classpath_from_file "${OZONE_HOME}/share/ozone/classpath/${cp_file}.classpath" | ||
| fi | ||
| done |
There was a problem hiding this comment.
Can we create a new submodule to depend on all other CLI modules in the POM? Benefits:
- can add all subcommands statically in
OzoneInteractiveShell, without reflection - avoid the need for custom classpath management
| if [[ "$OZONE_SUBCMD" == "--interactive" ]]; then | ||
| OZONE_SUBCMD="interactive" | ||
| fi | ||
|
|
There was a problem hiding this comment.
Let's not add --interactive for simplicity.
| if (cmd.getOut() != null) { | ||
| cmd.getOut().println("Command executed with exit code: " + exitCode); | ||
| } | ||
| if (System.getProperty("ozone.interactive.shell") == null) { |
There was a problem hiding this comment.
Please define a constant for "ozone.interactive.shell" and use in both places.
| // Dynamically add subcommands from other modules to avoid circular dependencies. | ||
| addDynamicSubcommand(topCmd, "admin", "org.apache.hadoop.ozone.admin.OzoneAdmin"); | ||
| addDynamicSubcommand(topCmd, "debug", "org.apache.hadoop.ozone.debug.OzoneDebug"); | ||
| addDynamicSubcommand(topCmd, "fs", "org.apache.hadoop.fs.ozone.OzoneFsShell"); |
There was a problem hiding this comment.
fs does not appear in help, probably because it's not implemented as GenericCli:
bash-5.1$ ozone interactive
ozone> help
- ozone registry
Summary: admin Developer tools for Ozone Admin operations
debug Developer tools for Ozone Debug operations
repair Advanced tool to repair Ozone. Check the --help output of the subcommand for
s3 Shell for S3 specific operations
sh Shell for Ozone object store
tenant Shell for multi-tenant specific operations
I think we can omit it for now, and maybe refactor OzoneFsShell later.
What changes were proposed in this pull request?
HDDS-11838. Introduce interactive shell mode for Ozone CLI
This PR introduces a new top-level interactive command mode for the Ozone CLI (ozone --interactive). The motivation behind this feature is to provide a cohesive and persistent shell environment where users can execute multiple ozone subcommands (such as sh, admin, debug, etc.) sequentially within the same JVM instance. This avoids the overhead of JVM startup time for each individual command and significantly improves the operational experience.
Approach used to solve the issue:
Interactive Shell Skeleton: Created OzoneInteractiveShell.java based on Picocli and JLine3 to provide a ozone> prompt.
Subcommand Registration: Statically added common module commands (sh, tenant, s3) and dynamically injected commands from other modules (admin, debug, fs, repair) using reflection to avoid circular dependencies across Maven modules.
Execution Isolation (Exception Handling): Modified the GenericCli base class to intercept ExitUtils.terminate(). In interactive mode, if a single command execution fails, the exception is caught and printed without exiting the entire JVM. This ensures the REPL shell persists and awaits the next input.
Shell Script Integration: Updated the hadoop-ozone/dist/src/shell/ozone/ozone startup script to recognize the --interactive flag, configure the OzoneInteractiveShell main class, and dynamically load all necessary classpaths (ozone-cli-admin, ozone-cli-debug, ozone-cli-repair, ozone-tools).
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-11838
How was this patch tested?
Manual Verification Steps:
mvn clean install -DskipTestsVerified that the ozone> prompt correctly appeared.
Executed multiple commands sequentially within the REPL environment:
Verified the execution isolation: intentionally executed failing commands (e.g., creating an existing volume or missing OM configuration) to confirm the interactive shell correctly prints the error message and gracefully recovers to accept the next command without terminating the JVM.