public DefaultStellarShellExecutor( Properties properties, Optional<String> zookeeperUrl) throws Exception { this(StellarFunctions.FUNCTION_RESOLVER(), properties, zookeeperUrl); }
private void transform(Map<String, String> transforms, Map<String, Object> variableMap, MapVariableResolver variableResolver) { for (Map.Entry<String, String> entry : transforms.entrySet()) { Object o = transformProcessor.parse(entry.getValue(), variableResolver, StellarFunctions.FUNCTION_RESOLVER(), stellarContext); if (o == null) { variableMap.remove(entry.getKey()); } else { variableMap.put(entry.getKey(), o); } } }
private Boolean filter(String filterPredicate, MapVariableResolver variableResolver) { if(StringUtils.isEmpty(filterPredicate)) { return true; } return filterProcessor.parse(filterPredicate, variableResolver, StellarFunctions.FUNCTION_RESOLVER(), stellarContext); }
public DefaultStellarStatefulExecutor() { this(StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT()); }
public String getHdfsPathExtension(String sourceType, String stellarFunction, JSONObject message) { // If no function is provided, just use the sourceType directly if(stellarFunction == null || stellarFunction.trim().isEmpty()) { return sourceType; } //processor is a StellarProcessor(); VariableResolver resolver = new MapVariableResolver(message); Object objResult = stellarProcessor.parse(stellarFunction, resolver, StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT()); if(objResult != null && !(objResult instanceof String)) { throw new IllegalArgumentException("Stellar Function <" + stellarFunction + "> did not return a String value. Returned: " + objResult); } return objResult == null ? "" : (String)objResult; }
@Override public Object initializeState(Map<String, Object> config) { if(STATE_INIT.existsIn(config)) { MapVariableResolver resolver = new MapVariableResolver(globalConfig); return transformProcessor.parse( config.get(STATE_INIT.toString()).toString() , resolver , StellarFunctions.FUNCTION_RESOLVER() , stellarContext ); } return null; }
@Override public Object mergeStates(List<? extends Object> states) { return transformProcessor.parse( stateMerge , new MapVariableResolver(new HashMap<String, Object>() {{ put(STATES_KEY, states); }}, globalConfig) , StellarFunctions.FUNCTION_RESOLVER() , stellarContext ); }
@Override public List<StellarFunctionDescription> getStellarFunctions() { List<StellarFunctionDescription> stellarFunctionDescriptions = new ArrayList<>(); Iterable<StellarFunctionInfo> stellarFunctionsInfo = StellarFunctions.FUNCTION_RESOLVER().getFunctionInfo(); stellarFunctionsInfo.forEach(stellarFunctionInfo -> { stellarFunctionDescriptions.add(new StellarFunctionDescription( stellarFunctionInfo.getName(), stellarFunctionInfo.getDescription(), stellarFunctionInfo.getParams(), stellarFunctionInfo.getReturns())); }); return stellarFunctionDescriptions; }
public static boolean runPredicate(String rule, VariableResolver resolver, Context context) { StellarPredicateProcessor processor = new StellarPredicateProcessor(); Assert.assertTrue(rule + " not valid.", processor.validate(rule)); return processor.parse(rule, resolver, StellarFunctions.FUNCTION_RESOLVER(), context); }
@Override public boolean test(PacketInfo input) { Map<String, Object> fields = packetToFields(input); VariableResolver resolver = new MapVariableResolver(fields); return predicateProcessor.parse(queryString, resolver, StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT()); }
@Override public boolean isValid( Map<String, Object> input , Map<String, Object> validationConfig , Map<String, Object> globalConfig , Context context ) { String condition = Config.CONDITION.get(validationConfig, String.class); if(condition == null) { return true; } else { StellarPredicateProcessor processor = new StellarPredicateProcessor(); return processor.parse(condition, new MapVariableResolver(input, validationConfig, globalConfig), StellarFunctions.FUNCTION_RESOLVER(), context); } }
public Object run(String rule, Map<String, Object> variables) throws Exception { StellarProcessor processor = new StellarProcessor(); return processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context); } }
/** * Execute each expression. * @param expression The expression to execute. */ private Object execute(String expression, Context context) { Object result = processor.parse( expression, new MapVariableResolver(fields), StellarFunctions.FUNCTION_RESOLVER(), context); return result; } }
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); }
private static ThreatTriageProcessor getProcessor(String config) throws IOException { SensorEnrichmentConfig c = JSONUtils.INSTANCE.load(config, SensorEnrichmentConfig.class); return new ThreatTriageProcessor(c, StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT()); } }
public Object run(String rule, Map<String, Object> variables) { 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); }
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); }
/** * Runs a Stellar expression. * @param expr The expression to run. */ private Object run(String expr) { StellarProcessor processor = new StellarProcessor(); assertTrue(processor.validate(expr)); return processor.parse(expr, new DefaultVariableResolver( x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT()); }
protected void initializeStellar() { this.stellarContext = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) .build(); StellarFunctions.initialize(stellarContext); this.functionResolver = StellarFunctions.FUNCTION_RESOLVER(); }
public Object run(String rule, Map<String, Object> variables) { StellarProcessor processor = new StellarProcessor(); Assert.assertTrue(rule + " not valid.", processor.validate(rule, context)); return processor.parse(rule, new DefaultVariableResolver(variables::get, variables::containsKey), StellarFunctions.FUNCTION_RESOLVER(), context); }