-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-9040 Add --all that includes dynamic and static config #7607
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
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,7 +305,7 @@ object ConfigCommand extends Config { | |
|
|
||
| entityType match { | ||
| case ConfigType.Topic => | ||
| val oldConfig = getConfig(adminClient, entityType, entityName, includeSynonyms = false) | ||
| val oldConfig = getConfig(adminClient, entityType, entityName, includeSynonyms = false, describeAll = false) | ||
| .map { entry => (entry.name, entry) }.toMap | ||
|
|
||
| // fail the command if any of the configs to be deleted does not exist | ||
|
|
@@ -321,7 +321,7 @@ object ConfigCommand extends Config { | |
| adminClient.incrementalAlterConfigs(Map(configResource -> alterEntries).asJava, alterOptions).all().get(60, TimeUnit.SECONDS) | ||
|
|
||
| case ConfigType.Broker => | ||
| val oldConfig = getConfig(adminClient, entityType, entityName, includeSynonyms = false) | ||
| val oldConfig = getConfig(adminClient, entityType, entityName, includeSynonyms = false, describeAll = false) | ||
| .map { entry => (entry.name, entry) }.toMap | ||
|
|
||
| // fail the command if any of the configs to be deleted does not exist | ||
|
|
@@ -340,7 +340,7 @@ object ConfigCommand extends Config { | |
| adminClient.alterConfigs(Map(configResource -> newConfig).asJava, alterOptions).all().get(60, TimeUnit.SECONDS) | ||
|
|
||
| case BrokerLoggerConfigType => | ||
| val validLoggers = getConfig(adminClient, entityType, entityName, includeSynonyms = true).map(_.name) | ||
| val validLoggers = getConfig(adminClient, entityType, entityName, includeSynonyms = true, describeAll = false).map(_.name) | ||
| // fail the command if any of the configured broker loggers do not exist | ||
| val invalidBrokerLoggers = configsToBeDeleted.filterNot(validLoggers.contains) ++ configsToBeAdded.keys.filterNot(validLoggers.contains) | ||
| if (invalidBrokerLoggers.nonEmpty) | ||
|
|
@@ -353,18 +353,19 @@ object ConfigCommand extends Config { | |
| ).asJavaCollection | ||
| adminClient.incrementalAlterConfigs(Map(configResource -> alterLogLevelEntries).asJava, alterOptions).all().get(60, TimeUnit.SECONDS) | ||
|
|
||
| case _ => throw new IllegalArgumentException(s"Unsupported entity type: ${entityType}") | ||
| case _ => throw new IllegalArgumentException(s"Unsupported entity type: $entityType") | ||
| } | ||
|
|
||
| if (entityName.nonEmpty) | ||
| println(s"Completed updating config for ${entityType.dropRight(1)} ${entityName}.") | ||
| println(s"Completed updating config for ${entityType.dropRight(1)} $entityName.") | ||
| else | ||
| println(s"Completed updating default config for ${entityType} in the cluster.") | ||
| println(s"Completed updating default config for $entityType in the cluster.") | ||
| } | ||
|
|
||
| private def describeConfig(adminClient: Admin, opts: ConfigCommandOptions): Unit = { | ||
| val entityType = opts.entityTypes.head | ||
| val entityName = opts.entityNames.headOption | ||
| val describeAll = opts.options.has(opts.allOpt) | ||
|
|
||
| val entities = entityName | ||
| .map(name => List(name)) | ||
|
|
@@ -378,24 +379,25 @@ object ConfigCommand extends Config { | |
| entities.foreach { entity => | ||
| entity match { | ||
| case "" => | ||
| println(s"Default config for ${entityType} in the cluster are:") | ||
| println(s"Default configs for $entityType in the cluster are:") | ||
| case _ => | ||
| println(s"Configs for ${entityType.dropRight(1)} ${entity} are:") | ||
| val configSourceStr = if (describeAll) "All" else "Dynamic" | ||
| println(s"$configSourceStr configs for ${entityType.dropRight(1)} $entity are:") | ||
| } | ||
| getConfig(adminClient, entityType, entity, includeSynonyms = true).foreach { entry => | ||
| getConfig(adminClient, entityType, entity, includeSynonyms = true, describeAll).foreach { entry => | ||
| val synonyms = entry.synonyms.asScala.map(synonym => s"${synonym.source}:${synonym.name}=${synonym.value}").mkString(", ") | ||
| println(s" ${entry.name}=${entry.value} sensitive=${entry.isSensitive} synonyms={$synonyms}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private def getConfig(adminClient: Admin, entityType: String, entityName: String, includeSynonyms: Boolean): Seq[ConfigEntry] = { | ||
| private def getConfig(adminClient: Admin, entityType: String, entityName: String, includeSynonyms: Boolean, describeAll: Boolean) = { | ||
| def validateBrokerId(): Unit = try entityName.toInt catch { | ||
| case _: NumberFormatException => | ||
| throw new IllegalArgumentException(s"The entity name for ${entityType} must be a valid integer broker id, found: ${entityName}") | ||
| throw new IllegalArgumentException(s"The entity name for $entityType must be a valid integer broker id, found: $entityName") | ||
| } | ||
|
|
||
| val (configResourceType, configSourceFilter) = entityType match { | ||
| val (configResourceType, dynamicConfigSource) = entityType match { | ||
| case ConfigType.Topic => | ||
| if (!entityName.isEmpty) | ||
| Topic.validate(entityName) | ||
|
|
@@ -413,6 +415,11 @@ object ConfigCommand extends Config { | |
| (ConfigResource.Type.BROKER_LOGGER, None) | ||
| } | ||
|
|
||
| val configSourceFilter = if (describeAll) | ||
| None | ||
| else | ||
| dynamicConfigSource | ||
|
|
||
| val configResource = new ConfigResource(configResourceType, entityName) | ||
| val configs = adminClient.describeConfigs(Collections.singleton(configResource)).all.get(30, TimeUnit.SECONDS) | ||
| configs.get(configResource).entries.asScala | ||
|
|
@@ -545,6 +552,8 @@ object ConfigCommand extends Config { | |
| .ofType(classOf[String]) | ||
| val alterOpt = parser.accepts("alter", "Alter the configuration for the entity.") | ||
| val describeOpt = parser.accepts("describe", "List configs for the given entity.") | ||
| val allOpt = parser.accepts("all", "List all configs for the given entity (includes static configuration when the entity type is brokers)") | ||
|
|
||
| val entityType = parser.accepts("entity-type", "Type of entity (topics/clients/users/brokers/broker-loggers)") | ||
| .withRequiredArg | ||
| .ofType(classOf[String]) | ||
|
|
@@ -654,6 +663,10 @@ object ConfigCommand extends Config { | |
| else if (options.has(bootstrapServerOpt) && options.has(zkConnectOpt)) | ||
| throw new IllegalArgumentException("Only one of --bootstrap-server or --zookeeper must be specified") | ||
|
|
||
| if (options.has(allOpt) && options.has(zkConnectOpt)) { | ||
| throw new IllegalArgumentException(s"--bootstrap-server must be specified for --all") | ||
|
Contributor
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. Since the user may not have seen the 'Only one of --bootstrap-server or --zookeeper' error above, it would be clearer to mention that zkConnectOpt should be dropped while adding '--bootstrap-server' |
||
| } | ||
|
|
||
| if (hasEntityName && (entityTypeVals.contains(ConfigType.Broker) || entityTypeVals.contains(BrokerLoggerConfigType))) { | ||
| Seq(entityName, broker, brokerLogger).filter(options.has(_)).map(options.valueOf(_)).foreach { brokerId => | ||
| try brokerId.toInt catch { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.