use of org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource in project incubator-servicecomb-java-chassis by apache.
the class ConfigUtil method createConfigFromConfigCenter.
public static DynamicWatchedConfiguration createConfigFromConfigCenter(Configuration localConfiguration) {
ConfigCenterConfigurationSource configCenterConfigurationSource = SPIServiceUtils.getTargetService(ConfigCenterConfigurationSource.class);
if (null == configCenterConfigurationSource) {
LOGGER.info("config center SPI service can not find, skip to load configuration from config center");
return null;
}
if (!configCenterConfigurationSource.isValidSource(localConfiguration)) {
LOGGER.info("Config Source serverUri is not correctly configured.");
return null;
}
configCenterConfigurationSource.init(localConfiguration);
return new DynamicWatchedConfiguration(configCenterConfigurationSource);
}
use of org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource in project java-chassis by ServiceComb.
the class ConfigUtil method createConfigCenterConfigurationSource.
private static ConfigCenterConfigurationSource createConfigCenterConfigurationSource(Configuration localConfiguration) {
ConfigCenterConfigurationSource configCenterConfigurationSource = ConfigCenterConfigurationSourceLoader.getConfigCenterConfigurationSource(localConfiguration);
if (null == configCenterConfigurationSource) {
LOGGER.info("none of config center source enabled.");
return null;
}
LOGGER.info("use config center source {}", configCenterConfigurationSource.getClass().getName());
return configCenterConfigurationSource;
}
use of org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource in project java-chassis by ServiceComb.
the class TestConfigUtil method destroyConfigCenterConfigurationSource.
@Test
public void destroyConfigCenterConfigurationSource() {
AtomicInteger count = new AtomicInteger();
ConfigCenterConfigurationSource source = new MockUp<ConfigCenterConfigurationSource>() {
@Mock
void destroy() {
count.incrementAndGet();
}
}.getMockInstance();
new Expectations(SPIServiceUtils.class) {
{
SPIServiceUtils.getAllService(ConfigCenterConfigurationSource.class);
result = Arrays.asList(source, source);
}
};
ConfigUtil.destroyConfigCenterConfigurationSource();
Assert.assertEquals(2, count.get());
}
use of org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource in project java-chassis by ServiceComb.
the class ConfigUtil method installDynamicConfig.
public static ConfigCenterConfigurationSource installDynamicConfig() {
if (ConfigurationManager.isConfigurationInstalled()) {
LOGGER.warn("Configuration installed by others, will ignore this configuration.");
return null;
}
ConcurrentCompositeConfiguration compositeConfig = ConfigUtil.createLocalConfig();
ConfigCenterConfigurationSource configCenterConfigurationSource = createConfigCenterConfigurationSource(compositeConfig);
if (configCenterConfigurationSource != null) {
// add listeners
createDynamicWatchedConfiguration(compositeConfig, configCenterConfigurationSource);
// then init data
configCenterConfigurationSource.init(compositeConfig);
}
ConfigurationManager.install(compositeConfig);
return configCenterConfigurationSource;
}
Aggregations