Search in sources :

Example 26 with AbstractConfiguration

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

the class DynamicPropertyUpdaterTest method testUpdateProperties.

/**
 * Test method for {@link com.charter.aesd.archaius.DynamicPropertyUpdater#updateProperties(com.netflix.config.WatchedUpdateResult, org.apache.commons.configuration.Configuration, boolean)}.
 * @throws InterruptedException
 */
@Test
public void testUpdateProperties() throws InterruptedException {
    AbstractConfiguration.setDefaultListDelimiter(',');
    AbstractConfiguration config = new ConcurrentCompositeConfiguration();
    config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
    MyListener.resetCount();
    config.setProperty("test", "host,host1,host2");
    config.setProperty("test12", "host12");
    Map<String, Object> added = Maps.newHashMap();
    added.put("test.host", "test,test1");
    Map<String, Object> changed = Maps.newHashMap();
    changed.put("test", "host,host1");
    changed.put("test.host", "");
    dynamicPropertyUpdater.updateProperties(WatchedUpdateResult.createIncremental(added, changed, null), config, false);
    assertEquals("", config.getProperty("test.host"));
    assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test"))).contains("host"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test"))).contains("host1"));
    assertEquals(5, MyListener.count);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) ExpandedConfigurationListenerAdapter(com.netflix.config.ExpandedConfigurationListenerAdapter) Test(org.junit.Test)

Example 27 with AbstractConfiguration

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

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

the class ArchaiusEndpoint method invoke.

@ReadOperation
public Map<String, Object> invoke() {
    Map<String, Object> map = new LinkedHashMap<>();
    AbstractConfiguration config = ConfigurationManager.getConfigInstance();
    if (config instanceof ConcurrentCompositeConfiguration) {
        ConcurrentCompositeConfiguration composite = (ConcurrentCompositeConfiguration) config;
        for (Configuration item : composite.getConfigurations()) {
            append(map, item);
        }
    } else {
        append(map, config);
    }
    return map;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Configuration(org.apache.commons.configuration.Configuration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) LinkedHashMap(java.util.LinkedHashMap) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 29 with AbstractConfiguration

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

the class ArchaiusAutoConfigurationTests method configurationCreated.

@Test
public void configurationCreated() {
    this.context = new AnnotationConfigApplicationContext(ArchaiusAutoConfiguration.class);
    AbstractConfiguration config = this.context.getBean(ConfigurableEnvironmentConfiguration.class);
    assertNotNull(config.getString("java.io.tmpdir"));
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 30 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project hazelcast-eureka by hazelcast.

the class HazelcastClientTestCase method configure.

private void configure(String namespace, String appName) {
    URI serviceUri = server.getServiceURI();
    AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance();
    configInstance.setProperty(namespace + ".serviceUrl.default", serviceUri.toString());
    configInstance.setProperty(namespace + ".port", serviceUri.getPort());
    configInstance.setProperty(namespace + ".name", appName);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) URI(java.net.URI)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2