MINOR: Displaying default entity name in MetadataShell (#12053)

When debugging some bugs related to configs, I find we are unable to show default broker/topic entity name since the resourceName="". Changed it to similar to how we trait default client quotas.

Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
dengziming 2022-08-30 11:28:49 +08:00 committed by GitHub
parent 2d5871d57e
commit 7fb178aad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -215,7 +215,7 @@ public final class MetadataNodeManager implements AutoCloseable {
}
private void handleCommitImpl(MetadataRecordType type, ApiMessage message)
throws Exception {
throws Exception {
switch (type) {
case REGISTER_BROKER_RECORD: {
DirectoryNode brokersNode = data.root.mkdirs("brokers");
@ -268,7 +268,7 @@ public final class MetadataNodeManager implements AutoCloseable {
"Can't handle ConfigResource.Type " + record.resourceType());
}
DirectoryNode configDirectory = data.root.mkdirs("configs").
mkdirs(typeString).mkdirs(record.resourceName());
mkdirs(typeString).mkdirs(record.resourceName().isEmpty() ? "<default>" : record.resourceName());
if (record.value() == null) {
configDirectory.rmrf(record.name());
} else {

View File

@ -138,26 +138,32 @@ public class MetadataNodeManagerTest {
@Test
public void testValidConfigRecord() {
checkValidConfigRecord(ConfigResource.Type.BROKER.id(), "broker");
checkValidConfigRecord(ConfigResource.Type.TOPIC.id(), "topic");
checkValidConfigRecord(ConfigResource.Type.BROKER.id(), "broker", "0", "0");
checkValidConfigRecord(ConfigResource.Type.TOPIC.id(), "topic", "0", "0");
}
private void checkValidConfigRecord(byte resourceType, String typeString) {
@Test
public void testDefaultBrokerRecord() {
checkValidConfigRecord(ConfigResource.Type.BROKER.id(), "broker", "", "<default>");
// Default topic resources are not allowed, so we don't test it.
}
private void checkValidConfigRecord(byte resourceType, String typeString, String resourceName, String resourceNameKey) {
ConfigRecord configRecord = new ConfigRecord()
.setResourceType(resourceType)
.setResourceName("0")
.setResourceName(resourceName)
.setName("name")
.setValue("kraft");
metadataNodeManager.handleMessage(configRecord);
assertEquals("kraft",
metadataNodeManager.getData().root().directory("configs", typeString, "0").file("name").contents());
metadataNodeManager.getData().root().directory("configs", typeString, resourceNameKey).file("name").contents());
// null value indicates delete
configRecord.setValue(null);
metadataNodeManager.handleMessage(configRecord);
assertFalse(
metadataNodeManager.getData().root().directory("configs", typeString, "0").children().containsKey("name"));
metadataNodeManager.getData().root().directory("configs", typeString, resourceNameKey).children().containsKey("name"));
}
@Test