use of com.tencent.polaris.api.config.verify.Verifier in project polaris-java by polarismesh.
the class PluginConfigImpl method getPluginConfigs.
@Override
public Map<String, Verifier> getPluginConfigs() throws PolarisException {
synchronized (lock) {
Map<String, Verifier> values = new HashMap<>();
if (plugin.size() == 0) {
return values;
}
for (Map.Entry<String, Map<?, ?>> entry : plugin.entrySet()) {
Map<?, ?> properties = entry.getValue();
if (MapUtils.isEmpty(properties)) {
continue;
}
String pluginName = entry.getKey();
Class<? extends Verifier> clazz = PluginConfigImpl.pluginConfigClazz.get(pluginName);
if (null == clazz) {
// String.format("unknown plugin config type for plugin %s", pluginName));
continue;
}
try {
Verifier result = mapper.convertValue(properties, clazz);
values.put(pluginName, result);
} catch (IllegalArgumentException e) {
throw new PolarisException(ErrorCode.INVALID_CONFIG, String.format("fail to deserialize properties %s to clazz %s for plugin %s", properties, clazz.getCanonicalName(), pluginName), e);
}
}
return values;
}
}
use of com.tencent.polaris.api.config.verify.Verifier in project polaris-java by polarismesh.
the class PluginConfigImpl method setDefaultPluginConfig.
public void setDefaultPluginConfig(PluginConfig pluginConfig) {
if (null == pluginConfig) {
return;
}
Map<String, Verifier> pluginConfigs = pluginConfig.getPluginConfigs();
if (MapUtils.isEmpty(pluginConfigs)) {
return;
}
for (Map.Entry<String, Verifier> entry : pluginConfigs.entrySet()) {
String pluginName = entry.getKey();
Verifier defaultObject = entry.getValue();
Class<? extends Verifier> pluginConfigClazz = defaultObject.getClass();
Verifier existConfig = getPluginConfig(pluginName, pluginConfigClazz);
existConfig.setDefault(defaultObject);
setPluginConfig(pluginName, existConfig);
}
}
use of com.tencent.polaris.api.config.verify.Verifier in project polaris-java by polarismesh.
the class PluginConfigImpl method getPluginConfig.
@Override
public <T extends Verifier> T getPluginConfig(String pluginName, Class<T> clazz) throws PolarisException {
synchronized (lock) {
Map<?, ?> properties = plugin.get(pluginName);
if (null == properties) {
Verifier config = getConfigByName(clazz);
properties = mutableSetPluginConfig(pluginName, config);
}
T result;
try {
result = mapper.convertValue(properties, clazz);
} catch (IllegalArgumentException e) {
throw new PolarisException(ErrorCode.INVALID_CONFIG, String.format("fail to deserialize properties %s to clazz %s for plugin %s", properties, clazz.getCanonicalName(), pluginName), e);
}
return result;
}
}
Aggregations