Search in sources :

Example 1 with ConfigEntry

use of org.apache.kafka.clients.admin.ConfigEntry in project ksql by confluentinc.

the class KafkaTopicClientImplTest method defaultConfigEntry.

private ConfigEntry defaultConfigEntry(final String key, final String value) {
    final ConfigEntry config = mock(ConfigEntry.class);
    expect(config.name()).andReturn(key);
    expect(config.value()).andReturn(value);
    expect(config.source()).andReturn(ConfigEntry.ConfigSource.DEFAULT_CONFIG);
    replay(config);
    return config;
}
Also used : ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry)

Example 2 with ConfigEntry

use of org.apache.kafka.clients.admin.ConfigEntry in project ksql by confluentinc.

the class KafkaTopicClientImplTest method overriddenConfigEntry.

private ConfigEntry overriddenConfigEntry(final String key, final String value) {
    final ConfigEntry config = mock(ConfigEntry.class);
    expect(config.name()).andReturn(key);
    expect(config.value()).andReturn(value);
    expect(config.source()).andReturn(ConfigEntry.ConfigSource.DYNAMIC_TOPIC_CONFIG);
    replay(config);
    return config;
}
Also used : ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry)

Example 3 with ConfigEntry

use of org.apache.kafka.clients.admin.ConfigEntry 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());
}
Also used : ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) Config(org.apache.kafka.clients.admin.Config) ArrayList(java.util.ArrayList) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.Test)

Example 4 with ConfigEntry

use of org.apache.kafka.clients.admin.ConfigEntry 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));
}
Also used : Config(org.apache.kafka.clients.admin.Config) Node(org.apache.kafka.common.Node) ArrayList(java.util.ArrayList) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) Map(java.util.Map)

Example 5 with ConfigEntry

use of org.apache.kafka.clients.admin.ConfigEntry in project strimzi by strimzi.

the class ControllerIT method alterTopicConfig.

private void alterTopicConfig(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
    // Get the topic config
    ConfigResource configResource = topicConfigResource(topicName);
    org.apache.kafka.clients.admin.Config config = getTopicConfig(configResource);
    String key = "compression.type";
    Map<String, ConfigEntry> m = new HashMap<>();
    for (ConfigEntry entry : config.entries()) {
        m.put(entry.name(), entry);
    }
    final String changedValue;
    if ("snappy".equals(m.get(key).value())) {
        changedValue = "lz4";
    } else {
        changedValue = "snappy";
    }
    m.put(key, new ConfigEntry(key, changedValue));
    LOGGER.info("Changing topic config {} to {}", key, changedValue);
    // Update the topic config
    AlterConfigsResult cgf = adminClient.alterConfigs(singletonMap(configResource, new org.apache.kafka.clients.admin.Config(m.values())));
    cgf.all().get();
    // Wait for the configmap to be modified
    waitFor(context, () -> {
        ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
        LOGGER.info("Polled configmap {}, waiting for config change", configMapName);
        String gotValue = TopicSerialization.fromConfigMap(cm).getConfig().get(key);
        LOGGER.info("Got value {}", gotValue);
        return changedValue.equals(gotValue);
    }, timeout, "Expected the configmap to have been deleted by now");
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) AlterConfigsResult(org.apache.kafka.clients.admin.AlterConfigsResult)

Aggregations

ConfigEntry (org.apache.kafka.clients.admin.ConfigEntry)11 Config (org.apache.kafka.clients.admin.Config)7 ConfigResource (org.apache.kafka.common.config.ConfigResource)7 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)4 Node (org.apache.kafka.common.Node)4 TopicConfig (org.apache.kafka.common.config.TopicConfig)4 HashMap (java.util.HashMap)3 NewTopic (org.apache.kafka.clients.admin.NewTopic)3 Lists (com.google.common.collect.Lists)2 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 KafkaTopicException (io.confluent.ksql.exception.KafkaTopicException)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2