From 77c9cbe480aff1d8e7432c784f15e3a7aa87fe1e Mon Sep 17 00:00:00 2001 From: pancx Date: Mon, 20 Jan 2025 15:41:31 +0800 Subject: [PATCH] [#6326] improve(CLI): Make CLI more extendable and maintainable. Add config class. --- .../gravitino/cli/GravitinoCommandLine.java | 5 +- .../gravitino/cli/MetalakeCommandHandler.java | 96 +++---- .../gravitino/cli/TestableCommandLine.java | 61 +++-- .../cli/commands/CreateMetalake.java | 16 +- .../cli/commands/DeleteMetalake.java | 16 +- .../cli/commands/ListMetalakeProperties.java | 14 +- .../gravitino/cli/commands/ListMetalakes.java | 21 +- .../gravitino/cli/commands/MetalakeAudit.java | 13 +- .../cli/commands/MetalakeDetails.java | 27 +- .../cli/commands/MetalakeDisable.java | 15 +- .../cli/commands/MetalakeEnable.java | 18 +- .../cli/commands/RemoveMetalakeProperty.java | 17 +- .../cli/commands/SetMetalakeProperty.java | 20 +- .../cli/commands/UpdateMetalakeComment.java | 17 +- .../cli/commands/UpdateMetalakeName.java | 24 +- .../gravitino/cli/config/CreateConfig.java | 58 +++++ .../gravitino/cli/config/DeleteConfig.java | 59 +++++ .../gravitino/cli/config/GenericConfig.java | 238 ++++++++++++++++++ .../gravitino/cli/config/RemoveConfig.java | 60 +++++ .../gravitino/cli/config/SetConfig.java | 65 +++++ .../gravitino/cli/config/UpdateConfig.java | 89 +++++++ .../cli/outputs/BaseOutputFormat.java | 4 +- .../gravitino/cli/outputs/OutputProperty.java | 6 +- .../gravitino/cli/outputs/PlainFormat.java | 2 +- .../gravitino/cli/outputs/TableFormat.java | 2 +- .../gravitino/cli/TestMetalakeCommands.java | 95 ++++--- 26 files changed, 813 insertions(+), 245 deletions(-) create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/config/CreateConfig.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/config/DeleteConfig.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/config/GenericConfig.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/config/RemoveConfig.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/config/SetConfig.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/config/UpdateConfig.java diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java index 84c7fafdbec..58b9f5dc00e 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java @@ -27,6 +27,7 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; +import org.apache.gravitino.cli.config.GenericConfig; /* Gravitino Command line */ public class GravitinoCommandLine extends TestableCommandLine { @@ -107,7 +108,7 @@ public static void displayHelp(Options options) { /** Executes the appropriate command based on the command type. */ private void executeCommand() { - + GenericConfig genericConfig = GenericConfig.fromCommandLine(line); if (CommandActions.HELP.equals(command)) { handleHelpCommand(); } else if (line.hasOption(GravitinoOptions.OWNER)) { @@ -121,7 +122,7 @@ private void executeCommand() { } else if (entity.equals(CommandEntities.CATALOG)) { new CatalogCommandHandler(this, line, command, ignore).handle(); } else if (entity.equals(CommandEntities.METALAKE)) { - new MetalakeCommandHandler(this, line, command, ignore).handle(); + new MetalakeCommandHandler(this, command, genericConfig).handle(); } else if (entity.equals(CommandEntities.TOPIC)) { new TopicCommandHandler(this, line, command, ignore).handle(); } else if (entity.equals(CommandEntities.FILESET)) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java b/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java index d490822adb9..b8b83c9e753 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java @@ -21,41 +21,35 @@ import org.apache.commons.cli.CommandLine; import org.apache.gravitino.cli.commands.Command; -import org.apache.gravitino.cli.outputs.OutputProperty; +import org.apache.gravitino.cli.config.CreateConfig; +import org.apache.gravitino.cli.config.DeleteConfig; +import org.apache.gravitino.cli.config.GenericConfig; +import org.apache.gravitino.cli.config.RemoveConfig; +import org.apache.gravitino.cli.config.SetConfig; +import org.apache.gravitino.cli.config.UpdateConfig; /** * Handles the command execution for Metalakes based on command type and the command line options. */ public class MetalakeCommandHandler extends CommandHandler { + private String command; + private GravitinoCommandLine gravitinoCommandLine; + private CommandLine line; + private GenericConfig genericConfig; + private FullName name; - private final GravitinoCommandLine gravitinoCommandLine; - private final CommandLine line; - private final String command; - private final boolean ignore; - private final String url; - private String metalake; - - /** - * Constructs a MetalakeCommandHandler instance. - * - * @param gravitinoCommandLine The Gravitino command line instance. - * @param line The command line arguments. - * @param command The command to execute. - * @param ignore Ignore server version mismatch. - */ public MetalakeCommandHandler( - GravitinoCommandLine gravitinoCommandLine, CommandLine line, String command, boolean ignore) { + GravitinoCommandLine gravitinoCommandLine, String command, GenericConfig config) { this.gravitinoCommandLine = gravitinoCommandLine; - this.line = line; this.command = command; - this.ignore = ignore; - this.url = getUrl(line); + this.genericConfig = config; + this.line = config.getCommandLine(); + this.name = new FullName(line); } /** Handles the command execution logic based on the provided command. */ public void handle() { String userName = line.getOptionValue(GravitinoOptions.LOGIN); - FullName name = new FullName(line); Command.setAuthenticationMode(getAuth(line), userName); if (CommandActions.LIST.equals(command)) { @@ -63,8 +57,6 @@ public void handle() { return; } - metalake = name.getMetalakeName(); - if (!executeCommand()) { System.err.println(ErrorMessages.UNSUPPORTED_COMMAND); Main.exit(-1); @@ -113,56 +105,45 @@ private boolean executeCommand() { /** Handles the "LIST" command. */ private void handleListCommand() { - // TODO: move this to GravitinoCommandLine class - OutputProperty property = OutputProperty.fromLine(line); - gravitinoCommandLine.newListMetalakes(url, ignore, property).validate().handle(); + gravitinoCommandLine.newListMetalakes(genericConfig).validate().handle(); } /** Handles the "DETAILS" command. */ private void handleDetailsCommand() { - OutputProperty property = OutputProperty.fromLine(line); if (line.hasOption(GravitinoOptions.AUDIT)) { - gravitinoCommandLine.newMetalakeAudit(url, ignore, metalake).validate().handle(); + gravitinoCommandLine.newMetalakeAudit(genericConfig, name).validate().handle(); } else { - // TODO: move this to GravitinoCommandLine class - gravitinoCommandLine.newMetalakeDetails(url, ignore, property, metalake).validate().handle(); + gravitinoCommandLine.newMetalakeDetails(genericConfig, name).validate().handle(); } } /** Handles the "CREATE" command. */ private void handleCreateCommand() { - String comment = line.getOptionValue(GravitinoOptions.COMMENT); - gravitinoCommandLine.newCreateMetalake(url, ignore, metalake, comment).validate().handle(); + CreateConfig createConfig = new CreateConfig(genericConfig); + gravitinoCommandLine.newCreateMetalake(createConfig, name).validate().handle(); } /** Handles the "DELETE" command. */ private void handleDeleteCommand() { - boolean force = line.hasOption(GravitinoOptions.FORCE); - gravitinoCommandLine.newDeleteMetalake(url, ignore, force, metalake).validate().handle(); + DeleteConfig deleteConfig = new DeleteConfig(genericConfig); + gravitinoCommandLine.newDeleteMetalake(deleteConfig, name).validate().handle(); } /** Handles the "SET" command. */ private void handleSetCommand() { - String property = line.getOptionValue(GravitinoOptions.PROPERTY); - String value = line.getOptionValue(GravitinoOptions.VALUE); - gravitinoCommandLine - .newSetMetalakeProperty(url, ignore, metalake, property, value) - .validate() - .handle(); + SetConfig setConfig = new SetConfig(genericConfig); + gravitinoCommandLine.newSetMetalakeProperty(setConfig, name).validate().handle(); } /** Handles the "REMOVE" command. */ private void handleRemoveCommand() { - String property = line.getOptionValue(GravitinoOptions.PROPERTY); - gravitinoCommandLine - .newRemoveMetalakeProperty(url, ignore, metalake, property) - .validate() - .handle(); + RemoveConfig removeConfig = new RemoveConfig(genericConfig); + gravitinoCommandLine.newRemoveMetalakeProperty(removeConfig, name).validate().handle(); } /** Handles the "PROPERTIES" command. */ private void handlePropertiesCommand() { - gravitinoCommandLine.newListMetalakeProperties(url, ignore, metalake).validate().handle(); + gravitinoCommandLine.newListMetalakeProperties(genericConfig, name).validate().handle(); } /** Handles the "UPDATE" command. */ @@ -171,31 +152,20 @@ private void handleUpdateCommand() { System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE); Main.exit(-1); } + + UpdateConfig updateConfig = new UpdateConfig(genericConfig); if (line.hasOption(GravitinoOptions.ENABLE)) { - boolean enableAllCatalogs = line.hasOption(GravitinoOptions.ALL); - gravitinoCommandLine - .newMetalakeEnable(url, ignore, metalake, enableAllCatalogs) - .validate() - .handle(); + gravitinoCommandLine.newMetalakeEnable(updateConfig, name).validate().handle(); } if (line.hasOption(GravitinoOptions.DISABLE)) { - gravitinoCommandLine.newMetalakeDisable(url, ignore, metalake).validate().handle(); + gravitinoCommandLine.newMetalakeDisable(updateConfig, name).validate().handle(); } if (line.hasOption(GravitinoOptions.COMMENT)) { - String comment = line.getOptionValue(GravitinoOptions.COMMENT); - gravitinoCommandLine - .newUpdateMetalakeComment(url, ignore, metalake, comment) - .validate() - .handle(); + gravitinoCommandLine.newUpdateMetalakeComment(updateConfig, name).validate().handle(); } if (line.hasOption(GravitinoOptions.RENAME)) { - String newName = line.getOptionValue(GravitinoOptions.RENAME); - boolean force = line.hasOption(GravitinoOptions.FORCE); - gravitinoCommandLine - .newUpdateMetalakeName(url, ignore, force, metalake, newName) - .validate() - .handle(); + gravitinoCommandLine.newUpdateMetalakeName(updateConfig, name).validate().handle(); } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java index 4751ca509a7..3de7748910f 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java @@ -141,6 +141,12 @@ import org.apache.gravitino.cli.commands.UpdateTopicComment; import org.apache.gravitino.cli.commands.UserAudit; import org.apache.gravitino.cli.commands.UserDetails; +import org.apache.gravitino.cli.config.CreateConfig; +import org.apache.gravitino.cli.config.DeleteConfig; +import org.apache.gravitino.cli.config.GenericConfig; +import org.apache.gravitino.cli.config.RemoveConfig; +import org.apache.gravitino.cli.config.SetConfig; +import org.apache.gravitino.cli.config.UpdateConfig; import org.apache.gravitino.cli.outputs.OutputProperty; /* @@ -158,52 +164,46 @@ protected ServerVersion newServerVersion(String url, boolean ignore) { return new ServerVersion(url, ignore); } - protected MetalakeAudit newMetalakeAudit(String url, boolean ignore, String metalake) { - return new MetalakeAudit(url, ignore, metalake); + protected MetalakeAudit newMetalakeAudit(GenericConfig config, FullName name) { + return new MetalakeAudit(config, name); } - protected MetalakeDetails newMetalakeDetails( - String url, boolean ignore, OutputProperty property, String metalake) { - return new MetalakeDetails(url, ignore, property, metalake); + protected MetalakeDetails newMetalakeDetails(GenericConfig config, FullName name) { + return new MetalakeDetails(config, name); } - protected ListMetalakes newListMetalakes(String url, boolean ignore, OutputProperty property) { - return new ListMetalakes(url, ignore, property); + protected ListMetalakes newListMetalakes(GenericConfig config) { + return new ListMetalakes(config); } - protected CreateMetalake newCreateMetalake( - String url, boolean ignore, String metalake, String comment) { - return new CreateMetalake(url, ignore, metalake, comment); + protected CreateMetalake newCreateMetalake(CreateConfig config, FullName name) { + return new CreateMetalake(config, name); } - protected DeleteMetalake newDeleteMetalake( - String url, boolean ignore, boolean force, String metalake) { - return new DeleteMetalake(url, ignore, force, metalake); + protected DeleteMetalake newDeleteMetalake(DeleteConfig deleteConfig, FullName name) { + return new DeleteMetalake(deleteConfig, name); } - protected SetMetalakeProperty newSetMetalakeProperty( - String url, boolean ignore, String metalake, String property, String value) { - return new SetMetalakeProperty(url, ignore, metalake, property, value); + protected SetMetalakeProperty newSetMetalakeProperty(SetConfig setConfig, FullName name) { + return new SetMetalakeProperty(setConfig, name); } protected RemoveMetalakeProperty newRemoveMetalakeProperty( - String url, boolean ignore, String metalake, String property) { - return new RemoveMetalakeProperty(url, ignore, metalake, property); + RemoveConfig removeConfig, FullName name) { + return new RemoveMetalakeProperty(removeConfig, name); } - protected ListMetalakeProperties newListMetalakeProperties( - String url, boolean ignore, String metalake) { - return new ListMetalakeProperties(url, ignore, metalake); + protected ListMetalakeProperties newListMetalakeProperties(GenericConfig config, FullName name) { + return new ListMetalakeProperties(config, name); } protected UpdateMetalakeComment newUpdateMetalakeComment( - String url, boolean ignore, String metalake, String comment) { - return new UpdateMetalakeComment(url, ignore, metalake, comment); + UpdateConfig updateConfig, FullName name) { + return new UpdateMetalakeComment(updateConfig, name); } - protected UpdateMetalakeName newUpdateMetalakeName( - String url, boolean ignore, boolean force, String metalake, String newName) { - return new UpdateMetalakeName(url, ignore, force, metalake, newName); + protected UpdateMetalakeName newUpdateMetalakeName(UpdateConfig updateConfig, FullName name) { + return new UpdateMetalakeName(updateConfig, name); } protected CatalogAudit newCatalogAudit( @@ -908,13 +908,12 @@ protected RevokeAllPrivileges newRevokeAllPrivileges( return new RevokeAllPrivileges(url, ignore, metalake, role, entity); } - protected MetalakeEnable newMetalakeEnable( - String url, boolean ignore, String metalake, boolean enableAllCatalogs) { - return new MetalakeEnable(url, ignore, metalake, enableAllCatalogs); + protected MetalakeEnable newMetalakeEnable(UpdateConfig updateConfig, FullName name) { + return new MetalakeEnable(updateConfig, name); } - protected MetalakeDisable newMetalakeDisable(String url, boolean ignore, String metalake) { - return new MetalakeDisable(url, ignore, metalake); + protected MetalakeDisable newMetalakeDisable(UpdateConfig updateConfig, FullName name) { + return new MetalakeDisable(updateConfig, name); } protected CatalogEnable newCatalogEnable( diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java index 9a3c033f028..bc5336a20b5 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java @@ -20,6 +20,8 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.CreateConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.MetalakeAlreadyExistsException; @@ -30,15 +32,13 @@ public class CreateMetalake extends Command { /** * Create a new metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. - * @param comment The metalake's comment. + * @param config the {@link CreateConfig} instance containing the configuration for the command. + * @param name the {@link FullName} instance containing the full name of the metalake. */ - public CreateMetalake(String url, boolean ignoreVersions, String metalake, String comment) { - super(url, ignoreVersions); - this.metalake = metalake; - this.comment = comment; + public CreateMetalake(CreateConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); + this.comment = config.getComment(); } /** Create a new metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java index 3bad108a9ec..1304d625164 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java @@ -21,6 +21,8 @@ import org.apache.gravitino.cli.AreYouSure; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.DeleteConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.MetalakeInUseException; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -32,15 +34,13 @@ public class DeleteMetalake extends Command { /** * Delete a metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param force Force operation. - * @param metalake The name of the metalake. + * @param config the {@link DeleteConfig} instance containing the configuration for the command. + * @param name the {@link FullName} instance containing the full name of the metalake. */ - public DeleteMetalake(String url, boolean ignoreVersions, boolean force, String metalake) { - super(url, ignoreVersions); - this.force = force; - this.metalake = metalake; + public DeleteMetalake(DeleteConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.force = config.isForce(); + this.metalake = name.getMetalakeName(); } /** Delete a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java index b7d794d4455..849297f3d3e 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java @@ -22,6 +22,8 @@ import java.util.Map; import org.apache.gravitino.Metalake; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.GenericConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -33,13 +35,13 @@ public class ListMetalakeProperties extends ListProperties { /** * List the properties of a metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. + * @param config the {@link GenericConfig} instance containing the URL and other configuration + * parameters. + * @param name the {@link FullName} instance containing the full name of the metalake. */ - public ListMetalakeProperties(String url, boolean ignoreVersions, String metalake) { - super(url, ignoreVersions); - this.metalake = metalake; + public ListMetalakeProperties(GenericConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); } /** List the properties of a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java index 59859c6c9de..5e56ccef6a2 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.Metalake; +import org.apache.gravitino.cli.config.GenericConfig; import org.apache.gravitino.cli.outputs.OutputProperty; import org.apache.gravitino.client.GravitinoAdminClient; @@ -29,12 +30,22 @@ public class ListMetalakes extends Command { /** * List all metalakes. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param property The output format. + * @param config the {@link GenericConfig} instance containing the configuration for the command. */ - public ListMetalakes(String url, boolean ignoreVersions, OutputProperty property) { - super(url, ignoreVersions, property); + public ListMetalakes(GenericConfig config) { + super( + config.getUrl(), + config.isIgnoreVersion(), + new OutputProperty( + false, + config.isQuiet(), + config.getLimit(), + config.getBorderStyle(), + config.getHeaderAlign(), + config.getDataAlign(), + config.getFooterAlign(), + config.getOutputFormat(), + config.isRowNumbersEnabled())); } /** Lists all metalakes. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java index b966a1ae291..4472b91c221 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java @@ -21,6 +21,8 @@ import org.apache.gravitino.Audit; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.GenericConfig; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -31,13 +33,12 @@ public class MetalakeAudit extends AuditCommand { /** * Displays metalake audit information. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. + * @param config The {@link GenericConfig} instance containing the configuration. + * @param name The {@link FullName} instance containing the full name of the metalake. */ - public MetalakeAudit(String url, boolean ignoreVersions, String metalake) { - super(url, ignoreVersions); - this.metalake = metalake; + public MetalakeAudit(GenericConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); } /** Displays the audit information of a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java index 53537af5a72..4faf819b54f 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java @@ -21,6 +21,8 @@ import org.apache.gravitino.Metalake; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.GenericConfig; import org.apache.gravitino.cli.outputs.OutputProperty; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -32,15 +34,24 @@ public class MetalakeDetails extends Command { /** * Displays metalake details. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param property The output property to use. - * @param metalake The name of the metalake. + * @param config The {@link GenericConfig} instance containing the CLI configuration. + * @param name The {@link FullName} instance containing the full name of the metalake to display. */ - public MetalakeDetails( - String url, boolean ignoreVersions, OutputProperty property, String metalake) { - super(url, ignoreVersions, property); - this.metalake = metalake; + public MetalakeDetails(GenericConfig config, FullName name) { + super( + config.getUrl(), + config.isIgnoreVersion(), + new OutputProperty( + false, + config.isQuiet(), + config.getLimit(), + config.getBorderStyle(), + config.getHeaderAlign(), + config.getDataAlign(), + config.getFooterAlign(), + config.getOutputFormat(), + config.isRowNumbersEnabled())); + this.metalake = name.getMetalakeName(); } /** Displays the name and comment of a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java index 02e33a45d45..772d5b0aa87 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java @@ -20,6 +20,8 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.UpdateConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -28,15 +30,14 @@ public class MetalakeDisable extends Command { private String metalake; /** - * Disable metalake + * Disable metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. + * @param config The {@link UpdateConfig} instance containing the configuration. + * @param name The {@link FullName} instance containing the full name of metalake name. */ - public MetalakeDisable(String url, boolean ignoreVersions, String metalake) { - super(url, ignoreVersions); - this.metalake = metalake; + public MetalakeDisable(UpdateConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); } /** Disable metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java index 34ba23a61bb..492aa052113 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java @@ -21,6 +21,8 @@ import java.util.Arrays; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.UpdateConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.client.GravitinoMetalake; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -34,16 +36,14 @@ public class MetalakeEnable extends Command { /** * Enable a metalake * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. - * @param enableAllCatalogs Whether to enable all catalogs. + * @param updateConfig The {@link UpdateConfig} instance containing the configuration for the + * update. + * @param name The {@link FullName} instance containing the full name of the metalake. */ - public MetalakeEnable( - String url, boolean ignoreVersions, String metalake, boolean enableAllCatalogs) { - super(url, ignoreVersions); - this.metalake = metalake; - this.enableAllCatalogs = enableAllCatalogs; + public MetalakeEnable(UpdateConfig updateConfig, FullName name) { + super(updateConfig.getUrl(), updateConfig.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); + this.enableAllCatalogs = updateConfig.isAll(); } /** Enable metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java index ce3a50fee16..484e7125f05 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java @@ -21,6 +21,8 @@ import org.apache.gravitino.MetalakeChange; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.RemoveConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -33,16 +35,13 @@ public class RemoveMetalakeProperty extends Command { /** * Remove a property of a metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. - * @param property The name of the property. + * @param config The {@link RemoveConfig} instance contain the configuration for the command. + * @param name The {@link FullName} instance contain the full name of metalake. */ - public RemoveMetalakeProperty( - String url, boolean ignoreVersions, String metalake, String property) { - super(url, ignoreVersions); - this.metalake = metalake; - this.property = property; + public RemoveMetalakeProperty(RemoveConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); + this.property = config.getProperty(); } /** Remove a property of a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java index ef67d008bc8..8bdd44c8234 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java @@ -21,6 +21,8 @@ import org.apache.gravitino.MetalakeChange; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.SetConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -34,18 +36,14 @@ public class SetMetalakeProperty extends Command { /** * Set a property of a metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. - * @param property The name of the property. - * @param value The value of the property. + * @param setConfig The {@link SetConfig} instance containing the configuration for the command. + * @param name The {@link FullName} instance containing the full name of the metalake. */ - public SetMetalakeProperty( - String url, boolean ignoreVersions, String metalake, String property, String value) { - super(url, ignoreVersions); - this.metalake = metalake; - this.property = property; - this.value = value; + public SetMetalakeProperty(SetConfig setConfig, FullName name) { + super(setConfig.getUrl(), setConfig.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); + this.property = setConfig.getProperty(); + this.value = setConfig.getValue(); } /** Set a property of a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java index 9ca63084e75..2ce4efb9690 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java @@ -21,6 +21,8 @@ import org.apache.gravitino.MetalakeChange; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.UpdateConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -33,16 +35,13 @@ public class UpdateMetalakeComment extends Command { /** * Update the comment of a metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param metalake The name of the metalake. - * @param comment New metalake comment. + * @param config The {@link UpdateConfig} instance containing the configuration for the command. + * @param name The {@link FullName} instance containing the full name of the metalake. */ - public UpdateMetalakeComment( - String url, boolean ignoreVersions, String metalake, String comment) { - super(url, ignoreVersions); - this.metalake = metalake; - this.comment = comment; + public UpdateMetalakeComment(UpdateConfig config, FullName name) { + super(config.getUrl(), config.isIgnoreVersion()); + this.metalake = name.getMetalakeName(); + this.comment = config.getComment(); } /** Update the comment of a metalake. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java index 275ba3165df..6df609c3cb5 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java @@ -22,6 +22,8 @@ import org.apache.gravitino.MetalakeChange; import org.apache.gravitino.cli.AreYouSure; import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.config.UpdateConfig; import org.apache.gravitino.client.GravitinoAdminClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -29,24 +31,20 @@ public class UpdateMetalakeName extends Command { protected final String metalake; - protected final String name; + protected final String newName; protected final boolean force; /** * Update the name of a metalake. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. - * @param force Force operation. - * @param metalake The name of the metalake. - * @param name The new metalake name. + * @param config the update configuration. + * @param newName the {@link FullName} instance containing the full name of the metalake. */ - public UpdateMetalakeName( - String url, boolean ignoreVersions, boolean force, String metalake, String name) { - super(url, ignoreVersions); - this.force = force; - this.metalake = metalake; - this.name = name; + public UpdateMetalakeName(UpdateConfig config, FullName newName) { + super(config.getUrl(), config.isIgnoreVersion()); + this.force = config.isForce(); + this.metalake = newName.getMetalakeName(); + this.newName = config.getNewName(); } /** Update the name of a metalake. */ @@ -59,7 +57,7 @@ public void handle() { try { GravitinoAdminClient client = buildAdminClient(); - MetalakeChange change = MetalakeChange.rename(name); + MetalakeChange change = MetalakeChange.rename(newName); client.alterMetalake(metalake, change); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/config/CreateConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/config/CreateConfig.java new file mode 100644 index 00000000000..bf50d3d5dc4 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/config/CreateConfig.java @@ -0,0 +1,58 @@ +/* + * 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.gravitino.cli.config; + +import org.apache.commons.cli.CommandLine; +import org.apache.gravitino.cli.GravitinoOptions; + +/** + * Configuration class specifically for create operations, extending GenericConfig with additional + * comment functionality. + * + * @author pancx + */ +public class CreateConfig extends GenericConfig { + private final String comment; + + /** + * Creates a CreateConfig instance from command line arguments. + * + * @param commandLine The {@link CommandLine} instance. + * @return A new CreateConfig instance with settings from command line + */ + public static CreateConfig fromCommandLine(CommandLine commandLine) { + GenericConfig genericConfig = GenericConfig.fromCommandLine(commandLine); + return new CreateConfig(genericConfig); + } + + /** + * Creates a CreateConfig instance from an existing GenericConfig instance. + * + * @param genericConfig The base GenericConfig to inherit settings from + */ + public CreateConfig(GenericConfig genericConfig) { + super(genericConfig); + this.comment = genericConfig.getCommandLine().getOptionValue(GravitinoOptions.COMMENT); + } + + public String getComment() { + return comment; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/config/DeleteConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/config/DeleteConfig.java new file mode 100644 index 00000000000..64d2e7482b1 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/config/DeleteConfig.java @@ -0,0 +1,59 @@ +/* + * 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.gravitino.cli.config; + +import org.apache.commons.cli.CommandLine; +import org.apache.gravitino.cli.GravitinoOptions; + +/** + * Configuration class for delete operations, extending GenericConfig with additional force deletion + * option. + * + * @author pancx + */ +public class DeleteConfig extends GenericConfig { + private final boolean force; + + /** + * Creates a {@code DeleteConfig} instance from command line arguments. + * + * @param commandLine The {@link CommandLine} instance. + * @return A new DeleteConfig instance configured from command line + */ + public static DeleteConfig fromCommandLine(CommandLine commandLine) { + GenericConfig genericConfig = GenericConfig.fromCommandLine(commandLine); + return new DeleteConfig(genericConfig); + } + + /** + * Constructs a {@code DeleteConfig} instance from an existing GenericConfig, extracting the force + * option from the command line. + * + * @param genericConfig The existing {@link GenericConfig} instance. + */ + public DeleteConfig(GenericConfig genericConfig) { + super(genericConfig); + this.force = genericConfig.getCommandLine().hasOption(GravitinoOptions.FORCE); + } + + public boolean isForce() { + return force; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/config/GenericConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/config/GenericConfig.java new file mode 100644 index 00000000000..6613a442b39 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/config/GenericConfig.java @@ -0,0 +1,238 @@ +/* + * 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.gravitino.cli.config; + +import static org.apache.gravitino.cli.outputs.OutputProperty.OUTPUT_FORMAT_PLAIN; + +import org.apache.commons.cli.CommandLine; +import org.apache.gravitino.cli.GravitinoConfig; +import org.apache.gravitino.cli.GravitinoOptions; +import org.apache.gravitino.cli.outputs.BorderStyle; +import org.apache.gravitino.cli.outputs.HorizontalAlign; + +/** + * Generic configuration class that handles command-line options, environment variables, and + * configuration file settings for a Gravitino application. + */ +public class GenericConfig { + public static final String DEFAULT_URL = "http://localhost:8090"; + public static final int WITHOUT_LIMIT = -1; + private String url; + private CommandLine commandLine; + private boolean ignoreVersion; + private String outputFormat; + private boolean quiet; + private int limit; + private BorderStyle borderStyle; + private HorizontalAlign headerAlign; + private HorizontalAlign dataAlign; + private final HorizontalAlign footerAlign; + private boolean rowNumbersEnabled; + private String ignoreEnv; + private boolean ignoreSet = false; + private String urlEnv; + private boolean urlSet = false; + GravitinoConfig config = new GravitinoConfig(null); + + /** + * Creates a {@code GenericConfig} instance from command line arguments. + * + * @param commandLine The parsed command line arguments. + * @return A new GenericConfig instance. + */ + public static GenericConfig fromCommandLine(CommandLine commandLine) { + String outputFormat = + commandLine.getOptionValue(GravitinoOptions.OUTPUT) == null + ? OUTPUT_FORMAT_PLAIN + : commandLine.getOptionValue(GravitinoOptions.OUTPUT); + boolean quiet = commandLine.hasOption(GravitinoOptions.QUIET); + + return new GenericConfig( + commandLine, + outputFormat, + WITHOUT_LIMIT, + quiet, + BorderStyle.BASIC2, + HorizontalAlign.CENTER, + HorizontalAlign.LEFT, + HorizontalAlign.CENTER, + true); + } + + /** + * Constructs a new {@code GenericConfig} with specified settings. + * + * @param line Command line arguments + * @param outputFormat Format for output (e.g., plain, table) + * @param limit Maximum number of rows to display (-1 for unlimited) + * @param quiet Whether to suppress non-essential output + * @param borderStyle Style for table borders + * @param headerAlign Alignment for header text + * @param dataAlign Alignment for data cells + * @param footerAlign Alignment for footer text + * @param rowNumbersEnabled Whether to display row numbers + */ + public GenericConfig( + CommandLine line, + String outputFormat, + int limit, + boolean quiet, + BorderStyle borderStyle, + HorizontalAlign headerAlign, + HorizontalAlign dataAlign, + HorizontalAlign footerAlign, + boolean rowNumbersEnabled) { + this.commandLine = line; + this.outputFormat = outputFormat; + this.quiet = quiet; + + this.borderStyle = borderStyle; + this.headerAlign = headerAlign; + this.dataAlign = dataAlign; + this.footerAlign = footerAlign; + this.limit = limit; + this.rowNumbersEnabled = rowNumbersEnabled; + + this.url = resolveUrl(); + this.ignoreVersion = resolveIgnoreVersion(); + } + + public GenericConfig(GenericConfig base) { + this.commandLine = base.commandLine; + this.outputFormat = base.outputFormat; + this.quiet = base.quiet; + + this.borderStyle = base.borderStyle; + this.headerAlign = base.headerAlign; + this.dataAlign = base.dataAlign; + this.footerAlign = base.footerAlign; + this.limit = base.limit; + this.rowNumbersEnabled = base.rowNumbersEnabled; + + this.url = base.url; + this.ignoreVersion = base.ignoreVersion; + } + + private String resolveUrl() { + GravitinoConfig config = new GravitinoConfig(null); + + // If specified on the command line use that + if (commandLine.hasOption(GravitinoOptions.URL)) { + return commandLine.getOptionValue(GravitinoOptions.URL); + } + + // Cache the Gravitino URL environment variable + if (urlEnv == null && !urlSet) { + urlEnv = System.getenv("GRAVITINO_URL"); + urlSet = true; + } + + // If set return the Gravitino URL environment variable + if (urlEnv != null) { + return urlEnv; + } + + // Check if the Gravitino URL is specified in the configuration file + if (config.fileExists()) { + config.read(); + String configURL = config.getGravitinoURL(); + if (configURL != null) { + return configURL; + } + } + + // Return the default localhost URL + return DEFAULT_URL; + } + + private boolean resolveIgnoreVersion() { + boolean ignore = false; + + /* Check if you should ignore client/version versions */ + if (commandLine.hasOption(GravitinoOptions.IGNORE)) { + ignore = true; + } else { + // Cache the ignore environment variable + if (ignoreEnv == null && !ignoreSet) { + ignoreEnv = System.getenv("GRAVITINO_IGNORE"); + ignore = ignoreEnv != null && ignoreEnv.equals("true"); + ignoreSet = true; + } + + // Check if the ignore name is specified in the configuration file + if (ignoreEnv == null) { + if (config.fileExists()) { + config.read(); + ignore = config.getIgnore(); + } + } + } + + return ignore; + } + + public String getUrl() { + return url; + } + + public boolean isQuiet() { + return quiet; + } + + public void setQuiet(boolean quiet) { + this.quiet = quiet; + } + + public CommandLine getCommandLine() { + return commandLine; + } + + public int getLimit() { + return limit; + } + + public String getOutputFormat() { + return outputFormat; + } + + public BorderStyle getBorderStyle() { + return borderStyle; + } + + public HorizontalAlign getHeaderAlign() { + return headerAlign; + } + + public HorizontalAlign getDataAlign() { + return dataAlign; + } + + public HorizontalAlign getFooterAlign() { + return footerAlign; + } + + public boolean isRowNumbersEnabled() { + return rowNumbersEnabled; + } + + public boolean isIgnoreVersion() { + return ignoreVersion; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/config/RemoveConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/config/RemoveConfig.java new file mode 100644 index 00000000000..75e362f7c12 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/config/RemoveConfig.java @@ -0,0 +1,60 @@ +/* + * 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.gravitino.cli.config; + +import org.apache.commons.cli.CommandLine; +import org.apache.gravitino.cli.GravitinoOptions; + +/** + * Configuration class for property removal operations, extending GenericConfig with property + * specification functionality. + * + * @author pancx + */ +public class RemoveConfig extends GenericConfig { + private String property; + + /** + * Creates a {@code RemoveConfig} instance from command line arguments. + * + * @param commandLine The {@link CommandLine} instance. + * @return A new {@code RemoveConfig} instance configured from command line. + */ + public static RemoveConfig fromCommandLine(CommandLine commandLine) { + GenericConfig genericConfig = GenericConfig.fromCommandLine(commandLine); + return new RemoveConfig(genericConfig); + } + + /** + * Constructs a {@code RemoveConfig} instance from an existing GenericConfig, extracting the + * property to be removed from the command line. + * + * @param config The base configuration to inherit from + * @throws IllegalArgumentException if the property option is missing + */ + public RemoveConfig(GenericConfig config) { + super(config); + this.property = config.getCommandLine().getOptionValue(GravitinoOptions.PROPERTY); + } + + public String getProperty() { + return property; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/config/SetConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/config/SetConfig.java new file mode 100644 index 00000000000..95288a68e2e --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/config/SetConfig.java @@ -0,0 +1,65 @@ +/* + * 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.gravitino.cli.config; + +import org.apache.commons.cli.CommandLine; +import org.apache.gravitino.cli.GravitinoOptions; + +/** + * Configuration class for property setting operations, extending GenericConfig to support setting + * property name and value pairs. + * + * @author pancx + */ +public class SetConfig extends GenericConfig { + private String property; + private String value; + + /** + * Constructs a {@code SetConfig} instance from an existing GenericConfig, extracting the property + * and value from command line options. + * + * @param genericConfig The base configuration to inherit from + */ + public SetConfig(GenericConfig genericConfig) { + super(genericConfig); + this.property = genericConfig.getCommandLine().getOptionValue(GravitinoOptions.PROPERTY); + this.value = genericConfig.getCommandLine().getOptionValue(GravitinoOptions.VALUE); + } + + /** + * Creates a {@code SetConfig} instance from command line arguments. + * + * @param commandLine The {@link CommandLine} instance. + * @return A new {@code SetConfig} instance + */ + public static SetConfig fromCommandLine(CommandLine commandLine) { + GenericConfig genericConfig = GenericConfig.fromCommandLine(commandLine); + return new SetConfig(genericConfig); + } + + public String getProperty() { + return property; + } + + public String getValue() { + return value; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/config/UpdateConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/config/UpdateConfig.java new file mode 100644 index 00000000000..6874c6edac3 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/config/UpdateConfig.java @@ -0,0 +1,89 @@ +/* + * 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.gravitino.cli.config; + +import org.apache.commons.cli.CommandLine; +import org.apache.gravitino.cli.GravitinoOptions; + +/** + * Configuration class for update operations, extending GenericConfig with comprehensive update + * options including enable/disable flags, renaming, and comments. + * + * @author pancx + */ +public class UpdateConfig extends GenericConfig { + + private final boolean enable; + private final boolean disable; + private final boolean all; + private final boolean force; + private final String newName; + private final String comment; + + /** + * Constructs an {@code UpdateConfig} instance from an existing GenericConfig, extracting all + * update-specific options from the command line. + * + * @param config The base configuration to inherit from + */ + public UpdateConfig(GenericConfig config) { + super(config); + this.enable = config.getCommandLine().hasOption(GravitinoOptions.ENABLE); + this.disable = config.getCommandLine().hasOption(GravitinoOptions.DISABLE); + this.all = config.getCommandLine().hasOption(GravitinoOptions.ALL); + this.force = config.getCommandLine().hasOption(GravitinoOptions.FORCE); + this.newName = config.getCommandLine().getOptionValue(GravitinoOptions.RENAME); + this.comment = config.getCommandLine().getOptionValue(GravitinoOptions.COMMENT); + } + + /** + * Creates an {@code UpdateConfig} instance from command line arguments. + * + * @param commandLine The {@link CommandLine} instance. + * @return A new {@code UpdateConfig} instance + */ + public static UpdateConfig fromCommandLine(CommandLine commandLine) { + return new UpdateConfig(GenericConfig.fromCommandLine(commandLine)); + } + + public boolean isEnable() { + return enable; + } + + public boolean isDisable() { + return disable; + } + + public boolean isAll() { + return all; + } + + public boolean isForce() { + return force; + } + + public String getNewName() { + return newName; + } + + public String getComment() { + return comment; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BaseOutputFormat.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BaseOutputFormat.java index d982f28e02d..0139bff8b81 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BaseOutputFormat.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BaseOutputFormat.java @@ -43,12 +43,10 @@ public abstract class BaseOutputFormat implements OutputFormat { * * @param quiet If true, suppresses all output except for errors. * @param limit Maximum number of items to output (use a negative for unlimited). - * @param sort If true, output will be sorted according to implementation. */ - public BaseOutputFormat(boolean quiet, int limit, boolean sort) { + public BaseOutputFormat(boolean quiet, int limit) { this.quiet = quiet; this.limit = limit; - this.sort = sort; } /** diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java index f470abad147..c31e5d19e73 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java @@ -42,7 +42,6 @@ public class OutputProperty { HorizontalAlign.LEFT, HorizontalAlign.CENTER, OUTPUT_FORMAT_PLAIN, - OverflowBehaviour.CLIP_RIGHT, true); private boolean sort; @@ -67,7 +66,6 @@ public class OutputProperty { * @param dataAlign Data cell alignment. * @param footerAlign Footer text alignment. * @param outputFormat Output format type. - * @param overflowBehaviour Overflow handling strategy. * @param rowNumbersEnabled Whether to show row numbers. */ public OutputProperty( @@ -79,7 +77,6 @@ public OutputProperty( HorizontalAlign dataAlign, HorizontalAlign footerAlign, String outputFormat, - OverflowBehaviour overflowBehaviour, boolean rowNumbersEnabled) { this.sort = sort; this.quiet = quiet; @@ -89,7 +86,7 @@ public OutputProperty( this.dataAlign = dataAlign; this.footerAlign = footerAlign; this.outputFormat = outputFormat; - this.overflowBehaviour = overflowBehaviour; + this.overflowBehaviour = OverflowBehaviour.CLIP_RIGHT; this.rowNumbersEnabled = rowNumbersEnabled; } @@ -209,7 +206,6 @@ public OutputProperty copy() { dataAlign, footerAlign, outputFormat, - overflowBehaviour, rowNumbersEnabled); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java index fd3873f3db4..71ba0204b57 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java @@ -69,7 +69,7 @@ public static void output(Object object, OutputProperty property) { * @param property Configuration for controlling output behavior */ public PlainFormat(OutputProperty property) { - super(property.isQuiet(), property.getLimit(), property.isSort()); + super(property.isQuiet(), property.getLimit()); } /** diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java index 05d1dc6b4c6..de23399d4cd 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java @@ -97,7 +97,7 @@ public static void output(Object entity, OutputProperty property) { * @param property Configuration for table formatting and output behavior */ public TableFormat(OutputProperty property) { - super(property.isQuiet(), property.getLimit(), property.isSort()); + super(property.isQuiet(), property.getLimit()); this.property = property; this.borderStyle = property.getStyle(); this.rowNumbersEnabled = property.isRowNumbersEnabled(); diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java index e16569e2753..a7595651d39 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -48,6 +48,8 @@ import org.apache.gravitino.cli.commands.SetMetalakeProperty; import org.apache.gravitino.cli.commands.UpdateMetalakeComment; import org.apache.gravitino.cli.commands.UpdateMetalakeName; +import org.apache.gravitino.cli.config.RemoveConfig; +import org.apache.gravitino.cli.config.SetConfig; import org.junit.Assert; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -91,7 +93,7 @@ void testListMetalakesCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.LIST)); doReturn(mockList) .when(commandLine) - .newListMetalakes(eq(GravitinoCommandLine.DEFAULT_URL), eq(false), any()); + .newListMetalakes(argThat(config -> config.getCommandLine().equals(mockCommandLine))); doReturn(mockList).when(mockList).validate(); commandLine.handleCommandLine(); verify(mockList).handle(); @@ -99,6 +101,7 @@ void testListMetalakesCommand() { @Test void testMetalakeDetailsCommand() { + Main.useExit = false; MetalakeDetails mockDetails = mock(MetalakeDetails.class); when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true); when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo"); @@ -109,8 +112,7 @@ void testMetalakeDetailsCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.DETAILS)); doReturn(mockDetails) .when(commandLine) - .newMetalakeDetails( - eq(GravitinoCommandLine.DEFAULT_URL), eq(false), any(), eq("metalake_demo")); + .newMetalakeDetails(any(), argThat(n -> "metalake_demo".equals(n.getMetalakeName()))); doReturn(mockDetails).when(mockDetails).validate(); commandLine.handleCommandLine(); verify(mockDetails).handle(); @@ -128,7 +130,8 @@ void testMetalakeAuditCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.DETAILS)); doReturn(mockAudit) .when(commandLine) - .newMetalakeAudit(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo"); + .newMetalakeAudit( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockAudit).when(mockAudit).validate(); commandLine.handleCommandLine(); verify(mockAudit).handle(); @@ -147,7 +150,8 @@ void testCreateMetalakeCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.CREATE)); doReturn(mockCreate) .when(commandLine) - .newCreateMetalake(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "comment"); + .newCreateMetalake( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockCreate).when(mockCreate).validate(); commandLine.handleCommandLine(); verify(mockCreate).handle(); @@ -164,7 +168,8 @@ void testCreateMetalakeCommandNoComment() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.CREATE)); doReturn(mockCreate) .when(commandLine) - .newCreateMetalake(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", null); + .newCreateMetalake( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockCreate).when(mockCreate).validate(); commandLine.handleCommandLine(); verify(mockCreate).handle(); @@ -181,7 +186,8 @@ void testDeleteMetalakeCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.DELETE)); doReturn(mockDelete) .when(commandLine) - .newDeleteMetalake(GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo"); + .newDeleteMetalake( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -199,7 +205,8 @@ void testDeleteMetalakeForceCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.DELETE)); doReturn(mockDelete) .when(commandLine) - .newDeleteMetalake(GravitinoCommandLine.DEFAULT_URL, false, true, "metalake_demo"); + .newDeleteMetalake( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -221,7 +228,7 @@ void testSetMetalakePropertyCommand() { doReturn(mockSetProperty) .when(commandLine) .newSetMetalakeProperty( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "property", "value"); + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockSetProperty).when(mockSetProperty).validate(); commandLine.handleCommandLine(); verify(mockSetProperty).handle(); @@ -230,10 +237,12 @@ void testSetMetalakePropertyCommand() { @Test void testSetMetalakePropertyCommandWithoutPropertyAndValue() { Main.useExit = false; - SetMetalakeProperty metalakeProperty = - spy( - new SetMetalakeProperty( - GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", null, null)); + SetConfig mockConfig = mock(SetConfig.class); + when(mockConfig.getProperty()).thenReturn(null); + when(mockConfig.getValue()).thenReturn(null); + FullName mockFullName = mock(FullName.class); + when(mockFullName.getMetalakeName()).thenReturn("metalake_demo"); + SetMetalakeProperty metalakeProperty = spy(new SetMetalakeProperty(mockConfig, mockFullName)); assertThrows(RuntimeException.class, metalakeProperty::validate); String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); @@ -243,10 +252,12 @@ void testSetMetalakePropertyCommandWithoutPropertyAndValue() { @Test void testSetMetalakePropertyCommandWithoutProperty() { Main.useExit = false; - SetMetalakeProperty metalakeProperty = - spy( - new SetMetalakeProperty( - GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", null, "val1")); + SetConfig mockConfig = mock(SetConfig.class); + when(mockConfig.getProperty()).thenReturn(null); + when(mockConfig.getValue()).thenReturn("value"); + FullName mockFullName = mock(FullName.class); + when(mockFullName.getMetalakeName()).thenReturn("metalake_demo"); + SetMetalakeProperty metalakeProperty = spy(new SetMetalakeProperty(mockConfig, mockFullName)); assertThrows(RuntimeException.class, metalakeProperty::validate); String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); @@ -256,10 +267,12 @@ void testSetMetalakePropertyCommandWithoutProperty() { @Test void testSetMetalakePropertyCommandWithoutValue() { Main.useExit = false; - SetMetalakeProperty metalakeProperty = - spy( - new SetMetalakeProperty( - GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", "property1", null)); + SetConfig mockConfig = mock(SetConfig.class); + when(mockConfig.getProperty()).thenReturn("property"); + when(mockConfig.getValue()).thenReturn(null); + FullName mockFullName = mock(FullName.class); + when(mockFullName.getMetalakeName()).thenReturn("metalake_demo"); + SetMetalakeProperty metalakeProperty = spy(new SetMetalakeProperty(mockConfig, mockFullName)); assertThrows(RuntimeException.class, metalakeProperty::validate); String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); @@ -280,7 +293,7 @@ void testRemoveMetalakePropertyCommand() { doReturn(mockRemoveProperty) .when(commandLine) .newRemoveMetalakeProperty( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "property"); + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockRemoveProperty).when(mockRemoveProperty).validate(); commandLine.handleCommandLine(); verify(mockRemoveProperty).handle(); @@ -289,10 +302,13 @@ void testRemoveMetalakePropertyCommand() { @Test void testRemoveMetalakePropertyCommandWithoutProperty() { Main.useExit = false; + RemoveConfig mockRemoveConfig = mock(RemoveConfig.class); + when(mockRemoveConfig.getProperty()).thenReturn(null); + FullName mockFullName = mock(FullName.class); + when(mockFullName.getMetalakeName()).thenReturn("metalake_demo"); + RemoveMetalakeProperty mockRemoveProperty = - spy( - new RemoveMetalakeProperty( - GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", null)); + spy(new RemoveMetalakeProperty(mockRemoveConfig, mockFullName)); assertThrows(RuntimeException.class, mockRemoveProperty::validate); String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); @@ -310,7 +326,8 @@ void testListMetalakePropertiesCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.PROPERTIES)); doReturn(mockListProperties) .when(commandLine) - .newListMetalakeProperties(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo"); + .newListMetalakeProperties( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockListProperties).when(mockListProperties).validate(); commandLine.handleCommandLine(); verify(mockListProperties).handle(); @@ -327,10 +344,7 @@ void testUpdateMetalakeCommentCommand() { spy( new GravitinoCommandLine( mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); - doReturn(mockUpdateComment) - .when(commandLine) - .newUpdateMetalakeComment( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "new comment"); + doReturn(mockUpdateComment).when(commandLine).newUpdateMetalakeComment(any(), any()); doReturn(mockUpdateComment).when(mockUpdateComment).validate(); commandLine.handleCommandLine(); verify(mockUpdateComment).handle(); @@ -350,7 +364,7 @@ void testUpdateMetalakeNameCommand() { doReturn(mockUpdateName) .when(commandLine) .newUpdateMetalakeName( - GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "new_name"); + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockUpdateName).when(mockUpdateName).validate(); commandLine.handleCommandLine(); verify(mockUpdateName).handle(); @@ -371,7 +385,7 @@ void testUpdateMetalakeNameForceCommand() { doReturn(mockUpdateName) .when(commandLine) .newUpdateMetalakeName( - GravitinoCommandLine.DEFAULT_URL, false, true, "metalake_demo", "new_name"); + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockUpdateName).when(mockUpdateName).validate(); commandLine.handleCommandLine(); verify(mockUpdateName).handle(); @@ -389,7 +403,8 @@ void testEnableMetalakeCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); doReturn(mockEnable) .when(commandLine) - .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); + .newMetalakeEnable( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockEnable).when(mockEnable).validate(); commandLine.handleCommandLine(); verify(mockEnable).handle(); @@ -408,7 +423,8 @@ void testEnableMetalakeCommandWithRecursive() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); doReturn(mockEnable) .when(commandLine) - .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", true); + .newMetalakeEnable( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockEnable).when(mockEnable).validate(); commandLine.handleCommandLine(); verify(mockEnable).handle(); @@ -427,7 +443,8 @@ void testDisableMetalakeCommand() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); doReturn(mockDisable) .when(commandLine) - .newMetalakeDisable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo"); + .newMetalakeDisable( + any(), argThat(fullName -> "metalake_demo".equals(fullName.getMetalakeName()))); doReturn(mockDisable).when(mockDisable).validate(); commandLine.handleCommandLine(); verify(mockDisable).handle(); @@ -448,10 +465,8 @@ void testMetalakeWithDisableAndEnableOptions() { mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); Assert.assertThrows(RuntimeException.class, commandLine::handleCommandLine); - verify(commandLine, never()) - .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); - verify(commandLine, never()) - .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); + verify(commandLine, never()).newMetalakeEnable(any(), any()); + verify(commandLine, never()).newMetalakeEnable(any(), any()); assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE)); } }