public Iterable<Tuple2<CorrelationKey, StandardEvent>>
call(Tuple2<StandardEvent, Void> t) throws Exception {
List<Tuple2<CorrelationKey, StandardEvent>> result =
new ArrayList<Tuple2<CorrelationKey, StandardEvent>>(2);
StandardEvent event = t._1();
long loTimestamp = createLoTimestamp(event.getTimestamp());
long hiTimestamp = createHiTimestamp(event.getTimestamp());
String ip = event.getIp().toString();
result.add(new Tuple2<CorrelationKey, StandardEvent>(
new CorrelationKey(loTimestamp, ip), event));
result.add(new Tuple2<CorrelationKey, StandardEvent>(
new CorrelationKey(hiTimestamp, ip), event));
return result;
}
});
// Group the events by they correlation key
JavaPairRDD<CorrelationKey, Iterable<StandardEvent>> groupedEvents = mappedEvents.groupByKey();
// Generate potential matches by creating a list of alerts along with the
// matched list of clicks. If no alerts were found with this correlation
// key, then output an empty pair
JavaPairRDD<List<StandardEvent>, List<StandardEvent>> potentialMatches = groupedEvents.mapToPair(
new PairFunction<Tuple2<CorrelationKey, Iterable<StandardEvent>>, List<StandardEvent>, List<StandardEvent>>(){
@Override
public Tuple2<List<StandardEvent>, List<StandardEvent>> call(Tuple2<CorrelationKey, Iterable<StandardEvent>> t) throws Exception {
Iterable<StandardEvent> allEvents = t._2();
List<StandardEvent> alerts = new ArrayList<StandardEvent>();
List<StandardEvent> clicks = new ArrayList<StandardEvent>();
for (StandardEvent event : allEvents) {
if (event.getEventDetails() != null &&
event.getEventDetails().containsKey(new Utf8("type")) &&
"alert".equals(event.getEventDetails().get(new Utf8("type")).toString())) {
alerts.add(event);
} else if (event.getEventDetails() != null &&
event.getEventDetails().containsKey(new Utf8("type")) &&
"click".equals(event.getEventDetails().get(new Utf8("type")).toString())) {
clicks.add(event);
}
}
if (alerts.isEmpty()) {