Search in sources :

Example 1 with ZooKeeperConfigurationSource

use of com.netflix.config.source.ZooKeeperConfigurationSource 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 ZooKeeperConfigurationSource

use of com.netflix.config.source.ZooKeeperConfigurationSource in project chassis by Kixeye.

the class DynamicZookeeperConfigurationSource method initializeZookeeperConfigurationSource.

private void initializeZookeeperConfigurationSource() {
    if (running) {
        LOGGER.warn("Detected creation of node {}, but zookeeper configuration source already running. This should not happen. Ignoring event...", instanceConfigPath);
        return;
    }
    this.zooKeeperConfigurationSource = new ZooKeeperConfigurationSource(curatorFramework, instanceConfigPath);
    listeners.forEach(new Function<WatchedUpdateListener, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable WatchedUpdateListener watchedUpdateListener) {
            zooKeeperConfigurationSource.addUpdateListener(watchedUpdateListener);
            return null;
        }
    });
    try {
        zooKeeperConfigurationSource.start();
    } catch (Exception e) {
        LOGGER.error("errro starting zookeeper configuration source", e);
        throw new BootstrapException("Error initializing zookeeper configuration source", e);
    }
    running = true;
}
Also used : ZooKeeperConfigurationSource(com.netflix.config.source.ZooKeeperConfigurationSource) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) WatchedUpdateListener(com.netflix.config.WatchedUpdateListener) Nullable(javax.annotation.Nullable) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException)

Aggregations

BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)2 ZooKeeperConfigurationSource (com.netflix.config.source.ZooKeeperConfigurationSource)2 IOException (java.io.IOException)2 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)1 DynamicWatchedConfiguration (com.netflix.config.DynamicWatchedConfiguration)1 WatchedUpdateListener (com.netflix.config.WatchedUpdateListener)1 Nullable (javax.annotation.Nullable)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1