Search in sources :

Example 1 with ConfigurationException

use of org.apache.dubbo.admin.common.exception.ConfigurationException 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)

Example 2 with ConfigurationException

use of org.apache.dubbo.admin.common.exception.ConfigurationException in project incubator-dubbo-ops by apache.

the class ConfigCenter method getRegistry.

/*
     * generate registry client
     */
@Bean("dubboRegistry")
@DependsOn("governanceConfiguration")
Registry getRegistry() {
    Registry registry = null;
    if (registryUrl == null) {
        if (StringUtils.isBlank(registryAddress)) {
            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");
        }
        registryUrl = formUrl(registryAddress, registryGroup, registryNameSpace, username, password);
    }
    RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
    registry = registryFactory.getRegistry(registryUrl);
    return registry;
}
Also used : RegistryFactory(org.apache.dubbo.registry.RegistryFactory) ConfigurationException(org.apache.dubbo.admin.common.exception.ConfigurationException) Registry(org.apache.dubbo.registry.Registry) DependsOn(org.springframework.context.annotation.DependsOn) Bean(org.springframework.context.annotation.Bean)

Aggregations

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