use of com.hortonworks.streamline.streams.runtime.rule.RuleRuntime in project streamline by hortonworks.
the class RuleProcessorRuntime method buildStreamToRulesRuntime.
private void buildStreamToRulesRuntime() {
Map<String, List<RuleRuntime>> map = new HashMap<>();
for (RuleRuntime rr : rulesRuntime) {
for (String streamId : rr.getRule().getStreams()) {
List<RuleRuntime> ruleRuntimes = map.get(streamId);
if (ruleRuntimes == null) {
ruleRuntimes = new ArrayList<>();
map.put(streamId, ruleRuntimes);
}
ruleRuntimes.add(rr);
}
}
streamToRuleRuntimes = ImmutableMap.copyOf(map);
ImmutableSet.Builder<RuleRuntime> builder = ImmutableSet.builder();
for (List<RuleRuntime> ruleRuntimes : streamToRuleRuntimes.values()) {
builder.addAll(ruleRuntimes);
}
allRuleRuntimes = builder.build().asList();
}
use of com.hortonworks.streamline.streams.runtime.rule.RuleRuntime in project streamline by hortonworks.
the class RuleProcessorRuntime method initializeRuleRuntimes.
private void initializeRuleRuntimes(Map<String, Object> config) {
List<Rule> rules = rulesProcessor.getRules();
if (rules != null) {
for (Rule rule : rules) {
RuleRuntime ruleRuntime;
Script script = null;
if (ScriptType.GROOVY.equals(scriptType)) {
script = createGroovyScript(rule);
} else if (ScriptType.SQL.equals(scriptType)) {
script = createSqlScript(rule);
} else {
throw new RuntimeException("Ruleruntime scriptType unsupported: " + scriptType);
}
ruleRuntime = new RuleRuntime(rule, script, createActionRuntimes(rule));
rulesRuntime.add(ruleRuntime);
ruleRuntime.initialize(config);
}
LOG.info("ruleRuntimes [{}]", rulesRuntime);
}
}
use of com.hortonworks.streamline.streams.runtime.rule.RuleRuntime in project streamline by hortonworks.
the class RuleProcessorRuntime method process.
@Override
public List<Result> process(StreamlineEvent event) throws ProcessingException {
List<Result> results = new ArrayList<>();
try {
List<RuleRuntime> ruleRuntimes = getRulesRuntime(event);
LOG.debug("Process event {}, rule runtimes {}", event, ruleRuntimes);
for (RuleRuntime rr : ruleRuntimes) {
boolean succeeded = false;
for (StreamlineEvent result : rr.evaluate(event)) {
if (result != null) {
results.addAll(rr.process(result));
succeeded = true;
}
}
if (!processAll && succeeded)
break;
}
} catch (Exception e) {
String message = String.format("Error evaluating rule processor with id: %s, error: %s", rulesProcessor.getId(), e.getMessage());
LOG.error(message, e);
throw new ProcessingException(message, e);
}
return results;
}
Aggregations