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));
}
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));
}
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);
}
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));
}
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;
}
Aggregations