Search in sources :

Example 1 with Result

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

the class NormalizationBolt method process.

public void process(Tuple inputTuple, StreamlineEvent event) throws Exception {
    LOG.debug("Normalizing received StreamlineEvent: [{}] with tuple: [{}]", event, inputTuple);
    // todo this bolt will be replaced with custom baseprocessor bolt.
    StreamlineEventImpl eventWithStream = StreamlineEventImpl.builder().from(event).sourceStream(inputTuple.getSourceStreamId()).build();
    List<Result> outputEvents = normalizationProcessorRuntime.process(eventWithStream);
    LOG.debug("Emitting events to collector: [{}]", outputEvents);
    for (Result outputEvent : outputEvents) {
        for (StreamlineEvent e : outputEvent.events) {
            collector.emit(outputEvent.stream, inputTuple, new Values(e));
        }
    }
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) Result(com.hortonworks.streamline.streams.Result)

Example 2 with Result

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

the class WindowRulesBolt method processAndEmit.

private void processAndEmit(StreamlineEvent event, Map<String, Tuple> curGroup) throws ProcessingException {
    List<Result> results = ruleProcessorRuntime.process(eventWithWindowId(event));
    for (Result result : results) {
        for (StreamlineEvent e : result.events) {
            // anchor parent events if such information is available
            if (EventCorrelationInjector.containsParentIds(e)) {
                Set<String> parentIds = EventCorrelationInjector.getParentIds(e);
                List<Tuple> parents = parentIds.stream().map(pid -> {
                    if (!curGroup.containsKey(pid)) {
                        throw new IllegalStateException("parents should be in grouped tuples");
                    }
                    return curGroup.get(pid);
                }).collect(Collectors.toList());
                collector.emit(result.stream, parents, new Values(updateHeaders(e, parents)));
            } else {
                // put all events in current group if there's no information
                collector.emit(result.stream, curGroup.values(), new Values(updateHeaders(e, curGroup.values())));
            }
        }
    }
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) IdPreservedStreamlineEvent(com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent) Utils(com.hortonworks.streamline.common.util.Utils) TopologyContext(org.apache.storm.task.TopologyContext) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HEADER_FIELD_EVENT_IDS(com.hortonworks.streamline.streams.runtime.transform.AddHeaderTransformRuntime.HEADER_FIELD_EVENT_IDS) AbstractWindowedProcessorBolt(com.hortonworks.streamline.streams.runtime.storm.bolt.AbstractWindowedProcessorBolt) Result(com.hortonworks.streamline.streams.Result) RuleProcessorRuntime(com.hortonworks.streamline.streams.runtime.processor.RuleProcessorRuntime) Values(org.apache.storm.tuple.Values) GROUP_BY_TRIGGER_EVENT(com.hortonworks.streamline.streams.common.StreamlineEventImpl.GROUP_BY_TRIGGER_EVENT) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Tuple(org.apache.storm.tuple.Tuple) TupleWindow(org.apache.storm.windowing.TupleWindow) OutputCollector(org.apache.storm.task.OutputCollector) Map(java.util.Map) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) Logger(org.slf4j.Logger) Stream(com.hortonworks.streamline.streams.layout.component.Stream) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException) Collection(java.util.Collection) StreamlineWindowedBolt(com.hortonworks.streamline.streams.runtime.storm.bolt.StreamlineWindowedBolt) Set(java.util.Set) Fields(org.apache.storm.tuple.Fields) Collectors(java.util.stream.Collectors) HEADER_FIELD_DATASOURCE_IDS(com.hortonworks.streamline.streams.runtime.transform.AddHeaderTransformRuntime.HEADER_FIELD_DATASOURCE_IDS) List(java.util.List) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) Collections(java.util.Collections) EventCorrelationInjector(com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector) IdPreservedStreamlineEvent(com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) Result(com.hortonworks.streamline.streams.Result)

Example 3 with Result

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

the class TransformRuntimePipelineActionTest method testMergeSubstituteProject.

@Test
public void testMergeSubstituteProject() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "one");
    fieldsAndValues.put("2", "${1} plus ${1}");
    Map<String, Object> defaults = new HashMap<>();
    defaults.put("2", "TWO");
    defaults.put("3", "THREE");
    defaults.put("4", "${2} plus ${2}");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    MergeTransform merge = new MergeTransform(defaults);
    SubstituteTransform substitute = new SubstituteTransform();
    ProjectionTransform projection = new ProjectionTransform("test-projection", defaults.keySet());
    TransformAction transformAction = new TransformAction(ImmutableList.of(merge, substitute, projection));
    transformAction.setOutputStreams(ImmutableSet.of("streamid"));
    ActionRuntime actionRuntime = new TransformActionRuntime(transformAction);
    List<StreamlineEvent> resultEvents = new ArrayList<>();
    for (Result result : actionRuntime.execute(event)) {
        resultEvents.addAll(result.events);
    }
    assertEquals(1, resultEvents.size());
    assertEquals(3, resultEvents.get(0).size());
    assertEquals("THREE", resultEvents.get(0).get("3"));
    assertEquals("one plus one", resultEvents.get(0).get("2"));
    assertEquals("one plus one plus one plus one", resultEvents.get(0).get("4"));
}
Also used : ProjectionTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform) MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) SubstituteTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) Result(com.hortonworks.streamline.streams.Result) Test(org.junit.Test)

Example 4 with Result

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

the class TransformRuntimePipelineActionTest method testMergeProject.

@Test
public void testMergeProject() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "one");
    fieldsAndValues.put("2", "two");
    Map<String, String> defaults = new HashMap<>();
    defaults.put("2", "TWO");
    defaults.put("3", "THREE");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    MergeTransform merge = new MergeTransform(defaults);
    ProjectionTransform projection = new ProjectionTransform("test-projection", defaults.keySet());
    TransformAction transformAction = new TransformAction(ImmutableList.of(merge, projection));
    transformAction.setOutputStreams(ImmutableSet.of("streamid"));
    ActionRuntime actionRuntime = new TransformActionRuntime(transformAction);
    List<StreamlineEvent> resultEvents = new ArrayList<>();
    for (Result result : actionRuntime.execute(event)) {
        resultEvents.addAll(result.events);
    }
    assertEquals(1, resultEvents.size());
    assertEquals(2, resultEvents.get(0).size());
    assertEquals("THREE", resultEvents.get(0).get("3"));
    assertEquals("two", resultEvents.get(0).get("2"));
}
Also used : ProjectionTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform) MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) Result(com.hortonworks.streamline.streams.Result) Test(org.junit.Test)

Example 5 with Result

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

the class SplitJoinTest method runSplitJoin.

protected void runSplitJoin(SplitAction splitAction, JoinAction joinAction, Map<String, Object> config) {
    SplitActionRuntime splitActionRuntime = new SplitActionRuntime(splitAction);
    splitActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, splitAction));
    splitActionRuntime.initialize(config);
    StreamlineEvent event = createRootEvent();
    final List<Result> results = splitActionRuntime.execute(event);
    JoinActionRuntime joinActionRuntime = new JoinActionRuntime(joinAction);
    joinActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, joinAction));
    joinActionRuntime.initialize(config);
    List<Result> effectiveResult = null;
    for (Result result : results) {
        for (StreamlineEvent e : result.events) {
            List<Result> processedResult = joinActionRuntime.execute(e);
            if (processedResult != null) {
                effectiveResult = processedResult;
            }
        }
    }
    Assert.assertNotNull(effectiveResult);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) Result(com.hortonworks.streamline.streams.Result)

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