Search in sources :

Example 11 with ConfigResource

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

the class RequestResponseTest method createAlterConfigsRequest.

private AlterConfigsRequest createAlterConfigsRequest(short version) {
    Map<ConfigResource, AlterConfigsRequest.Config> configs = new HashMap<>();
    List<AlterConfigsRequest.ConfigEntry> configEntries = asList(new AlterConfigsRequest.ConfigEntry("config_name", "config_value"), new AlterConfigsRequest.ConfigEntry("another_name", "another value"));
    configs.put(new ConfigResource(ConfigResource.Type.BROKER, "0"), new AlterConfigsRequest.Config(configEntries));
    configs.put(new ConfigResource(ConfigResource.Type.TOPIC, "topic"), new AlterConfigsRequest.Config(emptyList()));
    return new AlterConfigsRequest.Builder(configs, false).build(version);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) CreateableTopicConfig(org.apache.kafka.common.message.CreateTopicsRequestData.CreateableTopicConfig) AlterableConfig(org.apache.kafka.common.message.IncrementalAlterConfigsRequestData.AlterableConfig) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 12 with ConfigResource

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

the class RequestResponseTest method verifyDescribeConfigsResponse.

private void verifyDescribeConfigsResponse(DescribeConfigsResponse expected, DescribeConfigsResponse actual, short version) {
    for (Map.Entry<ConfigResource, DescribeConfigsResult> resource : expected.resultMap().entrySet()) {
        List<DescribeConfigsResourceResult> actualEntries = actual.resultMap().get(resource.getKey()).configs();
        List<DescribeConfigsResourceResult> expectedEntries = expected.resultMap().get(resource.getKey()).configs();
        assertEquals(expectedEntries.size(), actualEntries.size());
        for (int i = 0; i < actualEntries.size(); ++i) {
            DescribeConfigsResourceResult actualEntry = actualEntries.get(i);
            DescribeConfigsResourceResult expectedEntry = expectedEntries.get(i);
            assertEquals(expectedEntry.name(), actualEntry.name());
            assertEquals(expectedEntry.value(), actualEntry.value(), "Non-matching values for " + actualEntry.name() + " in version " + version);
            assertEquals(expectedEntry.readOnly(), actualEntry.readOnly(), "Non-matching readonly for " + actualEntry.name() + " in version " + version);
            assertEquals(expectedEntry.isSensitive(), actualEntry.isSensitive(), "Non-matching isSensitive for " + actualEntry.name() + " in version " + version);
            if (version < 3) {
                assertEquals(ConfigType.UNKNOWN.id(), actualEntry.configType(), "Non-matching configType for " + actualEntry.name() + " in version " + version);
            } else {
                assertEquals(expectedEntry.configType(), actualEntry.configType(), "Non-matching configType for " + actualEntry.name() + " in version " + version);
            }
            if (version == 0) {
                assertEquals(DescribeConfigsResponse.ConfigSource.STATIC_BROKER_CONFIG.id(), actualEntry.configSource(), "Non matching configSource for " + actualEntry.name() + " in version " + version);
            } else {
                assertEquals(expectedEntry.configSource(), actualEntry.configSource(), "Non-matching configSource for " + actualEntry.name() + " in version " + version);
            }
        }
    }
}
Also used : DescribeConfigsResult(org.apache.kafka.common.message.DescribeConfigsResponseData.DescribeConfigsResult) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) DescribeConfigsResourceResult(org.apache.kafka.common.message.DescribeConfigsResponseData.DescribeConfigsResourceResult) ConfigResource(org.apache.kafka.common.config.ConfigResource) UpdateMetadataEndpoint(org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataEndpoint)

Example 13 with ConfigResource

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

the class ConfigurationControlManager method describeConfigs.

public Map<ConfigResource, ResultOrError<Map<String, String>>> describeConfigs(long lastCommittedOffset, Map<ConfigResource, Collection<String>> resources) {
    Map<ConfigResource, ResultOrError<Map<String, String>>> results = new HashMap<>();
    for (Entry<ConfigResource, Collection<String>> resourceEntry : resources.entrySet()) {
        ConfigResource resource = resourceEntry.getKey();
        try {
            validator.validate(resource, Collections.emptyMap());
        } catch (Throwable e) {
            results.put(resource, new ResultOrError<>(ApiError.fromThrowable(e)));
            continue;
        }
        Map<String, String> foundConfigs = new HashMap<>();
        TimelineHashMap<String, String> configs = configData.get(resource, lastCommittedOffset);
        if (configs != null) {
            Collection<String> targetConfigs = resourceEntry.getValue();
            if (targetConfigs.isEmpty()) {
                Iterator<Entry<String, String>> iter = configs.entrySet(lastCommittedOffset).iterator();
                while (iter.hasNext()) {
                    Entry<String, String> entry = iter.next();
                    foundConfigs.put(entry.getKey(), entry.getValue());
                }
            } else {
                for (String key : targetConfigs) {
                    String value = configs.get(key, lastCommittedOffset);
                    if (value != null) {
                        foundConfigs.put(key, value);
                    }
                }
            }
        }
        results.put(resource, new ResultOrError<>(foundConfigs));
    }
    return results;
}
Also used : TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) HashMap(java.util.HashMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) Entry(java.util.Map.Entry) Collection(java.util.Collection)

Example 14 with ConfigResource

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

the class ConfigurationControlManager method replay.

/**
 * Apply a configuration record to the in-memory state.
 *
 * @param record            The ConfigRecord.
 */
public void replay(ConfigRecord record) {
    Type type = Type.forId(record.resourceType());
    ConfigResource configResource = new ConfigResource(type, record.resourceName());
    TimelineHashMap<String, String> configs = configData.get(configResource);
    if (configs == null) {
        configs = new TimelineHashMap<>(snapshotRegistry, 0);
        configData.put(configResource, configs);
    }
    if (record.value() == null) {
        configs.remove(record.name());
    } else {
        configs.put(record.name(), record.value());
    }
    if (configs.isEmpty()) {
        configData.remove(configResource);
    }
    log.info("{}: set configuration {} to {}", configResource, record.name(), record.value());
}
Also used : OpType(org.apache.kafka.clients.admin.AlterConfigOp.OpType) Type(org.apache.kafka.common.config.ConfigResource.Type) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 15 with ConfigResource

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

the class ConfigurationsDelta method finishSnapshot.

public void finishSnapshot() {
    for (Entry<ConfigResource, ConfigurationImage> entry : image.resourceData().entrySet()) {
        ConfigResource resource = entry.getKey();
        ConfigurationImage configImage = entry.getValue();
        ConfigurationDelta configDelta = changes.computeIfAbsent(resource, __ -> new ConfigurationDelta(configImage));
        configDelta.finishSnapshot();
    }
}
Also used : 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