Search in sources :

Example 81 with StreamlineEvent

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

the class StormEventCorrelationInjectorTest method tupleArgsTestWithTwoParentsWhichAreRootEvents.

@Test
public void tupleArgsTestWithTwoParentsWhichAreRootEvents() throws Exception {
    int parent1TaskId = 1;
    String parent1ComponentName = "1-parentComponent";
    int parent2TaskId = 2;
    String parent2ComponentName = "2-parentComponent2";
    new Expectations() {

        {
            mockedTopologyContext.getComponentId(parent1TaskId);
            result = parent1ComponentName;
            mockedTopologyContext.getComponentId(parent2TaskId);
            result = parent2ComponentName;
            mockedTopologyContext.getComponentOutputFields(parent1ComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
            result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
            mockedTopologyContext.getComponentOutputFields(parent2ComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
            result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
        }
    };
    StreamlineEvent parentEvent1 = copyEventWithNewID();
    parentEvent1 = eventCorrelationInjector.injectCorrelationInformation(parentEvent1, Collections.emptyList(), TEST_COMPONENT_NAME);
    Tuple parentTuple1 = new TupleImpl(mockedTopologyContext, new Values(parentEvent1), parent1TaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
    StreamlineEvent parentEvent2 = copyEventWithNewID();
    parentEvent2 = eventCorrelationInjector.injectCorrelationInformation(parentEvent2, Collections.emptyList(), TEST_COMPONENT_NAME);
    Tuple parentTuple2 = new TupleImpl(mockedTopologyContext, new Values(parentEvent2), parent2TaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
    StreamlineEvent injectedEvent = sut.injectCorrelationInformation(new Values(INPUT_STREAMLINE_EVENT), Lists.newArrayList(parentTuple1, parentTuple2), TEST_COMPONENT_NAME);
    StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
    // added headers
    assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
    assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
    assertEquals(StormTopologyUtil.extractStreamlineComponentName(TEST_COMPONENT_NAME), EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
Also used : Expectations(mockit.Expectations) Fields(org.apache.storm.tuple.Fields) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 82 with StreamlineEvent

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

the class StormEventCorrelationInjectorTest method tupleArgsTestWithAParentWhichIsRootEvent.

@Test
public void tupleArgsTestWithAParentWhichIsRootEvent() throws Exception {
    StreamlineEvent parentEvent = copyEventWithNewID();
    // use same component name for parent and ancestor for easy testing
    parentEvent = eventCorrelationInjector.injectCorrelationInformation(parentEvent, Collections.emptyList(), TEST_COMPONENT_NAME);
    int parentTaskId = 1;
    String parentComponentName = "1-parentComponent";
    new Expectations() {

        {
            mockedTopologyContext.getComponentId(parentTaskId);
            result = parentComponentName;
            mockedTopologyContext.getComponentOutputFields(parentComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
            result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
        }
    };
    Tuple parentTuple = new TupleImpl(mockedTopologyContext, new Values(parentEvent), parentTaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
    StreamlineEvent injectedEvent = sut.injectCorrelationInformation(new Values(INPUT_STREAMLINE_EVENT), Collections.singletonList(parentTuple), TEST_COMPONENT_NAME);
    StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
    // added headers
    assertEquals(Collections.singleton(parentEvent.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
    assertEquals(Collections.singleton(parentEvent.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
    assertEquals(StormTopologyUtil.extractStreamlineComponentName(TEST_COMPONENT_NAME), EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
Also used : Expectations(mockit.Expectations) Fields(org.apache.storm.tuple.Fields) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 83 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, List<Object> tuple, Object messageId) {
    StreamlineEvent newEvent = injectCorrelationInformation(tuple);
    delegate.emitDirect(taskId, new Values(newEvent), messageId);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values)

Example 84 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, List<Object> tuple) {
    StreamlineEvent newEvent = injectCorrelationInformation(tuple);
    delegate.emitDirect(taskId, new Values(newEvent));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values)

Example 85 with StreamlineEvent

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

the class StreamlineJPMMLModelRunner method toStreamLineEvents.

private Map<String, List<Object>> toStreamLineEvents(Map<FieldName, ?> predScores, final Tuple input) {
    LOG.debug("Processing tuple {}", input);
    final Set<String> inserted = new HashSet<>();
    final Map<String, List<Object>> streamsToEvents = new HashMap<>();
    final StreamlineEventImpl.Builder eventBuilder = StreamlineEventImpl.builder();
    // add to StreamlineEvent the predicted scores for PMML model predicted fields
    putPmmlScoresInEvent(predScores, inserted, eventBuilder, getPredictedFields(), "Added PMML predicted (field,val)=({},{}) to StreamlineEvent");
    // add to StreamlineEvent the predicted scores for PMML model output fields
    putPmmlScoresInEvent(predScores, inserted, eventBuilder, getOutputFields(), "Added PMML output (field,val)=({},{}) to StreamlineEvent");
    final StreamlineEvent scoredEvent = eventBuilder.build();
    LOG.debug("Scored StreamlineEvent {}", scoredEvent);
    final StreamlineEvent eventInTuple = getStreamlineEventFromTuple(input);
    for (Stream stream : outputStreams) {
        // Will contain scored and non scored events that match output fields
        final StreamlineEventImpl.Builder finalEventBuilder = StreamlineEventImpl.builder();
        finalEventBuilder.putAll(scoredEvent);
        if (eventInTuple != null) {
            // Add previous tuple's StreamlineEvent to this tuple's StreamlineEvent to pass it downstream
            Map<String, Object> nonScoredFieldsEvent = eventInTuple.entrySet().stream().filter((e) -> !inserted.contains(e.getKey()) && // include only tuple fields that are in output fields, i.e. were chosen by the user in the UI
            stream.getSchema().getFields().stream().anyMatch((of) -> of.getName().equals(e.getKey()))).peek((e) -> LOG.debug("Adding entry {} to StreamlineEvent", e)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
            if (nonScoredFieldsEvent != null) {
                finalEventBuilder.putAll(nonScoredFieldsEvent);
            }
        }
        streamsToEvents.put(stream.getId(), Collections.singletonList(finalEventBuilder.dataSourceId(modelId).build()));
    }
    return streamsToEvents;
}
Also used : Evaluator(org.jpmml.evaluator.Evaluator) Logger(org.slf4j.Logger) Stream(com.hortonworks.streamline.streams.layout.component.Stream) JPmmlModelRunner(org.apache.storm.pmml.runner.jpmml.JPmmlModelRunner) LoggerFactory(org.slf4j.LoggerFactory) ModelOutputs(org.apache.storm.pmml.model.ModelOutputs) Set(java.util.Set) HashMap(java.util.HashMap) EvaluatorUtil(org.jpmml.evaluator.EvaluatorUtil) Collectors(java.util.stream.Collectors) FieldName(org.dmg.pmml.FieldName) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) FieldValue(org.jpmml.evaluator.FieldValue) List(java.util.List) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Tuple(org.apache.storm.tuple.Tuple) Map(java.util.Map) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) Collections(java.util.Collections) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) List(java.util.List) Stream(com.hortonworks.streamline.streams.layout.component.Stream) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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