Search in sources :

Example 11 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project chassis by Kixeye.

the class ConfigurationBuilder method initApplicationFileConfiguration.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void initApplicationFileConfiguration() {
    if (applicationPropertiesPath == null) {
        LOGGER.debug("No client application properties to configure. Skipping...");
        applicationFileConfiguration = new ConcurrentMapConfiguration();
        return;
    }
    this.applicationFileConfiguration = new ConcurrentCompositeConfiguration();
    String path = SystemPropertyUtils.resolvePlaceholders(applicationPropertiesPath);
    LOGGER.debug("Configuring client application properties from path " + applicationPropertiesPath);
    Map applicationProperties = new Properties();
    if (SystemUtils.IS_OS_WINDOWS) {
        if (path.startsWith("file://")) {
            if (!path.startsWith("file:///")) {
                path = path.replaceFirst(Pattern.quote("file://"), "file:///");
            }
        }
    }
    try (InputStream is = resourceLoader.getResource(path).getInputStream()) {
        ((Properties) applicationProperties).load(is);
    } catch (Exception e) {
        BootstrapException.resourceLoadingFailed(path, applicationPropertiesPath, e);
    }
    Map environmentApplicationProperties = getEnvironmentSpecificProperties(path);
    if (environmentApplicationProperties != null) {
        ((ConcurrentCompositeConfiguration) this.applicationFileConfiguration).addConfiguration(new ConcurrentMapConfiguration(environmentApplicationProperties));
    }
    ((ConcurrentCompositeConfiguration) this.applicationFileConfiguration).addConfiguration(new ConcurrentMapConfiguration(applicationProperties));
    if (applicationFileConfiguration.containsKey(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName())) {
        this.publishDefaults = applicationFileConfiguration.getBoolean(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName());
    }
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) InputStream(java.io.InputStream) Properties(java.util.Properties) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ApplicationConfigurationNotFoundException(com.kixeye.chassis.bootstrap.BootstrapException.ApplicationConfigurationNotFoundException)

Example 12 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration 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 13 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration 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 14 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration 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

ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)14 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)10 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)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 Map (java.util.Map)3 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)3 BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)2 ApplicationConfigurationNotFoundException (com.kixeye.chassis.bootstrap.BootstrapException.ApplicationConfigurationNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Configuration (org.apache.commons.configuration.Configuration)2 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)1 DynamicDoubleProperty (com.netflix.config.DynamicDoubleProperty)1 DynamicWatchedConfiguration (com.netflix.config.DynamicWatchedConfiguration)1