use of org.apache.kafka.common.config.TopicConfig in project ksql by confluentinc.
the class KafkaTopicClientImpl method addTopicConfig.
@Override
public boolean addTopicConfig(final String topicName, final Map<String, ?> overrides) {
final ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, topicName);
try {
final Map<String, String> existingConfig = topicConfig(topicName, false);
final boolean changed = overrides.entrySet().stream().anyMatch(e -> !Objects.equals(existingConfig.get(e.getKey()), e.getValue()));
if (!changed) {
return false;
}
existingConfig.putAll(toStringConfigs(overrides));
final Set<ConfigEntry> entries = existingConfig.entrySet().stream().map(e -> new ConfigEntry(e.getKey(), e.getValue())).collect(Collectors.toSet());
final Map<ConfigResource, Config> request = Collections.singletonMap(resource, new Config(entries));
executeWithRetries(() -> adminClient.alterConfigs(request).all());
return true;
} catch (final Exception e) {
throw new KafkaResponseGetFailedException("Failed to set config for Kafka Topic " + topicName, e);
}
}
use of org.apache.kafka.common.config.TopicConfig in project ksql by confluentinc.
the class KafkaTopicClientImpl method topicConfig.
private Map<String, String> topicConfig(final String topicName, final boolean includeDefaults) {
final ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, topicName);
final List<ConfigResource> request = Collections.singletonList(resource);
try {
final Config config = executeWithRetries(() -> adminClient.describeConfigs(request).all()).get(resource);
return config.entries().stream().filter(e -> includeDefaults || e.source().equals(ConfigEntry.ConfigSource.DYNAMIC_TOPIC_CONFIG)).collect(Collectors.toMap(ConfigEntry::name, ConfigEntry::value));
} catch (final Exception e) {
throw new KafkaResponseGetFailedException("Failed to get config for Kafka Topic " + topicName, e);
}
}
Aggregations