use of org.apache.metron.zookeeper.SimpleEventListener in project metron by apache.
the class ProfileBuilderBolt method setupZookeeper.
private void setupZookeeper() {
try {
if (zookeeperClient == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
zookeeperClient = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
}
zookeeperClient.start();
// this is temporary to ensure that any validation passes. the individual bolt
// will reinitialize stellar to dynamically pull from zookeeper.
ConfigurationsUtils.setupStellarStatically(zookeeperClient);
if (zookeeperCache == null) {
ConfigurationsUpdater<ProfilerConfigurations> updater = createUpdater();
SimpleEventListener listener = new SimpleEventListener.Builder().with(updater::update, TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(updater::delete, TreeCacheEvent.Type.NODE_REMOVED).build();
zookeeperCache = new ZKCache.Builder().withClient(zookeeperClient).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
updater.forceUpdate(zookeeperClient);
zookeeperCache.start();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.metron.zookeeper.SimpleEventListener in project metron by apache.
the class ConfiguredBolt method prepCache.
protected void prepCache() {
try {
if (client == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
}
client.start();
// this is temporary to ensure that any validation passes.
// The individual bolt will reinitialize stellar to dynamically pull from
// zookeeper.
ConfigurationsUtils.setupStellarStatically(client);
if (cache == null) {
ConfigurationsUpdater<CONFIG_T> updater = createUpdater();
SimpleEventListener listener = new SimpleEventListener.Builder().with(updater::update, TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(updater::delete, TreeCacheEvent.Type.NODE_REMOVED).build();
cache = new ZKCache.Builder().withClient(client).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
updater.forceUpdate(client);
cache.start();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.metron.zookeeper.SimpleEventListener in project metron by apache.
the class ProfileBuilderBolt method setupZookeeper.
/**
* Setup connectivity to Zookeeper which provides the necessary configuration for the bolt.
*/
private void setupZookeeper() {
try {
if (zookeeperClient == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
zookeeperClient = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
}
zookeeperClient.start();
// this is temporary to ensure that any validation passes. the individual bolt
// will reinitialize stellar to dynamically pull from zookeeper.
ConfigurationsUtils.setupStellarStatically(zookeeperClient);
if (zookeeperCache == null) {
ConfigurationsUpdater<ProfilerConfigurations> updater = createUpdater();
SimpleEventListener listener = new SimpleEventListener.Builder().with(updater::update, TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(updater::delete, TreeCacheEvent.Type.NODE_REMOVED).build();
zookeeperCache = new ZKCache.Builder().withClient(zookeeperClient).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
updater.forceUpdate(zookeeperClient);
zookeeperCache.start();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.metron.zookeeper.SimpleEventListener in project metron by apache.
the class ConfiguredBolt method prepCache.
/**
* Prepares the cache that will be used during Metron's interaction with ZooKeeper.
*/
protected void prepCache() {
try {
if (client == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
}
client.start();
// this is temporary to ensure that any validation passes.
// The individual bolt will reinitialize stellar to dynamically pull from
// zookeeper.
ConfigurationsUtils.setupStellarStatically(client);
if (cache == null) {
ConfigurationsUpdater<CONFIG_T> updater = createUpdater();
SimpleEventListener listener = new SimpleEventListener.Builder().with(updater::update, TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(updater::delete, TreeCacheEvent.Type.NODE_REMOVED).build();
cache = new ZKCache.Builder().withClient(client).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
updater.forceUpdate(client);
cache.start();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.metron.zookeeper.SimpleEventListener in project metron by apache.
the class ZKConfigurationsCache method initializeCache.
private void initializeCache(CuratorFramework client) {
Lock writeLock = lock.writeLock();
try {
writeLock.lock();
SimpleEventListener listener = new SimpleEventListener.Builder().with(Iterables.transform(updaters, u -> u::update), TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(Iterables.transform(updaters, u -> u::delete), TreeCacheEvent.Type.NODE_REMOVED).build();
cache = new ZKCache.Builder().withClient(client).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
for (ConfigurationsUpdater<? extends Configurations> updater : updaters) {
updater.forceUpdate(client);
}
cache.start();
} catch (Exception e) {
LOG.error("Unable to initialize zookeeper cache: " + e.getMessage(), e);
throw new IllegalStateException("Unable to initialize zookeeper cache: " + e.getMessage(), e);
} finally {
writeLock.unlock();
}
}
Aggregations