Search in sources :

Example 6 with SystemConfiguration

use of org.apache.commons.configuration.SystemConfiguration 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 7 with SystemConfiguration

use of org.apache.commons.configuration.SystemConfiguration in project es6draft by anba.

the class Resources method loadConfiguration.

/**
     * Loads the configuration file.
     */
public static Configuration loadConfiguration(Class<?> clazz) {
    TestConfiguration config = clazz.getAnnotation(TestConfiguration.class);
    String file = config.file();
    String name = config.name();
    try {
        PropertiesConfiguration properties = new PropertiesConfiguration();
        // entries are mandatory unless an explicit default value was given
        properties.setThrowExceptionOnMissing(true);
        properties.getInterpolator().setParentInterpolator(MISSING_VAR);
        properties.load(resource(file), "UTF-8");
        Configuration configuration = new CompositeConfiguration(Arrays.asList(new SystemConfiguration(), properties));
        return configuration.subset(name);
    } catch (ConfigurationException | IOException e) {
        throw new RuntimeException(e);
    } catch (NoSuchElementException e) {
        throw e;
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 8 with SystemConfiguration

use of org.apache.commons.configuration.SystemConfiguration in project chassis by Kixeye.

the class ConfigurationBuilder method build.

/**
     * Build the Configuration
     *
     * @return the configuration
     */
public AbstractConfiguration build() {
    initApplicationFileConfiguration();
    initAppVersion();
    initApplicationConfiguration();
    initModuleConfiguration();
    ConcurrentCompositeConfiguration finalConfiguration = new ConcurrentCompositeConfiguration();
    if (addSystemConfigs) {
        finalConfiguration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
    }
    finalConfiguration.addProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);
    addServerInstanceProperties(finalConfiguration);
    if (applicationConfiguration == null) {
        LOGGER.warn("\n\n    ****** Default configuration being used ******\n    client application \"" + appName + "\" is being configured with modules defaults. Defaults should only be used in development environments.\n    In non-developement environments, a configuration provider should be used to configure the client application and it should define ALL required configuration properties.\n");
        finalConfiguration.addConfiguration(applicationFileConfiguration);
        finalConfiguration.addConfiguration(moduleDefaultConfiguration);
    } else {
        finalConfiguration.addConfiguration(applicationConfiguration);
        finalConfiguration.addConfiguration(applicationFileConfiguration);
    }
    finalConfiguration.setProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);
    configureArchaius(finalConfiguration);
    logConfiguration(finalConfiguration);
    return finalConfiguration;
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 9 with SystemConfiguration

use of org.apache.commons.configuration.SystemConfiguration in project chassis by Kixeye.

the class CuratorFrameworkBuilder method buildConfiguration.

private ConcurrentCompositeConfiguration buildConfiguration() {
    ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration();
    configuration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
    configuration.addConfiguration(this.configuration);
    configuration.addConfiguration(defaults);
    return configuration;
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 10 with SystemConfiguration

use of org.apache.commons.configuration.SystemConfiguration 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
    YAMLConfigurationSource configSource = new YAMLConfigurationSource();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(configSource, 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");
    ConfigurationManager.install(finalConfig);
    DynamicDoubleProperty myprop = DynamicPropertyFactory.getInstance().getDoubleProperty("trace.handler.sampler.percent", 0.1);
    Assert.assertEquals(0.5, myprop.getValue().doubleValue(), 0.5);
    //        DynamicStringListProperty property = new DynamicStringListProperty("trace.handler.tlist", "|", DynamicStringListProperty.DEFAULT_DELIMITER);
    //        List<String> ll = property.get();
    //        for (String s : ll) {
    //            System.out.println(s);
    //        }
    Object o = ConfigUtil.getProperty("zq");
    @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
    Assert.assertEquals(3, listO.size());
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) DynamicDoubleProperty(com.netflix.config.DynamicDoubleProperty) DynamicConfiguration(com.netflix.config.DynamicConfiguration) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)10 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)7 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)6 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 Test (org.junit.Test)4 NeverStartPollingScheduler (io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)3 YAMLConfigurationSource (io.servicecomb.config.archaius.sources.YAMLConfigurationSource)3 IOException (java.io.IOException)2 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 DynamicDoubleProperty (com.netflix.config.DynamicDoubleProperty)1 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)1 FixedDelayPollingScheduler (com.netflix.config.FixedDelayPollingScheduler)1 File (java.io.File)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1