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;
}
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));
}
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));
}
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));
}
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));
}
Aggregations