use of com.hortonworks.streamline.streams.layout.component.Stream 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;
}
use of com.hortonworks.streamline.streams.layout.component.Stream in project streamline by hortonworks.
the class RulesProcessor method setRules.
public void setRules(List<Rule> rules) {
this.rules = rules;
Set<String> streamIds = new HashSet<>(Collections2.transform(getOutputStreams(), new Function<Stream, String>() {
@Override
public String apply(Stream input) {
return input.getId();
}
}));
for (Rule rule : rules) {
for (Action action : rule.getActions()) {
for (String stream : action.getOutputStreams()) {
if (!streamIds.contains(stream)) {
String errorMsg = String.format("Action [%s] stream [%s] does not exist in processor [%s]'s output streams [%s]", action, stream, getName(), streamIds);
log.error(errorMsg);
throw new IllegalArgumentException(errorMsg);
}
}
}
}
}
Aggregations