adoroszlai commented on code in PR #10134:
URL: https://github.com/apache/ozone/pull/10134#discussion_r3165980736
##########
hadoop-hdds/cli-common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java:
##########
@@ -78,7 +78,12 @@ public void run(String[] argv) {
int exitCode = execute(argv);
if (exitCode != ExitCode.OK) {
- ExitUtils.terminate(exitCode, null, null);
+ if (cmd.getOut() != null) {
+ cmd.getOut().println("Command executed with exit code: " + exitCode);
+ }
Review Comment:
This looks like extra output, why is this added?
##########
hadoop-ozone/dist/src/shell/ozone/ozone:
##########
@@ -221,6 +221,17 @@ function ozonecmd_case
OZONE_CLASSNAME=org.apache.hadoop.security.token.DtUtilShell
OZONE_RUN_ARTIFACT_NAME="ozone-tools"
;;
+ interactive | --interactive)
+ OZONE_CLASSNAME=org.apache.hadoop.ozone.shell.OzoneInteractiveShell
+ 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
Review 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
##########
hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/OzoneInteractiveShell.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.shell;
+
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.shell.jline3.PicocliCommands.PicocliCommandsFactory;
+
+/**
+ * Interactive Shell for all Ozone commands.
+ */
+public final class OzoneInteractiveShell {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(OzoneInteractiveShell.class);
+
+ private OzoneInteractiveShell() {
+ }
+
+ public static void main(String[] argv) throws Exception {
+ PicocliCommandsFactory factory = new PicocliCommandsFactory();
+ CommandLine topCmd = new CommandLine(new TopCommand(), factory);
+
+ // Add known subcommands statically if they are in the same module.
+ topCmd.addSubcommand("sh", new OzoneShell().getCmd());
+ topCmd.addSubcommand("tenant", new
org.apache.hadoop.ozone.shell.tenant.TenantShell().getCmd());
+ topCmd.addSubcommand("s3", new
org.apache.hadoop.ozone.shell.s3.S3Shell().getCmd());
+
+ // 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");
Review 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.
##########
hadoop-hdds/cli-common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java:
##########
@@ -78,7 +78,12 @@ public void run(String[] argv) {
int exitCode = execute(argv);
if (exitCode != ExitCode.OK) {
- ExitUtils.terminate(exitCode, null, null);
+ if (cmd.getOut() != null) {
+ cmd.getOut().println("Command executed with exit code: " + exitCode);
+ }
+ if (System.getProperty("ozone.interactive.shell") == null) {
Review Comment:
Please define a constant for `"ozone.interactive.shell"` and use in both
places.
##########
hadoop-ozone/dist/src/shell/ozone/ozone:
##########
@@ -318,6 +329,10 @@ fi
OZONE_SUBCMD=$1
+if [[ "$OZONE_SUBCMD" == "--interactive" ]]; then
+ OZONE_SUBCMD="interactive"
+fi
+
Review Comment:
Let's not add `--interactive` for simplicity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]