Search in sources :

Example 6 with Context

use of org.apache.metron.stellar.dsl.Context in project metron by apache.

the class KafkaFunctionsIntegrationTest method run.

/**
 * Runs a Stellar expression.
 * @param expr The expression to run.
 */
private Object run(String expr) {
    // make the global properties available to the function
    Context context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> global).build();
    FunctionResolver functionResolver = new SimpleFunctionResolver().withClass(KafkaFunctions.KafkaGet.class).withClass(KafkaFunctions.KafkaPut.class).withClass(KafkaFunctions.KafkaProps.class).withClass(KafkaFunctions.KafkaTail.class);
    StellarProcessor processor = new StellarProcessor();
    return processor.parse(expr, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), functionResolver, context);
}
Also used : Context(org.apache.metron.stellar.dsl.Context) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) ComponentRunner(org.apache.metron.integration.ComponentRunner) FunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) BeforeClass(org.junit.BeforeClass) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) KafkaComponent(org.apache.metron.integration.components.KafkaComponent) ArrayList(java.util.ArrayList) List(java.util.List) BaseIntegrationTest(org.apache.metron.integration.BaseIntegrationTest) After(org.junit.After) Map(java.util.Map) ZKServerComponent(org.apache.metron.integration.components.ZKServerComponent) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) FunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)

Example 7 with Context

use of org.apache.metron.stellar.dsl.Context in project metron by apache.

the class GeoEnrichmentFunctionsTest method run.

public Object run(String rule, Map<String, Object> variables) throws Exception {
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    return processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) BeforeClass(org.junit.BeforeClass) ImmutableMap(com.google.common.collect.ImmutableMap) JSONParser(org.json.simple.parser.JSONParser) UnitTestHelper(org.apache.metron.test.utils.UnitTestHelper) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) File(java.io.File) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) Multiline(org.adrianwalker.multilinestring.Multiline) Map(java.util.Map) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) GeoLiteDatabase(org.apache.metron.enrichment.adapters.geo.GeoLiteDatabase) Assert(org.junit.Assert) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 8 with Context

use of org.apache.metron.stellar.dsl.Context in project metron by apache.

the class SimpleHBaseEnrichmentFunctionsTest method run.

public Object run(String rule, Map<String, Object> variables) throws Exception {
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    return processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) EnrichmentHelper(org.apache.metron.enrichment.converter.EnrichmentHelper) ImmutableMap(com.google.common.collect.ImmutableMap) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) MockHBaseTableProvider(org.apache.metron.hbase.mock.MockHBaseTableProvider) ArrayList(java.util.ArrayList) MockHTable(org.apache.metron.hbase.mock.MockHTable) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) List(java.util.List) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Map(java.util.Map) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) Assert(org.junit.Assert) ParseException(org.apache.metron.stellar.dsl.ParseException) Context(org.apache.metron.stellar.dsl.Context) Before(org.junit.Before) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 9 with Context

use of org.apache.metron.stellar.dsl.Context in project metron by apache.

the class MathFunctionsTest method run.

public static Object run(String rule, Map<String, Object> variables) {
    Context context = Context.EMPTY_CONTEXT();
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    return processor.parse(rule, new DefaultVariableResolver(v -> variables.get(v), v -> variables.containsKey(v)), StellarFunctions.FUNCTION_RESOLVER(), context);
}
Also used : Context(org.apache.metron.stellar.dsl.Context) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) StellarProcessorUtils.runPredicate(org.apache.metron.stellar.common.utils.StellarProcessorUtils.runPredicate) Map(java.util.Map) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) Test(org.junit.Test) HashMap(java.util.HashMap) Assert(org.junit.Assert) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) ParseException(org.apache.metron.stellar.dsl.ParseException) Context(org.apache.metron.stellar.dsl.Context) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Example 10 with Context

use of org.apache.metron.stellar.dsl.Context in project metron by apache.

the class ShellFunctionsTest method testMap2Table.

@Test
public void testMap2Table() {
    Map<String, Object> variables = ImmutableMap.of("map_field", ImmutableMap.of("field1", "val1", "field2", "val2"));
    Context context = Context.EMPTY_CONTEXT();
    Object out = run("SHELL_MAP2TABLE(map_field)", variables, context);
    Assert.assertEquals(expectedMap2Table, out);
}
Also used : Context(org.apache.metron.stellar.dsl.Context) Test(org.junit.Test)

Aggregations

Context (org.apache.metron.stellar.dsl.Context)27 Test (org.junit.Test)15 HashMap (java.util.HashMap)14 Map (java.util.Map)12 StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)9 List (java.util.List)8 ArrayList (java.util.ArrayList)6 DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 StellarFunctions (org.apache.metron.stellar.dsl.StellarFunctions)5 Assert (org.junit.Assert)5 ImmutableList (com.google.common.collect.ImmutableList)3 MapVariableResolver (org.apache.metron.stellar.dsl.MapVariableResolver)3 VariableResolver (org.apache.metron.stellar.dsl.VariableResolver)3 Before (org.junit.Before)3 Collectors (java.util.stream.Collectors)2 StellarPredicateProcessor (org.apache.metron.stellar.common.StellarPredicateProcessor)2 ConversionUtils (org.apache.metron.stellar.common.utils.ConversionUtils)2 ParseException (org.apache.metron.stellar.dsl.ParseException)2 FunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver)2