This is an automated email from the ASF dual-hosted git repository. jmclean pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push: new c24f1d60e9 [#6417] improve(CLI): Add model command context CLI (#6430) c24f1d60e9 is described below commit c24f1d60e9842ab8f2c744d60b729621cb850b0e Author: Lord of Abyss <103809695+abyss-l...@users.noreply.github.com> AuthorDate: Tue Feb 11 08:24:49 2025 +0800 [#6417] improve(CLI): Add model command context CLI (#6430) ### What changes were proposed in this pull request? Add model command context CLI ### Why are the changes needed? Fix: #6417 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? local test --- .../apache/gravitino/cli/GravitinoCommandLine.java | 2 +- .../apache/gravitino/cli/ModelCommandHandler.java | 37 +++++------- .../apache/gravitino/cli/TestableCommandLine.java | 32 ++++------- .../apache/gravitino/cli/commands/DeleteModel.java | 21 +++---- .../apache/gravitino/cli/commands/LinkModel.java | 11 ++-- .../apache/gravitino/cli/commands/ListModel.java | 11 ++-- .../apache/gravitino/cli/commands/ModelAudit.java | 21 +++---- .../gravitino/cli/commands/ModelDetails.java | 15 ++--- .../gravitino/cli/commands/RegisterModel.java | 15 ++--- .../apache/gravitino/cli/TestModelCommands.java | 65 +++++++++++----------- 10 files changed, 95 insertions(+), 135 deletions(-) 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 c3404334be..3106c3ea50 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 @@ -138,7 +138,7 @@ public class GravitinoCommandLine extends TestableCommandLine { } else if (entity.equals(CommandEntities.ROLE)) { new RoleCommandHandler(this, line, command, ignore).handle(); } else if (entity.equals(CommandEntities.MODEL)) { - new ModelCommandHandler(this, line, command, ignore).handle(); + new ModelCommandHandler(this, line, command, context).handle(); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ModelCommandHandler.java b/clients/cli/src/main/java/org/apache/gravitino/cli/ModelCommandHandler.java index 9e3c385757..0a0c8e8885 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/ModelCommandHandler.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ModelCommandHandler.java @@ -30,8 +30,7 @@ public class ModelCommandHandler extends CommandHandler { private final GravitinoCommandLine gravitinoCommandLine; private final CommandLine line; private final String command; - private final boolean ignore; - private final String url; + private final CommandContext context; private final FullName name; private final String metalake; private final String catalog; @@ -44,16 +43,19 @@ public class ModelCommandHandler extends CommandHandler { * @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. + * @param context The command context. */ public ModelCommandHandler( - GravitinoCommandLine gravitinoCommandLine, CommandLine line, String command, boolean ignore) { + GravitinoCommandLine gravitinoCommandLine, + CommandLine line, + String command, + CommandContext context) { this.gravitinoCommandLine = gravitinoCommandLine; this.line = line; this.command = command; - this.ignore = ignore; - this.url = getUrl(line); + this.context = context; + this.context.setUrl(getUrl(line)); this.name = new FullName(line); this.metalake = name.getMetalakeName(); this.catalog = name.getCatalogName(); @@ -119,12 +121,12 @@ public class ModelCommandHandler extends CommandHandler { private void handleDetailsCommand() { if (line.hasOption(GravitinoOptions.AUDIT)) { gravitinoCommandLine - .newModelAudit(url, ignore, metalake, catalog, schema, model) + .newModelAudit(context, metalake, catalog, schema, model) .validate() .handle(); } else { gravitinoCommandLine - .newModelDetails(url, ignore, metalake, catalog, schema, model) + .newModelDetails(context, metalake, catalog, schema, model) .validate() .handle(); } @@ -136,17 +138,15 @@ public class ModelCommandHandler extends CommandHandler { String[] createProperties = line.getOptionValues(GravitinoOptions.PROPERTIES); Map<String, String> createPropertyMap = new Properties().parse(createProperties); gravitinoCommandLine - .newCreateModel( - url, ignore, metalake, catalog, schema, model, createComment, createPropertyMap) + .newCreateModel(context, metalake, catalog, schema, model, createComment, createPropertyMap) .validate() .handle(); } /** Handles the "DELETE" command. */ private void handleDeleteCommand() { - boolean force = line.hasOption(GravitinoOptions.FORCE); gravitinoCommandLine - .newDeleteModel(url, ignore, force, metalake, catalog, schema, model) + .newDeleteModel(context, metalake, catalog, schema, model) .validate() .handle(); } @@ -160,22 +160,13 @@ public class ModelCommandHandler extends CommandHandler { Map<String, String> linkPropertityMap = new Properties().parse(linkProperties); gravitinoCommandLine .newLinkModel( - url, - ignore, - metalake, - catalog, - schema, - model, - uri, - alias, - linkComment, - linkPropertityMap) + context, metalake, catalog, schema, model, uri, alias, linkComment, linkPropertityMap) .validate() .handle(); } /** Handles the "LIST" command. */ private void handleListCommand() { - gravitinoCommandLine.newListModel(url, ignore, metalake, catalog, schema).validate().handle(); + gravitinoCommandLine.newListModel(context, metalake, catalog, schema).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 3c6193f9d8..58dc0ac9e8 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 @@ -903,46 +903,38 @@ public class TestableCommandLine { } protected ListModel newListModel( - String url, boolean ignore, String metalake, String catalog, String schema) { - return new ListModel(url, ignore, metalake, catalog, schema); + CommandContext context, String metalake, String catalog, String schema) { + return new ListModel(context, metalake, catalog, schema); } protected ModelAudit newModelAudit( - String url, boolean ignore, String metalake, String catalog, String schema, String model) { - return new ModelAudit(url, ignore, metalake, catalog, schema, model); + CommandContext context, String metalake, String catalog, String schema, String model) { + return new ModelAudit(context, metalake, catalog, schema, model); } protected ModelDetails newModelDetails( - String url, boolean ignore, String metalake, String catalog, String schema, String model) { - return new ModelDetails(url, ignore, metalake, catalog, schema, model); + CommandContext context, String metalake, String catalog, String schema, String model) { + return new ModelDetails(context, metalake, catalog, schema, model); } protected RegisterModel newCreateModel( - String url, - boolean ignore, + CommandContext context, String metalake, String catalog, String schema, String model, String comment, Map<String, String> properties) { - return new RegisterModel(url, ignore, metalake, catalog, schema, model, comment, properties); + return new RegisterModel(context, metalake, catalog, schema, model, comment, properties); } protected DeleteModel newDeleteModel( - String url, - boolean ignore, - boolean force, - String metalake, - String catalog, - String schema, - String model) { - return new DeleteModel(url, ignore, force, metalake, catalog, schema, model); + CommandContext context, String metalake, String catalog, String schema, String model) { + return new DeleteModel(context, metalake, catalog, schema, model); } protected LinkModel newLinkModel( - String url, - boolean ignore, + CommandContext context, String metalake, String catalog, String schema, @@ -952,6 +944,6 @@ public class TestableCommandLine { String comment, Map<String, String> properties) { return new LinkModel( - url, ignore, metalake, catalog, schema, model, uri, alias, comment, properties); + context, metalake, catalog, schema, model, uri, alias, comment, properties); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteModel.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteModel.java index f44814ce68..8dc283ee4d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteModel.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteModel.java @@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.cli.AreYouSure; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; @@ -40,24 +41,16 @@ public class DeleteModel extends Command { /** * Deletes an existing model. * - * @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 context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of the schema. * @param model The name of the model. */ public DeleteModel( - String url, - boolean ignoreVersions, - boolean force, - String metalake, - String catalog, - String schema, - String model) { - super(url, ignoreVersions); - this.force = force; + CommandContext context, String metalake, String catalog, String schema, String model) { + super(context); + this.force = context.force(); this.metalake = metalake; this.catalog = catalog; this.schema = schema; @@ -88,9 +81,9 @@ public class DeleteModel extends Command { } if (deleted) { - System.out.println(model + " deleted."); + printInformation(model + " deleted."); } else { - System.out.println(model + " not deleted."); + printInformation(model + " not deleted."); } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/LinkModel.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/LinkModel.java index cf34eae882..94a5f99a5b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/LinkModel.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/LinkModel.java @@ -22,6 +22,7 @@ package org.apache.gravitino.cli.commands; import java.util.Arrays; import java.util.Map; import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.ModelVersionAliasesAlreadyExistException; @@ -44,8 +45,7 @@ public class LinkModel extends Command { /** * Link a new model version to the registered model. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. + * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of schema. @@ -56,8 +56,7 @@ public class LinkModel extends Command { * @param properties The properties of the model version. */ public LinkModel( - String url, - boolean ignoreVersions, + CommandContext context, String metalake, String catalog, String schema, @@ -66,7 +65,7 @@ public class LinkModel extends Command { String[] alias, String comment, Map<String, String> properties) { - super(url, ignoreVersions); + super(context); this.metalake = metalake; this.catalog = catalog; this.schema = schema; @@ -100,7 +99,7 @@ public class LinkModel extends Command { exitWithError(err.getMessage()); } - System.out.println( + printResults( "Linked model " + model + " to " + uri + " with aliases " + Arrays.toString(alias)); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListModel.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListModel.java index 1528e954b1..fb39e08a93 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListModel.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListModel.java @@ -22,6 +22,7 @@ import com.google.common.base.Joiner; import java.util.Arrays; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.Namespace; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; @@ -37,15 +38,13 @@ public class ListModel extends Command { /** * List the names of all models in a schema. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. + * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of schema. */ - public ListModel( - String url, boolean ignoreVersions, String metalake, String catalog, String schema) { - super(url, ignoreVersions); + public ListModel(CommandContext context, String metalake, String catalog, String schema) { + super(context); this.metalake = metalake; this.catalog = catalog; this.schema = schema; @@ -75,6 +74,6 @@ public class ListModel extends Command { ? "No models exist." : Joiner.on(",").join(Arrays.stream(models).map(model -> model.name()).iterator()); - System.out.println(output); + printResults(output); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelAudit.java index 841afd2de9..b6127937f9 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelAudit.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; @@ -39,21 +40,15 @@ public class ModelAudit extends AuditCommand { /** * Displays the audit information of a model. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. + * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of the schema. * @param model The name of the model. */ public ModelAudit( - String url, - boolean ignoreVersions, - String metalake, - String catalog, - String schema, - String model) { - super(url, ignoreVersions); + CommandContext context, String metalake, String catalog, String schema, String model) { + super(context); this.metalake = metalake; this.catalog = catalog; this.schema = schema; @@ -70,16 +65,16 @@ public class ModelAudit extends AuditCommand { ModelCatalog modelCatalog = client.loadCatalog(catalog).asModelCatalog(); result = modelCatalog.getModel(name); } catch (NoSuchMetalakeException err) { - System.err.println(ErrorMessages.UNKNOWN_METALAKE); + exitWithError(ErrorMessages.UNKNOWN_METALAKE); return; } catch (NoSuchCatalogException err) { - System.err.println(ErrorMessages.UNKNOWN_CATALOG); + exitWithError(ErrorMessages.UNKNOWN_CATALOG); return; } catch (NoSuchModelException err) { - System.err.println(ErrorMessages.UNKNOWN_MODEL); + exitWithError(ErrorMessages.UNKNOWN_MODEL); return; } catch (Exception exp) { - System.err.println(exp.getMessage()); + exitWithError(exp.getMessage()); return; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java index 6c3aec08fa..4c5f1a57d4 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java @@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands; import java.util.Arrays; import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; @@ -40,21 +41,15 @@ public class ModelDetails extends Command { /** * Displays the details of a model. * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. + * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of schema. * @param model The name of model. */ public ModelDetails( - String url, - boolean ignoreVersions, - String metalake, - String catalog, - String schema, - String model) { - super(url, ignoreVersions); + CommandContext context, String metalake, String catalog, String schema, String model) { + super(context); this.metalake = metalake; this.catalog = catalog; this.schema = schema; @@ -87,6 +82,6 @@ public class ModelDetails extends Command { String basicInfo = String.format("Model name %s, latest version: %s%n", gModel.name(), gModel.latestVersion()); String versionInfo = Arrays.toString(versions); - System.out.printf(basicInfo + "versions: " + versionInfo); + printResults(basicInfo + "versions: " + versionInfo); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java index 7c8cd120bf..8d86bd32f7 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java @@ -21,8 +21,8 @@ package org.apache.gravitino.cli.commands; import java.util.Map; import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; -import org.apache.gravitino.cli.Main; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.ModelAlreadyExistsException; import org.apache.gravitino.exceptions.NoSuchCatalogException; @@ -44,8 +44,7 @@ public class RegisterModel extends Command { /** * Register a model in the catalog * - * @param url The URL of the Gravitino server. - * @param ignoreVersions If true don't check the client/server versions match. + * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of schema. @@ -54,15 +53,14 @@ public class RegisterModel extends Command { * @param properties The properties of the model version. */ public RegisterModel( - String url, - boolean ignoreVersions, + CommandContext context, String metalake, String catalog, String schema, String model, String comment, Map<String, String> properties) { - super(url, ignoreVersions); + super(context); this.metalake = metalake; this.catalog = catalog; this.schema = schema; @@ -94,10 +92,9 @@ public class RegisterModel extends Command { } if (registeredModel != null) { - System.out.println("Successful register " + registeredModel.name() + "."); + printInformation("Successful register " + registeredModel.name() + "."); } else { - System.err.println(ErrorMessages.REGISTER_FAILED + model + "."); - Main.exit(-1); + exitWithError(ErrorMessages.REGISTER_FAILED + model + "."); } } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java index 4f1507cc70..6f5e607c91 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java @@ -21,6 +21,7 @@ package org.apache.gravitino.cli; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; @@ -88,8 +89,7 @@ public class TestModelCommands { doReturn(mockList) .when(commandLine) - .newListModel( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", "schema"); + .newListModel(any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema")); doReturn(mockList).when(mockList).validate(); commandLine.handleCommandLine(); verify(mockList).handle(); @@ -108,7 +108,7 @@ public class TestModelCommands { assertThrows(RuntimeException.class, commandLine::handleCommandLine); verify(commandLine, never()) - .newListModel(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", null, null); + .newListModel(any(CommandContext.class), eq("metalake_demo"), isNull(), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals( ErrorMessages.MISSING_NAME @@ -132,7 +132,7 @@ public class TestModelCommands { assertThrows(RuntimeException.class, commandLine::handleCommandLine); verify(commandLine, never()) - .newListModel(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", null); + .newListModel(any(CommandContext.class), eq("metalake_demo"), eq("catalog"), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals( ErrorMessages.MALFORMED_NAME @@ -157,7 +157,11 @@ public class TestModelCommands { doReturn(mockList) .when(commandLine) .newModelDetails( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", "schema", "model"); + any(CommandContext.class), + eq("metalake_demo"), + eq("catalog"), + eq("schema"), + eq("model")); doReturn(mockList).when(mockList).validate(); commandLine.handleCommandLine(); verify(mockList).handle(); @@ -178,7 +182,7 @@ public class TestModelCommands { verify(commandLine, never()) .newModelDetails( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", null, null, null); + any(CommandContext.class), eq("metalake_demo"), isNull(), isNull(), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals( ErrorMessages.MISSING_NAME @@ -206,7 +210,7 @@ public class TestModelCommands { verify(commandLine, never()) .newModelDetails( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", null, null); + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), isNull(), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals( ErrorMessages.MALFORMED_NAME @@ -232,7 +236,7 @@ public class TestModelCommands { verify(commandLine, never()) .newModelDetails( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", "schema", null); + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals( ErrorMessages.MALFORMED_NAME @@ -258,7 +262,11 @@ public class TestModelCommands { doReturn(mockAudit) .when(commandLine) .newModelAudit( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", "schema", "model"); + any(CommandContext.class), + eq("metalake_demo"), + eq("catalog"), + eq("schema"), + eq("model")); doReturn(mockAudit).when(mockAudit).validate(); commandLine.handleCommandLine(); verify(mockAudit).handle(); @@ -281,8 +289,7 @@ public class TestModelCommands { doReturn(mockCreate) .when(commandLine) .newCreateModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), @@ -311,8 +318,7 @@ public class TestModelCommands { doReturn(mockCreate) .when(commandLine) .newCreateModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), @@ -343,8 +349,7 @@ public class TestModelCommands { doReturn(mockCreate) .when(commandLine) .newCreateModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), @@ -380,8 +385,7 @@ public class TestModelCommands { doReturn(mockCreate) .when(commandLine) .newCreateModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), @@ -412,13 +416,11 @@ public class TestModelCommands { doReturn(mockDelete) .when(commandLine) .newDeleteModel( - GravitinoCommandLine.DEFAULT_URL, - false, - false, - "metalake_demo", - "catalog", - "schema", - "model"); + any(CommandContext.class), + eq("metalake_demo"), + eq("catalog"), + eq("schema"), + eq("model")); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -442,8 +444,7 @@ public class TestModelCommands { doReturn(linkModelMock) .when(commandLine) .newLinkModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), @@ -477,8 +478,7 @@ public class TestModelCommands { doReturn(linkModelMock) .when(commandLine) .newLinkModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"), @@ -499,12 +499,12 @@ public class TestModelCommands { @Test void testLinkModelCommandWithoutURI() { Main.useExit = false; - + CommandContext mockContext = mock(CommandContext.class); + when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL); LinkModel spyLinkModel = spy( new LinkModel( - GravitinoCommandLine.DEFAULT_URL, - false, + mockContext, "metalake_demo", "catalog", "schema", @@ -545,8 +545,7 @@ public class TestModelCommands { doReturn(linkModelMock) .when(commandLine) .newLinkModel( - eq(GravitinoCommandLine.DEFAULT_URL), - eq(false), + any(CommandContext.class), eq("metalake_demo"), eq("catalog"), eq("schema"),