Search in sources :

Example 11 with StreamlineEvent

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())));
            }
        }
    }
}
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 12 with StreamlineEvent

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));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values)

Example 13 with StreamlineEvent

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));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values)

Example 14 with StreamlineEvent

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);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent)

Example 15 with StreamlineEvent

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"));
        }
    };
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Verifications(mockit.Verifications) File(java.io.File) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

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