Search in sources :

Example 1 with GovernanceConfiguration

use of org.apache.dubbo.admin.registry.config.GovernanceConfiguration in project incubator-dubbo-ops by apache.

the class ConfigCenter method getDynamicConfiguration.

/*
     * generate dynamic configuration client
     */
@Bean("governanceConfiguration")
GovernanceConfiguration getDynamicConfiguration() {
    GovernanceConfiguration dynamicConfiguration = null;
    if (StringUtils.isNotEmpty(configCenter)) {
        configCenterUrl = formUrl(configCenter, configCenterGroup, configCenterGroupNameSpace, username, password);
        dynamicConfiguration = ExtensionLoader.getExtensionLoader(GovernanceConfiguration.class).getDefaultExtension();
        dynamicConfiguration.setUrl(configCenterUrl);
        dynamicConfiguration.init();
        String config = dynamicConfiguration.getConfig(Constants.DUBBO_PROPERTY);
        if (StringUtils.isNotEmpty(config)) {
            Arrays.stream(config.split("\n")).forEach(s -> {
                if (s.startsWith(Constants.REGISTRY_ADDRESS)) {
                    String registryAddress = removerConfigKey(s);
                    registryUrl = formUrl(registryAddress, registryGroup, registryNameSpace, username, password);
                } else if (s.startsWith(Constants.METADATA_ADDRESS)) {
                    metadataUrl = formUrl(removerConfigKey(s), metadataGroup, metadataGroupNameSpace, username, password);
                }
            });
        }
    }
    if (dynamicConfiguration == null) {
        if (StringUtils.isNotEmpty(registryAddress)) {
            registryUrl = formUrl(registryAddress, registryGroup, registryNameSpace, username, password);
            dynamicConfiguration = ExtensionLoader.getExtensionLoader(GovernanceConfiguration.class).getDefaultExtension();
            dynamicConfiguration.setUrl(registryUrl);
            dynamicConfiguration.init();
            logger.warn("you are using dubbo.registry.address, which is not recommend, please refer to: https://github.com/apache/incubator-dubbo-admin/wiki/Dubbo-Admin-configuration");
        } else {
            throw new ConfigurationException("Either config center or registry address is needed, please refer to https://github.com/apache/incubator-dubbo-admin/wiki/Dubbo-Admin-configuration");
        // throw exception
        }
    }
    return dynamicConfiguration;
}
Also used : ConfigurationException(org.apache.dubbo.admin.common.exception.ConfigurationException) GovernanceConfiguration(org.apache.dubbo.admin.registry.config.GovernanceConfiguration) Bean(org.springframework.context.annotation.Bean)

Aggregations

ConfigurationException (org.apache.dubbo.admin.common.exception.ConfigurationException)1 GovernanceConfiguration (org.apache.dubbo.admin.registry.config.GovernanceConfiguration)1 Bean (org.springframework.context.annotation.Bean)1