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