Search in sources :

Example 26 with ConfigResource

use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.

the class ControllerIT method testConfigMapModifiedRetentionChanged.

@Test
public void testConfigMapModifiedRetentionChanged(TestContext context) throws Exception {
    // create the cm
    String topicName = "test-configmap-modified-retention-changed";
    ConfigMap cm = createCm(context, topicName);
    // now change the cm
    kubeClient.configMaps().inNamespace(NAMESPACE).withName(cm.getMetadata().getName()).edit().addToData(TopicSerialization.CM_KEY_CONFIG, "{\"retention.ms\":\"12341234\"}").done();
    // Wait for that to be reflected in the topic
    waitFor(context, () -> {
        ConfigResource configResource = topicConfigResource(topicName);
        org.apache.kafka.clients.admin.Config config = getTopicConfig(configResource);
        String retention = config.get("retention.ms").value();
        LOGGER.debug("retention of {}, waiting for 12341234", retention);
        return "12341234".equals(retention);
    }, timeout, "Expected the topic to be updated");
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) Test(org.junit.Test)

Example 27 with ConfigResource

use of org.apache.kafka.common.config.ConfigResource 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());
}
Also used : Config(org.apache.kafka.clients.admin.Config) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NewTopic(org.apache.kafka.clients.admin.NewTopic) HashMap(java.util.HashMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) Test(org.junit.Test)

Example 28 with ConfigResource

use of org.apache.kafka.common.config.ConfigResource 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);
}
Also used : ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) Config(org.apache.kafka.clients.admin.Config) LogConfig(kafka.log.LogConfig) HashMap(java.util.HashMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) ConfigResource(org.apache.kafka.common.config.ConfigResource) HashSet(java.util.HashSet)

Example 29 with ConfigResource

use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.

the class BaseKafkaImpl method topicMetadata.

/**
 * Get a topic config via the Kafka AdminClient API, calling the given handler
 * (in a different thread) with the result.
 */
@Override
public void topicMetadata(TopicName topicName, Handler<AsyncResult<TopicMetadata>> handler) {
    LOGGER.debug("Getting metadata for topic {}", topicName);
    ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, topicName.toString());
    KafkaFuture<TopicDescription> descriptionFuture = adminClient.describeTopics(Collections.singleton(topicName.toString())).values().get(topicName.toString());
    KafkaFuture<Config> configFuture = adminClient.describeConfigs(Collections.singleton(resource)).values().get(resource);
    queueWork(new MetadataWork(descriptionFuture, configFuture, result -> handler.handle(result)));
}
Also used : Config(org.apache.kafka.clients.admin.Config) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) KafkaFuture(org.apache.kafka.common.KafkaFuture) Future(io.vertx.core.Future) AdminClient(org.apache.kafka.clients.admin.AdminClient) ExecutionException(java.util.concurrent.ExecutionException) ConfigResource(org.apache.kafka.common.config.ConfigResource) Map(java.util.Map) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) AsyncResult(io.vertx.core.AsyncResult) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Config(org.apache.kafka.clients.admin.Config) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 30 with ConfigResource

use of org.apache.kafka.common.config.ConfigResource in project ksql by confluentinc.

the class KafkaTopicClientImplTest method topicConfigResponse.

private static DescribeConfigsResult topicConfigResponse(final String topicName, final ConfigEntry... entries) {
    final Map<ConfigResource, Config> config = ImmutableMap.of(new ConfigResource(ConfigResource.Type.TOPIC, topicName), new Config(Arrays.asList(entries)));
    final DescribeConfigsResult response = mock(DescribeConfigsResult.class);
    expect(response.all()).andReturn(KafkaFuture.completedFuture(config));
    replay(response);
    return response;
}
Also used : TopicConfig(org.apache.kafka.common.config.TopicConfig) Config(org.apache.kafka.clients.admin.Config) DescribeConfigsResult(org.apache.kafka.clients.admin.DescribeConfigsResult) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Aggregations

ConfigResource (org.apache.kafka.common.config.ConfigResource)64 HashMap (java.util.HashMap)32 Config (org.apache.kafka.clients.admin.Config)23 Map (java.util.Map)22 KafkaFuture (org.apache.kafka.common.KafkaFuture)20 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)20 TopicConfig (org.apache.kafka.common.config.TopicConfig)18 ArrayList (java.util.ArrayList)17 ConfigEntry (org.apache.kafka.clients.admin.ConfigEntry)16 Test (org.junit.Test)15 Collection (java.util.Collection)14 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)13 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)13 Node (org.apache.kafka.common.Node)13 AdminClient (org.apache.kafka.clients.admin.AdminClient)12 ProducerConfig (org.apache.kafka.clients.producer.ProducerConfig)12 Collections (java.util.Collections)11 Collectors (java.util.stream.Collectors)11 TopicMetadataAndConfig (org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig)11 StreamsConfig (org.apache.kafka.streams.StreamsConfig)11