MINOR: Improve printing topic name when created topic in TopicCommand (#14661)

The topic name was displayed as `Optional<String>` when the topic was created.
```
% bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
Created topic Optional[test].
```
This PR fixed to print the topic name as `String` instead of `Optional<String>`.
```
% bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
Created topic test.
```

Reviewers: Ismael Juma <ismael@juma.me.uk>
This commit is contained in:
runom 2023-11-20 09:03:07 +09:00 committed by GitHub
parent b9556611cd
commit 066635819a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -247,7 +247,7 @@ public abstract class TopicCommand {
} }
static class CommandTopicPartition { static class CommandTopicPartition {
private final Optional<String> name; private final String name;
private final Optional<Integer> partitions; private final Optional<Integer> partitions;
private final Optional<Integer> replicationFactor; private final Optional<Integer> replicationFactor;
private final Map<Integer, List<Integer>> replicaAssignment; private final Map<Integer, List<Integer>> replicaAssignment;
@ -257,7 +257,7 @@ public abstract class TopicCommand {
public CommandTopicPartition(TopicCommandOptions options) { public CommandTopicPartition(TopicCommandOptions options) {
opts = options; opts = options;
name = options.topic(); name = options.topic().get();
partitions = options.partitions(); partitions = options.partitions();
replicationFactor = options.replicationFactor(); replicationFactor = options.replicationFactor();
replicaAssignment = options.replicaAssignment().orElse(Collections.emptyMap()); replicaAssignment = options.replicaAssignment().orElse(Collections.emptyMap());
@ -439,7 +439,7 @@ public abstract class TopicCommand {
public void createTopic(TopicCommandOptions opts) throws Exception { public void createTopic(TopicCommandOptions opts) throws Exception {
CommandTopicPartition topic = new CommandTopicPartition(opts); CommandTopicPartition topic = new CommandTopicPartition(opts);
if (Topic.hasCollisionChars(topic.name.get())) { if (Topic.hasCollisionChars(topic.name)) {
System.out.println("WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could " + System.out.println("WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could " +
"collide. To avoid issues it is best to use either, but not both."); "collide. To avoid issues it is best to use either, but not both.");
} }
@ -457,9 +457,9 @@ public abstract class TopicCommand {
try { try {
NewTopic newTopic; NewTopic newTopic;
if (topic.hasReplicaAssignment()) { if (topic.hasReplicaAssignment()) {
newTopic = new NewTopic(topic.name.get(), topic.replicaAssignment); newTopic = new NewTopic(topic.name, topic.replicaAssignment);
} else { } else {
newTopic = new NewTopic(topic.name.get(), topic.partitions, topic.replicationFactor.map(Integer::shortValue)); newTopic = new NewTopic(topic.name, topic.partitions, topic.replicationFactor.map(Integer::shortValue));
} }
Map<String, String> configsMap = topic.configsToAdd.stringPropertyNames().stream() Map<String, String> configsMap = topic.configsToAdd.stringPropertyNames().stream()