Search in sources :

Example 6 with ConcurrentCompositeConfiguration

use of com.netflix.config.ConcurrentCompositeConfiguration in project java-chassis by ServiceComb.

the class SSLOptionTest method testSSLOptionYamlOption2.

@Test
public void testSSLOptionYamlOption2() throws Exception {
    System.setProperty("ssl.protocols", "TLSv1.2");
    YAMLConfigurationSource configSource = new YAMLConfigurationSource();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(configSource, new NeverStartPollingScheduler());
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");
    SSLOption option = SSLOption.buildFromYaml("server", finalConfig);
    String protocols = option.getProtocols();
    option.setProtocols(protocols);
    Assert.assertEquals("TLSv1.2", protocols);
    System.getProperties().clear();
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) YAMLConfigurationSource(io.servicecomb.config.archaius.sources.YAMLConfigurationSource) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Test(org.junit.Test)

Example 7 with ConcurrentCompositeConfiguration

use of com.netflix.config.ConcurrentCompositeConfiguration in project java-chassis by ServiceComb.

the class SSLOptionTest method testSSLOptionYamlOption.

@Test
public void testSSLOptionYamlOption() throws Exception {
    YAMLConfigurationSource configSource = new YAMLConfigurationSource();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(configSource, new NeverStartPollingScheduler());
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");
    SSLOption option = SSLOption.buildFromYaml("server", finalConfig);
    String protocols = option.getProtocols();
    option.setProtocols(protocols);
    Assert.assertEquals("TLSv1.2,TLSv1.1,TLSv1,SSLv2Hello", protocols);
    String ciphers = option.getCiphers();
    option.setCiphers(ciphers);
    Assert.assertEquals("TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SH" + "A,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA", ciphers);
    boolean authPeer = option.isAuthPeer();
    option.setAuthPeer(authPeer);
    Assert.assertEquals(true, authPeer);
    boolean checkCNHost = option.isCheckCNHost();
    option.setCheckCNHost(checkCNHost);
    Assert.assertEquals(true, checkCNHost);
    boolean checkCNWhite = option.isCheckCNWhite();
    option.setCheckCNWhite(checkCNWhite);
    Assert.assertEquals(true, checkCNWhite);
    String checkCNWhiteFile = option.getCheckCNWhiteFile();
    option.setCheckCNWhiteFile(checkCNWhiteFile);
    Assert.assertEquals("white.list", checkCNWhiteFile);
    boolean allowRenegociate = option.isAllowRenegociate();
    option.setAllowRenegociate(allowRenegociate);
    Assert.assertEquals(false, allowRenegociate);
    String storePath = option.getStorePath();
    option.setStorePath(storePath);
    Assert.assertEquals("internal", storePath);
    String trustStore = option.getTrustStore();
    option.setTrustStore(trustStore);
    Assert.assertEquals("trust.jks", trustStore);
    String trustStoreType = option.getTrustStoreType();
    option.setTrustStoreType(trustStoreType);
    Assert.assertEquals("JKS", trustStoreType);
    String trustStoreValue = option.getTrustStoreValue();
    option.setTrustStoreValue(trustStoreValue);
    Assert.assertEquals("Changeme_123", trustStoreValue);
    String keyStore = option.getKeyStore();
    option.setKeyStore(keyStore);
    Assert.assertEquals("server.p12", keyStore);
    String keyStoreType = option.getKeyStoreType();
    option.setKeyStoreType(keyStoreType);
    Assert.assertEquals("PKCS12", keyStoreType);
    String keyStoreValue = option.getKeyStoreValue();
    option.setKeyStoreValue(keyStoreValue);
    Assert.assertEquals("Changeme_123", keyStoreValue);
    String crl = option.getCrl();
    option.setCrl(crl);
    Assert.assertEquals("revoke.crl", crl);
    option.setSslCustomClass("123");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    Assert.assertArrayEquals(custom.decode("123".toCharArray()), "123".toCharArray());
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) YAMLConfigurationSource(io.servicecomb.config.archaius.sources.YAMLConfigurationSource) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Test(org.junit.Test)

Example 8 with ConcurrentCompositeConfiguration

use of com.netflix.config.ConcurrentCompositeConfiguration in project java-chassis by ServiceComb.

the class SSLOptionTest method testSSLOptionYaml.

@Test
public void testSSLOptionYaml() {
    // configuration from yaml files: default microservice.yaml
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(new YAMLConfigurationSource(), new FixedDelayPollingScheduler());
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    // create a hierarchy of configuration that makes
    // 1) dynamic configuration source override system properties
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");
    ConfigurationManager.install(finalConfig);
    SSLOption option = SSLOption.buildFromYaml("server");
    String protocols = option.getProtocols();
    option.setProtocols(protocols);
    Assert.assertEquals("TLSv1.2,TLSv1.1,TLSv1,SSLv2Hello", protocols);
    String ciphers = option.getCiphers();
    option.setCiphers(ciphers);
    Assert.assertEquals("TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SH" + "A,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA", ciphers);
    boolean authPeer = option.isAuthPeer();
    option.setAuthPeer(authPeer);
    Assert.assertEquals(true, authPeer);
    boolean checkCNHost = option.isCheckCNHost();
    option.setCheckCNHost(checkCNHost);
    Assert.assertEquals(true, checkCNHost);
    boolean checkCNWhite = option.isCheckCNWhite();
    option.setCheckCNWhite(checkCNWhite);
    Assert.assertEquals(true, checkCNWhite);
    String checkCNWhiteFile = option.getCheckCNWhiteFile();
    option.setCheckCNWhiteFile(checkCNWhiteFile);
    Assert.assertEquals("white.list", checkCNWhiteFile);
    boolean allowRenegociate = option.isAllowRenegociate();
    option.setAllowRenegociate(allowRenegociate);
    Assert.assertEquals(false, allowRenegociate);
    String storePath = option.getStorePath();
    option.setStorePath(storePath);
    Assert.assertEquals("internal", storePath);
    String trustStore = option.getTrustStore();
    option.setTrustStore(trustStore);
    Assert.assertEquals("trust.jks", trustStore);
    String trustStoreType = option.getTrustStoreType();
    option.setTrustStoreType(trustStoreType);
    Assert.assertEquals("JKS", trustStoreType);
    String trustStoreValue = option.getTrustStoreValue();
    option.setTrustStoreValue(trustStoreValue);
    Assert.assertEquals("Changeme_123", trustStoreValue);
    String keyStore = option.getKeyStore();
    option.setKeyStore(keyStore);
    Assert.assertEquals("server.p12", keyStore);
    String keyStoreType = option.getKeyStoreType();
    option.setKeyStoreType(keyStoreType);
    Assert.assertEquals("PKCS12", keyStoreType);
    String keyStoreValue = option.getKeyStoreValue();
    option.setKeyStoreValue(keyStoreValue);
    Assert.assertEquals("Changeme_123", keyStoreValue);
    String crl = option.getCrl();
    option.setCrl(crl);
    Assert.assertEquals("revoke.crl", crl);
    option.setSslCustomClass("123");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    Assert.assertArrayEquals(custom.decode("123".toCharArray()), "123".toCharArray());
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) YAMLConfigurationSource(io.servicecomb.config.archaius.sources.YAMLConfigurationSource) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Test(org.junit.Test)

Example 9 with ConcurrentCompositeConfiguration

use of com.netflix.config.ConcurrentCompositeConfiguration 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 10 with ConcurrentCompositeConfiguration

use of com.netflix.config.ConcurrentCompositeConfiguration in project java-chassis by ServiceComb.

the class CseEndpoint method invoke.

@Override
public Map<String, Object> invoke() {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    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)

Aggregations

ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)21 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)11 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)8 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)8 Test (org.junit.Test)7 DynamicConfiguration (com.netflix.config.DynamicConfiguration)5 NeverStartPollingScheduler (io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)4 YAMLConfigurationSource (io.servicecomb.config.archaius.sources.YAMLConfigurationSource)4 BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Configuration (org.apache.commons.configuration.Configuration)3 DynamicWatchedConfiguration (com.netflix.config.DynamicWatchedConfiguration)2 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 CombinedConfiguration (org.apache.commons.configuration.CombinedConfiguration)2 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 TestingServer (org.apache.curator.test.TestingServer)2