-
Notifications
You must be signed in to change notification settings - Fork 599
HDDS-11838. Top-level shell to allow access to admin/debug/sh commands #10134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please define a constant for |
||
| ExitUtils.terminate(exitCode, null, null); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we can omit it for now, and maybe refactor |
||
| addDynamicSubcommand(topCmd, "repair", "org.apache.hadoop.ozone.repair.OzoneRepair"); | ||
|
|
||
| Shell dummyShell = new Shell() { | ||
| @Override | ||
| public String name() { | ||
| return "ozone"; | ||
| } | ||
|
|
||
| @Override | ||
| public String prompt() { | ||
| return "ozone"; | ||
| } | ||
| }; | ||
|
|
||
| new REPL(dummyShell, topCmd, factory, null); | ||
| } | ||
|
|
||
| private static void addDynamicSubcommand(CommandLine topCmd, String name, String className) { | ||
| try { | ||
| Class<?> clazz = Class.forName(className); | ||
| GenericCli instance = (GenericCli) clazz.getDeclaredConstructor().newInstance(); | ||
| topCmd.addSubcommand(name, instance.getCmd()); | ||
| } catch (Exception e) { | ||
| LOG.debug("Subcommand {} not loaded: class {} not found or could not be instantiated", | ||
| name, className, e); | ||
| } | ||
| } | ||
|
|
||
| @Command(name = "ozone", description = "Interactive Shell for all Ozone commands", mixinStandardHelpOptions = true) | ||
| private static class TopCommand implements Runnable { | ||
| @Override | ||
| public void run() { | ||
| // The top-level command is only used to group subcommands and has no execution logic itself. | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Comment on lines
+226
to
+233
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create a new submodule to depend on all other CLI modules in the POM? Benefits:
|
||
| ;; | ||
| admin) | ||
| OZONE_CLASSNAME=org.apache.hadoop.ozone.admin.OzoneAdmin | ||
| OZONE_ADMIN_OPTS="${OZONE_ADMIN_OPTS} ${RATIS_OPTS} ${OZONE_MODULE_ACCESS_ARGS}" | ||
|
|
@@ -318,6 +329,10 @@ fi | |
|
|
||
| OZONE_SUBCMD=$1 | ||
|
|
||
| if [[ "$OZONE_SUBCMD" == "--interactive" ]]; then | ||
| OZONE_SUBCMD="interactive" | ||
| fi | ||
|
|
||
|
Comment on lines
+332
to
+335
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not add |
||
| if [[ "$OZONE_SUBCMD" == "auditparser" ]] || [[ "$OZONE_SUBCMD" == "checknative" ]]; then | ||
| echo "warning: 'ozone $OZONE_SUBCMD' is deprecated, use 'ozone debug $OZONE_SUBCMD' instead." | ||
| OZONE_SUBCMD="debug" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like extra output, why is this added?