Search in sources :

Example 1 with RuleRuntime

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) RuleRuntime(com.hortonworks.streamline.streams.runtime.rule.RuleRuntime)

Example 2 with RuleRuntime

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);
    }
}
Also used : Script(com.hortonworks.streamline.streams.runtime.script.Script) GroovyScript(com.hortonworks.streamline.streams.runtime.script.GroovyScript) SqlScript(com.hortonworks.streamline.streams.runtime.rule.sql.SqlScript) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) RuleRuntime(com.hortonworks.streamline.streams.runtime.rule.RuleRuntime)

Example 3 with RuleRuntime

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;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) RuleRuntime(com.hortonworks.streamline.streams.runtime.rule.RuleRuntime) ScriptException(javax.script.ScriptException) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException) Result(com.hortonworks.streamline.streams.Result) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Aggregations

RuleRuntime (com.hortonworks.streamline.streams.runtime.rule.RuleRuntime)3 ArrayList (java.util.ArrayList)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Result (com.hortonworks.streamline.streams.Result)1 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)1 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)1 SqlScript (com.hortonworks.streamline.streams.runtime.rule.sql.SqlScript)1 GroovyScript (com.hortonworks.streamline.streams.runtime.script.GroovyScript)1 Script (com.hortonworks.streamline.streams.runtime.script.Script)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ScriptException (javax.script.ScriptException)1