Search in sources :

Example 1 with NeverStartPollingScheduler

use of org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler in project java-chassis by ServiceComb.

the class ConfigUtil method createLocalConfig.

private static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
    ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
    duplicateCseConfigToServicecomb(config, new ConcurrentMapConfigurationExt(new SystemConfiguration()), "configFromSystem");
    duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfigurationExt(new EnvironmentConfiguration())), "configFromEnvironment");
    // If there is extra configurations, add it into config.
    EXTRA_CONFIG_MAP.entrySet().stream().filter(mapEntry -> !mapEntry.getValue().isEmpty()).forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfigurationExt(configMapEntry.getValue()), configMapEntry.getKey()));
    // we have already copy the cse config to the serviceComb config when we load the config from local yaml files
    // hence, we do not need duplicate copy it.
    config.addConfiguration(new DynamicConfigurationExt(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile");
    duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfigurationExt(ConfigMapping.getConvertedMap(config)), "configFromMapping");
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CONFIG_KEY_SPLITER(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_KEY_SPLITER) StringUtils(org.apache.commons.lang.StringUtils) WatchedUpdateListener(com.netflix.config.WatchedUpdateListener) DynamicConfigurationChangedEvent(org.apache.servicecomb.config.event.DynamicConfigurationChangedEvent) FieldUtils(org.apache.commons.lang.reflect.FieldUtils) ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) CONFIG_CSE_PREFIX(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_CSE_PREFIX) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SPIServiceUtils(org.apache.servicecomb.foundation.common.utils.SPIServiceUtils) HashMap(java.util.HashMap) ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource) LinkedHashMap(java.util.LinkedHashMap) EventManager(org.apache.servicecomb.foundation.common.event.EventManager) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) DynamicProperty(com.netflix.config.DynamicProperty) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) ConfigCenterConfigurationSourceLoader(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSourceLoader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigurationManager(com.netflix.config.ConfigurationManager) CONFIG_SERVICECOMB_PREFIX(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_SERVICECOMB_PREFIX) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) WatchedUpdateResult(com.netflix.config.WatchedUpdateResult) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) Objects(java.util.Objects) List(java.util.List) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) PropertyConverter(org.apache.commons.configuration.PropertyConverter) MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)

Example 2 with NeverStartPollingScheduler

use of org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler in project incubator-servicecomb-java-chassis by apache.

the class ConfigUtil method createLocalConfig.

private static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
    ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
    duplicateCseConfigToServicecomb(config, new ConcurrentMapConfigurationExt(new SystemConfiguration()), "configFromSystem");
    duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfigurationExt(new EnvironmentConfiguration())), "configFromEnvironment");
    // If there is extra configurations, add it into config.
    EXTRA_CONFIG_MAP.entrySet().stream().filter(mapEntry -> !mapEntry.getValue().isEmpty()).forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfigurationExt(configMapEntry.getValue()), configMapEntry.getKey()));
    // we have already copy the cse config to the serviceComb config when we load the config from local yaml files
    // hence, we do not need duplicate copy it.
    config.addConfiguration(new DynamicConfigurationExt(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile");
    duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfigurationExt(ConfigMapping.getConvertedMap(config)), "configFromMapping");
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CONFIG_KEY_SPLITER(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_KEY_SPLITER) StringUtils(org.apache.commons.lang.StringUtils) WatchedUpdateListener(com.netflix.config.WatchedUpdateListener) DynamicConfigurationChangedEvent(org.apache.servicecomb.config.event.DynamicConfigurationChangedEvent) FieldUtils(org.apache.commons.lang.reflect.FieldUtils) ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) CONFIG_CSE_PREFIX(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_CSE_PREFIX) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SPIServiceUtils(org.apache.servicecomb.foundation.common.utils.SPIServiceUtils) HashMap(java.util.HashMap) ConfigCenterConfigurationSource(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource) LinkedHashMap(java.util.LinkedHashMap) EventManager(org.apache.servicecomb.foundation.common.event.EventManager) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) DynamicProperty(com.netflix.config.DynamicProperty) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) ConfigCenterConfigurationSourceLoader(org.apache.servicecomb.config.spi.ConfigCenterConfigurationSourceLoader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigurationManager(com.netflix.config.ConfigurationManager) CONFIG_SERVICECOMB_PREFIX(org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_SERVICECOMB_PREFIX) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) WatchedUpdateResult(com.netflix.config.WatchedUpdateResult) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) Objects(java.util.Objects) List(java.util.List) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) PropertyConverter(org.apache.commons.configuration.PropertyConverter) MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)

Example 3 with NeverStartPollingScheduler

use of org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler in project incubator-servicecomb-java-chassis by apache.

the class TestYAMLConfigurationSource method testFullOperation.

@Test
public void testFullOperation() {
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    // configuration from yaml file
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler());
    // create a hierarchy of configuration that makes
    // 1) dynamic configuration source override system properties
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    Assert.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5);
    Object o = finalConfig.getProperty("zq");
    @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
    Assert.assertEquals(3, listO.size());
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) List(java.util.List) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Map(java.util.Map) Test(org.junit.Test)

Example 4 with NeverStartPollingScheduler

use of org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler in project java-chassis by ServiceComb.

the class TestYAMLConfigurationSource method testFullOperation.

@Test
public void testFullOperation() {
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    // configuration from yaml file
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler());
    // create a hierarchy of configuration that makes
    // 1) dynamic configuration source override system properties
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    Assert.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5);
    Object o = finalConfig.getProperty("zq");
    @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
    Assert.assertEquals(3, listO.size());
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) List(java.util.List) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)4 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)4 List (java.util.List)4 Map (java.util.Map)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 NeverStartPollingScheduler (org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)4 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicConfiguration (com.netflix.config.DynamicConfiguration)2 DynamicProperty (com.netflix.config.DynamicProperty)2 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)2 WatchedUpdateListener (com.netflix.config.WatchedUpdateListener)2 WatchedUpdateResult (com.netflix.config.WatchedUpdateResult)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 Objects (java.util.Objects)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2