-
Notifications
You must be signed in to change notification settings - Fork 14.4k
KAFKA-18904: kafka-configs.sh return resource doesn't exist message [3/N] #19808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a20928d
KAFKA-18904: kafka-configs.sh and kafka-client-metrics.sh return reso…
FrankYang0529 939eac8
Merge branch 'trunk' into KAFKA-18904-3
FrankYang0529 2161248
Merge branch 'trunk' into KAFKA-18904-3
FrankYang0529 d87c770
address comment
FrankYang0529 9858d88
Merge branch 'trunk' into KAFKA-18904-3
FrankYang0529 298f347
address comment
FrankYang0529 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
|
@@ -21,7 +21,7 @@ import joptsimple._ | |
import kafka.server.DynamicConfig | ||
import kafka.utils.Implicits._ | ||
import kafka.utils.Logging | ||
import org.apache.kafka.clients.admin.{Admin, AlterClientQuotasOptions, AlterConfigOp, AlterConfigsOptions, ConfigEntry, DescribeClusterOptions, DescribeConfigsOptions, ListTopicsOptions, ScramCredentialInfo, UserScramCredentialDeletion, UserScramCredentialUpsertion, ScramMechanism => PublicScramMechanism} | ||
import org.apache.kafka.clients.admin.{Admin, AlterClientQuotasOptions, AlterConfigOp, AlterConfigsOptions, ConfigEntry, DescribeClusterOptions, DescribeConfigsOptions, ListConfigResourcesOptions, ListTopicsOptions, ScramCredentialInfo, UserScramCredentialDeletion, UserScramCredentialUpsertion, ScramMechanism => PublicScramMechanism} | ||
import org.apache.kafka.common.config.ConfigResource | ||
import org.apache.kafka.common.errors.{InvalidConfigurationException, UnsupportedVersionException} | ||
import org.apache.kafka.common.internals.Topic | ||
|
@@ -342,6 +342,42 @@ object ConfigCommand extends Logging { | |
} | ||
|
||
private def describeResourceConfig(adminClient: Admin, entityType: String, entityName: Option[String], describeAll: Boolean): Unit = { | ||
if (!describeAll) { | ||
entityName.foreach { name => | ||
entityType match { | ||
case TopicType => | ||
Topic.validate(name) | ||
if (!adminClient.listTopics(new ListTopicsOptions().listInternal(true)).names.get.contains(name)) { | ||
System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.") | ||
return | ||
} | ||
case BrokerType | BrokerLoggerConfigType => | ||
if (adminClient.describeCluster.nodes.get.stream.anyMatch(_.idString == name)) { | ||
// valid broker id | ||
} else if (name == BrokerDefaultEntityName) { | ||
// default broker configs | ||
} else { | ||
System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.") | ||
return | ||
} | ||
case ClientMetricsType => | ||
if (adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.CLIENT_METRICS), new ListConfigResourcesOptions).all.get | ||
.stream.noneMatch(_.name == name)) { | ||
System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.") | ||
return | ||
} | ||
case GroupType => | ||
if (adminClient.listGroups().all.get.stream.noneMatch(_.groupId() == name) && | ||
adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.GROUP), new ListConfigResourcesOptions).all.get | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
.stream.noneMatch(_.name == name)) { | ||
System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.") | ||
return | ||
} | ||
case entityType => throw new IllegalArgumentException(s"Invalid entity type: $entityType") | ||
} | ||
} | ||
} | ||
|
||
val entities = entityName | ||
.map(name => List(name)) | ||
.getOrElse(entityType match { | ||
|
@@ -350,9 +386,10 @@ object ConfigCommand extends Logging { | |
case BrokerType | BrokerLoggerConfigType => | ||
adminClient.describeCluster(new DescribeClusterOptions()).nodes().get().asScala.map(_.idString).toSeq :+ BrokerDefaultEntityName | ||
case ClientMetricsType => | ||
adminClient.listClientMetricsResources().all().get().asScala.map(_.name).toSeq | ||
adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.CLIENT_METRICS), new ListConfigResourcesOptions).all().get().asScala.map(_.name).toSeq | ||
case GroupType => | ||
adminClient.listGroups().all.get.asScala.map(_.groupId).toSeq | ||
adminClient.listGroups().all.get.asScala.map(_.groupId).toSet ++ | ||
adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.GROUP), new ListConfigResourcesOptions).all().get().asScala.map(_.name).toSet | ||
case entityType => throw new IllegalArgumentException(s"Invalid entity type: $entityType") | ||
}) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can't this just be util.Set.of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to leave this as
java.util.xxx
because we already used this pattern like:kafka/core/src/main/scala/kafka/admin/ConfigCommand.scala
Line 311 in 48a5270
We can do some refactor for Scala code in core module after this PR. Or we can refactor it when migrating to Java eventually.