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 82087ef6ec [#6418] improve(CLI): Add stream command context CLI (#6434)
82087ef6ec is described below
commit 82087ef6ecdca54bd0bfe13e03028f665d4251ae
Author: Lord of Abyss <[email protected]>
AuthorDate: Tue Feb 11 12:41:12 2025 +0800
[#6418] improve(CLI): Add stream command context CLI (#6434)
### What changes were proposed in this pull request?
Add stream command context CLI
### Why are the changes needed?
Fix: #6418
### 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/TestableCommandLine.java | 42 +++---
.../apache/gravitino/cli/TopicCommandHandler.java | 31 ++---
.../apache/gravitino/cli/commands/CreateTopic.java | 11 +-
.../apache/gravitino/cli/commands/DeleteTopic.java | 21 +--
.../cli/commands/ListTopicProperties.java | 13 +-
.../apache/gravitino/cli/commands/ListTopics.java | 11 +-
.../cli/commands/RemoveTopicProperty.java | 11 +-
.../gravitino/cli/commands/SetTopicProperty.java | 11 +-
.../gravitino/cli/commands/TopicDetails.java | 15 +--
.../gravitino/cli/commands/UpdateTopicComment.java | 11 +-
.../apache/gravitino/cli/TestTopicCommands.java | 149 +++++++++------------
12 files changed, 140 insertions(+), 188 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 97fca069a9..b5e5838f1b 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
@@ -126,7 +126,7 @@ public class GravitinoCommandLine extends
TestableCommandLine {
} else if (entity.equals(CommandEntities.METALAKE)) {
new MetalakeCommandHandler(this, line, command, context).handle();
} else if (entity.equals(CommandEntities.TOPIC)) {
- new TopicCommandHandler(this, line, command, ignore).handle();
+ new TopicCommandHandler(this, line, command, context).handle();
} else if (entity.equals(CommandEntities.FILESET)) {
new FilesetCommandHandler(this, line, command, context).handle();
} else if (entity.equals(CommandEntities.USER)) {
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 d1c757345a..8a64c6c551 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
@@ -570,74 +570,64 @@ public class TestableCommandLine {
}
protected ListTopics newListTopics(
- String url, boolean ignore, String metalake, String catalog, String
schema) {
- return new ListTopics(url, ignore, metalake, catalog, schema);
+ CommandContext context, String metalake, String catalog, String schema) {
+ return new ListTopics(context, metalake, catalog, schema);
}
protected TopicDetails newTopicDetails(
- String url, boolean ignore, String metalake, String catalog, String
schema, String topic) {
- return new TopicDetails(url, ignore, metalake, catalog, schema, topic);
+ CommandContext context, String metalake, String catalog, String schema,
String topic) {
+ return new TopicDetails(context, metalake, catalog, schema, topic);
}
protected CreateTopic newCreateTopic(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String comment) {
- return new CreateTopic(url, ignore, metalake, catalog, schema, topic,
comment);
+ return new CreateTopic(context, metalake, catalog, schema, topic, comment);
}
protected DeleteTopic newDeleteTopic(
- String url,
- boolean ignore,
- boolean force,
- String metalake,
- String catalog,
- String schema,
- String topic) {
- return new DeleteTopic(url, ignore, force, metalake, catalog, schema,
topic);
+ CommandContext context, String metalake, String catalog, String schema,
String topic) {
+ return new DeleteTopic(context, metalake, catalog, schema, topic);
}
protected UpdateTopicComment newUpdateTopicComment(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String comment) {
- return new UpdateTopicComment(url, ignore, metalake, catalog, schema,
topic, comment);
+ return new UpdateTopicComment(context, metalake, catalog, schema, topic,
comment);
}
protected SetTopicProperty newSetTopicProperty(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String property,
String value) {
- return new SetTopicProperty(url, ignore, metalake, catalog, schema, topic,
property, value);
+ return new SetTopicProperty(context, metalake, catalog, schema, topic,
property, value);
}
protected RemoveTopicProperty newRemoveTopicProperty(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String property) {
- return new RemoveTopicProperty(url, ignore, metalake, catalog, schema,
topic, property);
+ return new RemoveTopicProperty(context, metalake, catalog, schema, topic,
property);
}
protected ListTopicProperties newListTopicProperties(
- String url, boolean ignore, String metalake, String catalog, String
schema, String topic) {
- return new ListTopicProperties(url, ignore, metalake, catalog, schema,
topic);
+ CommandContext context, String metalake, String catalog, String schema,
String topic) {
+ return new ListTopicProperties(context, metalake, catalog, schema, topic);
}
protected FilesetDetails newFilesetDetails(
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/TopicCommandHandler.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/TopicCommandHandler.java
index 7c2a75db91..f67d003b28 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/TopicCommandHandler.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/TopicCommandHandler.java
@@ -29,8 +29,7 @@ public class TopicCommandHandler extends CommandHandler {
private final GravitinoCommandLine gravitinoCommandLine;
private final CommandLine line;
private final String command;
- private final boolean ignore;
- private final String url;
+ private final CommandContext context;
private final FullName name;
private final String metalake;
private final String catalog;
@@ -43,16 +42,19 @@ public class TopicCommandHandler 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 TopicCommandHandler(
- 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();
this.catalog = name.getCatalogName();
@@ -128,7 +130,7 @@ public class TopicCommandHandler extends CommandHandler {
/** Handles the "DETAILS" command. */
private void handleDetailsCommand() {
gravitinoCommandLine
- .newTopicDetails(url, ignore, metalake, catalog, schema, topic)
+ .newTopicDetails(context, metalake, catalog, schema, topic)
.validate()
.handle();
}
@@ -137,16 +139,15 @@ public class TopicCommandHandler extends CommandHandler {
private void handleCreateCommand() {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
- .newCreateTopic(url, ignore, metalake, catalog, schema, topic, comment)
+ .newCreateTopic(context, metalake, catalog, schema, topic, comment)
.validate()
.handle();
}
/** Handles the "DELETE" command. */
private void handleDeleteCommand() {
- boolean force = line.hasOption(GravitinoOptions.FORCE);
gravitinoCommandLine
- .newDeleteTopic(url, ignore, force, metalake, catalog, schema, topic)
+ .newDeleteTopic(context, metalake, catalog, schema, topic)
.validate()
.handle();
}
@@ -156,7 +157,7 @@ public class TopicCommandHandler extends CommandHandler {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
- .newUpdateTopicComment(url, ignore, metalake, catalog, schema,
topic, comment)
+ .newUpdateTopicComment(context, metalake, catalog, schema, topic,
comment)
.validate()
.handle();
}
@@ -167,7 +168,7 @@ public class TopicCommandHandler extends CommandHandler {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
gravitinoCommandLine
- .newSetTopicProperty(url, ignore, metalake, catalog, schema, topic,
property, value)
+ .newSetTopicProperty(context, metalake, catalog, schema, topic,
property, value)
.validate()
.handle();
}
@@ -176,7 +177,7 @@ public class TopicCommandHandler extends CommandHandler {
private void handleRemoveCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
gravitinoCommandLine
- .newRemoveTopicProperty(url, ignore, metalake, catalog, schema, topic,
property)
+ .newRemoveTopicProperty(context, metalake, catalog, schema, topic,
property)
.validate()
.handle();
}
@@ -184,13 +185,13 @@ public class TopicCommandHandler extends CommandHandler {
/** Handles the "PROPERTIES" command. */
private void handlePropertiesCommand() {
gravitinoCommandLine
- .newListTopicProperties(url, ignore, metalake, catalog, schema, topic)
+ .newListTopicProperties(context, metalake, catalog, schema, topic)
.validate()
.handle();
}
/** Handles the "LIST" command. */
private void handleListCommand() {
- gravitinoCommandLine.newListTopics(url, ignore, metalake, catalog,
schema).validate().handle();
+ gravitinoCommandLine.newListTopics(context, metalake, catalog,
schema).validate().handle();
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTopic.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTopic.java
index 61d3db4472..c1fd5c4118 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTopic.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTopic.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -38,8 +39,7 @@ public class CreateTopic extends Command {
/**
* Add a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
@@ -47,14 +47,13 @@ public class CreateTopic extends Command {
* @param comment The comment for the topic.
*/
public CreateTopic(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String comment) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -80,6 +79,6 @@ public class CreateTopic extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(topic + " topic created.");
+ printInformation(topic + " topic created.");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTopic.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTopic.java
index 5d6f440dba..462c38a005 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTopic.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTopic.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.cli.AreYouSure;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -39,24 +40,16 @@ public class DeleteTopic extends Command {
/**
* Delete a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
- * @param force Force operation.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
* @param topic The name of the topic.
*/
public DeleteTopic(
- String url,
- boolean ignoreVersions,
- boolean force,
- String metalake,
- String catalog,
- String schema,
- String topic) {
- super(url, ignoreVersions);
- this.force = force;
+ CommandContext context, String metalake, String catalog, String schema,
String topic) {
+ super(context);
+ this.force = context.force();
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -87,9 +80,9 @@ public class DeleteTopic extends Command {
}
if (deleted) {
- System.out.println(topic + " deleted.");
+ printInformation(topic + " deleted.");
} else {
- System.out.println(topic + " not deleted.");
+ printInformation(topic + " not deleted.");
}
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java
index e308b1c6a1..038c29b3cb 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import java.util.Map;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,21 +41,15 @@ public class ListTopicProperties extends ListProperties {
/**
* List the properties of a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
* @param topic The name of the topic.
*/
public ListTopicProperties(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String topic) {
- super(url, ignoreVersions);
+ CommandContext context, String metalake, String catalog, String schema,
String topic) {
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java
index a2da6a69ad..9612ec0900 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java
@@ -23,6 +23,7 @@ import com.google.common.base.Joiner;
import java.util.Arrays;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -37,15 +38,13 @@ public class ListTopics extends Command {
/**
* List the names of all topics in a schema.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
*/
- public ListTopics(
- String url, boolean ignoreVersions, String metalake, String catalog,
String schema) {
- super(url, ignoreVersions);
+ public ListTopics(CommandContext context, String metalake, String catalog,
String schema) {
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -70,6 +69,6 @@ public class ListTopics extends Command {
topics.length == 0
? "No topics exist."
: Joiner.on(",").join(Arrays.stream(topics).map(topic ->
topic.name()).iterator());
- System.out.println(all);
+ printResults(all);
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTopicProperty.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTopicProperty.java
index 51be0a139d..497088c1be 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTopicProperty.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTopicProperty.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,8 +41,7 @@ public class RemoveTopicProperty extends Command {
/**
* Remove a property of a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
@@ -49,14 +49,13 @@ public class RemoveTopicProperty extends Command {
* @param property The name of the property.
*/
public RemoveTopicProperty(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String property) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -85,7 +84,7 @@ public class RemoveTopicProperty extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(property + " property removed.");
+ printInformation(property + " property removed.");
}
@Override
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTopicProperty.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTopicProperty.java
index 2641259cdd..67bedc88d7 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTopicProperty.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTopicProperty.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -41,8 +42,7 @@ public class SetTopicProperty extends Command {
/**
* Set a property of a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
@@ -51,15 +51,14 @@ public class SetTopicProperty extends Command {
* @param value The value of the property.
*/
public SetTopicProperty(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String property,
String value) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -90,7 +89,7 @@ public class SetTopicProperty extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(property + " property set.");
+ printInformation(property + " property set.");
}
@Override
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java
index 0ab31bd8b3..d72002419d 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -39,21 +40,15 @@ public class TopicDetails extends Command {
/**
* Displays the details of a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schenma.
* @param topic The name of the topic.
*/
public TopicDetails(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String topic) {
- super(url, ignoreVersions);
+ CommandContext context, String metalake, String catalog, String schema,
String topic) {
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -81,6 +76,6 @@ public class TopicDetails extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(gTopic.name() + "," + gTopic.comment());
+ printResults(gTopic.name() + "," + gTopic.comment());
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTopicComment.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTopicComment.java
index 1f81ad7fab..37121db4ac 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTopicComment.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTopicComment.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,8 +41,7 @@ public class UpdateTopicComment extends Command {
/**
* Update the comment of a topic.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
@@ -49,14 +49,13 @@ public class UpdateTopicComment extends Command {
* @param comment New metalake comment.
*/
public UpdateTopicComment(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String topic,
String comment) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -85,6 +84,6 @@ public class UpdateTopicComment extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(topic + " comment changed.");
+ printInformation(topic + " comment changed.");
}
}
diff --git
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java
index 31904b8856..695edb9dd4 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.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;
@@ -87,8 +90,7 @@ class TestTopicCommands {
mockCommandLine, mockOptions, CommandEntities.TOPIC,
CommandActions.LIST));
doReturn(mockList)
.when(commandLine)
- .newListTopics(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema");
+ .newListTopics(any(CommandContext.class), eq("metalake_demo"),
eq("catalog"), eq("schema"));
doReturn(mockList).when(mockList).validate();
commandLine.handleCommandLine();
verify(mockList).handle();
@@ -108,7 +110,11 @@ class TestTopicCommands {
doReturn(mockDetails)
.when(commandLine)
.newTopicDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "topic");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"));
doReturn(mockDetails).when(mockDetails).validate();
commandLine.handleCommandLine();
verify(mockDetails).handle();
@@ -131,13 +137,12 @@ class TestTopicCommands {
doReturn(mockCreate)
.when(commandLine)
.newCreateTopic(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- "comment");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"),
+ eq("comment"));
doReturn(mockCreate).when(mockCreate).validate();
commandLine.handleCommandLine();
verify(mockCreate).handle();
@@ -157,13 +162,11 @@ class TestTopicCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTopic(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -184,13 +187,11 @@ class TestTopicCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTopic(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- true,
- "metalake_demo",
- "catalog",
- "schema",
- "topic");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -213,13 +214,12 @@ class TestTopicCommands {
doReturn(mockUpdate)
.when(commandLine)
.newUpdateTopicComment(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- "new comment");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"),
+ eq("new comment"));
doReturn(mockUpdate).when(mockUpdate).validate();
commandLine.handleCommandLine();
verify(mockUpdate).handle();
@@ -240,7 +240,11 @@ class TestTopicCommands {
doReturn(mockListProperties)
.when(commandLine)
.newListTopicProperties(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "topic");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"));
doReturn(mockListProperties).when(mockListProperties).validate();
commandLine.handleCommandLine();
verify(mockListProperties).handle();
@@ -265,14 +269,13 @@ class TestTopicCommands {
doReturn(mockSetProperties)
.when(commandLine)
.newSetTopicProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- "property",
- "value");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"),
+ eq("property"),
+ eq("value"));
doReturn(mockSetProperties).when(mockSetProperties).validate();
commandLine.handleCommandLine();
verify(mockSetProperties).handle();
@@ -281,17 +284,12 @@ class TestTopicCommands {
@Test
void testSetTopicPropertyCommandWithoutPropertyAndValue() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTopicProperty spySetProperty =
spy(
new SetTopicProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- null,
- null));
+ mockContext, "metalake_demo", "catalog", "schema", "topic",
null, null));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -301,17 +299,12 @@ class TestTopicCommands {
@Test
void testSetTopicPropertyCommandWithoutProperty() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTopicProperty spySetProperty =
spy(
new SetTopicProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- null,
- "value"));
+ mockContext, "metalake_demo", "catalog", "schema", "topic",
null, "value"));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -321,17 +314,12 @@ class TestTopicCommands {
@Test
void testSetTopicPropertyCommandWithoutValue() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTopicProperty spySetProperty =
spy(
new SetTopicProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- "property",
- null));
+ mockContext, "metalake_demo", "catalog", "schema", "topic",
"property", null));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -355,13 +343,12 @@ class TestTopicCommands {
doReturn(mockSetProperties)
.when(commandLine)
.newRemoveTopicProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- "property");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("topic"),
+ eq("property"));
doReturn(mockSetProperties).when(mockSetProperties).validate();
commandLine.handleCommandLine();
verify(mockSetProperties).handle();
@@ -370,16 +357,12 @@ class TestTopicCommands {
@Test
void testRemoveTopicPropertyCommandWithoutProperty() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
RemoveTopicProperty spyRemoveProperty =
spy(
new RemoveTopicProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "topic",
- null));
+ mockContext, "metalake_demo", "catalog", "schema", "topic",
null));
assertThrows(RuntimeException.class, spyRemoveProperty::validate);
verify(spyRemoveProperty, never()).handle();
@@ -400,7 +383,7 @@ class TestTopicCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
- .newListTopics(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", null, null);
+ .newListTopics(any(CommandContext.class), eq("metalake_demo"),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -425,7 +408,7 @@ class TestTopicCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
- .newListTopics(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", "catalog", null);
+ .newListTopics(any(CommandContext.class), eq("metalake_demo"),
eq("catalog"), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -450,7 +433,7 @@ class TestTopicCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newTopicDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", null,
null, null);
+ any(CommandContext.class), eq("metalake_demo"), isNull(),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -479,7 +462,7 @@ class TestTopicCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newTopicDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", null, null);
+ any(CommandContext.class), eq("metalake_demo"), eq("catalog"),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -505,7 +488,7 @@ class TestTopicCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newTopicDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"schema", null, null);
+ any(CommandContext.class), eq("metalake_demo"), eq("schema"),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,