Search in sources :

Example 21 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class StellarProcessorUtils method validate.

public static void validate(String rule, Context context) {
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor)

Example 22 with StellarProcessor

use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.

the class StellarProcessorUtils method run.

/**
 * This utility class is intended for use while unit testing Stellar operators.
 * It is included in the "main" code so third-party operators will not need
 * a test dependency on Stellar's test-jar.
 *
 * This class ensures the basic contract of a stellar expression is adhered to:
 * 1. Validate works on the expression
 * 2. The output can be serialized and deserialized properly
 *
 * @param rule
 * @param variables
 * @param context
 * @return ret
 */
public static Object run(String rule, Map<String, Object> variables, Context context) {
    StellarProcessor processor = new StellarProcessor();
    Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
    Object ret = processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
    byte[] raw = SerDeUtils.toBytes(ret);
    Object actual = SerDeUtils.fromBytes(raw, Object.class);
    Assert.assertEquals(ret, actual);
    return ret;
}
Also used : StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) VariableResolver(org.apache.metron.stellar.dsl.VariableResolver) Spliterators(java.util.Spliterators) StellarProcessor(org.apache.metron.stellar.common.StellarProcessor) IntConsumer(java.util.function.IntConsumer) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) AbstractMap(java.util.AbstractMap) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) StellarFunctions(org.apache.metron.stellar.dsl.StellarFunctions) MapVariableResolver(org.apache.metron.stellar.dsl.MapVariableResolver) StreamSupport(java.util.stream.StreamSupport) Assert(org.junit.Assert) StellarPredicateProcessor(org.apache.metron.stellar.common.StellarPredicateProcessor) Context(org.apache.metron.stellar.dsl.Context) DefaultVariableResolver(org.apache.metron.stellar.dsl.DefaultVariableResolver)

Aggregations

StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)22 Context (org.apache.metron.stellar.dsl.Context)11 DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)11 Map (java.util.Map)10 StellarFunctions (org.apache.metron.stellar.dsl.StellarFunctions)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Assert (org.junit.Assert)7 ImmutableMap (com.google.common.collect.ImmutableMap)5 List (java.util.List)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4 MapVariableResolver (org.apache.metron.stellar.dsl.MapVariableResolver)4 ParseException (org.apache.metron.stellar.dsl.ParseException)4 Before (org.junit.Before)4 StellarPredicateProcessor (org.apache.metron.stellar.common.StellarPredicateProcessor)3 VariableResolver (org.apache.metron.stellar.dsl.VariableResolver)3 JSONObject (org.json.simple.JSONObject)3 Collectors (java.util.stream.Collectors)2 GaussianRandomGenerator (org.apache.commons.math3.random.GaussianRandomGenerator)2