Search in sources :

Example 6 with ConcurrentMapConfiguration

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

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

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

the class ConfigurationBuilder method initModuleConfiguration.

private void initModuleConfiguration() {
    if (!scanModuleConfigurations) {
        this.moduleDefaultConfiguration = new ConcurrentMapConfiguration();
        return;
    }
    HashMap<String, Object> base = new HashMap<>();
    Set<Class<?>> types = reflections.getTypesAnnotatedWith(PropertySource.class);
    for (Class<?> type : types) {
        PropertySource propertySource = type.getAnnotation(PropertySource.class);
        String[] propertiesFiles = propertySource.value();
        for (String propertyFile : propertiesFiles) {
            Properties properties = new Properties();
            try (InputStream is = resourceLoader.getResource(SystemPropertyUtils.resolvePlaceholders(propertyFile)).getInputStream()) {
                properties.load(is);
                LOGGER.debug("Initializing module properties from path " + propertyFile);
            } catch (Exception e) {
                BootstrapException.resourceLoadingFailed(propertyFile, e);
            }
            join(base, properties, propertyFile, propertiesFiles);
        }
    }
    this.moduleDefaultConfiguration = new ConcurrentMapConfiguration(base);
}
Also used : HashMap(java.util.HashMap) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) InputStream(java.io.InputStream) Properties(java.util.Properties) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ApplicationConfigurationNotFoundException(com.kixeye.chassis.bootstrap.BootstrapException.ApplicationConfigurationNotFoundException) PropertySource(org.springframework.context.annotation.PropertySource)

Example 9 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project archaius by Netflix.

the class ZooKeeperConfigurationSourceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    System.setProperty(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES, "true");
    server = new TestingServer();
    logger.info("Initialized local ZK with connect string [{}]", server.getConnectString());
    client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
    client.start();
    zkConfigSource = new ZooKeeperConfigurationSource(client, CONFIG_ROOT_PATH);
    zkConfigSource.start();
    // setup system properties
    System.setProperty("test.key4", "test.value4-system");
    System.setProperty("test.key5", "test.value5-system");
    final ConcurrentMapConfiguration systemConfig = new ConcurrentMapConfiguration();
    systemConfig.loadProperties(System.getProperties());
    final DynamicWatchedConfiguration zkDynamicOverrideConfig = new DynamicWatchedConfiguration(zkConfigSource);
    mapConfig = new ConcurrentMapConfiguration();
    mapConfig.addProperty("test.key1", "test.value1-map");
    mapConfig.addProperty("test.key2", "test.value2-map");
    mapConfig.addProperty("test.key3", "test.value3-map");
    mapConfig.addProperty("test.key4", "test.value4-map");
    final ConcurrentCompositeConfiguration compositeConfig = new ConcurrentCompositeConfiguration();
    compositeConfig.addConfiguration(zkDynamicOverrideConfig, "zk dynamic override configuration");
    compositeConfig.addConfiguration(mapConfig, "map configuration");
    compositeConfig.addConfiguration(systemConfig, "system configuration");
    // setup ZK properties
    setZkProperty("test.key1", "test.value1-zk");
    setZkProperty("test.key2", "test.value2-zk");
    setZkProperty("test.key4", "test.value4-zk");
    ConfigurationManager.install(compositeConfig);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) BeforeClass(org.junit.BeforeClass)

Example 10 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project ribbon by Netflix.

the class ClientPropertiesProcessor method exportPropertiesToArchaius.

private void exportPropertiesToArchaius(String groupName, IClientConfig config, String configName) {
    Map<String, Object> map = config.getProperties();
    Configuration configuration = ConfigurationManager.getConfigInstance();
    if (configuration instanceof AggregatedConfiguration) {
        AggregatedConfiguration ac = (AggregatedConfiguration) configuration;
        configuration = ac.getConfiguration(configName);
        if (configuration == null) {
            configuration = new ConcurrentMapConfiguration();
            ac.addConfiguration((AbstractConfiguration) configuration, configName);
        }
    }
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        configuration.setProperty(groupName + "." + config.getNameSpace() + "." + entry.getKey(), entry.getValue());
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) AggregatedConfiguration(com.netflix.config.AggregatedConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AggregatedConfiguration(com.netflix.config.AggregatedConfiguration) Map(java.util.Map)

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