Search in sources :

Example 1 with ConfigCenterConfigurationSource

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);
}
Also used : ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration)

Example 2 with 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;
}
Also used : ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource)

Example 3 with 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());
}
Also used : Expectations(mockit.Expectations) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource) Mock(mockit.Mock) Test(org.junit.Test)

Example 4 with ConfigCenterConfigurationSource

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;
}
Also used : ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Aggregations

ConfigCenterConfigurationSource (org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource)4 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)1 DynamicWatchedConfiguration (com.netflix.config.DynamicWatchedConfiguration)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Expectations (mockit.Expectations)1 Mock (mockit.Mock)1 Test (org.junit.Test)1