use of org.apache.metron.stellar.dsl.Context 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;
}
use of org.apache.metron.stellar.dsl.Context in project metron by apache.
the class StellarFilter method configure.
@Override
public void configure(Map<String, Object> config) {
Object o = config.get(QUERY_STRING_CONF);
if (o instanceof String) {
query = o.toString();
}
Context stellarContext = (Context) config.get("stellarContext");
if (stellarContext == null) {
stellarContext = Context.EMPTY_CONTEXT();
}
processor.validate(query, true, stellarContext);
}
use of org.apache.metron.stellar.dsl.Context in project metron by apache.
the class StellarClasspathFunctionResolver method create.
public static ClasspathFunctionResolver create(Properties config) {
ClasspathFunctionResolver resolver = new ClasspathFunctionResolver();
Context context = new Context.Builder().with(Context.Capabilities.STELLAR_CONFIG, () -> config).build();
resolver.initialize(context);
return resolver;
}
use of org.apache.metron.stellar.dsl.Context in project metron by apache.
the class BasicStellarTest method testContextActivityTypeReset.
@Test
public void testContextActivityTypeReset() {
String query = "someVar";
Context context = Context.EMPTY_CONTEXT();
validate(query, context);
Assert.assertNull(context.getActivityType());
run(query, ImmutableMap.of("someVar", "someValue"), context);
Assert.assertNull(context.getActivityType());
}
use of org.apache.metron.stellar.dsl.Context in project metron by apache.
the class ShellFunctionsTest method testListVarsWithVars.
@Test
public void testListVarsWithVars() {
Map<String, VariableResult> variables = ImmutableMap.of("foo", VariableResult.withExpression(2.0, "1 + 1"));
Context context = new Context.Builder().with(Context.Capabilities.SHELL_VARIABLES, () -> variables).build();
Object out = run("SHELL_LIST_VARS()", new HashMap<>(), context);
Assert.assertEquals(expectedListWithFoo, out);
}
Aggregations