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());
}
}
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"));
}
}
}
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());
}
}
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;
}
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;
}
Aggregations