private Map<String, EventInformation> buildRelatedEventsMap(String rootEventId) { Map<String, EventInformation> allEventsMap = events.stream() .collect(toMap(EventInformation::getEventId, e -> e)); Stream<EventInformation> eventsAssociatedToRootEventStream = events.stream().filter(e -> { boolean isRootEvent = e.getEventId().equals(rootEventId); boolean containsRootEvent = e.getRootIds() != null && e.getRootIds().contains(rootEventId); return isRootEvent || containsRootEvent; }); Map<String, EventInformation> relatedEventsMap = eventsAssociatedToRootEventStream.collect( toMap(EventInformation::getEventId, e -> e)); addNonExistingParents(allEventsMap, relatedEventsMap); return relatedEventsMap; }
/** * Returns the group of correlated events per source where the group of related source events * produces the same downstream events * * @param sources the set of source component names * @return the group of correlated events per source */ public List<Set<String>> groupByRelatedSourceEvents(Set<String> sources) { Multimap<Set<String>, String> allEventsToSourceEvents = LinkedHashMultimap.create(); Stream<String> rootEventIds = events.stream().filter(e -> e != null && e.getRootIds().isEmpty()) .map(EventInformation::getEventId); rootEventIds.forEach(rootEventId -> { Map<String, EventInformation> allRelatedEvents = buildRelatedEventsMap(rootEventId); allEventsToSourceEvents.put(allRelatedEvents.keySet(), rootEventId); }); List<Set<String>> result = new ArrayList<>(); allEventsToSourceEvents.asMap().values().forEach(v -> result.add(new HashSet<>(v)) ); return result; }
private void rearrangeEventIds(Map<String, EventInformation> allEvents, String selectedEventId, List<String> eventIds) { if (eventIds.size() <= 1) { // no need to rearrange return; } List<String> movingIds = new LinkedList<>(); Iterator<String> iter = eventIds.iterator(); while (iter.hasNext()) { String eventId = iter.next(); EventInformation eventInformation = allEvents.get(eventId); if (eventInformation == null) { return; } if (eventId.equals(selectedEventId)) { iter.remove(); // place first among moving ids movingIds.add(0, eventId); } else if (eventInformation.getRootIds().contains(selectedEventId)) { // check if the event contains selected event in root ids // if then place them to just right side of selected event iter.remove(); movingIds.add(eventId); } } eventIds.addAll(0, movingIds); }
public Map<String, EventInformationTreeNode> constructEventTreeAsMap(String rootEventId) { Stream<EventInformation> eventsAssociatedToRootEventStream = events.stream().filter(e -> { boolean isRootEvent = e.getEventId().equals(rootEventId); boolean containsRootEvent = e.getRootIds() != null && e.getRootIds().contains(rootEventId); return isRootEvent || containsRootEvent; }); Map<String, EventInformationTreeNode> nodes = eventsAssociatedToRootEventStream.collect( toMap(EventInformation::getEventId, EventInformationTreeNode::new)); nodes.forEach((eventId, node) -> { Set<String> parentIds = node.getEventInformation().getParentIds(); parentIds.forEach(parentId -> { EventInformationTreeNode parentNode = nodes.get(parentId); // parent will not be in nodes when parent is originated to another root event // if it's the case, just ignore it if (parentNode != null) { parentNode.addChild(node); } }); }); return nodes; }
@Override public int hashCode() { int result = (int) (getTimestamp() ^ (getTimestamp() >>> 32)); result = 31 * result + (getComponentName() != null ? getComponentName().hashCode() : 0); result = 31 * result + (getStreamId() != null ? getStreamId().hashCode() : 0); result = 31 * result + (getTargetComponents() != null ? getTargetComponents().hashCode() : 0); result = 31 * result + (getEventId() != null ? getEventId().hashCode() : 0); result = 31 * result + (getRootIds() != null ? getRootIds().hashCode() : 0); result = 31 * result + (getParentIds() != null ? getParentIds().hashCode() : 0); result = 31 * result + (getFieldsAndValues() != null ? getFieldsAndValues().hashCode() : 0); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof EventInformation)) return false; EventInformation that = (EventInformation) o; if (getTimestamp() != that.getTimestamp()) return false; if (getComponentName() != null ? !getComponentName().equals(that.getComponentName()) : that.getComponentName() != null) return false; if (getStreamId() != null ? !getStreamId().equals(that.getStreamId()) : that.getStreamId() != null) return false; if (getTargetComponents() != null ? !getTargetComponents().equals(that.getTargetComponents()) : that.getTargetComponents() != null) return false; if (getEventId() != null ? !getEventId().equals(that.getEventId()) : that.getEventId() != null) return false; if (getRootIds() != null ? !getRootIds().equals(that.getRootIds()) : that.getRootIds() != null) return false; if (getParentIds() != null ? !getParentIds().equals(that.getParentIds()) : that.getParentIds() != null) return false; return getFieldsAndValues() != null ? getFieldsAndValues().equals(that.getFieldsAndValues()) : that.getFieldsAndValues() == null; }