Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configSubscriber mode not support Map #1549

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import io.sermant.core.service.dynamicconfig.common.DynamicConfigEvent;
import io.sermant.core.service.dynamicconfig.common.DynamicConfigEventType;
import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener;
import io.sermant.core.utils.MapUtils;
import io.sermant.core.utils.StringUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

/**
Expand Down Expand Up @@ -112,9 +113,7 @@ private Map<String, Object> buildOrderData() {
final Map<String, Object> result = new HashMap<>(CAP_SIZE);
for (ConfigDataHolder dataHolder : dataHolders) {
for (Map<String, Object> data : dataHolder.getHolder().values()) {
if (data != null) {
result.putAll(data);
}
handleConfig(result, data);
}
}
return result;
Expand All @@ -125,12 +124,34 @@ private Map<String, Object> buildOrderData(DynamicConfigEvent originEvent) {
dataHolders.forEach(dataHolder -> {
final Map<String, Object> curContent = dataHolder.getHolder().get(originEvent.getKey());
if (curContent != null) {
result.putAll(curContent);
handleConfig(result, curContent);
}
});
return result;
}

private void handleConfig(Map<String, Object> result, Map<String, Object> config) {
if (config == null || config.isEmpty()) {
return;
}
for (Entry<String, Object> entry : config.entrySet()) {
String key = entry.getKey();
final Object value = entry.getValue();
if (value instanceof Map) {
Object resultValue = result.get(key);
Map<String, Object> map = resultValue instanceof Map ? (Map<String, Object>) resultValue
: new HashMap<>();
handleConfig(map, (Map<String, Object>) value);
result.put(key, map);
} else if (value instanceof Collection) {
result.put(key, value);
} else {
// Other types are reserved directly
result.put(key, value == null ? "" : value);
}
}
}

private boolean updateHolder(ConfigDataHolder targetHolder, DynamicConfigEvent originEvent) {
final Map<String, Object> olderDataMap =
targetHolder.getHolder().getOrDefault(originEvent.getKey(), new HashMap<>(CAP_SIZE));
Expand Down
Loading