Skip to content

KAFKA-14628: Move CommandLineUtils and CommandDefaultOptions shared classes#13131

Merged
mimaison merged 7 commits into
apache:trunkfrom
fvaleri:move-tools-shared
Jan 26, 2023
Merged

KAFKA-14628: Move CommandLineUtils and CommandDefaultOptions shared classes#13131
mimaison merged 7 commits into
apache:trunkfrom
fvaleri:move-tools-shared

Conversation

@fvaleri

@fvaleri fvaleri commented Jan 19, 2023

Copy link
Copy Markdown
Contributor

CommandLineUtils and CommandDefaultOptions are required by most commands, so they must be migrated first. This PR can be used as the base for other commands migration.

@fvaleri

fvaleri commented Jan 19, 2023

Copy link
Copy Markdown
Contributor Author

@mimaison @ijuma

@fvaleri

fvaleri commented Jan 19, 2023

Copy link
Copy Markdown
Contributor Author

@fvaleri

fvaleri commented Jan 19, 2023

Copy link
Copy Markdown
Contributor Author

Take a look at DumpLogSegments to see how CommandDefaultOptions is used. It is a much better approach than building the script option list at the start of the main/execute method. In Java, you simply create a private static class that extends CommandDefaultOptions and put all parsing logic there.

Comment thread server-common/src/main/java/org/apache/kafka/server/util/CommandLineUtils.java Outdated
Comment thread core/src/main/scala/kafka/admin/ConfigCommand.scala Outdated
Comment thread server-common/src/main/java/org/apache/kafka/server/util/CommandLineUtils.java Outdated
@fvaleri

fvaleri commented Jan 21, 2023

Copy link
Copy Markdown
Contributor Author

@clolov @vamossagar12 took your suggestions. Thanks.

@fvaleri fvaleri marked this pull request as draft January 21, 2023 18:45
Comment thread core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala Outdated
Comment thread core/src/main/scala/kafka/utils/ToolsUtils.scala Outdated
@vamossagar12

Copy link
Copy Markdown
Contributor

@clolov @vamossagar12 took your suggestions. Thanks.

Thanks @fvaleri ! Couple of minor comments. This should be good to go after that!

@vamossagar12

Copy link
Copy Markdown
Contributor

Thanks @fvaleri . LGTM.

@fvaleri fvaleri marked this pull request as ready for review January 23, 2023 10:16
Comment thread core/src/main/scala/kafka/admin/ZkSecurityMigrator.scala Outdated
Comment thread core/src/main/scala/kafka/tools/ConsoleConsumer.scala Outdated

@clolov clolov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, sorry, I still don't get it and I should have explained my question better. What I meant to ask is whether we can put all calls to Exit.exit(1) only in CommandLineUtils functions where we expect a termination of the program and not make explicit reference to it in other commands? For example, here

https://github.com/apache/kafka/blob/0803659dc5b5e0aeae82b29e6ba4d07cb855bc1c/core/src/main/scala/kafka/admin/ZkSecurityMigrator.scala#L74
we have pushed Exit.exit(1) down into CommandLineUtils. And here

https://github.com/apache/kafka/blob/0803659dc5b5e0aeae82b29e6ba4d07cb855bc1c/core/src/main/scala/kafka/admin/ZkSecurityMigrator.scala#L103-L104
we have not.

Reposting my question here as well, because I thought that continuing a resolved discussion will unresolve it, but apparently it does not :(

@mimaison mimaison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, it looks good overall. I left a few suggestions.

Comment thread server-common/src/main/java/org/apache/kafka/server/util/CommandLineUtils.java Outdated
Comment thread server-common/src/main/java/org/apache/kafka/server/util/CommandLineUtils.java Outdated
Comment thread server-common/src/main/java/org/apache/kafka/server/util/CommandLineUtils.java Outdated
@fvaleri

fvaleri commented Jan 24, 2023

Copy link
Copy Markdown
Contributor Author

we have pushed Exit.exit(1) down into CommandLineUtils.

@clolov it wasn't pushed down, that's the original logic. The code you are referring to in ZkSecurityMigrator.scala:103 is outdated. Now we are using ToolsUtils.printUsageAndExit in a few places for the reason expressed in the method comment. Please, pull latest changes and let me know.

@mimaison mimaison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll wait for the CI to complete and then merge

fvaleri and others added 7 commits January 26, 2023 16:48
…lasses

These classes are required by most commands, so they must be migrated first.

Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
@mimaison mimaison merged commit 72cfc99 into apache:trunk Jan 26, 2023
@fvaleri fvaleri deleted the move-tools-shared branch January 26, 2023 19:31
@ijuma

ijuma commented Jan 30, 2023

Copy link
Copy Markdown
Member

Thanks for doing this. One thing I didn't understand is why the shared classes are in server-common instead of tools. Is this because core also uses the class?

@fvaleri

fvaleri commented Jan 30, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for doing this. One thing I didn't understand is why the shared classes are in server-common instead of tools. Is this because core also uses the class?

Good question. CommandLineUtils is mostly used by tools, but Kafka.scala has a dependency on it. In order to move these 2 shared classes to the tools module, we would need to add tools dependency to core. Is this correct?

@ijuma

ijuma commented Jan 30, 2023

Copy link
Copy Markdown
Member

Got it, so it's useful for main methods too - not just CLI tools. Then it's fine for it to be in server-common.

guozhangwang pushed a commit to guozhangwang/kafka that referenced this pull request Jan 31, 2023
…apache#13131)


Reviewers: Mickael Maison <mickael.maison@gmail.com>, Christo Lolov <christololov@gmail.com>, Sagar Rao <sagarmeansocean@gmail.com>
@fvaleri fvaleri added the tools label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants