use of org.apache.kafka.common.metadata.ConfigRecord in project kafka by apache.
the class ConfigurationControlManager method legacyAlterConfigResource.
private void legacyAlterConfigResource(ConfigResource configResource, Map<String, String> newConfigs, Consumer<ConfigResource> existenceChecker, List<ApiMessageAndVersion> outputRecords, Map<ConfigResource, ApiError> outputResults) {
List<ApiMessageAndVersion> newRecords = new ArrayList<>();
Map<String, String> currentConfigs = configData.get(configResource);
if (currentConfigs == null) {
currentConfigs = Collections.emptyMap();
}
for (Entry<String, String> entry : newConfigs.entrySet()) {
String key = entry.getKey();
String newValue = entry.getValue();
String currentValue = currentConfigs.get(key);
if (!Objects.equals(newValue, currentValue)) {
newRecords.add(new ApiMessageAndVersion(new ConfigRecord().setResourceType(configResource.type().id()).setResourceName(configResource.name()).setName(key).setValue(newValue), CONFIG_RECORD.highestSupportedVersion()));
}
}
for (String key : currentConfigs.keySet()) {
if (!newConfigs.containsKey(key)) {
newRecords.add(new ApiMessageAndVersion(new ConfigRecord().setResourceType(configResource.type().id()).setResourceName(configResource.name()).setName(key).setValue(null), CONFIG_RECORD.highestSupportedVersion()));
}
}
ApiError error = validateAlterConfig(configResource, newRecords, existenceChecker);
if (error.isFailure()) {
outputResults.put(configResource, error);
return;
}
outputRecords.addAll(newRecords);
outputResults.put(configResource, ApiError.NONE);
}
use of org.apache.kafka.common.metadata.ConfigRecord in project kafka by apache.
the class ConfigurationControlManagerTest method testIncrementalAlterConfigsWithPolicy.
@Test
public void testIncrementalAlterConfigsWithPolicy() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
MockAlterConfigsPolicy policy = new MockAlterConfigsPolicy(asList(new RequestMetadata(MYTOPIC, Collections.emptyMap()), new RequestMetadata(BROKER0, toMap(entry("foo.bar", "123"), entry("quux", "456")))));
ConfigurationControlManager manager = new ConfigurationControlManager(new LogContext(), snapshotRegistry, CONFIGS, Optional.of(policy), ConfigurationValidator.NO_OP);
assertEquals(ControllerResult.atomicOf(asList(new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()).setResourceName("0").setName("foo.bar").setValue("123"), (short) 0), new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()).setResourceName("0").setName("quux").setValue("456"), (short) 0)), toMap(entry(MYTOPIC, new ApiError(Errors.POLICY_VIOLATION, "Expected: AlterConfigPolicy.RequestMetadata(resource=ConfigResource(" + "type=TOPIC, name='mytopic'), configs={}). Got: " + "AlterConfigPolicy.RequestMetadata(resource=ConfigResource(" + "type=TOPIC, name='mytopic'), configs={foo.bar=123})")), entry(BROKER0, ApiError.NONE))), manager.incrementalAlterConfigs(toMap(entry(MYTOPIC, toMap(entry("foo.bar", entry(SET, "123")))), entry(BROKER0, toMap(entry("foo.bar", entry(SET, "123")), entry("quux", entry(SET, "456"))))), NO_OP_EXISTENCE_CHECKER));
}
use of org.apache.kafka.common.metadata.ConfigRecord in project kafka by apache.
the class ConfigurationControlManagerTest method testIncrementalAlterConfigs.
@Test
public void testIncrementalAlterConfigs() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
ConfigurationControlManager manager = new ConfigurationControlManager(new LogContext(), snapshotRegistry, CONFIGS, Optional.empty(), ConfigurationValidator.NO_OP);
ControllerResult<Map<ConfigResource, ApiError>> result = manager.incrementalAlterConfigs(toMap(entry(BROKER0, toMap(entry("baz", entry(SUBTRACT, "abc")), entry("quux", entry(SET, "abc")))), entry(MYTOPIC, toMap(entry("abc", entry(APPEND, "123"))))), NO_OP_EXISTENCE_CHECKER);
assertEquals(ControllerResult.atomicOf(Collections.singletonList(new ApiMessageAndVersion(new ConfigRecord().setResourceType(TOPIC.id()).setResourceName("mytopic").setName("abc").setValue("123"), (short) 0)), toMap(entry(BROKER0, new ApiError(Errors.INVALID_CONFIG, "Can't SUBTRACT to key baz because its type is not LIST.")), entry(MYTOPIC, ApiError.NONE))), result);
RecordTestUtils.replayAll(manager, result.records());
assertEquals(ControllerResult.atomicOf(Collections.singletonList(new ApiMessageAndVersion(new ConfigRecord().setResourceType(TOPIC.id()).setResourceName("mytopic").setName("abc").setValue(null), (short) 0)), toMap(entry(MYTOPIC, ApiError.NONE))), manager.incrementalAlterConfigs(toMap(entry(MYTOPIC, toMap(entry("abc", entry(DELETE, "xyz"))))), NO_OP_EXISTENCE_CHECKER));
}
use of org.apache.kafka.common.metadata.ConfigRecord in project kafka by apache.
the class ConfigurationControlManagerTest method testLegacyAlterConfigs.
@Test
public void testLegacyAlterConfigs() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
ConfigurationControlManager manager = new ConfigurationControlManager(new LogContext(), snapshotRegistry, CONFIGS, Optional.empty(), ConfigurationValidator.NO_OP);
List<ApiMessageAndVersion> expectedRecords1 = asList(new ApiMessageAndVersion(new ConfigRecord().setResourceType(TOPIC.id()).setResourceName("mytopic").setName("abc").setValue("456"), (short) 0), new ApiMessageAndVersion(new ConfigRecord().setResourceType(TOPIC.id()).setResourceName("mytopic").setName("def").setValue("901"), (short) 0));
assertEquals(ControllerResult.atomicOf(expectedRecords1, toMap(entry(MYTOPIC, ApiError.NONE))), manager.legacyAlterConfigs(toMap(entry(MYTOPIC, toMap(entry("abc", "456"), entry("def", "901")))), NO_OP_EXISTENCE_CHECKER));
for (ApiMessageAndVersion message : expectedRecords1) {
manager.replay((ConfigRecord) message.message());
}
assertEquals(ControllerResult.atomicOf(asList(new ApiMessageAndVersion(new ConfigRecord().setResourceType(TOPIC.id()).setResourceName("mytopic").setName("abc").setValue(null), (short) 0)), toMap(entry(MYTOPIC, ApiError.NONE))), manager.legacyAlterConfigs(toMap(entry(MYTOPIC, toMap(entry("def", "901")))), NO_OP_EXISTENCE_CHECKER));
}
use of org.apache.kafka.common.metadata.ConfigRecord in project kafka by apache.
the class MetadataNodeManagerTest method checkInvalidConfigRecord.
private void checkInvalidConfigRecord(byte resourceType) {
ConfigRecord configRecord = new ConfigRecord().setResourceType(resourceType).setResourceName("0").setName("name").setValue("kraft");
metadataNodeManager.handleMessage(configRecord);
assertFalse(metadataNodeManager.getData().root().children().containsKey("configs"));
}
Aggregations