Search in sources :

Example 6 with ConfigRecord

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);
}
Also used : ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) ApiError(org.apache.kafka.common.requests.ApiError)

Example 7 with ConfigRecord

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));
}
Also used : ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) LogContext(org.apache.kafka.common.utils.LogContext) ApiError(org.apache.kafka.common.requests.ApiError) RequestMetadata(org.apache.kafka.server.policy.AlterConfigPolicy.RequestMetadata) Test(org.junit.jupiter.api.Test)

Example 8 with ConfigRecord

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));
}
Also used : ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) LogContext(org.apache.kafka.common.utils.LogContext) ApiError(org.apache.kafka.common.requests.ApiError) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 9 with ConfigRecord

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));
}
Also used : ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) LogContext(org.apache.kafka.common.utils.LogContext) Test(org.junit.jupiter.api.Test)

Example 10 with ConfigRecord

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"));
}
Also used : ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord)

Aggregations

ConfigRecord (org.apache.kafka.common.metadata.ConfigRecord)10 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)8 ApiError (org.apache.kafka.common.requests.ApiError)5 LogContext (org.apache.kafka.common.utils.LogContext)4 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RequestMetadata (org.apache.kafka.server.policy.AlterConfigPolicy.RequestMetadata)2 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 OpType (org.apache.kafka.clients.admin.AlterConfigOp.OpType)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 TimelineHashMap (org.apache.kafka.timeline.TimelineHashMap)1