Search in sources :

Example 1 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration in project archaius by Netflix.

the class ConfigurationManager method createDefaultConfigInstance.

private static AbstractConfiguration createDefaultConfigInstance() {
    ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
    try {
        DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration();
        config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME);
    } catch (Throwable e) {
        logger.warn("Failed to create default dynamic configuration", e);
    }
    if (!Boolean.getBoolean(DISABLE_DEFAULT_SYS_CONFIG)) {
        SystemConfiguration sysConfig = new SystemConfiguration();
        config.addConfiguration(sysConfig, SYS_CONFIG_NAME);
    }
    if (!Boolean.getBoolean(DISABLE_DEFAULT_ENV_CONFIG)) {
        EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
        config.addConfiguration(envConfig, ENV_CONFIG_NAME);
    }
    ConcurrentCompositeConfiguration appOverrideConfig = new ConcurrentCompositeConfiguration();
    config.addConfiguration(appOverrideConfig, APPLICATION_PROPERTIES);
    config.setContainerConfigurationIndex(config.getIndexOfConfiguration(appOverrideConfig));
    return config;
}
Also used : EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration)

Example 2 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration in project java-chassis by ServiceComb.

the class CseAutoConfiguration method configureArchaius.

protected void configureArchaius(ConfigurableEnvironmentConfiguration envConfig) {
    if (INITIALIZED.compareAndSet(false, true)) {
        String appName = this.env.getProperty("spring.application.name");
        if (appName == null) {
            appName = "application";
        //log.warn("No spring.application.name found, defaulting to 'application'");
        }
        System.setProperty(DeploymentContext.ContextKey.appId.getKey(), appName);
        ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
        // etc...)
        if (this.externalConfigurations != null) {
            for (AbstractConfiguration externalConfig : this.externalConfigurations) {
                config.addConfiguration(externalConfig);
            }
        }
        config.addConfiguration(envConfig, ConfigurableEnvironmentConfiguration.class.getSimpleName());
        // below come from ConfigurationManager.createDefaultConfigInstance()
        DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration();
        try {
            config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME);
        } catch (Throwable ex) {
        //log.error("Cannot create config from " + defaultURLConfig, ex);
        }
        // TODO: sys/env above urls?
        if (!Boolean.getBoolean(DISABLE_DEFAULT_SYS_CONFIG)) {
            SystemConfiguration sysConfig = new SystemConfiguration();
            config.addConfiguration(sysConfig, SYS_CONFIG_NAME);
        }
        if (!Boolean.getBoolean(DISABLE_DEFAULT_ENV_CONFIG)) {
            EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration();
            config.addConfiguration(environmentConfiguration, ENV_CONFIG_NAME);
        }
        ConcurrentCompositeConfiguration appOverrideConfig = new ConcurrentCompositeConfiguration();
        config.addConfiguration(appOverrideConfig, APPLICATION_PROPERTIES);
        config.setContainerConfigurationIndex(config.getIndexOfConfiguration(appOverrideConfig));
        addArchaiusConfiguration(config);
    }
//        else {
//            // TODO: reinstall ConfigurationManager
//            //log.warn(
//            //       "Netflix ConfigurationManager has already been installed, unable to re-install");
//        }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) DynamicURLConfiguration(com.netflix.config.DynamicURLConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 3 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration in project incubator-servicecomb-java-chassis by apache.

the class ConfigUtil method createLocalConfig.

public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
    ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
    duplicateServiceCombConfigToCse(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem");
    duplicateServiceCombConfigToCse(config, convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())), "configFromEnvironment");
    duplicateServiceCombConfigToCse(config, new DynamicConfiguration(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile");
    return config;
}
Also used : MicroserviceConfigurationSource(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource) DynamicConfiguration(com.netflix.config.DynamicConfiguration) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)

Example 4 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration in project spring-cloud-netflix by spring-cloud.

the class ArchaiusAutoConfiguration method configureArchaius.

protected static void configureArchaius(ConfigurableEnvironmentConfiguration envConfig, ConfigurableEnvironment env, List<AbstractConfiguration> externalConfigurations) {
    if (initialized.compareAndSet(false, true)) {
        String appName = env.getProperty("spring.application.name");
        if (appName == null) {
            appName = "application";
            log.warn("No spring.application.name found, defaulting to 'application'");
        }
        System.setProperty(DeploymentContext.ContextKey.appId.getKey(), appName);
        ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
        // etc...)
        if (externalConfigurations != null) {
            for (AbstractConfiguration externalConfig : externalConfigurations) {
                config.addConfiguration(externalConfig);
            }
        }
        config.addConfiguration(envConfig, ConfigurableEnvironmentConfiguration.class.getSimpleName());
        defaultURLConfig = new DynamicURLConfiguration();
        try {
            config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME);
        } catch (Throwable ex) {
            log.error("Cannot create config from " + defaultURLConfig, ex);
        }
        // TODO: sys/env above urls?
        if (!Boolean.getBoolean(DISABLE_DEFAULT_SYS_CONFIG)) {
            SystemConfiguration sysConfig = new SystemConfiguration();
            config.addConfiguration(sysConfig, SYS_CONFIG_NAME);
        }
        if (!Boolean.getBoolean(DISABLE_DEFAULT_ENV_CONFIG)) {
            EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration();
            config.addConfiguration(environmentConfiguration, ENV_CONFIG_NAME);
        }
        ConcurrentCompositeConfiguration appOverrideConfig = new ConcurrentCompositeConfiguration();
        config.addConfiguration(appOverrideConfig, APPLICATION_PROPERTIES);
        config.setContainerConfigurationIndex(config.getIndexOfConfiguration(appOverrideConfig));
        addArchaiusConfiguration(config);
    } else {
        // TODO: reinstall ConfigurationManager
        log.warn("Netflix ConfigurationManager has already been installed, unable to re-install");
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) DynamicURLConfiguration(com.netflix.config.DynamicURLConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 5 with EnvironmentConfiguration

use of org.apache.commons.configuration.EnvironmentConfiguration 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)

Aggregations

EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)6 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)5 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)4 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2 NeverStartPollingScheduler (org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)2 MicroserviceConfigurationSource (org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource)2 ConfigurationManager (com.netflix.config.ConfigurationManager)1 DynamicConfiguration (com.netflix.config.DynamicConfiguration)1 DynamicProperty (com.netflix.config.DynamicProperty)1 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)1 WatchedUpdateListener (com.netflix.config.WatchedUpdateListener)1 WatchedUpdateResult (com.netflix.config.WatchedUpdateResult)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1