Search in sources :

Example 1 with Verifier

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;
    }
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) HashMap(java.util.HashMap) Verifier(com.tencent.polaris.api.config.verify.Verifier) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Verifier

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);
    }
}
Also used : Verifier(com.tencent.polaris.api.config.verify.Verifier) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Verifier

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;
    }
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) Verifier(com.tencent.polaris.api.config.verify.Verifier)

Aggregations

Verifier (com.tencent.polaris.api.config.verify.Verifier)3 PolarisException (com.tencent.polaris.api.exception.PolarisException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2