Search in sources :

Example 6 with Result

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

the class NormalizationProcessorRuntime method process.

/*
     * todo: It should receive input Stream also and generate output Stream along with StreamlineEvent. This support should
     * come from processor framework, will add later.
     */
@Override
public List<Result> process(StreamlineEvent event) throws ProcessingException {
    String currentStreamId = event.getSourceStream() != null ? event.getSourceStream() : NormalizationProcessor.DEFAULT_STREAM_ID;
    NormalizationRuntime normalizationRuntime = schemasWithNormalizationRuntime.get(currentStreamId);
    LOG.debug("Normalization runtime for this stream [{}]", normalizationRuntime);
    StreamlineEvent outputEvent = event;
    if (normalizationRuntime != null) {
        try {
            outputEvent = normalizationRuntime.execute(event);
            schemaValidator.validate(outputEvent);
        } catch (NormalizationException e) {
            throw new RuntimeException(e);
        }
    } else {
        LOG.debug("No normalization defined for stream: [{}]", currentStreamId);
    }
    // which does not have normalization configuration.
    return Collections.singletonList(new Result(NormalizationProcessor.DEFAULT_STREAM_ID, Collections.singletonList(outputEvent)));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Result(com.hortonworks.streamline.streams.Result)

Example 7 with Result

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

the class RuleRuntime method process.

/**
 * Executes a {@link Rule}'s Action
 *
 * @param event runtime input to this rule
 */
@Override
public List<Result> process(StreamlineEvent event) throws ProcessingException {
    LOG.debug("process invoked with StreamlineEvent {}", event);
    List<Result> allResults = new ArrayList<>();
    try {
        for (ActionRuntime action : actions) {
            List<Result> actionResults = action.execute(event);
            LOG.debug("Applied action {}, Result {}", action, actionResults);
            if (actionResults != null) {
                allResults.addAll(actionResults);
            }
        }
    } catch (Exception e) {
        String message = "Error evaluating rule with id:" + rule.getId();
        LOG.error(message);
        throw new ProcessingException(message, e);
    }
    LOG.debug("Returning allResults {}", allResults);
    return allResults;
}
Also used : ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException) ConditionEvaluationException(com.hortonworks.streamline.streams.layout.component.rule.exception.ConditionEvaluationException) ScriptException(javax.script.ScriptException) Result(com.hortonworks.streamline.streams.Result) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Example 8 with Result

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

the class JoinActionRuntime method joinEvents.

/**
 * Join all subevents and generate an event for the given output stream.
 *
 * @param eventGroup
 */
protected List<Result> joinEvents(EventGroup eventGroup) {
    StreamlineEvent joinedEvent = joiner.join(eventGroup);
    List<Result> results = new ArrayList<>();
    for (String stream : getOutputStreams()) {
        results.add(new Result(stream, Collections.singletonList(getStreamlineEvent(joinedEvent, stream))));
    }
    groupedEvents.invalidate(eventGroup.getGroupId());
    return results;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Result(com.hortonworks.streamline.streams.Result)

Example 9 with Result

use of com.hortonworks.streamline.streams.Result 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 10 with Result

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

Aggregations

Result (com.hortonworks.streamline.streams.Result)15 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)13 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)5 ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)4 Map (java.util.Map)4 Test (org.junit.Test)4 ActionRuntime (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime)3 Values (org.apache.storm.tuple.Values)3 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)2 StageAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction)2 TransformAction (com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)2 EnrichmentTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform)2 InmemoryTransformDataProvider (com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider)2 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)2 ProjectionTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform)2 List (java.util.List)2 ScriptException (javax.script.ScriptException)2 Utils (com.hortonworks.streamline.common.util.Utils)1