Skip to content

KAFKA-9945: TopicCommand should support --if-exists and --if-not-exists when --bootstrap-server is used#8598

Closed
cmccabe wants to merge 1 commit intoapache:trunkfrom
cmccabe:KAFKA-9945
Closed

KAFKA-9945: TopicCommand should support --if-exists and --if-not-exists when --bootstrap-server is used#8598
cmccabe wants to merge 1 commit intoapache:trunkfrom
cmccabe:KAFKA-9945

Conversation

@cmccabe
Copy link
Copy Markdown
Contributor

@cmccabe cmccabe commented May 1, 2020

No description provided.

Copy link
Copy Markdown
Contributor

@ctan888 ctan888 left a comment

Choose a reason for hiding this comment

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

I think we should take out ++Set(bootstrapServerOpt) from the last parameter of checkInvalidArgs

CommandLineUtils.checkInvalidArgs(parser, options, ifExistsOpt, allTopicLevelOpts -- Set(alterOpt, deleteOpt, describeOpt) ++ Set(bootstrapServerOpt))
CommandLineUtils.checkInvalidArgs(parser, options, ifNotExistsOpt, allTopicLevelOpts -- Set(createOpt) ++ Set(bootstrapServerOpt))

Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I have left few comments.

} catch {
case e: ExecutionException => {
val cause = e.getCause
if (cause.isInstanceOf[TopicExistsException] || topic.ifTopicDoesntExist()) {
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.

Shouldn't we re-throw all exceptions except TopicExistsException if topic.ifTopicDoesntExist?


println(s"Created topic ${topic.name}.")
} else {
throw new IllegalArgumentException(s"Topic ${topic.name} already exists")
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.

Apparently, we already verify the existence of the topic prior to creating it. Should we also handle --if-not-exists in this case?

new util.ArrayList(replicaMap.map(p => p._2.asJava).asJavaCollection).asInstanceOf[util.List[util.List[Integer]]]
if(opts.topicConfig.isDefined || opts.configsToDelete.isDefined) {
throw new RuntimeException("Using --config or --delete-config is not supported " +
"when altering a topic via the broker API. Use kafka-configs.sh instead.")
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.

nit: Extra space after the first ..

"logic or ordering of the messages will be affected")
val topicDescription = try {
adminClient.describeTopics(Collections.singleton(tp.name)).
all().get().get(tp.name)
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.

nit: unnecessary spaces before all().

val createResult = adminClient.createTopics(Collections.singleton(newTopic))
createResult.all().get()
try {
createResult.all().get()
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.

nit: the parenthesis are not necessary. there is other cases when they can be removed.

topicName -> NewPartitions.increaseTo(topic.partitions.get, newAssignment)
}
if (topicDescription.partitions().size() == tp.partitions.get) {
println(s"Topic ${tp.name} already has ${tp.partitions.get} partitions. " +
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.

nit: extra space after the .. same below.

"if set when describing topics, only show topics that have overridden configs")
private val ifExistsOpt = parser.accepts("if-exists",
"if set when altering or deleting or describing topics, the action will only execute if the topic exists. Not supported with the --bootstrap-server option.")
"if set when altering or deleting or describing topics, the action will only execute if the topic exists.")
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.

We need to update checkArgs to accept them with bootstrap-server. As the moment, the tool refuses them with the following error:

Option "[if-not-exists]" can't be used with option "[bootstrap-server]"

@cmccabe
Copy link
Copy Markdown
Contributor Author

cmccabe commented Jun 2, 2020

duplicate of #8737

@cmccabe cmccabe closed this Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants