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 734993e1bf [#6423] improve(CLI): Add tags command context CLI (#6435)
734993e1bf is described below
commit 734993e1bf70fbba18deabf92347dd833556b2d8
Author: Lord of Abyss <[email protected]>
AuthorDate: Wed Feb 12 07:32:18 2025 +0800
[#6423] improve(CLI): Add tags command context CLI (#6435)
### What changes were proposed in this pull request?
Add tags command context CLI
### Why are the changes needed?
Fix: #6423
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
local test
---
.../apache/gravitino/cli/GravitinoCommandLine.java | 2 +-
.../apache/gravitino/cli/TagCommandHandler.java | 43 +++--
.../apache/gravitino/cli/TestableCommandLine.java | 54 +++----
.../apache/gravitino/cli/commands/CreateTag.java | 15 +-
.../apache/gravitino/cli/commands/DeleteTag.java | 22 ++-
.../apache/gravitino/cli/commands/ListAllTags.java | 16 +-
.../gravitino/cli/commands/ListEntityTags.java | 10 +-
.../gravitino/cli/commands/ListTagProperties.java | 8 +-
.../gravitino/cli/commands/RemoveAllTags.java | 16 +-
.../gravitino/cli/commands/RemoveTagProperty.java | 11 +-
.../gravitino/cli/commands/SetTagProperty.java | 15 +-
.../apache/gravitino/cli/commands/TagDetails.java | 10 +-
.../apache/gravitino/cli/commands/TagEntity.java | 11 +-
.../apache/gravitino/cli/commands/UntagEntity.java | 13 +-
.../gravitino/cli/commands/UpdateTagComment.java | 11 +-
.../gravitino/cli/commands/UpdateTagName.java | 11 +-
.../org/apache/gravitino/cli/TestTagCommands.java | 176 +++++++++------------
17 files changed, 197 insertions(+), 247 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 7230604655..2bb40373a6 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
@@ -134,7 +134,7 @@ public class GravitinoCommandLine extends
TestableCommandLine {
} else if (entity.equals(CommandEntities.GROUP)) {
new GroupCommandHandler(this, line, command, ignore).handle();
} else if (entity.equals(CommandEntities.TAG)) {
- new TagCommandHandler(this, line, command, ignore).handle();
+ new TagCommandHandler(this, line, command, context).handle();
} else if (entity.equals(CommandEntities.ROLE)) {
new RoleCommandHandler(this, line, command, ignore).handle();
} else if (entity.equals(CommandEntities.MODEL)) {
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/TagCommandHandler.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/TagCommandHandler.java
index e274c271f9..13567ac064 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/TagCommandHandler.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/TagCommandHandler.java
@@ -26,18 +26,20 @@ public class TagCommandHandler 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 String[] tags;
private String metalake;
public TagCommandHandler(
- GravitinoCommandLine gravitinoCommandLine, CommandLine line, String
command, boolean ignore) {
+ GravitinoCommandLine gravitinoCommandLine,
+ CommandLine line,
+ String command,
+ CommandContext context) {
this.gravitinoCommandLine = gravitinoCommandLine;
this.line = line;
this.command = command;
- this.ignore = ignore;
- this.url = getUrl(line);
+ this.context = context;
+ this.context.setUrl(getUrl(line));
this.tags = line.getOptionValues(GravitinoOptions.TAG);
if (tags != null) {
@@ -107,27 +109,26 @@ public class TagCommandHandler extends CommandHandler {
private void handleListCommand() {
FullName name = new FullName(line);
if (!name.hasCatalogName()) {
- gravitinoCommandLine.newListTags(url, ignore,
metalake).validate().handle();
+ gravitinoCommandLine.newListTags(context, metalake).validate().handle();
} else {
- gravitinoCommandLine.newListEntityTags(url, ignore, metalake,
name).validate().handle();
+ gravitinoCommandLine.newListEntityTags(context, metalake,
name).validate().handle();
}
}
/** Handles the "DETAILS" command. */
private void handleDetailsCommand() {
- gravitinoCommandLine.newTagDetails(url, ignore, metalake,
getOneTag(tags)).validate().handle();
+ gravitinoCommandLine.newTagDetails(context, metalake,
getOneTag(tags)).validate().handle();
}
/** Handles the "CREATE" command. */
private void handleCreateCommand() {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
- gravitinoCommandLine.newCreateTags(url, ignore, metalake, tags,
comment).validate().handle();
+ gravitinoCommandLine.newCreateTags(context, metalake, tags,
comment).validate().handle();
}
/** Handles the "DELETE" command. */
private void handleDeleteCommand() {
- boolean forceDelete = line.hasOption(GravitinoOptions.FORCE);
- gravitinoCommandLine.newDeleteTag(url, ignore, forceDelete, metalake,
tags).validate().handle();
+ gravitinoCommandLine.newDeleteTag(context, metalake,
tags).validate().handle();
}
/** Handles the "SET" command. */
@@ -136,12 +137,12 @@ public class TagCommandHandler extends CommandHandler {
String value = line.getOptionValue(GravitinoOptions.VALUE);
if (property == null && value == null) {
gravitinoCommandLine
- .newTagEntity(url, ignore, metalake, new FullName(line), tags)
+ .newTagEntity(context, metalake, new FullName(line), tags)
.validate()
.handle();
} else {
gravitinoCommandLine
- .newSetTagProperty(url, ignore, metalake, getOneTag(tags), property,
value)
+ .newSetTagProperty(context, metalake, getOneTag(tags), property,
value)
.validate()
.handle();
}
@@ -152,20 +153,16 @@ public class TagCommandHandler extends CommandHandler {
boolean isTag = line.hasOption(GravitinoOptions.TAG);
FullName name = new FullName(line);
if (!isTag) {
- boolean forceRemove = line.hasOption(GravitinoOptions.FORCE);
- gravitinoCommandLine
- .newRemoveAllTags(url, ignore, metalake, name, forceRemove)
- .validate()
- .handle();
+ gravitinoCommandLine.newRemoveAllTags(context, metalake,
name).validate().handle();
} else {
String propertyRemove = line.getOptionValue(GravitinoOptions.PROPERTY);
if (propertyRemove != null) {
gravitinoCommandLine
- .newRemoveTagProperty(url, ignore, metalake, getOneTag(tags),
propertyRemove)
+ .newRemoveTagProperty(context, metalake, getOneTag(tags),
propertyRemove)
.validate()
.handle();
} else {
- gravitinoCommandLine.newUntagEntity(url, ignore, metalake, name,
tags).validate().handle();
+ gravitinoCommandLine.newUntagEntity(context, metalake, name,
tags).validate().handle();
}
}
}
@@ -173,7 +170,7 @@ public class TagCommandHandler extends CommandHandler {
/** Handles the "PROPERTIES" command. */
private void handlePropertiesCommand() {
gravitinoCommandLine
- .newListTagProperties(url, ignore, metalake, getOneTag(tags))
+ .newListTagProperties(context, metalake, getOneTag(tags))
.validate()
.handle();
}
@@ -184,14 +181,14 @@ public class TagCommandHandler extends CommandHandler {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String updateComment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
- .newUpdateTagComment(url, ignore, metalake, getOneTag(tags),
updateComment)
+ .newUpdateTagComment(context, metalake, getOneTag(tags),
updateComment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
gravitinoCommandLine
- .newUpdateTagName(url, ignore, metalake, getOneTag(tags), newName)
+ .newUpdateTagName(context, metalake, getOneTag(tags), newName)
.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 b27e24fde9..0217d21d27 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
@@ -474,67 +474,65 @@ public class TestableCommandLine {
return new DeleteRole(url, ignore, force, metalake, roles);
}
- protected TagDetails newTagDetails(String url, boolean ignore, String
metalake, String tag) {
- return new TagDetails(url, ignore, metalake, tag);
+ protected TagDetails newTagDetails(CommandContext context, String metalake,
String tag) {
+ return new TagDetails(context, metalake, tag);
}
- protected ListAllTags newListTags(String url, boolean ignore, String
metalake) {
- return new ListAllTags(url, ignore, metalake);
+ protected ListAllTags newListTags(CommandContext context, String metalake) {
+ return new ListAllTags(context, metalake);
}
protected CreateTag newCreateTags(
- String url, boolean ignore, String metalake, String[] tags, String
comment) {
- return new CreateTag(url, ignore, metalake, tags, comment);
+ CommandContext context, String metalake, String[] tags, String comment) {
+ return new CreateTag(context, metalake, tags, comment);
}
- protected DeleteTag newDeleteTag(
- String url, boolean ignore, boolean force, String metalake, String[]
tags) {
- return new DeleteTag(url, ignore, force, metalake, tags);
+ protected DeleteTag newDeleteTag(CommandContext context, String metalake,
String[] tags) {
+ return new DeleteTag(context, metalake, tags);
}
protected SetTagProperty newSetTagProperty(
- String url, boolean ignore, String metalake, String tag, String
property, String value) {
- return new SetTagProperty(url, ignore, metalake, tag, property, value);
+ CommandContext context, String metalake, String tag, String property,
String value) {
+ return new SetTagProperty(context, metalake, tag, property, value);
}
protected RemoveTagProperty newRemoveTagProperty(
- String url, boolean ignore, String metalake, String tag, String
property) {
- return new RemoveTagProperty(url, ignore, metalake, tag, property);
+ CommandContext context, String metalake, String tag, String property) {
+ return new RemoveTagProperty(context, metalake, tag, property);
}
- protected RemoveAllTags newRemoveAllTags(
- String url, boolean ignore, String metalake, FullName name, boolean
force) {
- return new RemoveAllTags(url, ignore, metalake, name, force);
+ protected RemoveAllTags newRemoveAllTags(CommandContext context, String
metalake, FullName name) {
+ return new RemoveAllTags(context, metalake, name);
}
protected ListTagProperties newListTagProperties(
- String url, boolean ignore, String metalake, String tag) {
- return new ListTagProperties(url, ignore, metalake, tag);
+ CommandContext context, String metalake, String tag) {
+ return new ListTagProperties(context, metalake, tag);
}
protected UpdateTagComment newUpdateTagComment(
- String url, boolean ignore, String metalake, String tag, String comment)
{
- return new UpdateTagComment(url, ignore, metalake, tag, comment);
+ CommandContext context, String metalake, String tag, String comment) {
+ return new UpdateTagComment(context, metalake, tag, comment);
}
protected UpdateTagName newUpdateTagName(
- String url, boolean ignore, String metalake, String tag, String newName)
{
- return new UpdateTagName(url, ignore, metalake, tag, newName);
+ CommandContext context, String metalake, String tag, String newName) {
+ return new UpdateTagName(context, metalake, tag, newName);
}
protected ListEntityTags newListEntityTags(
- String url, boolean ignore, String metalake, FullName name) {
- return new ListEntityTags(url, ignore, metalake, name);
+ CommandContext context, String metalake, FullName name) {
+ return new ListEntityTags(context, metalake, name);
}
protected TagEntity newTagEntity(
- String url, boolean ignore, String metalake, FullName name, String[]
tags) {
- return new TagEntity(url, ignore, metalake, name, tags);
+ CommandContext context, String metalake, FullName name, String[] tags) {
+ return new TagEntity(context, metalake, name, tags);
}
protected UntagEntity newUntagEntity(
- String url, boolean ignore, String metalake, FullName name, String[]
tags) {
- return new UntagEntity(url, ignore, metalake, name, tags);
+ CommandContext context, String metalake, FullName name, String[] tags) {
+ return new UntagEntity(context, metalake, name, tags);
}
protected ColumnAudit newColumnAudit(
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java
index dabf34c8b1..46bd517f34 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.cli.commands;
import java.util.ArrayList;
import java.util.Arrays;
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;
@@ -35,15 +36,13 @@ public class CreateTag extends Command {
/**
* Create tags.
*
- * @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 tags The names of the tags.
* @param comment The comment of the tag.
*/
- public CreateTag(
- String url, boolean ignoreVersions, String metalake, String[] tags,
String comment) {
- super(url, ignoreVersions);
+ public CreateTag(CommandContext context, String metalake, String[] tags,
String comment) {
+ super(context);
this.metalake = metalake;
this.tags = tags;
this.comment = comment;
@@ -76,7 +75,7 @@ public class CreateTag extends Command {
exitWithError(exp.getMessage());
}
- System.out.println("Tag " + tags[0] + " created");
+ printInformation("Tag " + tags[0] + " created");
}
private void handleMultipleTags() {
@@ -95,12 +94,12 @@ public class CreateTag extends Command {
exitWithError(exp.getMessage());
}
if (!created.isEmpty()) {
- System.out.println("Tags " + String.join(",", created) + " created");
+ printInformation("Tags " + String.join(",", created) + " created");
}
if (created.size() < tags.length) {
List<String> remaining = Arrays.asList(tags);
remaining.removeAll(created);
- System.out.println("Tags " + String.join(",", remaining) + " not
created");
+ printInformation("Tags " + String.join(",", remaining) + " not created");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
index 26919e06ac..f0bdf2f3c5 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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;
@@ -37,16 +38,13 @@ public class DeleteTag extends Command {
/**
* Delete tags.
*
- * @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 tags The names of the tags.
*/
- public DeleteTag(
- String url, boolean ignoreVersions, boolean force, String metalake,
String[] tags) {
- super(url, ignoreVersions);
- this.force = force;
+ public DeleteTag(CommandContext context, String metalake, String[] tags) {
+ super(context);
+ this.force = context.force();
this.metalake = metalake;
this.tags = tags;
}
@@ -59,7 +57,7 @@ public class DeleteTag extends Command {
}
if (tags == null || tags.length == 0) {
- System.err.println(ErrorMessages.MISSING_TAG);
+ exitWithError(ErrorMessages.MISSING_TAG);
} else {
boolean hasOnlyOneTag = tags.length == 1;
if (hasOnlyOneTag) {
@@ -87,12 +85,12 @@ public class DeleteTag extends Command {
exitWithError(exp.getMessage());
}
if (!deleted.isEmpty()) {
- System.out.println("Tags " + String.join(",", deleted) + " deleted.");
+ printInformation("Tags " + String.join(",", deleted) + " deleted.");
}
if (deleted.size() < tags.length) {
List<String> remaining = Arrays.asList(tags);
remaining.removeAll(deleted);
- System.out.println("Tags " + String.join(",", remaining) + " not
deleted.");
+ printInformation("Tags " + String.join(",", remaining) + " not
deleted.");
}
}
@@ -111,9 +109,9 @@ public class DeleteTag extends Command {
}
if (deleted) {
- System.out.println("Tag " + tags[0] + " deleted.");
+ printInformation("Tag " + tags[0] + " deleted.");
} else {
- System.out.println("Tag " + tags[0] + " not deleted.");
+ printInformation("Tag " + tags[0] + " not deleted.");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java
index e3bd42ae04..63657bb0fd 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.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 ListAllTags extends Command {
/**
* Lists all tags 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 ListAllTags(String url, boolean ignoreVersions, String metalake) {
- super(url, ignoreVersions);
+ public ListAllTags(CommandContext context, String metalake) {
+ super(context);
this.metalake = metalake;
}
@@ -53,8 +53,10 @@ public class ListAllTags extends Command {
exitWithError(exp.getMessage());
}
- String all = tags.length == 0 ? "No tags exist." : String.join(",", tags);
-
- System.out.println(all);
+ if (tags.length == 0) {
+ printInformation("No tags exist.");
+ } else {
+ printResults(String.join(",", tags));
+ }
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java
index 90b1000fa0..e0ebf4b58f 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Schema;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.cli.FullName;
import org.apache.gravitino.cli.utils.FullNameUtil;
@@ -43,13 +44,12 @@ public class ListEntityTags extends Command {
/**
* Lists all tags 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.
* @param name The name of the entity.
*/
- public ListEntityTags(String url, boolean ignoreVersions, String metalake,
FullName name) {
- super(url, ignoreVersions);
+ public ListEntityTags(CommandContext context, String metalake, FullName
name) {
+ super(context);
this.metalake = metalake;
this.name = name;
}
@@ -113,6 +113,6 @@ public class ListEntityTags extends Command {
String all = String.join(",", tags);
- System.out.println(all);
+ printResults(all);
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java
index 5e191003ed..13ace743f7 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import java.util.Map;
+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,13 +36,12 @@ public class ListTagProperties extends ListProperties {
/**
* List the properties of a tag.
*
- * @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 tag The name of the tag.
*/
- public ListTagProperties(String url, boolean ignoreVersions, String
metalake, String tag) {
- super(url, ignoreVersions);
+ public ListTagProperties(CommandContext context, String metalake, String
tag) {
+ super(context);
this.metalake = metalake;
this.tag = tag;
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllTags.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllTags.java
index 9c774dfaac..123f6d32f8 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllTags.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllTags.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Schema;
import org.apache.gravitino.cli.AreYouSure;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.cli.FullName;
import org.apache.gravitino.cli.utils.FullNameUtil;
@@ -49,18 +50,15 @@ public class RemoveAllTags extends Command {
/**
* Removes all the tags of an entity
*
- * @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 name The name of the entity.
- * @param force Force operation.
*/
- public RemoveAllTags(
- String url, boolean ignoreVersions, String metalake, FullName name,
boolean force) {
- super(url, ignoreVersions);
+ public RemoveAllTags(CommandContext context, String metalake, FullName name)
{
+ super(context);
this.metalake = metalake;
this.name = name;
- this.force = force;
+ this.force = context.force();
}
@Override
@@ -152,10 +150,10 @@ public class RemoveAllTags extends Command {
}
if (tags.length > 0) {
- System.out.println(
+ printInformation(
entity + " removed tags " + String.join(",", tags) + " now tagged
with nothing");
} else {
- System.out.println(entity + " has no tags");
+ printInformation(entity + " has no tags");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java
index a91395baf8..b92cd5cc45 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.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;
@@ -35,15 +36,13 @@ public class RemoveTagProperty extends Command {
/**
* Remove a property of a tag.
*
- * @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 tag The name of the tag.
* @param property The name of the property.
*/
- public RemoveTagProperty(
- String url, boolean ignoreVersions, String metalake, String tag, String
property) {
- super(url, ignoreVersions);
+ public RemoveTagProperty(CommandContext context, String metalake, String
tag, String property) {
+ super(context);
this.metalake = metalake;
this.tag = tag;
this.property = property;
@@ -64,6 +63,6 @@ public class RemoveTagProperty extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(property + " property removed.");
+ printInformation(property + " property removed.");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java
index da7a267b8d..e0b66e6e6d 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.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;
@@ -36,21 +37,15 @@ public class SetTagProperty extends Command {
/**
* Set a property of a tag.
*
- * @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 tag The name of the tag.
* @param property The name of the property.
* @param value The value of the property.
*/
public SetTagProperty(
- String url,
- boolean ignoreVersions,
- String metalake,
- String tag,
- String property,
- String value) {
- super(url, ignoreVersions);
+ CommandContext context, String metalake, String tag, String property,
String value) {
+ super(context);
this.metalake = metalake;
this.tag = tag;
this.property = property;
@@ -72,7 +67,7 @@ public class SetTagProperty extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(tag + " property set.");
+ printInformation(tag + " property set.");
}
@Override
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java
index 871a7e7074..75b127cf55 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.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.NoSuchCatalogException;
@@ -33,13 +34,12 @@ public class TagDetails extends Command {
/**
* Displays the name and comment of a catalog.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param tag The name of the tag.
*/
- public TagDetails(String url, boolean ignoreVersions, String metalake,
String tag) {
- super(url, ignoreVersions);
+ public TagDetails(CommandContext context, String metalake, String tag) {
+ super(context);
this.metalake = metalake;
this.tag = tag;
}
@@ -61,7 +61,7 @@ public class TagDetails extends Command {
}
if (result != null) {
- System.out.println(result.name() + "," + result.comment());
+ printResults(result.name() + "," + result.comment());
}
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java
index 3b97778818..2ea2de5df7 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Schema;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.cli.FullName;
import org.apache.gravitino.cli.utils.FullNameUtil;
@@ -43,15 +44,13 @@ public class TagEntity extends Command {
/**
* Tag an entity with existing tags.
*
- * @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 name The name of the entity.
* @param tags The names of the tags.
*/
- public TagEntity(
- String url, boolean ignoreVersions, String metalake, FullName name,
String[] tags) {
- super(url, ignoreVersions);
+ public TagEntity(CommandContext context, String metalake, FullName name,
String[] tags) {
+ super(context);
this.metalake = metalake;
this.name = name;
this.tags = tags;
@@ -130,7 +129,7 @@ public class TagEntity extends Command {
String all = tagsToAdd.length == 0 ? "nothing" : String.join(",",
tagsToAdd);
- System.out.println(entity + " now tagged with " + all);
+ printInformation(entity + " now tagged with " + all);
}
@Override
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java
index 205242135b..9fd1c4ca39 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Schema;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.cli.FullName;
import org.apache.gravitino.cli.utils.FullNameUtil;
@@ -42,15 +43,13 @@ public class UntagEntity extends Command {
/**
* Remove existing tags from an entity.
*
- * @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 name The name of the entity.
* @param tags The names of the tags.
*/
- public UntagEntity(
- String url, boolean ignoreVersions, String metalake, FullName name,
String[] tags) {
- super(url, ignoreVersions);
+ public UntagEntity(CommandContext context, String metalake, FullName name,
String[] tags) {
+ super(context);
this.metalake = metalake;
this.name = name;
this.tags = tags;
@@ -132,10 +131,10 @@ public class UntagEntity extends Command {
}
if (tags.length > 1) {
- System.out.println(
+ printInformation(
entity + " removed tags " + String.join(",", tags) + " now tagged
with " + all);
} else {
- System.out.println(entity + " removed tag " + tags[0].toString() + " now
tagged with " + all);
+ printInformation(entity + " removed tag " + tags[0].toString() + " now
tagged with " + all);
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java
index 2994d78f30..3abc7f29c3 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.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;
@@ -35,15 +36,13 @@ public class UpdateTagComment extends Command {
/**
* Update the comment of a tag.
*
- * @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 tag The name of the tag.
* @param comment New metalake comment.
*/
- public UpdateTagComment(
- String url, boolean ignoreVersions, String metalake, String tag, String
comment) {
- super(url, ignoreVersions);
+ public UpdateTagComment(CommandContext context, String metalake, String tag,
String comment) {
+ super(context);
this.metalake = metalake;
this.tag = tag;
this.comment = comment;
@@ -64,6 +63,6 @@ public class UpdateTagComment extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(tag + " comment changed.");
+ printInformation(tag + " comment changed.");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java
index f4ef43412d..1dc79b76e9 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.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;
@@ -35,15 +36,13 @@ public class UpdateTagName extends Command {
/**
* Update the name of a tag.
*
- * @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 tag.
* @param tag The name of the catalog.
* @param name The new tag name.
*/
- public UpdateTagName(
- String url, boolean ignoreVersions, String metalake, String tag, String
name) {
- super(url, ignoreVersions);
+ public UpdateTagName(CommandContext context, String metalake, String tag,
String name) {
+ super(context);
this.metalake = metalake;
this.tag = tag;
this.name = name;
@@ -64,6 +63,6 @@ public class UpdateTagName extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(tag + " name changed.");
+ printInformation(tag + " name changed.");
}
}
diff --git
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java
index a94ccee7da..4a7549510b 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.cli;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
@@ -93,7 +94,7 @@ class TestTagCommands {
mockCommandLine, mockOptions, CommandEntities.TAG,
CommandActions.LIST));
doReturn(mockList)
.when(commandLine)
- .newListTags(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo");
+ .newListTags(any(CommandContext.class), eq("metalake_demo"));
doReturn(mockList).when(mockList).validate();
commandLine.handleCommandLine();
verify(mockList).handle();
@@ -112,7 +113,7 @@ class TestTagCommands {
mockCommandLine, mockOptions, CommandEntities.TAG,
CommandActions.DETAILS));
doReturn(mockDetails)
.when(commandLine)
- .newTagDetails(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", "tagA");
+ .newTagDetails(any(CommandContext.class), eq("metalake_demo"),
eq("tagA"));
doReturn(mockDetails).when(mockDetails).validate();
commandLine.handleCommandLine();
verify(mockDetails).handle();
@@ -132,7 +133,7 @@ class TestTagCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
- .newTagDetails(eq(GravitinoCommandLine.DEFAULT_URL), eq(false),
eq("metalake_demo"), any());
+ .newTagDetails(any(CommandContext.class), eq("metalake_demo"), any());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR, output);
}
@@ -153,11 +154,10 @@ class TestTagCommands {
doReturn(mockCreate)
.when(commandLine)
.newCreateTags(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- new String[] {"tagA"},
- "comment");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ argThat(argument -> argument.length == 1 &&
argument[0].equals("tagA")),
+ eq("comment"));
doReturn(mockCreate).when(mockCreate).validate();
commandLine.handleCommandLine();
verify(mockCreate).handle();
@@ -166,10 +166,9 @@ class TestTagCommands {
@Test
void testCreateCommandWithoutTagOption() {
Main.useExit = false;
- CreateTag spyCreate =
- spy(
- new CreateTag(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
null, "comment"));
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
+ CreateTag spyCreate = spy(new CreateTag(mockContext, "metalake_demo",
null, "comment"));
assertThrows(RuntimeException.class, spyCreate::validate);
verify(spyCreate, never()).handle();
@@ -194,8 +193,7 @@ class TestTagCommands {
doReturn(mockCreate)
.when(commandLine)
.newCreateTags(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
+ any(CommandContext.class),
eq("metalake_demo"),
argThat(
argument ->
@@ -222,7 +220,10 @@ class TestTagCommands {
doReturn(mockCreate)
.when(commandLine)
.newCreateTags(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", new
String[] {"tagA"}, null);
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ argThat(argument -> argument.length == 1),
+ isNull());
doReturn(mockCreate).when(mockCreate).validate();
commandLine.handleCommandLine();
verify(mockCreate).handle();
@@ -242,7 +243,9 @@ class TestTagCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTag(
- GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo",
new String[] {"tagA"});
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ argThat(argument -> argument.length == 1 &&
argument[0].equals("tagA")));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -263,11 +266,13 @@ class TestTagCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTag(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- false,
- "metalake_demo",
- new String[] {"tagA", "tagB"});
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ argThat(
+ argument ->
+ argument.length == 2
+ && argument[0].equals("tagA")
+ && argument[1].equals("tagB")));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -288,7 +293,9 @@ class TestTagCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTag(
- GravitinoCommandLine.DEFAULT_URL, false, true, "metalake_demo",
new String[] {"tagA"});
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ argThat(argument -> argument.length == 1 &&
argument[0].equals("tagA")));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -312,7 +319,11 @@ class TestTagCommands {
doReturn(mockSetProperty)
.when(commandLine)
.newSetTagProperty(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "tagA",
"property", "value");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("tagA"),
+ eq("property"),
+ eq("value"));
doReturn(mockSetProperty).when(mockSetProperty).validate();
commandLine.handleCommandLine();
verify(mockSetProperty).handle();
@@ -321,10 +332,10 @@ class TestTagCommands {
@Test
void testSetTagPropertyCommandWithoutPropertyAndValue() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTagProperty spySetProperty =
- spy(
- new SetTagProperty(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"tagA", null, null));
+ spy(new SetTagProperty(mockContext, "metalake_demo", "tagA", null,
null));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -334,10 +345,10 @@ class TestTagCommands {
@Test
void testSetTagPropertyCommandWithoutPropertyOption() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTagProperty spySetProperty =
- spy(
- new SetTagProperty(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"tagA", null, "value"));
+ spy(new SetTagProperty(mockContext, "metalake_demo", "tagA", null,
"value"));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -347,15 +358,10 @@ class TestTagCommands {
@Test
void testSetTagPropertyCommandWithoutValueOption() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTagProperty spySetProperty =
- spy(
- new SetTagProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "tagA",
- "property",
- null));
+ spy(new SetTagProperty(mockContext, "metalake_demo", "tagA",
"property", null));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -381,12 +387,7 @@ class TestTagCommands {
Assertions.assertThrows(RuntimeException.class,
commandLine::handleCommandLine);
verify(commandLine, never())
.newSetTagProperty(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
- eq("metalake_demo"),
- any(),
- eq("property"),
- eq("value"));
+ any(CommandContext.class), eq("metalake_demo"), any(),
eq("property"), eq("value"));
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR, output);
}
@@ -407,7 +408,7 @@ class TestTagCommands {
doReturn(mockRemoveProperty)
.when(commandLine)
.newRemoveTagProperty(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "tagA",
"property");
+ any(CommandContext.class), eq("metalake_demo"), eq("tagA"),
eq("property"));
doReturn(mockRemoveProperty).when(mockRemoveProperty).validate();
commandLine.handleCommandLine();
verify(mockRemoveProperty).handle();
@@ -431,13 +432,9 @@ class TestTagCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newRemoveTagProperty(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
- eq("metalake_demo"),
- any(),
- eq("property"));
+ any(CommandContext.class), eq("metalake_demo"), any(),
eq("property"));
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
- assertEquals(ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR, output);
+ Assertions.assertEquals(ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR, output);
}
@Test
@@ -453,7 +450,7 @@ class TestTagCommands {
mockCommandLine, mockOptions, CommandEntities.TAG,
CommandActions.PROPERTIES));
doReturn(mockListProperties)
.when(commandLine)
- .newListTagProperties(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", "tagA");
+ .newListTagProperties(any(CommandContext.class), eq("metalake_demo"),
eq("tagA"));
doReturn(mockListProperties).when(mockListProperties).validate();
commandLine.handleCommandLine();
verify(mockListProperties).handle();
@@ -474,12 +471,7 @@ class TestTagCommands {
mockCommandLine, mockOptions, CommandEntities.TAG,
CommandActions.REMOVE));
doReturn(mockRemoveAllTags)
.when(commandLine)
- .newRemoveAllTags(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
- eq("metalake_demo"),
- any(FullName.class),
- eq(true));
+ .newRemoveAllTags(any(CommandContext.class), eq("metalake_demo"),
any(FullName.class));
doReturn(mockRemoveAllTags).when(mockRemoveAllTags).validate();
commandLine.handleCommandLine();
verify(mockRemoveAllTags).handle();
@@ -501,7 +493,7 @@ class TestTagCommands {
doReturn(mockUpdateComment)
.when(commandLine)
.newUpdateTagComment(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "tagA",
"new comment");
+ any(CommandContext.class), eq("metalake_demo"), eq("tagA"),
eq("new comment"));
doReturn(mockUpdateComment).when(mockUpdateComment).validate();
commandLine.handleCommandLine();
verify(mockUpdateComment).handle();
@@ -525,11 +517,7 @@ class TestTagCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newUpdateTagComment(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
- eq("metalake_demo"),
- any(),
- eq("new comment"));
+ any(CommandContext.class), eq("metalake_demo"), any(), eq("new
comment"));
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR, output);
}
@@ -549,7 +537,7 @@ class TestTagCommands {
mockCommandLine, mockOptions, CommandEntities.TAG,
CommandActions.UPDATE));
doReturn(mockUpdateName)
.when(commandLine)
- .newUpdateTagName(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", "tagA", "tagB");
+ .newUpdateTagName(any(CommandContext.class), eq("metalake_demo"),
eq("tagA"), eq("tagB"));
doReturn(mockUpdateName).when(mockUpdateName).validate();
commandLine.handleCommandLine();
verify(mockUpdateName).handle();
@@ -572,12 +560,7 @@ class TestTagCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
- .newUpdateTagName(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
- eq("metalake_demo"),
- any(),
- eq("tagC"));
+ .newUpdateTagName(any(CommandContext.class), eq("metalake_demo"),
any(), eq("tagC"));
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR, output);
}
@@ -595,8 +578,7 @@ class TestTagCommands {
mockCommandLine, mockOptions, CommandEntities.TAG,
CommandActions.LIST));
doReturn(mockListTags)
.when(commandLine)
- .newListEntityTags(
- eq(GravitinoCommandLine.DEFAULT_URL), eq(false),
eq("metalake_demo"), any());
+ .newListEntityTags(any(CommandContext.class), eq("metalake_demo"),
any(FullName.class));
doReturn(mockListTags).when(mockListTags).validate();
commandLine.handleCommandLine();
verify(mockListTags).handle();
@@ -618,8 +600,7 @@ class TestTagCommands {
doReturn(mockTagEntity)
.when(commandLine)
.newTagEntity(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
+ any(CommandContext.class),
eq("metalake_demo"),
any(),
argThat(
@@ -637,14 +618,10 @@ class TestTagCommands {
@Test
void testTagEntityCommandWithoutName() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
TagEntity spyTagEntity =
- spy(
- new TagEntity(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- null,
- new String[] {"tagA"}));
+ spy(new TagEntity(mockContext, "metalake_demo", null, new String[]
{"tagA"}));
assertThrows(RuntimeException.class, spyTagEntity::validate);
verify(spyTagEntity, never()).handle();
@@ -669,8 +646,7 @@ class TestTagCommands {
doReturn(mockTagEntity)
.when(commandLine)
.newTagEntity(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
+ any(CommandContext.class),
eq("metalake_demo"),
any(),
argThat(
@@ -707,8 +683,7 @@ class TestTagCommands {
doReturn(mockUntagEntity)
.when(commandLine)
.newUntagEntity(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
+ any(CommandContext.class),
eq("metalake_demo"),
any(),
argThat(
@@ -726,14 +701,10 @@ class TestTagCommands {
@Test
void testUntagEntityCommandWithoutName() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
UntagEntity spyUntagEntity =
- spy(
- new UntagEntity(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- null,
- new String[] {"tagA"}));
+ spy(new UntagEntity(mockContext, "metalake_demo", null, new String[]
{"tagA"}));
assertThrows(RuntimeException.class, spyUntagEntity::validate);
verify(spyUntagEntity, never()).handle();
@@ -760,8 +731,7 @@ class TestTagCommands {
doReturn(mockUntagEntity)
.when(commandLine)
.newUntagEntity(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
+ any(CommandContext.class),
eq("metalake_demo"),
any(),
argThat(
@@ -782,8 +752,9 @@ class TestTagCommands {
@Test
void testDeleteTagCommandWithoutTagOption() {
Main.useExit = false;
- DeleteTag spyDeleteTag =
- spy(new DeleteTag(GravitinoCommandLine.DEFAULT_URL, false, false,
"metalake", null));
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
+ DeleteTag spyDeleteTag = spy(new DeleteTag(mockContext, "metalake", null));
assertThrows(RuntimeException.class, spyDeleteTag::validate);
verify(spyDeleteTag, never()).handle();
@@ -809,16 +780,14 @@ class TestTagCommands {
doReturn(mockRemoveAllTags)
.when(commandLine)
.newRemoveAllTags(
- eq(GravitinoCommandLine.DEFAULT_URL),
- eq(false),
+ any(CommandContext.class),
eq("metalake_demo"),
argThat(
argument ->
argument != null
&& "catalog".equals(argument.getCatalogName())
&& "schema".equals(argument.getSchemaName())
- && "table".equals(argument.getTableName())),
- eq(true));
+ && "table".equals(argument.getTableName())));
doReturn(mockRemoveAllTags).when(mockRemoveAllTags).validate();
commandLine.handleCommandLine();
verify(mockRemoveAllTags).handle();
@@ -827,10 +796,9 @@ class TestTagCommands {
@Test
void testRemoveAllTagsCommandWithoutName() {
Main.useExit = false;
- RemoveAllTags spyRemoveAllTags =
- spy(
- new RemoveAllTags(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
null, false));
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
+ RemoveAllTags spyRemoveAllTags = spy(new RemoveAllTags(mockContext,
"metalake_demo", null));
assertThrows(RuntimeException.class, spyRemoveAllTags::validate);
verify(spyRemoveAllTags, never()).handle();