public static List<GraphVertex> calculateImpact(BusinessServiceGraph graph, GraphVertex vertex) { if (vertex == null) { return Collections.emptyList(); } // Gather the list of parent vertices that are impacted by the current vertex final List<GraphVertex> impactedParentVertices = graph.getInEdges(vertex).stream() .filter(e -> calculateImpacting(graph, graph.getOpposite(vertex, e)).contains(e)) .map(e -> graph.getOpposite(vertex, e)) .sorted() .collect(Collectors.toList()); // Recurse final List<GraphVertex> impacts = Lists.newArrayList(impactedParentVertices); for (GraphVertex impactedParentVertex : impactedParentVertices) { impacts.addAll(calculateImpact(graph, impactedParentVertex)); } return impacts; }
public static List<GraphVertex> calculateRootCause(BusinessServiceGraph graph, GraphVertex vertex) { if (vertex == null || vertex.getStatus().isLessThanOrEqual(Status.NORMAL)) { return Collections.emptyList(); } // Gather the list of child vertices that impact the current vertex final List<GraphVertex> childVerticesWithImpact = calculateImpacting(graph, vertex) .stream() .map(e -> graph.getOpposite(vertex, e)) .sorted() .collect(Collectors.toList()); // Recurse final List<GraphVertex> causes = Lists.newArrayList(childVerticesWithImpact); for (GraphVertex childVertexWithImpact : childVerticesWithImpact) { causes.addAll(calculateRootCause(graph, childVertexWithImpact)); } return causes; }
private void createRowForVertex(BusinessServiceGraph graph, GraphVertex graphVertex, BusinessServiceRow parentRow) { final BusinessService businessService = graphVertex.getBusinessService(); if (businessService == null) { return; } final long rowId = rowIdCounter.incrementAndGet(); final Long parentBusinessServiceId = parentRow != null ? parentRow.getBusinessService().getId() : null; final BusinessServiceRow row = new BusinessServiceRow(rowId, businessService, parentBusinessServiceId); if (parentRow != null) { rowIdToParentRowIdMapping.put(rowId, parentRow.getRowId()); } addBean(row); // Recurse with all of the children graph.getOutEdges(graphVertex).stream() .map(e -> graph.getOpposite(graphVertex, e)) .filter(v -> v.getBusinessService() != null) .sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())) .forEach(v -> createRowForVertex(graph, v, row)); }
private void createRowForVertex(BusinessServiceGraph graph, GraphVertex graphVertex, BusinessServiceRow parentRow) { final BusinessService businessService = graphVertex.getBusinessService(); if (businessService == null) { return; } final long rowId = rowIdCounter.incrementAndGet(); final Long parentBusinessServiceId = parentRow != null ? parentRow.getBusinessService().getId() : null; final BusinessServiceRow row = new BusinessServiceRow(rowId, businessService, parentBusinessServiceId); if (parentRow != null) { rowIdToParentRowIdMapping.put(rowId, parentRow.getRowId()); } addBean(row); // Recurse with all of the children graph.getOutEdges(graphVertex).stream() .map(e -> graph.getOpposite(graphVertex, e)) .filter(v -> v.getBusinessService() != null) .sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())) .forEach(v -> createRowForVertex(graph, v, row)); }
private void addVertex(BusinessServiceGraph graph, GraphVertex graphVertex, AbstractBusinessServiceVertex topologyVertex) { if (topologyVertex == null) { // Create a topology vertex for the current vertex topologyVertex = createTopologyVertex(graphVertex); addVertices(topologyVertex); } for (GraphEdge graphEdge : graph.getOutEdges(graphVertex)) { GraphVertex childVertex = graph.getOpposite(graphVertex, graphEdge); // Create a topology vertex for the child vertex AbstractBusinessServiceVertex childTopologyVertex = createTopologyVertex(childVertex); graph.getInEdges(childVertex).stream() .map(GraphEdge::getFriendlyName) .filter(s -> !Strings.isNullOrEmpty(s)) .findFirst() .ifPresent(childTopologyVertex::setLabel); addVertices(childTopologyVertex); // Connect the two childTopologyVertex.setParent(topologyVertex); Edge edge = new BusinessServiceEdge(graphEdge, topologyVertex, childTopologyVertex); addEdges(edge); // Recurse addVertex(graph, childVertex, childTopologyVertex); } }
reduceUpdateAndPropagateVertex(graph, graph.getOpposite(vertex, edge));