Search in sources :

Example 21 with ConfigResource

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

the class InternalTopicManagerTest method shouldThrowWhenDescribeConfigsThrowsUnexpectedExceptionDuringValidation.

@Test
public void shouldThrowWhenDescribeConfigsThrowsUnexpectedExceptionDuringValidation() {
    final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
    final InternalTopicManager topicManager = new InternalTopicManager(time, admin, new StreamsConfig(config));
    final KafkaFutureImpl<Config> configDescriptionFailFuture = new KafkaFutureImpl<>();
    configDescriptionFailFuture.completeExceptionally(new IllegalStateException("Nobody expects the Spanish inquisition"));
    final ConfigResource topicResource = new ConfigResource(Type.TOPIC, topic1);
    EasyMock.expect(admin.describeConfigs(Collections.singleton(topicResource))).andStubAnswer(() -> new MockDescribeConfigsResult(mkMap(mkEntry(topicResource, configDescriptionFailFuture))));
    EasyMock.replay(admin);
    final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
    assertThrows(Throwable.class, () -> topicManager.validate(Collections.singletonMap(topic1, internalTopicConfig)));
}
Also used : TopicConfig(org.apache.kafka.common.config.TopicConfig) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.kafka.clients.admin.Config) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ConfigResource(org.apache.kafka.common.config.ConfigResource) AdminClient(org.apache.kafka.clients.admin.AdminClient) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 22 with ConfigResource

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

the class ClientCompatibilityTest method testDescribeConfigsMethod.

private void testDescribeConfigsMethod(final Admin client) throws Throwable {
    tryFeature("describeConfigsSupported", testConfig.describeConfigsSupported, () -> {
        try {
            Collection<Node> nodes = client.describeCluster().nodes().get();
            final ConfigResource configResource = new ConfigResource(ConfigResource.Type.BROKER, nodes.iterator().next().idString());
            Map<ConfigResource, Config> brokerConfig = client.describeConfigs(Collections.singleton(configResource)).all().get();
            if (brokerConfig.get(configResource).entries().isEmpty()) {
                throw new KafkaException("Expected to see config entries, but got zero entries");
            }
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    });
}
Also used : ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.kafka.clients.admin.Config) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) Node(org.apache.kafka.common.Node) KafkaException(org.apache.kafka.common.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 23 with ConfigResource

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

the class MockController method legacyAlterConfigs.

@Override
public CompletableFuture<Map<ConfigResource, ApiError>> legacyAlterConfigs(Map<ConfigResource, Map<String, String>> newConfigs, boolean validateOnly) {
    Map<ConfigResource, ApiError> results = new HashMap<>();
    if (!validateOnly) {
        for (Entry<ConfigResource, Map<String, String>> entry : newConfigs.entrySet()) {
            ConfigResource resource = entry.getKey();
            Map<String, String> map = configs.computeIfAbsent(resource, __ -> new HashMap<>());
            map.clear();
            map.putAll(entry.getValue());
        }
    }
    CompletableFuture<Map<ConfigResource, ApiError>> future = new CompletableFuture<>();
    future.complete(results);
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) ApiError(org.apache.kafka.common.requests.ApiError) HashMap(java.util.HashMap) Map(java.util.Map) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 24 with ConfigResource

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

the class ReplicationControlManagerTest method assertCreatedTopicConfigs.

private void assertCreatedTopicConfigs(ReplicationControlTestContext ctx, String topic, CreateTopicsRequestData.CreateableTopicConfigCollection requestConfigs) {
    Map<String, String> configs = ctx.configurationControl.getConfigs(new ConfigResource(ConfigResource.Type.TOPIC, topic));
    assertEquals(requestConfigs.size(), configs.size());
    for (CreateTopicsRequestData.CreateableTopicConfig requestConfig : requestConfigs) {
        String value = configs.get(requestConfig.name());
        assertEquals(requestConfig.value(), value);
    }
}
Also used : CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 25 with ConfigResource

use of org.apache.kafka.common.config.ConfigResource 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

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