Search in sources :

Example 1 with ConfigHandler

use of org.apache.metron.common.configuration.enrichment.handler.ConfigHandler in project metron by apache.

the class StellarEnrichmentConfigTest method testGetSubgroups_grouped.

@Test
public void testGetSubgroups_grouped() throws IOException {
    for (String c : GROUPED_CONFIGS) {
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, EnrichmentConfig.class);
        Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
        ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
        List<String> subgroups = Configs.STELLAR.getSubgroups(handler);
        Assert.assertEquals("group1", subgroups.get(0));
        Assert.assertEquals("group2", subgroups.get(1));
        Assert.assertEquals(2, subgroups.size());
    }
}
Also used : EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 2 with ConfigHandler

use of org.apache.metron.common.configuration.enrichment.handler.ConfigHandler in project metron by apache.

the class StellarEnrichmentConfigTest method testSplitter_grouped.

@Test
public void testSplitter_grouped() throws IOException {
    JSONObject message = getMessage();
    for (String c : GROUPED_CONFIGS) {
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, EnrichmentConfig.class);
        Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
        ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
        List<JSONObject> splits = Configs.STELLAR.splitByFields(message, null, x -> null, handler);
        Assert.assertEquals(2, splits.size());
        {
            Map<String, Object> split = (Map<String, Object>) splits.get(0).get("group1");
            Assert.assertEquals(2, split.size());
            Assert.assertEquals("stellar_test", split.get("source.type"));
            Assert.assertNull(split.get("stmt1"));
        }
        {
            Map<String, Object> split = (Map<String, Object>) splits.get(1).get("group2");
            Assert.assertEquals(1, split.size());
            Assert.assertEquals("foo", split.get("string"));
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) JSONObject(org.json.simple.JSONObject) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 3 with ConfigHandler

use of org.apache.metron.common.configuration.enrichment.handler.ConfigHandler in project metron by apache.

the class StellarEnrichmentConfigTest method testGetSubgroups_default.

@Test
public void testGetSubgroups_default() throws IOException {
    for (String c : DEFAULT_CONFIGS) {
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, EnrichmentConfig.class);
        Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
        ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
        List<String> subgroups = Configs.STELLAR.getSubgroups(handler);
        Assert.assertEquals("", subgroups.get(0));
        Assert.assertEquals(1, subgroups.size());
    }
}
Also used : EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 4 with ConfigHandler

use of org.apache.metron.common.configuration.enrichment.handler.ConfigHandler in project metron by apache.

the class StellarAdapter method enrich.

@Override
public JSONObject enrich(CacheKey value) {
    Context stellarContext = (Context) value.getConfig().getConfiguration().get(STELLAR_CONTEXT_CONF);
    ConfigHandler handler = getHandler.apply(value.getConfig());
    Map<String, Object> globalConfig = value.getConfig().getConfiguration();
    Map<String, Object> sensorConfig = value.getConfig().getEnrichment().getConfig();
    if (handler == null) {
        _LOG.trace("Stellar ConfigHandler is null.");
        return new JSONObject();
    }
    Long slowLogThreshold = null;
    if (_PERF_LOG.isDebugEnabled()) {
        slowLogThreshold = ConversionUtils.convert(globalConfig.getOrDefault(STELLAR_SLOW_LOG, STELLAR_SLOW_LOG_DEFAULT), Long.class);
    }
    // Ensure that you clone the message, because process will modify the message.  If the message object is modified
    // then cache misses will happen because the cache will be modified.
    Map<String, Object> message = new HashMap<>(value.getValue(Map.class));
    VariableResolver resolver = new MapVariableResolver(message, sensorConfig, globalConfig);
    StellarProcessor processor = new StellarProcessor();
    JSONObject enriched = process(message, handler, value.getField(), slowLogThreshold, processor, resolver, stellarContext);
    _LOG.trace("Stellar Enrichment Success: {}", enriched);
    return enriched;
}
Also used : Context(org.apache.metron.stellar.dsl.Context) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) MapVariableResolver(org.apache.metron.stellar.dsl.MapVariableResolver) JSONObject(org.json.simple.JSONObject) VariableResolver(org.apache.metron.stellar.dsl.VariableResolver) MapVariableResolver(org.apache.metron.stellar.dsl.MapVariableResolver) HashMap(java.util.HashMap) Map(java.util.Map) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler)

Example 5 with ConfigHandler

use of org.apache.metron.common.configuration.enrichment.handler.ConfigHandler in project metron by apache.

the class ParallelEnricher method splitMessage.

/**
 * Take a message and a config and return a list of tasks indexed by adapter enrichment types.
 * @param message
 * @param enrichmentStrategy
 * @param config
 * @return
 */
public Map<String, List<JSONObject>> splitMessage(JSONObject message, EnrichmentStrategy enrichmentStrategy, SensorEnrichmentConfig config) {
    Map<String, List<JSONObject>> streamMessageMap = new HashMap<>();
    Map<String, Object> enrichmentFieldMap = enrichmentStrategy.getUnderlyingConfig(config).getFieldMap();
    Map<String, ConfigHandler> fieldToHandler = enrichmentStrategy.getUnderlyingConfig(config).getEnrichmentConfigs();
    Set<String> enrichmentTypes = new HashSet<>(enrichmentFieldMap.keySet());
    // the set of enrichments configured
    enrichmentTypes.addAll(fieldToHandler.keySet());
    // which represent the individual enrichment tasks.
    for (String enrichmentType : enrichmentTypes) {
        Object fields = enrichmentFieldMap.get(enrichmentType);
        ConfigHandler retriever = fieldToHandler.get(enrichmentType);
        // How this is split depends on the ConfigHandler
        List<JSONObject> enrichmentObject = retriever.getType().splitByFields(message, fields, field -> enrichmentStrategy.fieldToEnrichmentKey(enrichmentType, field), retriever);
        streamMessageMap.put(enrichmentType, enrichmentObject);
    }
    return streamMessageMap;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.simple.JSONObject) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) HashSet(java.util.HashSet)

Aggregations

ConfigHandler (org.apache.metron.common.configuration.enrichment.handler.ConfigHandler)17 EnrichmentConfig (org.apache.metron.common.configuration.enrichment.EnrichmentConfig)13 JSONObject (org.json.simple.JSONObject)13 Test (org.junit.Test)12 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 StellarEnrichmentTest (org.apache.metron.common.configuration.StellarEnrichmentTest)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 List (java.util.List)2 ArrayList (java.util.ArrayList)1 StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)1 Context (org.apache.metron.stellar.dsl.Context)1 MapVariableResolver (org.apache.metron.stellar.dsl.MapVariableResolver)1 VariableResolver (org.apache.metron.stellar.dsl.VariableResolver)1