use of org.apache.kafka.clients.admin.Config in project ksql by confluentinc.
the class KafkaTopicClientImpl method isTopicDeleteEnabled.
private static boolean isTopicDeleteEnabled(final AdminClient adminClient) {
try {
DescribeClusterResult describeClusterResult = adminClient.describeCluster();
Collection<Node> nodes = describeClusterResult.nodes().get();
if (nodes.isEmpty()) {
log.warn("No available broker found to fetch config info.");
throw new KsqlException("Could not fetch broker information. KSQL cannot initialize");
}
ConfigResource resource = new ConfigResource(ConfigResource.Type.BROKER, String.valueOf(nodes.iterator().next().id()));
Map<ConfigResource, Config> config = executeWithRetries(() -> adminClient.describeConfigs(Collections.singleton(resource)).all());
return config.get(resource).entries().stream().anyMatch(configEntry -> configEntry.name().equalsIgnoreCase("delete.topic.enable") && configEntry.value().equalsIgnoreCase("true"));
} catch (final Exception e) {
log.error("Failed to initialize TopicClient: {}", e.getMessage());
throw new KsqlException("Could not fetch broker information. KSQL cannot initialize", e);
}
}
use of org.apache.kafka.clients.admin.Config in project strimzi by strimzi.
the class TopicSerializationTest method testFromTopicMetadata.
@Test
public void testFromTopicMetadata() {
List<ConfigEntry> entries = new ArrayList<>();
entries.add(new ConfigEntry("foo", "bar"));
Config topicConfig = new Config(entries);
TopicMetadata meta = Utils.getTopicMetadata("test-topic", topicConfig);
Topic topic = TopicSerialization.fromTopicMetadata(meta);
assertEquals(new TopicName("test-topic"), topic.getTopicName());
// Null map name because Kafka doesn't know about the map
assertNull(topic.getMapName());
assertEquals(singletonMap("foo", "bar"), topic.getConfig());
assertEquals(2, topic.getNumPartitions());
assertEquals(3, topic.getNumReplicas());
}
use of org.apache.kafka.clients.admin.Config in project strimzi by strimzi.
the class Utils method getTopicMetadata.
public static TopicMetadata getTopicMetadata(Topic kubeTopic) {
List<Node> nodes = new ArrayList<>();
for (int nodeId = 0; nodeId < kubeTopic.getNumReplicas(); nodeId++) {
nodes.add(new Node(nodeId, "localhost", 9092 + nodeId));
}
List<TopicPartitionInfo> partitions = new ArrayList<>();
for (int partitionId = 0; partitionId < kubeTopic.getNumPartitions(); partitionId++) {
partitions.add(new TopicPartitionInfo(partitionId, nodes.get(0), nodes, nodes));
}
List<ConfigEntry> configs = new ArrayList<>();
for (Map.Entry<String, String> entry : kubeTopic.getConfig().entrySet()) {
configs.add(new ConfigEntry(entry.getKey(), entry.getValue()));
}
return new TopicMetadata(new TopicDescription(kubeTopic.getTopicName().toString(), false, partitions), new Config(configs));
}
use of org.apache.kafka.clients.admin.Config in project strimzi by strimzi.
the class TopicSerializationTest method testToTopicConfig.
@Test
public void testToTopicConfig() {
Topic topic = new Topic.Builder().withTopicName("test-topic").withConfigEntry("foo", "bar").withNumPartitions(3).withNumReplicas((short) 2).withMapName("gee").build();
Map<ConfigResource, Config> config = TopicSerialization.toTopicConfig(topic);
assertEquals(1, config.size());
Map.Entry<ConfigResource, Config> c = config.entrySet().iterator().next();
assertEquals(c.getKey().type(), ConfigResource.Type.TOPIC);
assertEquals(c.getKey().name(), "test-topic");
assertEquals(1, c.getValue().entries().size());
assertEquals("foo", c.getValue().get("foo").name());
assertEquals("bar", c.getValue().get("foo").value());
}
use of org.apache.kafka.clients.admin.Config in project strimzi by strimzi.
the class TopicSerialization method toTopicConfig.
/**
* Return a singleton map from the topic {@link ConfigResource} for the given topic,
* to the {@link Config} of the given topic.
*/
public static Map<ConfigResource, Config> toTopicConfig(Topic topic) {
Set<ConfigEntry> configEntries = new HashSet<>();
for (Map.Entry<String, String> entry : topic.getConfig().entrySet()) {
configEntries.add(new ConfigEntry(entry.getKey(), entry.getValue()));
}
Config config = new Config(configEntries);
return Collections.singletonMap(new ConfigResource(ConfigResource.Type.TOPIC, topic.getTopicName().toString()), config);
}
Aggregations