Search in sources :

Example 1 with SimpleEventListener

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);
    }
}
Also used : SimpleEventListener(org.apache.metron.zookeeper.SimpleEventListener) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKCache(org.apache.metron.zookeeper.ZKCache) RetryPolicy(org.apache.curator.RetryPolicy) ProfilerConfigurations(org.apache.metron.common.configuration.profiler.ProfilerConfigurations)

Example 2 with SimpleEventListener

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);
    }
}
Also used : SimpleEventListener(org.apache.metron.zookeeper.SimpleEventListener) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKCache(org.apache.metron.zookeeper.ZKCache) RetryPolicy(org.apache.curator.RetryPolicy)

Example 3 with SimpleEventListener

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);
    }
}
Also used : SimpleEventListener(org.apache.metron.zookeeper.SimpleEventListener) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKCache(org.apache.metron.zookeeper.ZKCache) RetryPolicy(org.apache.curator.RetryPolicy) ProfilerConfigurations(org.apache.metron.common.configuration.profiler.ProfilerConfigurations)

Example 4 with SimpleEventListener

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);
    }
}
Also used : SimpleEventListener(org.apache.metron.zookeeper.SimpleEventListener) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKCache(org.apache.metron.zookeeper.ZKCache) RetryPolicy(org.apache.curator.RetryPolicy)

Example 5 with SimpleEventListener

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();
    }
}
Also used : Iterables(com.google.common.collect.Iterables) org.apache.metron.common.zookeeper.configurations(org.apache.metron.common.zookeeper.configurations) Logger(org.slf4j.Logger) ProfilerConfigurations(org.apache.metron.common.configuration.profiler.ProfilerConfigurations) ZKCache(org.apache.metron.zookeeper.ZKCache) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Constants(org.apache.metron.common.Constants) Supplier(java.util.function.Supplier) SimpleEventListener(org.apache.metron.zookeeper.SimpleEventListener) ArrayList(java.util.ArrayList) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) List(java.util.List) Lock(java.util.concurrent.locks.Lock) CuratorFramework(org.apache.curator.framework.CuratorFramework) Closeable(java.io.Closeable) Map(java.util.Map) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) org.apache.metron.common.configuration(org.apache.metron.common.configuration) SimpleEventListener(org.apache.metron.zookeeper.SimpleEventListener) ZKCache(org.apache.metron.zookeeper.ZKCache) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Aggregations

SimpleEventListener (org.apache.metron.zookeeper.SimpleEventListener)5 ZKCache (org.apache.metron.zookeeper.ZKCache)5 RetryPolicy (org.apache.curator.RetryPolicy)4 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)4 ProfilerConfigurations (org.apache.metron.common.configuration.profiler.ProfilerConfigurations)3 Iterables (com.google.common.collect.Iterables)1 Closeable (java.io.Closeable)1 MethodHandles (java.lang.invoke.MethodHandles)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Supplier (java.util.function.Supplier)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)1 Constants (org.apache.metron.common.Constants)1 org.apache.metron.common.configuration (org.apache.metron.common.configuration)1