Search in sources :

Example 36 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent 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)

Example 37 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class RulesBolt method process.

@Override
protected void process(Tuple input, StreamlineEvent event) {
    // Input tuple is expected to be an StreamlineEvent
    StreamlineEvent eventWithStream = getStreamlineEventWithStream(event, input);
    LOG.debug("++++++++ Executing tuple [{}], StreamlineEvent [{}]", input, eventWithStream);
    try {
        for (Result result : ruleProcessorRuntime.process(eventWithStream)) {
            for (StreamlineEvent e : result.events) {
                collector.emit(result.stream, input, new Values(e));
            }
        }
    } catch (ProcessingException e) {
        throw new RuntimeException(e);
    }
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) Result(com.hortonworks.streamline.streams.Result) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Example 38 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class EventCorrelatingSpoutOutputCollector method emitDirect.

@Override
public void emitDirect(int taskId, String streamId, List<Object> tuple, Object messageId) {
    StreamlineEvent newEvent = injectCorrelationInformation(tuple);
    delegate.emitDirect(taskId, streamId, new Values(newEvent), messageId);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values)

Example 39 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class EventCorrelatingSpoutOutputCollector method emitDirect.

@Override
public void emitDirect(int taskId, String streamId, List<Object> tuple) {
    StreamlineEvent newEvent = injectCorrelationInformation(tuple);
    delegate.emitDirect(taskId, streamId, new Values(newEvent));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values)

Example 40 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class FieldsGroupingAsCustomGrouping method chooseTasks.

@Override
public List<Integer> chooseTasks(int taskId, List<Object> values) {
    List<Integer> result = new ArrayList<>();
    StreamlineEvent streamlineEvent = (StreamlineEvent) values.get(0);
    List<Object> groupByObjects = new ArrayList<>(groupingFields.size());
    for (String groupingField : groupingFields) {
        groupByObjects.add(StreamlineRuntimeUtil.getFieldValue(streamlineEvent, groupingField));
    }
    int taskIndex = (Arrays.deepHashCode(groupByObjects.toArray()) & 0x7FFFFFFF) % targetTasks.size();
    result.add(targetTasks.get(taskIndex));
    return result;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)97 Test (org.junit.Test)47 HashMap (java.util.HashMap)41 Values (org.apache.storm.tuple.Values)25 ArrayList (java.util.ArrayList)19 Tuple (org.apache.storm.tuple.Tuple)14 Result (com.hortonworks.streamline.streams.Result)13 Expectations (mockit.Expectations)9 TupleImpl (org.apache.storm.tuple.TupleImpl)9 Map (java.util.Map)8 Verifications (mockit.Verifications)8 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)6 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)6 List (java.util.List)5 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)4 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)4 Fields (org.apache.storm.tuple.Fields)4 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)3 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)3