Search in sources :

Example 1 with ParallelEnricher

use of org.apache.metron.enrichment.parallel.ParallelEnricher in project metron by apache.

the class UnifiedEnrichmentBolt method prepare.

@Override
public final void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {
    super.prepare(map, topologyContext, outputCollector);
    collector = outputCollector;
    if (this.maxCacheSize == null) {
        throw new IllegalStateException("MAX_CACHE_SIZE_OBJECTS_NUM must be specified");
    }
    if (this.maxTimeRetain == null) {
        throw new IllegalStateException("MAX_TIME_RETAIN_MINUTES must be specified");
    }
    if (this.enrichmentsByType.isEmpty()) {
        throw new IllegalStateException("Adapter must be specified");
    }
    for (Map.Entry<String, EnrichmentAdapter<CacheKey>> adapterKv : enrichmentsByType.entrySet()) {
        boolean success = adapterKv.getValue().initializeAdapter(getConfigurations().getGlobalConfig());
        if (!success) {
            LOG.error("[Metron] Could not initialize adapter: " + adapterKv.getKey());
            throw new IllegalStateException("Could not initialize adapter: " + adapterKv.getKey());
        }
    }
    WorkerPoolStrategies workerPoolStrategy = WorkerPoolStrategies.FIXED;
    if (map.containsKey(THREADPOOL_TYPE_TOPOLOGY_CONF)) {
        workerPoolStrategy = WorkerPoolStrategies.valueOf(map.get(THREADPOOL_TYPE_TOPOLOGY_CONF) + "");
    }
    if (map.containsKey(THREADPOOL_NUM_THREADS_TOPOLOGY_CONF)) {
        int numThreads = getNumThreads(map.get(THREADPOOL_NUM_THREADS_TOPOLOGY_CONF));
        ConcurrencyContext.get(strategy).initialize(numThreads, maxCacheSize, maxTimeRetain, workerPoolStrategy, LOG, captureCacheStats);
    } else {
        throw new IllegalStateException("You must pass " + THREADPOOL_NUM_THREADS_TOPOLOGY_CONF + " via storm config.");
    }
    messageGetter = this.getterStrategy.get(messageFieldName);
    enricher = new ParallelEnricher(enrichmentsByType, ConcurrencyContext.get(strategy), captureCacheStats);
    perfLog = new PerformanceLogger(() -> getConfigurations().getGlobalConfig(), Perf.class.getName());
    GeoLiteDatabase.INSTANCE.update((String) getConfigurations().getGlobalConfig().get(GeoLiteDatabase.GEO_HDFS_FILE));
    initializeStellar();
    enrichmentContext = new EnrichmentContext(StellarFunctions.FUNCTION_RESOLVER(), stellarContext);
}
Also used : PerformanceLogger(org.apache.metron.common.performance.PerformanceLogger) EnrichmentAdapter(org.apache.metron.enrichment.interfaces.EnrichmentAdapter) WorkerPoolStrategies(org.apache.metron.enrichment.parallel.WorkerPoolStrategies) HashMap(java.util.HashMap) Map(java.util.Map) ParallelEnricher(org.apache.metron.enrichment.parallel.ParallelEnricher) EnrichmentContext(org.apache.metron.enrichment.parallel.EnrichmentContext)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 PerformanceLogger (org.apache.metron.common.performance.PerformanceLogger)1 EnrichmentAdapter (org.apache.metron.enrichment.interfaces.EnrichmentAdapter)1 EnrichmentContext (org.apache.metron.enrichment.parallel.EnrichmentContext)1 ParallelEnricher (org.apache.metron.enrichment.parallel.ParallelEnricher)1 WorkerPoolStrategies (org.apache.metron.enrichment.parallel.WorkerPoolStrategies)1