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);
}
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);
}
}
}
}
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;
}
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());
}
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();
}
}
Aggregations