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 67f25efb26 [#6421] improve(CLI): Add user and group command context
CLI (#6437)
67f25efb26 is described below
commit 67f25efb26e6b8a99aa304eff6590bb658f1c7a8
Author: Lord of Abyss <[email protected]>
AuthorDate: Wed Feb 12 07:33:28 2025 +0800
[#6421] improve(CLI): Add user and group command context CLI (#6437)
### What changes were proposed in this pull request?
Add user and group command context CLI
### Why are the changes needed?
Fix: #6421
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
local test.
---
.../apache/gravitino/cli/GravitinoCommandLine.java | 4 +-
.../apache/gravitino/cli/GroupCommandHandler.java | 34 ++++++------
.../apache/gravitino/cli/TestableCommandLine.java | 62 +++++++++++-----------
.../apache/gravitino/cli/UserCommandHandler.java | 49 ++++++-----------
.../gravitino/cli/commands/AddRoleToGroup.java | 11 ++--
.../gravitino/cli/commands/AddRoleToUser.java | 11 ++--
.../apache/gravitino/cli/commands/CreateGroup.java | 10 ++--
.../apache/gravitino/cli/commands/CreateUser.java | 10 ++--
.../apache/gravitino/cli/commands/DeleteGroup.java | 16 +++---
.../apache/gravitino/cli/commands/DeleteUser.java | 16 +++---
.../apache/gravitino/cli/commands/GroupAudit.java | 19 +++----
.../gravitino/cli/commands/GroupDetails.java | 16 +++---
.../apache/gravitino/cli/commands/ListGroups.java | 16 +++---
.../apache/gravitino/cli/commands/ListUsers.java | 16 +++---
.../gravitino/cli/commands/RemoveAllRoles.java | 13 +++--
.../cli/commands/RemoveRoleFromGroup.java | 11 ++--
.../gravitino/cli/commands/RemoveRoleFromUser.java | 11 ++--
.../apache/gravitino/cli/commands/UserAudit.java | 19 +++----
.../apache/gravitino/cli/commands/UserDetails.java | 16 +++---
.../apache/gravitino/cli/TestGroupCommands.java | 38 ++++++-------
.../org/apache/gravitino/cli/TestUserCommands.java | 34 ++++++------
21 files changed, 205 insertions(+), 227 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 2bb40373a6..e61051e538 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 @@ public class GravitinoCommandLine extends
TestableCommandLine {
} 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 7542b17974..6fcec1447b 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 @@ public class GroupCommandHandler extends CommandHandler {
/** 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 @@ public class GroupCommandHandler extends CommandHandler {
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 @@ public class GroupCommandHandler extends CommandHandler {
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 @@ public class GroupCommandHandler extends CommandHandler {
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 0217d21d27..a4f47239c7 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 @@ public class TestableCommandLine {
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 23698aa5cf..964d2ba6d9 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 @@ public class UserCommandHandler extends CommandHandler {
/** 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 @@ public class UserCommandHandler extends CommandHandler {
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 @@ public class UserCommandHandler extends CommandHandler {
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 @@ public class UserCommandHandler extends CommandHandler {
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 ebe3ea1520..7ea3d6b8e4 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 class AddRoleToGroup extends Command {
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 66985b7dfb..fd76ccfe2f 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 class AddRoleToUser extends Command {
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 8afd35c640..9cdefe3a7a 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 class CreateGroup extends Command {
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 6f786778e1..233f3eedc5 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 class CreateUser extends Command {
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 641b43ddac..12a9304eae 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 class DeleteGroup extends Command {
}
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 aa53a4d9f6..3e2000199e 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 @@ package org.apache.gravitino.cli.commands;
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 class DeleteUser extends Command {
}
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 9e79705bca..8e52f09bb5 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 class GroupAudit extends AuditCommand {
/** 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 58188c38a3..8667dc4b67 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 class GroupDetails extends Command {
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 844b8e21d0..b737498115 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 class ListGroups extends Command {
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 3df4b7ca6b..250d71e2f1 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 class ListUsers extends Command {
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 eb7b354223..70dacfd417 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 @@ package org.apache.gravitino.cli.commands;
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 @@ public class RemoveAllRoles extends Command {
} 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 @@ public class RemoveAllRoles extends Command {
} 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 7f2f7e2b2c..8cd1f18339 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 class RemoveRoleFromGroup extends Command {
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 85a1edbeae..d45db16133 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 class RemoveRoleFromUser extends Command {
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 44ac2babc6..73b4f32e5f 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 class UserAudit extends AuditCommand {
/** 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 d89597d169..26c11a0e12 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 class UserDetails extends Command {
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 cae8402d8b..eb8b923112 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 @@ 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.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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 @@ class TestGroupCommands {
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 47f003c96b..2d004ab959 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 @@ 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.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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
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 @@ class TestUserCommands {
// 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 @@ class TestUserCommands {
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);
}