Search in sources :

Example 1 with StreamlineEventImpl

use of com.hortonworks.streamline.streams.common.StreamlineEventImpl 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 StreamlineEventImpl

use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.

the class WindowedQueryBolt method doProjectionStreamLine.

// Overrides projection behavior to customize for handling of "streamline-event." prefix
protected ArrayList<Object> doProjectionStreamLine(ArrayList<Tuple> tuplesRow, FieldSelector[] projectionKeys) {
    String[] finalOutputFieldNames = new String[rawCommaSeparatedOutputKeys.length];
    for (int i = 0; i < rawCommaSeparatedOutputKeys.length; ++i) {
        finalOutputFieldNames[i] = getAliasOrKeyName(rawCommaSeparatedOutputKeys[i]);
    }
    StreamlineEventImpl.Builder eventBuilder = StreamlineEventImpl.builder();
    // Todo: note to self: may be able to optimize this ... perhaps inner loop can be outside to avoid rescanning tuples
    for (int i = 0; i < projectionKeys.length; i++) {
        for (Tuple cell : tuplesRow) {
            Object field = lookupField(projectionKeys[i], cell);
            if (field != null) {
                eventBuilder.put(finalOutputFieldNames[i], field);
                break;
            }
        }
    }
    ArrayList<Object> resultRow = new ArrayList<>();
    StreamlineEventImpl slEvent = eventBuilder.dataSourceId("multiple sources").build();
    resultRow.add(slEvent);
    return resultRow;
}
Also used : ArrayList(java.util.ArrayList) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) Tuple(org.apache.storm.tuple.Tuple)

Example 3 with StreamlineEventImpl

use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.

the class JsonFileReader method next.

// returns null when EOF is reached
public List<Object> next() throws IOException, ParseException {
    List<Object> lineTuple = super.next();
    if (lineTuple == null)
        return null;
    String jsonLine = (String) lineTuple.get(0);
    if (jsonLine.trim().isEmpty())
        return next();
    try {
        // 1- convert Json to Map<>
        HashMap<String, Object> jsonMap = new ObjectMapper().readValue(jsonLine, HashMap.class);
        // 2- make StreamlineEvent from map
        StreamlineEventImpl slEvent = StreamlineEventImpl.builder().putAll(jsonMap).dataSourceId("HdfsSpout").build();
        // 3- create tuple from StreamlineEvent
        return Collections.singletonList(slEvent);
    } catch (JsonProcessingException e) {
        throw new ParseException("Json parsing error at location : " + getFileOffset().toString(), e);
    }
}
Also used : ParseException(org.apache.storm.hdfs.spout.ParseException) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with StreamlineEventImpl

use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.

the class TestRunSourceSpout method nextTuple.

@Override
public void nextTuple() {
    int emitCount = 0;
    boolean allOutputStreamsCompleted = true;
    // loop output stream and emit at most one record per output stream
    for (Map.Entry<String, TestRecordsInformation> entry : testRecordsInformationPerOutputStream.entrySet()) {
        String outputStream = entry.getKey();
        TestRecordsInformation info = entry.getValue();
        if (info.isCompleted()) {
            continue;
        }
        allOutputStreamsCompleted = false;
        Optional<Map<String, Object>> recordOptional = info.nextRecord();
        if (recordOptional.isPresent()) {
            Map<String, Object> record = recordOptional.get();
            StreamlineEventImpl streamlineEvent = StreamlineEventImpl.builder().fieldsAndValues(record).dataSourceId(testRunSource.getId()).build();
            LOG.debug("Emitting event {} to stream {}", streamlineEvent, outputStream);
            collector.emit(outputStream, new Values(streamlineEvent), streamlineEvent.getId());
            emitCount++;
        }
    }
    if (allOutputStreamsCompleted) {
        LOG.info("All iterations are completed, sleeping...");
        Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
    } else if (emitCount == 0) {
        LOG.info("All output streams are finished last iteration and now in sleep phase, sleeping...");
        Uninterruptibles.sleepUninterruptibly(testRunSource.getSleepMsPerIteration(), TimeUnit.MILLISECONDS);
    }
}
Also used : Values(org.apache.storm.tuple.Values) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with StreamlineEventImpl

use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.

the class SLRealtimeJoinBolt method doProjection.

/**
 *  NOTE: Streamline specific convenience method. Creates output tuple as a StreamlineEvent
 * @param tuple1  can be null
 * @param tuple2  can be null
 * @return
 */
@Override
protected List<Object> doProjection(Tuple tuple1, Tuple tuple2) {
    StreamlineEventImpl.Builder eventBuilder = StreamlineEventImpl.builder();
    for (int i = 0; i < outputFields.length; i++) {
        FieldSelector outField = outputFields[i];
        Object field = outField.findField(tuple1);
        if (field == null)
            field = outField.findField(tuple2);
        String outputKeyName = dropStreamLineEventPrefix(outField.outputName);
        // adds null if field is not found in both tuples
        eventBuilder.put(outputKeyName, field);
    }
    StreamlineEventImpl slEvent = eventBuilder.dataSourceId("multiple sources").build();
    return Collections.singletonList(slEvent);
}
Also used : StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl)

Aggregations

StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Values (org.apache.storm.tuple.Values)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Result (com.hortonworks.streamline.streams.Result)1 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)1 ArrayList (java.util.ArrayList)1 ParseException (org.apache.storm.hdfs.spout.ParseException)1 Tuple (org.apache.storm.tuple.Tuple)1