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 2bb40373a69..e61051e5382 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 @@ -130,9 +130,9 @@ private void executeCommand() { } else if (entity.equals(CommandEntities.FILESET)) { new FilesetCommandHandler(this, line, command, context).handle(); } else if (entity.equals(CommandEntities.USER)) { - new UserCommandHandler(this, line, command, ignore).handle(); + new UserCommandHandler(this, line, command, context).handle(); } else if (entity.equals(CommandEntities.GROUP)) { - new GroupCommandHandler(this, line, command, ignore).handle(); + new GroupCommandHandler(this, line, command, context).handle(); } else if (entity.equals(CommandEntities.TAG)) { new TagCommandHandler(this, line, command, context).handle(); } else if (entity.equals(CommandEntities.ROLE)) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GroupCommandHandler.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GroupCommandHandler.java index 7542b17974b..6fcec1447b2 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GroupCommandHandler.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GroupCommandHandler.java @@ -27,8 +27,7 @@ public class GroupCommandHandler 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 String group; @@ -39,16 +38,19 @@ public class GroupCommandHandler 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 GroupCommandHandler( - 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.context = context; - this.url = getUrl(line); + this.context.setUrl(getUrl(line)); this.name = new FullName(line); this.metalake = name.getMetalakeName(); } @@ -111,21 +113,20 @@ private boolean executeCommand() { /** Handles the "DETAILS" command. */ private void handleDetailsCommand() { if (line.hasOption(GravitinoOptions.AUDIT)) { - gravitinoCommandLine.newGroupAudit(url, ignore, metalake, group).validate().handle(); + gravitinoCommandLine.newGroupAudit(context, metalake, group).validate().handle(); } else { - gravitinoCommandLine.newGroupDetails(url, ignore, metalake, group).validate().handle(); + gravitinoCommandLine.newGroupDetails(context, metalake, group).validate().handle(); } } /** Handles the "CREATE" command. */ private void handleCreateCommand() { - gravitinoCommandLine.newCreateGroup(url, ignore, metalake, group).validate().handle(); + gravitinoCommandLine.newCreateGroup(context, metalake, group).validate().handle(); } /** Handles the "DELETE" command. */ private void handleDeleteCommand() { - boolean force = line.hasOption(GravitinoOptions.FORCE); - gravitinoCommandLine.newDeleteGroup(url, ignore, force, metalake, group).validate().handle(); + gravitinoCommandLine.newDeleteGroup(context, metalake, group).validate().handle(); } /** Handles the "REVOKE" command. */ @@ -133,7 +134,7 @@ private void handleRevokeCommand() { boolean revokeAll = line.hasOption(GravitinoOptions.ALL); if (revokeAll) { gravitinoCommandLine - .newRemoveAllRoles(url, ignore, metalake, group, CommandEntities.GROUP) + .newRemoveAllRoles(context, metalake, group, CommandEntities.GROUP) .validate() .handle(); System.out.printf("Removed all roles from group %s%n", group); @@ -141,7 +142,7 @@ private void handleRevokeCommand() { String[] revokeRoles = line.getOptionValues(GravitinoOptions.ROLE); for (String role : revokeRoles) { gravitinoCommandLine - .newRemoveRoleFromGroup(url, ignore, metalake, group, role) + .newRemoveRoleFromGroup(context, metalake, group, role) .validate() .handle(); } @@ -153,16 +154,13 @@ private void handleRevokeCommand() { private void handleGrantCommand() { String[] grantRoles = line.getOptionValues(GravitinoOptions.ROLE); for (String role : grantRoles) { - gravitinoCommandLine - .newAddRoleToGroup(url, ignore, metalake, group, role) - .validate() - .handle(); + gravitinoCommandLine.newAddRoleToGroup(context, metalake, group, role).validate().handle(); } System.out.printf("Grant roles %s to group %s%n", COMMA_JOINER.join(grantRoles), group); } /** Handles the "LIST" command. */ private void handleListCommand() { - gravitinoCommandLine.newListGroups(url, ignore, metalake).validate().handle(); + gravitinoCommandLine.newListGroups(context, metalake).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 0217d21d273..a4f47239c71 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 @@ -386,71 +386,69 @@ protected ListTableProperties newListTableProperties( return new ListTableProperties(context, metalake, catalog, schema, table); } - protected UserDetails newUserDetails(String url, boolean ignore, String metalake, String user) { - return new UserDetails(url, ignore, metalake, user); + protected UserDetails newUserDetails(CommandContext context, String metalake, String user) { + return new UserDetails(context, metalake, user); } - protected ListUsers newListUsers(String url, boolean ignore, String metalake) { - return new ListUsers(url, ignore, metalake); + protected ListUsers newListUsers(CommandContext context, String metalake) { + return new ListUsers(context, metalake); } - protected UserAudit newUserAudit(String url, boolean ignore, String metalake, String user) { - return new UserAudit(url, ignore, metalake, user); + protected UserAudit newUserAudit(CommandContext context, String metalake, String user) { + return new UserAudit(context, metalake, user); } - protected CreateUser newCreateUser(String url, boolean ignore, String metalake, String user) { - return new CreateUser(url, ignore, metalake, user); + protected CreateUser newCreateUser(CommandContext context, String metalake, String user) { + return new CreateUser(context, metalake, user); } - protected DeleteUser newDeleteUser( - String url, boolean ignore, boolean force, String metalake, String user) { - return new DeleteUser(url, ignore, force, metalake, user); + protected DeleteUser newDeleteUser(CommandContext context, String metalake, String user) { + return new DeleteUser(context, metalake, user); } protected RemoveRoleFromUser newRemoveRoleFromUser( - String url, boolean ignore, String metalake, String user, String role) { - return new RemoveRoleFromUser(url, ignore, metalake, user, role); + CommandContext context, String metalake, String user, String role) { + return new RemoveRoleFromUser(context, metalake, user, role); } protected AddRoleToUser newAddRoleToUser( - String url, boolean ignore, String metalake, String user, String role) { - return new AddRoleToUser(url, ignore, metalake, user, role); + CommandContext context, String metalake, String user, String role) { + return new AddRoleToUser(context, metalake, user, role); } - protected GroupDetails newGroupDetails(String url, boolean ignore, String metalake, String user) { - return new GroupDetails(url, ignore, metalake, user); + protected GroupDetails newGroupDetails(CommandContext context, String metalake, String user) { + return new GroupDetails(context, metalake, user); } - protected ListGroups newListGroups(String url, boolean ignore, String metalake) { - return new ListGroups(url, ignore, metalake); + protected ListGroups newListGroups(CommandContext context, String metalake) { + return new ListGroups(context, metalake); } - protected GroupAudit newGroupAudit(String url, boolean ignore, String metalake, String group) { - return new GroupAudit(url, ignore, metalake, group); + protected GroupAudit newGroupAudit(CommandContext context, String metalake, String group) { + return new GroupAudit(context, metalake, group); } - protected CreateGroup newCreateGroup(String url, boolean ignore, String metalake, String user) { - return new CreateGroup(url, ignore, metalake, user); + protected CreateGroup newCreateGroup(CommandContext context, String metalake, String user) { + return new CreateGroup(context, metalake, user); } - protected DeleteGroup newDeleteGroup( - String url, boolean ignore, boolean force, String metalake, String user) { - return new DeleteGroup(url, ignore, force, metalake, user); + protected DeleteGroup newDeleteGroup(CommandContext context, String metalake, String user) { + return new DeleteGroup(context, metalake, user); } protected RemoveRoleFromGroup newRemoveRoleFromGroup( - String url, boolean ignore, String metalake, String group, String role) { - return new RemoveRoleFromGroup(url, ignore, metalake, group, role); + CommandContext context, String metalake, String group, String role) { + return new RemoveRoleFromGroup(context, metalake, group, role); } protected RemoveAllRoles newRemoveAllRoles( - String url, boolean ignore, String metalake, String entity, String entityType) { - return new RemoveAllRoles(url, ignore, metalake, entity, entityType); + CommandContext context, String metalake, String entity, String entityType) { + return new RemoveAllRoles(context, metalake, entity, entityType); } protected AddRoleToGroup newAddRoleToGroup( - String url, boolean ignore, String metalake, String group, String role) { - return new AddRoleToGroup(url, ignore, metalake, group, role); + CommandContext context, String metalake, String group, String role) { + return new AddRoleToGroup(context, metalake, group, role); } protected RoleDetails newRoleDetails(String url, boolean ignore, String metalake, String role) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/UserCommandHandler.java b/clients/cli/src/main/java/org/apache/gravitino/cli/UserCommandHandler.java index 23698aa5cf8..964d2ba6d99 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/UserCommandHandler.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/UserCommandHandler.java @@ -27,8 +27,7 @@ public class UserCommandHandler 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 String user; @@ -39,16 +38,19 @@ public class UserCommandHandler 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 UserCommandHandler( - 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.context = context; - this.url = getUrl(line); + this.context.setUrl(getUrl(line)); this.name = new FullName(line); this.metalake = name.getMetalakeName(); } @@ -110,42 +112,26 @@ private boolean executeCommand() { /** Handles the "LIST" command. */ private void handleListCommand() { - this.gravitinoCommandLine - .newListUsers(this.url, this.ignore, this.metalake) - .validate() - .handle(); + this.gravitinoCommandLine.newListUsers(context, metalake).validate().handle(); } /** Handles the "DETAILS" command. */ private void handleDetailsCommand() { if (line.hasOption(GravitinoOptions.AUDIT)) { - this.gravitinoCommandLine - .newUserAudit(this.url, this.ignore, this.metalake, user) - .validate() - .handle(); + this.gravitinoCommandLine.newUserAudit(context, metalake, user).validate().handle(); } else { - this.gravitinoCommandLine - .newUserDetails(this.url, this.ignore, this.metalake, user) - .validate() - .handle(); + this.gravitinoCommandLine.newUserDetails(context, metalake, user).validate().handle(); } } /** Handles the "CREATE" command. */ private void handleCreateCommand() { - this.gravitinoCommandLine - .newCreateUser(this.url, this.ignore, this.metalake, user) - .validate() - .handle(); + this.gravitinoCommandLine.newCreateUser(context, metalake, user).validate().handle(); } /** Handles the "DELETE" command. */ private void handleDeleteCommand() { - boolean force = line.hasOption(GravitinoOptions.FORCE); - this.gravitinoCommandLine - .newDeleteUser(this.url, this.ignore, force, this.metalake, user) - .validate() - .handle(); + this.gravitinoCommandLine.newDeleteUser(context, metalake, user).validate().handle(); } /** Handles the "REVOKE" command. */ @@ -153,7 +139,7 @@ private void handleRevokeCommand() { boolean removeAll = line.hasOption(GravitinoOptions.ALL); if (removeAll) { gravitinoCommandLine - .newRemoveAllRoles(url, ignore, metalake, user, CommandEntities.USER) + .newRemoveAllRoles(context, metalake, user, CommandEntities.USER) .validate() .handle(); System.out.printf("Removed all roles from user %s%n", user); @@ -161,7 +147,7 @@ private void handleRevokeCommand() { String[] revokeRoles = line.getOptionValues(GravitinoOptions.ROLE); for (String role : revokeRoles) { this.gravitinoCommandLine - .newRemoveRoleFromUser(this.url, this.ignore, this.metalake, user, role) + .newRemoveRoleFromUser(context, metalake, user, role) .validate() .handle(); } @@ -173,10 +159,7 @@ private void handleRevokeCommand() { private void handleGrantCommand() { String[] grantRoles = line.getOptionValues(GravitinoOptions.ROLE); for (String role : grantRoles) { - this.gravitinoCommandLine - .newAddRoleToUser(this.url, this.ignore, this.metalake, user, role) - .validate() - .handle(); + this.gravitinoCommandLine.newAddRoleToUser(context, metalake, user, role).validate().handle(); } System.out.printf("Add roles %s to user %s%n", COMMA_JOINER.join(grantRoles), user); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToGroup.java index ebe3ea15200..7ea3d6b8e4a 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToGroup.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToGroup.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import java.util.ArrayList; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -36,15 +37,13 @@ public class AddRoleToGroup extends Command { /** * Adds a role to a group. * - * @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 group The name of the group. * @param role The name of the role. */ - public AddRoleToGroup( - String url, boolean ignoreVersions, String metalake, String group, String role) { - super(url, ignoreVersions); + public AddRoleToGroup(CommandContext context, String metalake, String group, String role) { + super(context); this.metalake = metalake; this.group = group; this.role = role; @@ -68,6 +67,6 @@ public void handle() { exitWithError(exp.getMessage()); } - System.out.println(role + " added to " + group); + printInformation(role + " added to " + group); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToUser.java index 66985b7dfb8..fd76ccfe2f5 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToUser.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AddRoleToUser.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import java.util.ArrayList; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -36,15 +37,13 @@ public class AddRoleToUser extends Command { /** * Adds a role to a user. * - * @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 user The name of the user. * @param role The name of the role. */ - public AddRoleToUser( - String url, boolean ignoreVersions, String metalake, String user, String role) { - super(url, ignoreVersions); + public AddRoleToUser(CommandContext context, String metalake, String user, String role) { + super(context); this.metalake = metalake; this.user = user; this.role = role; @@ -68,6 +67,6 @@ public void handle() { exitWithError(exp.getMessage()); } - System.out.println(role + " added to " + user); + printInformation(role + " added to " + user); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java index 8afd35c6403..9cdefe3a7ad 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java @@ -19,6 +19,7 @@ package org.apache.gravitino.cli.commands; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.GroupAlreadyExistsException; @@ -31,13 +32,12 @@ public class CreateGroup extends Command { /** * Create a new group. * - * @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 group The name of the group. */ - public CreateGroup(String url, boolean ignoreVersions, String metalake, String group) { - super(url, ignoreVersions); + public CreateGroup(CommandContext context, String metalake, String group) { + super(context); this.metalake = metalake; this.group = group; } @@ -56,6 +56,6 @@ public void handle() { exitWithError(exp.getMessage()); } - System.out.println(group + " created"); + printInformation(group + " created"); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java index 6f786778e17..233f3eedc54 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java @@ -19,6 +19,7 @@ package org.apache.gravitino.cli.commands; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -31,13 +32,12 @@ public class CreateUser extends Command { /** * Create a new User. * - * @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 user The name of the user. */ - public CreateUser(String url, boolean ignoreVersions, String metalake, String user) { - super(url, ignoreVersions); + public CreateUser(CommandContext context, String metalake, String user) { + super(context); this.metalake = metalake; this.user = user; } @@ -56,6 +56,6 @@ public void handle() { exitWithError(exp.getMessage()); } - System.out.println(user + " created"); + printInformation(user + " created"); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java index 641b43ddac9..12a9304eae4 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; 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.NoSuchGroupException; @@ -34,16 +35,13 @@ public class DeleteGroup extends Command { /** * Delete a group. * - * @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 group The name of the group. */ - public DeleteGroup( - String url, boolean ignoreVersions, boolean force, String metalake, String group) { - super(url, ignoreVersions); - this.force = force; + public DeleteGroup(CommandContext context, String metalake, String group) { + super(context); + this.force = context.force(); this.metalake = metalake; this.group = group; } @@ -69,9 +67,9 @@ public void handle() { } if (deleted) { - System.out.println(group + " deleted."); + printInformation(group + " deleted."); } else { - System.out.println(group + " not deleted."); + printInformation(group + " not deleted."); } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java index aa53a4d9f66..3e2000199ef 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java @@ -21,6 +21,7 @@ import org.apache.gravitino.auth.AuthConstants; 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.NoSuchMetalakeException; @@ -35,16 +36,13 @@ public class DeleteUser extends Command { /** * Delete a user. * - * @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 user The name of the user. */ - public DeleteUser( - String url, boolean ignoreVersions, boolean force, String metalake, String user) { - super(url, ignoreVersions); - this.force = force; + public DeleteUser(CommandContext context, String metalake, String user) { + super(context); + this.force = context.force(); this.metalake = metalake; this.user = user; } @@ -74,9 +72,9 @@ public void handle() { } if (deleted) { - System.out.println(user + " deleted."); + printInformation(user + " deleted."); } else { - System.out.println(user + " not deleted."); + printInformation(user + " not deleted."); } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupAudit.java index 9e79705bca3..8e52f09bb55 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupAudit.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.authorization.Group; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchGroupException; @@ -33,13 +34,12 @@ public class GroupAudit extends AuditCommand { /** * Displays the audit information of a group. * - * @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 group The name of the group. */ - public GroupAudit(String url, boolean ignoreVersions, String metalake, String group) { - super(url, ignoreVersions); + public GroupAudit(CommandContext context, String metalake, String group) { + super(context); this.metalake = metalake; this.group = group; } @@ -47,19 +47,16 @@ public GroupAudit(String url, boolean ignoreVersions, String metalake, String gr /** Displays the audit information of a specified group. */ @Override public void handle() { - Group result; + Group result = null; try (GravitinoClient client = buildClient(metalake)) { result = client.getGroup(this.group); } catch (NoSuchMetalakeException err) { - System.err.println(ErrorMessages.UNKNOWN_METALAKE); - return; + exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (NoSuchGroupException err) { - System.err.println(ErrorMessages.UNKNOWN_GROUP); - return; + exitWithError(ErrorMessages.UNKNOWN_GROUP); } catch (Exception exp) { - System.err.println(exp.getMessage()); - return; + exitWithError(exp.getMessage()); } if (result != null) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java index 58188c38a3f..8667dc4b67b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import java.util.List; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -33,13 +34,12 @@ public class GroupDetails extends Command { /** * Displays the roles in a group. * - * @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 group The name of the group. */ - public GroupDetails(String url, boolean ignoreVersions, String metalake, String group) { - super(url, ignoreVersions); + public GroupDetails(CommandContext context, String metalake, String group) { + super(context); this.metalake = metalake; this.group = group; } @@ -60,8 +60,10 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = roles.isEmpty() ? "The group has no roles." : String.join(",", roles); - - System.out.println(all); + if (roles == null) { + printInformation("The group has no roles."); + } else { + printResults(String.join(",", roles)); + } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java index 844b8e21d09..b7374981152 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java @@ -19,6 +19,7 @@ package org.apache.gravitino.cli.commands; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -31,12 +32,11 @@ public class ListGroups extends Command { /** * Lists all groups in a metalake. * - * @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. */ - public ListGroups(String url, boolean ignoreVersions, String metalake) { - super(url, ignoreVersions); + public ListGroups(CommandContext context, String metalake) { + super(context); this.metalake = metalake; } @@ -53,8 +53,10 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = groups.length == 0 ? "No groups exist." : String.join(",", groups); - - System.out.println(all); + if (groups.length == 0) { + printInformation("No groups found in metalake " + metalake); + } else { + printResults(String.join(",", groups)); + } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java index 3df4b7ca6bc..250d71e2f18 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java @@ -19,6 +19,7 @@ package org.apache.gravitino.cli.commands; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -31,12 +32,11 @@ public class ListUsers extends Command { /** * Lists all users in a metalake. * - * @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. */ - public ListUsers(String url, boolean ignoreVersions, String metalake) { - super(url, ignoreVersions); + public ListUsers(CommandContext context, String metalake) { + super(context); this.metalake = metalake; } @@ -53,8 +53,10 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = users.length == 0 ? "No users exist." : String.join(",", users); - - System.out.println(all); + if (users.length == 0) { + printInformation("No users exist."); + } else { + printResults(String.join(",", users)); + } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllRoles.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllRoles.java index eb7b354223d..70dacfd4179 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllRoles.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllRoles.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.gravitino.authorization.Group; import org.apache.gravitino.authorization.User; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.CommandEntities; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; @@ -38,15 +39,13 @@ public class RemoveAllRoles extends Command { /** * Removes all roles from a group or user. * - * @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 entity the name of the group or user. * @param entityType The type of the entity (group or user). */ - public RemoveAllRoles( - String url, boolean ignoreVersions, String metalake, String entity, String entityType) { - super(url, ignoreVersions); + public RemoveAllRoles(CommandContext context, String metalake, String entity, String entityType) { + super(context); this.metalake = metalake; this.entity = entity; this.entityType = entityType; @@ -77,6 +76,8 @@ private void revokeAllRolesFromGroup() { } catch (Exception e) { exitWithError(e.getMessage()); } + + printInformation("All roles have been revoked from group " + entity); } /** Removes all roles from a user. */ @@ -94,5 +95,7 @@ private void revokeAllRolesFromUser() { } catch (Exception e) { exitWithError(e.getMessage()); } + + printInformation("All roles have been revoked from user " + entity); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromGroup.java index 7f2f7e2b2c4..8cd1f18339a 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromGroup.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromGroup.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import java.util.ArrayList; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -36,15 +37,13 @@ public class RemoveRoleFromGroup extends Command { /** * Remove a role from a group. * - * @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 group The name of the group. * @param role The name of the role. */ - public RemoveRoleFromGroup( - String url, boolean ignoreVersions, String metalake, String group, String role) { - super(url, ignoreVersions); + public RemoveRoleFromGroup(CommandContext context, String metalake, String group, String role) { + super(context); this.metalake = metalake; this.group = group; this.role = role; @@ -68,6 +67,6 @@ public void handle() { exitWithError(exp.getMessage()); } - System.out.println(role + " removed from " + group); + printInformation(role + " removed from " + group); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromUser.java index 85a1edbeae4..d45db161338 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromUser.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveRoleFromUser.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import java.util.ArrayList; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -36,15 +37,13 @@ public class RemoveRoleFromUser extends Command { /** * Removes a role from a user. * - * @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 user The name of the user. * @param role The name of the role. */ - public RemoveRoleFromUser( - String url, boolean ignoreVersions, String metalake, String user, String role) { - super(url, ignoreVersions); + public RemoveRoleFromUser(CommandContext context, String metalake, String user, String role) { + super(context); this.metalake = metalake; this.user = user; this.role = role; @@ -68,6 +67,6 @@ public void handle() { exitWithError(exp.getMessage()); } - System.out.println(role + " removed from " + user); + printInformation(role + " removed from " + user); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserAudit.java index 44ac2babc6f..73b4f32e5fa 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserAudit.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import org.apache.gravitino.authorization.User; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -33,13 +34,12 @@ public class UserAudit extends AuditCommand { /** * Displays the audit information of a user. * - * @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 user The name of the user. */ - public UserAudit(String url, boolean ignoreVersions, String metalake, String user) { - super(url, ignoreVersions); + public UserAudit(CommandContext context, String metalake, String user) { + super(context); this.metalake = metalake; this.user = user; } @@ -47,19 +47,16 @@ public UserAudit(String url, boolean ignoreVersions, String metalake, String use /** Displays the audit information of a specified user. */ @Override public void handle() { - User result; + User result = null; try (GravitinoClient client = buildClient(metalake)) { result = client.getUser(this.user); } catch (NoSuchMetalakeException err) { - System.err.println(ErrorMessages.UNKNOWN_METALAKE); - return; + exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (NoSuchUserException err) { - System.err.println(ErrorMessages.UNKNOWN_USER); - return; + exitWithError(ErrorMessages.UNKNOWN_USER); } catch (Exception exp) { - System.err.println(exp.getMessage()); - return; + exitWithError(exp.getMessage()); } if (result != null) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java index d89597d1698..26c11a0e12b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java @@ -20,6 +20,7 @@ package org.apache.gravitino.cli.commands; import java.util.List; +import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -33,13 +34,12 @@ public class UserDetails extends Command { /** * Displays the roles of a user. * - * @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 user The name of the user. */ - public UserDetails(String url, boolean ignoreVersions, String metalake, String user) { - super(url, ignoreVersions); + public UserDetails(CommandContext context, String metalake, String user) { + super(context); this.metalake = metalake; this.user = user; } @@ -60,8 +60,10 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = roles.isEmpty() ? "The user has no roles." : String.join(",", roles); - - System.out.println(all); + if (roles.isEmpty()) { + printInformation("The user has no roles."); + } else { + printResults(String.join(",", roles)); + } } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestGroupCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGroupCommands.java index cae8402d8bb..eb8b923112c 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestGroupCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGroupCommands.java @@ -21,6 +21,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -83,7 +86,7 @@ void testListGroupsCommand() { mockCommandLine, mockOptions, CommandEntities.GROUP, CommandActions.LIST)); doReturn(mockList) .when(commandLine) - .newListGroups(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo"); + .newListGroups(any(CommandContext.class), eq("metalake_demo")); doReturn(mockList).when(mockList).validate(); commandLine.handleCommandLine(); verify(mockList).handle(); @@ -102,7 +105,7 @@ void testGroupDetailsCommand() { mockCommandLine, mockOptions, CommandEntities.GROUP, CommandActions.DETAILS)); doReturn(mockDetails) .when(commandLine) - .newGroupDetails(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA"); + .newGroupDetails(any(CommandContext.class), eq("metalake_demo"), eq("groupA")); doReturn(mockDetails).when(mockDetails).validate(); commandLine.handleCommandLine(); verify(mockDetails).handle(); @@ -122,7 +125,7 @@ void testGroupAuditCommand() { mockCommandLine, mockOptions, CommandEntities.GROUP, CommandActions.DETAILS)); doReturn(mockAudit) .when(commandLine) - .newGroupAudit(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "group"); + .newGroupAudit(any(CommandContext.class), eq("metalake_demo"), eq("group")); doReturn(mockAudit).when(mockAudit).validate(); commandLine.handleCommandLine(); verify(mockAudit).handle(); @@ -141,7 +144,7 @@ void testCreateGroupCommand() { mockCommandLine, mockOptions, CommandEntities.GROUP, CommandActions.CREATE)); doReturn(mockCreate) .when(commandLine) - .newCreateGroup(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA"); + .newCreateGroup(any(CommandContext.class), eq("metalake_demo"), eq("groupA")); doReturn(mockCreate).when(mockCreate).validate(); commandLine.handleCommandLine(); verify(mockCreate).handle(); @@ -160,7 +163,7 @@ void testDeleteGroupCommand() { mockCommandLine, mockOptions, CommandEntities.GROUP, CommandActions.DELETE)); doReturn(mockDelete) .when(commandLine) - .newDeleteGroup(GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "groupA"); + .newDeleteGroup(any(CommandContext.class), eq("metalake_demo"), eq("groupA")); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -180,7 +183,7 @@ void testDeleteGroupForceCommand() { mockCommandLine, mockOptions, CommandEntities.GROUP, CommandActions.DELETE)); doReturn(mockDelete) .when(commandLine) - .newDeleteGroup(GravitinoCommandLine.DEFAULT_URL, false, true, "metalake_demo", "groupA"); + .newDeleteGroup(any(CommandContext.class), eq("metalake_demo"), eq("groupA")); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -201,7 +204,7 @@ void testRemoveRoleFromGroupCommand() { doReturn(mockRemove) .when(commandLine) .newRemoveRoleFromGroup( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("groupA"), eq("admin")); commandLine.handleCommandLine(); verify(mockRemove).handle(); } @@ -221,7 +224,7 @@ void testAddRoleToGroupCommand() { doReturn(mockAdd) .when(commandLine) .newAddRoleToGroup( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("groupA"), eq("admin")); commandLine.handleCommandLine(); verify(mockAdd).handle(); } @@ -245,13 +248,13 @@ void testRemoveRolesFromGroupCommand() { doReturn(mockRemoveFirstRole) .when(commandLine) .newRemoveRoleFromGroup( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("groupA"), eq("admin")); // Verify second role doReturn(mockRemoveSecondRole) .when(commandLine) .newRemoveRoleFromGroup( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA", "role1"); + any(CommandContext.class), eq("metalake_demo"), eq("groupA"), eq("role1")); doReturn(mockRemoveFirstRole).when(mockRemoveFirstRole).validate(); doReturn(mockRemoveSecondRole).when(mockRemoveSecondRole).validate(); @@ -277,11 +280,10 @@ void testRemoveAllRolesFromGroupCommand() { doReturn(mock) .when(commandLine) .newRemoveAllRoles( - GravitinoCommandLine.DEFAULT_URL, - false, - "metalake_demo", - "groupA", - CommandEntities.GROUP); + any(CommandContext.class), + eq("metalake_demo"), + eq("groupA"), + eq(CommandEntities.GROUP)); doReturn(mock).when(mock).validate(); commandLine.handleCommandLine(); verify(mock).handle(); @@ -306,13 +308,13 @@ void testAddRolesToGroupCommand() { doReturn(mockAddFirstRole) .when(commandLine) .newAddRoleToGroup( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("groupA"), eq("admin")); // Verify second role doReturn(mockAddSecondRole) .when(commandLine) .newAddRoleToGroup( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "groupA", "role1"); + any(CommandContext.class), eq("metalake_demo"), eq("groupA"), eq("role1")); doReturn(mockAddFirstRole).when(mockAddFirstRole).validate(); doReturn(mockAddSecondRole).when(mockAddSecondRole).validate(); @@ -336,7 +338,7 @@ void testDeleteGroupCommandWithoutGroupOption() { assertThrows(RuntimeException.class, commandLine::handleCommandLine); verify(commandLine, never()) - .newDeleteGroup(GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", null); + .newDeleteGroup(any(CommandContext.class), eq("metalake_demo"), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals(output, ErrorMessages.MISSING_GROUP); } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestUserCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestUserCommands.java index 47f003c96b4..2d004ab9599 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestUserCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestUserCommands.java @@ -21,6 +21,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -83,7 +86,7 @@ void testListUsersCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.LIST)); doReturn(mockList) .when(commandLine) - .newListUsers(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo"); + .newListUsers(any(CommandContext.class), eq("metalake_demo")); doReturn(mockList).when(mockList).validate(); commandLine.handleCommandLine(); verify(mockList).handle(); @@ -102,7 +105,7 @@ void testUserDetailsCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.DETAILS)); doReturn(mockDetails) .when(commandLine) - .newUserDetails(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user"); + .newUserDetails(any(CommandContext.class), eq("metalake_demo"), eq("user")); doReturn(mockDetails).when(mockDetails).validate(); commandLine.handleCommandLine(); verify(mockDetails).handle(); @@ -122,7 +125,7 @@ void testUserAuditCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.DETAILS)); doReturn(mockAudit) .when(commandLine) - .newUserAudit(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "admin"); + .newUserAudit(any(CommandContext.class), eq("metalake_demo"), eq("admin")); doReturn(mockAudit).when(mockAudit).validate(); commandLine.handleCommandLine(); verify(mockAudit).handle(); @@ -141,7 +144,7 @@ void testCreateUserCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.CREATE)); doReturn(mockCreate) .when(commandLine) - .newCreateUser(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user"); + .newCreateUser(any(CommandContext.class), eq("metalake_demo"), eq("user")); doReturn(mockCreate).when(mockCreate).validate(); commandLine.handleCommandLine(); verify(mockCreate).handle(); @@ -160,7 +163,7 @@ void testDeleteUserCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.DELETE)); doReturn(mockDelete) .when(commandLine) - .newDeleteUser(GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "user"); + .newDeleteUser(any(CommandContext.class), eq("metalake_demo"), eq("user")); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -180,7 +183,7 @@ void testDeleteUserForceCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.DELETE)); doReturn(mockDelete) .when(commandLine) - .newDeleteUser(GravitinoCommandLine.DEFAULT_URL, false, true, "metalake_demo", "user"); + .newDeleteUser(any(CommandContext.class), eq("metalake_demo"), eq("user")); doReturn(mockDelete).when(mockDelete).validate(); commandLine.handleCommandLine(); verify(mockDelete).handle(); @@ -201,7 +204,7 @@ void testRemoveRoleFromUserCommand() { doReturn(mockRemove) .when(commandLine) .newRemoveRoleFromUser( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("user"), eq("admin")); commandLine.handleCommandLine(); verify(mockRemove).handle(); } @@ -221,7 +224,7 @@ void testAddRoleToUserCommand() { doReturn(mockAdd) .when(commandLine) .newRemoveRoleFromUser( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("user"), eq("admin")); commandLine.handleCommandLine(); verify(mockAdd).handle(); } @@ -246,13 +249,13 @@ void testRemoveRolesFromUserCommand() { doReturn(mockRemoveFirstRole) .when(commandLine) .newRemoveRoleFromUser( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", "admin"); + any(CommandContext.class), eq("metalake_demo"), eq("user"), eq("admin")); // Verify second role doReturn(mockRemoveSecondRole) .when(commandLine) .newRemoveRoleFromUser( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", "role1"); + any(CommandContext.class), eq("metalake_demo"), eq("user"), eq("role1")); doReturn(mockRemoveFirstRole).when(mockRemoveFirstRole).validate(); doReturn(mockRemoveSecondRole).when(mockRemoveSecondRole).validate(); @@ -276,8 +279,7 @@ void removeAllRolesFromUserCommand() { mockCommandLine, mockOptions, CommandEntities.USER, CommandActions.REVOKE)); doReturn(mockRemove) .when(commandLine) - .newRemoveAllRoles( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", CommandEntities.USER); + .newRemoveAllRoles(any(CommandContext.class), eq("metalake_demo"), eq("user"), any()); doReturn(mockRemove).when(mockRemove).validate(); commandLine.handleCommandLine(); verify(mockRemove).handle(); @@ -302,14 +304,12 @@ void testAddRolesToUserCommand() { // Verify first role doReturn(mockAddFirstRole) .when(commandLine) - .newAddRoleToUser( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", "admin"); + .newAddRoleToUser(any(CommandContext.class), eq("metalake_demo"), eq("user"), eq("admin")); // Verify second role doReturn(mockAddSecondRole) .when(commandLine) - .newAddRoleToUser( - GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "user", "role1"); + .newAddRoleToUser(any(CommandContext.class), eq("metalake_demo"), eq("user"), eq("role1")); doReturn(mockAddFirstRole).when(mockAddFirstRole).validate(); doReturn(mockAddSecondRole).when(mockAddSecondRole).validate(); @@ -332,7 +332,7 @@ void testDeleteUserWithoutUserOption() { assertThrows(RuntimeException.class, commandLine::handleCommandLine); verify(commandLine, never()) - .newDeleteUser(GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", null); + .newDeleteUser(any(CommandContext.class), eq("metalake_demo"), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals(output, ErrorMessages.MISSING_USER); }