use of com.hortonworks.streamline.streams.StreamlineEvent 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())));
}
}
}
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class EventCorrelatingOutputCollector 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 EventCorrelatingOutputCollector method emitDirect.
@Override
public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
StreamlineEvent newEvent = injectCorrelationInformation(anchors, tuple);
delegate.emitDirect(taskId, streamId, anchors, new Values(newEvent));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class StreamlineEventLogger method buildLogMessage.
@Override
protected String buildLogMessage(EventInfo event) {
String timestampStr = dateFormat.format(event.getTs());
List<Object> values = event.getValues();
if (!values.isEmpty()) {
final Object eventObj = values.get(0);
if (eventObj instanceof StreamlineEvent) {
final StreamlineEvent slEvent = (StreamlineEvent) eventObj;
Set<String> rootIds;
if (EventCorrelationInjector.containsRootIds(slEvent)) {
rootIds = EventCorrelationInjector.getRootIds(slEvent);
} else {
rootIds = Collections.emptySet();
}
Set<String> parentIds;
if (EventCorrelationInjector.containsParentIds(slEvent)) {
parentIds = EventCorrelationInjector.getParentIds(slEvent);
} else {
parentIds = Collections.emptySet();
}
// Date, Marker, Component Name (Streamline), Event ID, Root IDs, Parent IDs,
// Event Fields, Header KV, Aux. Fields KV
// use DELIMITER to let parser understand it more easily
String format = String.join(DELIMITER, new String[] { "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s" });
return String.format(format, timestampStr, MARKER_FOR_STREAMLINE_EVENT, StormTopologyUtil.extractStreamlineComponentName(event.getComponent()), slEvent.getId(), rootIds, parentIds, ImmutableMap.copyOf(slEvent), slEvent.getHeader().toString(), slEvent.getAuxiliaryFieldsAndValues().toString());
}
}
// Date, Marker, Component Name (Storm), task ID, Message ID, Values
// use comma-separated delimiter since this is not for machine, but for users
Object messageId = event.getMessageId();
return String.format("%s,%s,%s,%s,%s,%s", timestampStr, MARKER_FOR_OTHER_EVENT, event.getComponent(), String.valueOf(event.getTask()), (messageId == null ? "" : messageId.toString()), values);
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class StreamsShellBoltTest method testStreamsShellBoltTest.
@Test
public void testStreamsShellBoltTest() throws Exception {
setUpExpectations();
copyFiles(readFile("/splitsentence.py"), new File("/tmp/splitsentence.py"));
copyFiles(readFile("/streamline.py"), new File("/tmp/streamline.py"));
String command = "python splitsentence.py";
StreamsShellBolt streamsShellBolt = new StreamsShellBolt(command, 60000);
streamsShellBolt = streamsShellBolt.withOutputStreams(Arrays.asList("stream1"));
streamsShellBolt.prepare(new HashMap(), mockContext, mockCollector);
streamsShellBolt.execute(getNextTuple(1));
new Verifications() {
{
String streamId;
Tuple anchor;
List<List<Object>> tuples = new ArrayList<>();
mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
Assert.assertEquals("stream", streamId);
Assert.assertEquals(4, tuples.size());
Map<String, Object> fieldsAndValues = ((StreamlineEvent) tuples.get(0).get(0));
Assert.assertEquals("THIS", fieldsAndValues.get("word"));
fieldsAndValues = ((StreamlineEvent) tuples.get(1).get(0));
Assert.assertEquals("IS", fieldsAndValues.get("word"));
fieldsAndValues = ((StreamlineEvent) tuples.get(2).get(0));
Assert.assertEquals("RANDOM", fieldsAndValues.get("word"));
fieldsAndValues = ((StreamlineEvent) tuples.get(3).get(0));
Assert.assertEquals("SENTENCE1", fieldsAndValues.get("word"));
}
};
}
Aggregations