Search in sources :

Example 1 with DynamicWatchedConfiguration

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

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

the class DynamicZookeeperConfigurationSourceTest method instanceConfigDeletedAfterStartup.

@Test
public void instanceConfigDeletedAfterStartup() throws Exception {
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
    config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
    config.addConfiguration(defaultConfiguration);
    Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override".getBytes());
    Thread.sleep(1000);
    Assert.assertEquals("override", config.getString(DEF_KEY1));
    curatorFramework.delete().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1);
    curatorFramework.delete().forPath(CONFIG_BASE_PATH + "/" + node);
    Thread.sleep(1000);
    Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
}
Also used : DynamicZookeeperConfigurationSource(com.kixeye.chassis.bootstrap.configuration.zookeeper.DynamicZookeeperConfigurationSource) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration) Test(org.junit.Test)

Example 3 with DynamicWatchedConfiguration

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

the class DynamicZookeeperConfigurationSourceTest method instanceConfigPropertyUpdated.

@Test
public void instanceConfigPropertyUpdated() throws Exception {
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
    config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
    config.addConfiguration(defaultConfiguration);
    Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override".getBytes());
    Thread.sleep(1000);
    Assert.assertEquals("override", config.getString(DEF_KEY1));
    curatorFramework.setData().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override2".getBytes());
    Thread.sleep(1000);
    Assert.assertEquals("override2", config.getString(DEF_KEY1));
}
Also used : DynamicZookeeperConfigurationSource(com.kixeye.chassis.bootstrap.configuration.zookeeper.DynamicZookeeperConfigurationSource) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration) Test(org.junit.Test)

Example 4 with DynamicWatchedConfiguration

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

the class DynamicZookeeperConfigurationSourceTest method instanceConfigPropertyAdded.

@Test
public void instanceConfigPropertyAdded() throws Exception {
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
    config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
    config.addConfiguration(defaultConfiguration);
    Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override".getBytes());
    Thread.sleep(1000);
    Assert.assertEquals("override", config.getString(DEF_KEY1));
}
Also used : DynamicZookeeperConfigurationSource(com.kixeye.chassis.bootstrap.configuration.zookeeper.DynamicZookeeperConfigurationSource) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration) Test(org.junit.Test)

Example 5 with DynamicWatchedConfiguration

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

the class DynamicZookeeperConfigurationSourceTest method instanceConfigDeletedAndReadded.

@Test
public void instanceConfigDeletedAndReadded() throws Exception {
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
    config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
    config.addConfiguration(defaultConfiguration);
    Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override".getBytes());
    Thread.sleep(1000);
    Assert.assertEquals("override", config.getString(DEF_KEY1));
    curatorFramework.delete().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1);
    curatorFramework.delete().forPath(CONFIG_BASE_PATH + "/" + node);
    Thread.sleep(1000);
    Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
    Thread.sleep(1000);
    curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override".getBytes());
    Thread.sleep(1000);
    Assert.assertEquals("override", config.getString(DEF_KEY1));
}
Also used : DynamicZookeeperConfigurationSource(com.kixeye.chassis.bootstrap.configuration.zookeeper.DynamicZookeeperConfigurationSource) DynamicWatchedConfiguration(com.netflix.config.DynamicWatchedConfiguration) Test(org.junit.Test)

Aggregations

DynamicWatchedConfiguration (com.netflix.config.DynamicWatchedConfiguration)10 DynamicZookeeperConfigurationSource (com.kixeye.chassis.bootstrap.configuration.zookeeper.DynamicZookeeperConfigurationSource)8 Test (org.junit.Test)8 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)2 BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)1 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)1 ZooKeeperConfigurationSource (com.netflix.config.source.ZooKeeperConfigurationSource)1 IOException (java.io.IOException)1 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)1 TestingServer (org.apache.curator.test.TestingServer)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1 BeforeClass (org.junit.BeforeClass)1