Search in sources :

Example 11 with ConcurrentCompositeConfiguration

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

the class CuratorFrameworkBuilder method build.

public CuratorFramework build() {
    if (this.exhibitors == null && this.zookeeperConnectionString == null) {
        throw new BootstrapException("Cannot build a CuratorFramework instance because no Zookeeper or Exhibitor connection information was provided.");
    }
    ConcurrentCompositeConfiguration configuration = buildConfiguration();
    CuratorFramework curatorFramework = null;
    if (zookeeperConnectionString != null) {
        curatorFramework = buildCuratorWithZookeeperDirectly(configuration);
    } else {
        curatorFramework = buildCuratorWithExhibitor(configuration);
    }
    if (startOnBuild) {
        try {
            curatorFramework.start();
        } catch (Exception e) {
            BootstrapException.zookeeperInitializationFailed(this.zookeeperConnectionString, this.exhibitors, e);
        }
    }
    return curatorFramework;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException)

Example 12 with ConcurrentCompositeConfiguration

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

the class ZookeeperConfigurationProvider method getApplicationConfiguration.

/**
     * @see ConfigurationProvider#getApplicationConfiguration(String, String, String, com.kixeye.chassis.bootstrap.aws.ServerInstanceContext)
     */
@Override
public AbstractConfiguration getApplicationConfiguration(String environment, String applicationName, String applicationVersion, ServerInstanceContext serverInstanceContext) {
    String instanceId = serverInstanceContext == null ? "local" : serverInstanceContext.getInstanceId();
    String configRoot = getPath(environment, applicationName, applicationVersion);
    String primaryConfigPath = configRoot += "/config";
    String instanceConfigNode = instanceId + "-config";
    checkPath(primaryConfigPath);
    ZooKeeperConfigurationSource source = new ZooKeeperConfigurationSource(curatorFramework, primaryConfigPath);
    try {
        source.start();
    } catch (Exception e) {
        source.close();
        BootstrapException.zookeeperInitializationFailed(zookeeperConnectionString, primaryConfigPath, e);
    }
    logger.debug("Initializing zookeeper configuration from host " + zookeeperConnectionString + " at path " + primaryConfigPath);
    ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration();
    configuration.addConfiguration(getServerInstanceSpecificApplicationConfiguration(configRoot, instanceConfigNode));
    configuration.addConfiguration(new DynamicWatchedConfiguration(source));
    return configuration;
}
Also used : ZooKeeperConfigurationSource(com.netflix.config.source.ZooKeeperConfigurationSource) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 13 with ConcurrentCompositeConfiguration

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

the class DynamicZookeeperConfigurationSourceTest method beforeClass.

@Before
public void beforeClass() throws Exception {
    zookeeper = new TestingServer(SocketUtils.findAvailableTcpPort());
    curatorFramework = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), new RetryOneTime(1000));
    curatorFramework.start();
    curatorFramework.create().forPath(CONFIG_BASE_PATH);
    Map<String, Object> defaults = new HashMap<>();
    defaults.put(DEF_KEY1, DEF_VAL1);
    defaults.put(DEF_KEY2, DEF_VAL2);
    defaultConfiguration = new MapConfiguration(defaults);
    node = UUID.randomUUID().toString();
    config = new ConcurrentCompositeConfiguration();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryOneTime(org.apache.curator.retry.RetryOneTime) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Before(org.junit.Before)

Example 14 with ConcurrentCompositeConfiguration

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

the class DynamicPropertyUpdaterTest method testAddorChangeProperty.

@Test
public void testAddorChangeProperty() {
    AbstractConfiguration.setDefaultListDelimiter(',');
    AbstractConfiguration config = new ConcurrentCompositeConfiguration();
    config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
    MyListener.resetCount();
    config.setProperty("test.host", "test,test1,test2");
    assertEquals(1, MyListener.count);
    dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config);
    assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2"));
    assertEquals(1, MyListener.count);
    dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config);
    assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2"));
    assertEquals(1, MyListener.count);
    dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1", config);
    assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
    assertEquals(2, MyListener.count);
    dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1,test12", config);
    assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host1"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test1"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test12"));
    assertEquals(3, MyListener.count);
    config.setProperty("test.host1", "test1.test12");
    dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config);
    assertEquals("test1.test12", config.getProperty("test.host1"));
    assertEquals(4, 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 15 with ConcurrentCompositeConfiguration

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

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