@Override public StreamlineEvent entity(Result result) { String id = Bytes.toString(result.getRow()); Map<String, Object> fieldsAndValues = new HashMap<>(); for(Map.Entry<byte[], byte[]> entry: result.getFamilyMap(CF_FIELDS).entrySet()) { fieldsAndValues.put(Bytes.toString(entry.getKey()), Bytes.toString(entry.getValue())); } String dataSourceId = Bytes.toString(result.getFamilyMap(CF_DATASOURCE_ID).firstEntry().getKey()); StreamlineEventImpl event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId(dataSourceId).build(); return new IdPreservedStreamlineEvent(event, id); }
public StreamlineEventImpl build() { Map<String, Object> fieldsAndValues; if (kvBuilder != null) { fieldsAndValues = kvBuilder.build(); } else if (kv != null) { fieldsAndValues = kv; } else { fieldsAndValues = Collections.emptyMap(); } Map<String, Object> header = this.header != null ? ImmutableMap.copyOf(this.header) : ImmutableMap.of(); Map<String, Object> aux = this.auxiliaryFieldsAndValues != null ? ImmutableMap.copyOf(this.auxiliaryFieldsAndValues) : ImmutableMap.of(); return new StreamlineEventImpl( fieldsAndValues, this.dataSourceId, header, this.sourceStream, aux); }
@Override public StreamlineEvent addFieldAndValue(String key, Object value) { return addFieldsAndValues(Collections.singletonMap(key, value)); }
@Override public StreamlineEvent addAuxiliaryFieldAndValue(String field, Object value) { Map<String, Object> aux = new HashMap<>(); aux.putAll(this.getAuxiliaryFieldsAndValues()); aux.put(field, value); return StreamlineEventImpl.builder().from(this) .auxiliaryFieldsAndValues(aux) .build(); }
/** * Returns a new Streamline event with the given headers added to the existing headers. * All the other fields are copied from this event. * @param headers the map of fieldsAndValues to add or overwrite * @return the new StreamlineEvent */ @Override public StreamlineEvent addHeaders(Map<String, Object> headers) { Map<String, Object> headerMap = new HashMap<>(); headerMap.putAll(this.getHeader()); headerMap.putAll(headers); return StreamlineEventImpl.builder().from(this) .header(headerMap) .build(); }
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++;
/** * Creates an StreamlineEvent with given keyValues, dataSourceId, id, header and sourceStream. */ private StreamlineEventImpl(Map<String, Object> keyValues, String dataSourceId, Map<String, Object> header, String sourceStream, Map<String, Object> auxiliaryFieldsAndValues) { if (keyValues instanceof StreamlineEventImpl) { this.delegate = ImmutableMap.copyOf(((StreamlineEventImpl) keyValues).delegate()); } else { this.delegate = ImmutableMap.copyOf(keyValues); } this.dataSourceId = dataSourceId; this.sourceStream = sourceStream; this.header = header != null ? ImmutableMap.copyOf(header) : ImmutableMap.of(); this.auxiliaryFieldsAndValues = auxiliaryFieldsAndValues != null ? ImmutableMap.copyOf(auxiliaryFieldsAndValues) : ImmutableMap.of(); }
@Override public void nextTuple() { try (BufferedReader br = new BufferedReader(Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8))) { String line; while ((line = br.readLine()) != null) { String[] result = line.split(delimiter); if (result.length != 2) { LOG.error("Format of input file not as expected. Expecting {} separated first name and last name", delimiter); } else { List<Object> values = new ArrayList<>(); values.add(StreamlineEventImpl.builder().sourceStream(outputStream).put(FIRST_NAME, result[0].trim()).put(LAST_NAME, result[1].trim()) .build()); spoutOutputCollector.emit(outputStream, values, UUID.randomUUID()); } } } catch (IOException e) { LOG.error("Got exception while reading file at {}", path); throw new RuntimeException(e); } }
public static StreamlineEvent fromString(String s) { ObjectMapper mapper = new ObjectMapper(); try { Map<String, Object> event = mapper.readValue( s.substring(s.indexOf(TO_STRING_PREFIX) + TO_STRING_PREFIX.length()), new TypeReference<Map<String, Object>>() {}); return StreamlineEventImpl.builder() .header((Map<String, Object>) event.get("header")) .sourceStream((String) event.get("sourceStream")) .auxiliaryFieldsAndValues((Map<String, Object>) event.get("auxiliaryFieldsAndValues")) .dataSourceId((String) event.get("dataSourceId")) .putAll((Map<String, Object>) event.get("fieldsAndValues")) .build(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Returns a new Streamline event with the given fieldsAndValues added to the existing fieldsAndValues * * @param fieldsAndValues the map of fieldsAndValues to add * @return the new StreamlineEvent */ @Override public StreamlineEvent addFieldsAndValues(Map<String, Object> fieldsAndValues) { Objects.requireNonNull(fieldsAndValues, "keyValues is null"); return builder().from(this).putAll(fieldsAndValues).build(); }
@Override public List<StreamlineEvent> execute(StreamlineEvent input) { Map<String, Object> header = new HashMap<>(input.getHeader()); if(addHeaderTransform.getFixedHeader() != null) { header.putAll(addHeaderTransform.getFixedHeader()); } header.put(HEADER_FIELD_DATASOURCE_IDS, Collections.singletonList(input.getDataSourceId())); header.put(HEADER_FIELD_EVENT_IDS, Collections.singletonList(input.getId())); header.put(HEADER_FIELD_TIMESTAMP, System.currentTimeMillis()); return Collections.singletonList( StreamlineEventImpl.builder().from(input).header(header).build()); }
private StreamlineEvent createPartitionEvent(StreamlineEvent event, String groupId, int partNo, String stream, int totalParts) { Map<String, Object> headers = new HashMap<>(); if (event.getHeader() != null) { headers.putAll(event.getHeader()); } headers.put(SplitActionRuntime.SPLIT_GROUP_ID, groupId); headers.put(SplitActionRuntime.SPLIT_PARTITION_ID, partNo); headers.put(SplitActionRuntime.SPLIT_TOTAL_PARTITIONS_ID, totalParts); return StreamlineEventImpl.builder().from(event).header(headers).sourceStream(stream).build(); }
@Override public List<StreamlineEvent> execute(StreamlineEvent input) { StreamlineEventImpl.Builder builder = StreamlineEventImpl.builder(); builder.putAll(input); for (Map.Entry<String, ?> entry : mergeTransform.getDefaults().entrySet()) { if (!input.containsKey(entry.getKey())) { builder.put(entry.getKey(), entry.getValue()); } } return Collections.<StreamlineEvent>singletonList(builder.dataSourceId(input.getDataSourceId()).build()); }
private List<StreamlineEvent> substitute(StreamlineEvent input) { StreamlineEventImpl.Builder builder = StreamlineEventImpl.builder(); StrSubstitutor substitutor = new StrSubstitutor(input); for(Map.Entry<String, Object> entry: input.entrySet()) { if(shouldSubstitue(entry.getKey(), entry.getValue())) { builder.put(entry.getKey(), substitutor.replace(entry.getValue())); } else { builder.put(entry.getKey(), entry.getValue()); } } return Collections.<StreamlineEvent>singletonList(builder.dataSourceId(input.getDataSourceId()).build()); }
return StreamlineEventImpl.builder() .from(event) .header(header)
private StreamlineEvent getStreamlineEvent(StreamlineEvent event, String stream) { return StreamlineEventImpl.builder().from(event).sourceStream(stream).build(); }
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); } } }
header.put(AddHeaderTransformRuntime.HEADER_FIELD_TIMESTAMP, System.currentTimeMillis()); StreamlineEvent streamlineEvent = StreamlineEventImpl.builder() .fieldsAndValues(fieldsMap) .dataSourceId("notificationsTestBolt") header.put(AddHeaderTransformRuntime.HEADER_FIELD_TIMESTAMP, System.currentTimeMillis()); StreamlineEvent streamlineEvent = StreamlineEventImpl.builder() .fieldsAndValues(fieldsMap) .dataSourceId("notificationsTestBolt")
final Set<String> inserted = new HashSet<>(); final Map<String, List<Object>> streamsToEvents = new HashMap<>(); final StreamlineEventImpl.Builder eventBuilder = StreamlineEventImpl.builder(); for (Stream stream : outputStreams) { final StreamlineEventImpl.Builder finalEventBuilder = StreamlineEventImpl.builder(); finalEventBuilder.putAll(scoredEvent);
private StreamlineEvent convertShellEvent(ShellMsg.ShellEvent shellEvent, StreamlineEvent inputEvent) { return StreamlineEventImpl.builder() .from(inputEvent) .fieldsAndValues(shellEvent.getFieldsAndValues()) .build(); }