use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.
the class WindowLookbackTest method testSpecifyingOnlySelector.
@Test
public void testSpecifyingOnlySelector() {
String stellarStatement = "PROFILE_WINDOW('1 hour')";
Map<String, Object> variables = new HashMap<>();
StellarProcessor stellar = new StellarProcessor();
List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, new DefaultVariableResolver(k -> variables.get(k), k -> variables.containsKey(k)), resolver, context);
Assert.assertEquals(TimeUnit.HOURS.toMillis(1) / getDurationMs(), periods.size());
}
use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.
the class WindowLookbackTest method test.
public State test(String windowSelector, Date now, Optional<Map<String, Object>> config, Assertions... assertions) {
List<Range<Long>> windowIntervals = WindowProcessor.process(windowSelector).toIntervals(now.getTime());
String stellarStatement = "PROFILE_WINDOW('" + windowSelector + "', now" + (config.isPresent() ? ", config" : "") + ")";
Map<String, Object> variables = new HashMap<>();
variables.put("now", now.getTime());
if (config.isPresent()) {
variables.put("config", config.get());
}
StellarProcessor stellar = new StellarProcessor();
List<ProfilePeriod> periods = (List<ProfilePeriod>) stellar.parse(stellarStatement, new DefaultVariableResolver(k -> variables.get(k), k -> variables.containsKey(k)), resolver, context);
State state = new State(windowIntervals, periods);
for (Assertions assertion : assertions) {
Assert.assertTrue(assertion.name(), assertion.test(state));
}
return state;
}
use of org.apache.metron.stellar.common.StellarProcessor 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.stellar.common.StellarProcessor in project metron by apache.
the class HdfsWriter method init.
@Override
public void init(Map stormConfig, TopologyContext topologyContext, WriterConfiguration configurations) {
this.stormConfig = stormConfig;
this.stellarProcessor = new StellarProcessor();
this.fileNameFormat.prepare(stormConfig, topologyContext);
if (syncPolicy != null) {
// if the user has specified the sync policy, we don't want to override their wishes.
syncPolicyCreator = new ClonedSyncPolicyCreator(syncPolicy);
} else {
// if the user has not, then we want to have the sync policy depend on the batch size.
syncPolicyCreator = (source, config) -> new CountSyncPolicy(config == null ? 1 : config.getBatchSize(source));
}
}
use of org.apache.metron.stellar.common.StellarProcessor 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);
}
Aggregations