public static AbstractBusinessServiceVertex createTopologyVertex(GraphVertex graphVertex) { if (graphVertex.getBusinessService() != null) { return new BusinessServiceVertex(graphVertex); } if (graphVertex.getIpService() != null) { return new IpServiceVertex(graphVertex); } if (graphVertex.getReductionKey() != null) { return new ReductionKeyVertex(graphVertex); } if (graphVertex.getApplication() != null) { return new ApplicationVertex(graphVertex); } throw new IllegalArgumentException("Cannot convert GraphVertex to BusinessServiceVertex: " + graphVertex); } }
public BusinessServiceVertex(GraphVertex graphVertex) { this(graphVertex.getBusinessService(), graphVertex.getLevel()); }
@Override public Status getStatus() { return reductionKeyVertex.getStatus(); } });
public IpServiceVertex(GraphVertex graphVertex) { this(graphVertex.getIpService(), graphVertex.getLevel()); }
public ApplicationVertex(GraphVertex graphVertex) { this(graphVertex.getApplication(), graphVertex.getLevel()); }
@Override public String transform(GraphVertex vertex) { if (vertex.getBusinessService() != null) { return String.format("BS[%s]", vertex.getBusinessService().getName()); } if (vertex.getIpService() != null) { IpService ipService = vertex.getIpService(); return String.format("IP_SERVICE[%s,%s]", ipService.getId(), ipService.getServiceName()); } if (vertex.getReductionKey() != null) { return String.format("RK[%s]", vertex.getReductionKey()); } return "UNKNOWN"; } });
public ReductionKeyVertex(GraphVertex graphVertex) { this(graphVertex.getReductionKey(), graphVertex.getLevel()); }
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 onStatusUpdated(BusinessServiceGraph graph, GraphVertex vertex, Status previousStatus) { BusinessService businessService = vertex.getBusinessService(); if (businessService == null) { // Only send updates for business services (and not for reduction keys) return; } if (graph != m_g) { // We're working with a new graph, only send a status update if the new status is different // than the one in the previous graph GraphVertex previousVertex = m_g.getVertexByBusinessServiceId(businessService.getId()); if (previousVertex != null && vertex.getStatus().equals(previousVertex.getStatus())) { // The vertex for this business service in the previous graph // had the same status, don't issue any notifications return; } } for (BusinessServiceStateChangeHandler handler : m_handlers) { handler.handleBusinessServiceStateChanged(businessService, vertex.getStatus(), previousStatus); } }
private void calculateAndIndexLevels() { // Start by finding the root vertices // These are the vertices with no incoming edges final Set<GraphVertex> rootVertices = Sets.newHashSet(); for (GraphVertex vertex : getVertices()) { if (getInEdges(vertex).size() == 0) { rootVertices.add(vertex); } } // Now calculate the distance of every node to each of the root nodes final GraphLevelIndexer<GraphVertex, GraphEdge> levelIndexer = new GraphLevelIndexer<>(); levelIndexer.indexLevel(this, rootVertices); for (Entry<GraphVertex, Integer> entry : levelIndexer.getLevelMap().entrySet()) { final int level = entry.getValue().intValue(); final GraphVertexImpl vertex = (GraphVertexImpl)entry.getKey(); // Store the maximum level within the vertex vertex.setLevel(Math.max(level, vertex.getLevel())); } // Index the vertices by level for (GraphVertex vertex : getVertices()) { Set<GraphVertex> verticesAtLevel = m_verticesByLevel.get(vertex.getLevel()); if (verticesAtLevel == null) { verticesAtLevel = Sets.newHashSet(); m_verticesByLevel.put(vertex.getLevel(), verticesAtLevel); } verticesAtLevel.add(vertex); } }
@Override public Void visit(ApplicationEdge edge) { vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getApplication()); addVertex(vertexForEdge[0]); m_verticesByApplicationId.put(vertexForEdge[0].getApplication().getId(), vertexForEdge[0]); for (IpService ipService : edge.getApplication().getIpServices()) { final GraphVertex ipServiceVertex = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, ipService); final GraphEdgeImpl ipVertexEdgeEdge = new GraphEdgeImpl(MAP_IDENTITY); addVertex(ipServiceVertex); m_verticesByIpServiceId.put(ipServiceVertex.getIpService().getId(), ipServiceVertex); addEdge(ipVertexEdgeEdge, vertexForEdge[0], ipServiceVertex); addReductionKeyVerticesToVertex(ipServiceVertex, ipService.getReductionKeys()); } return null; }
@Override public Void visit(IpServiceEdge edge) { // There are multiple reductions keys for this edge // Create an intermediary vertex using the Most Critical reduction function vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getIpService()); addVertex(vertexForEdge[0]); m_verticesByIpServiceId.put(vertexForEdge[0].getIpService().getId(), vertexForEdge[0]); addReductionKeyVerticesToVertex(vertexForEdge[0], edge.getReductionKeys()); return null; }
public static Set<GraphEdge> calculateImpacting(BusinessServiceGraph graph, GraphVertex parent) { // Grab all of the child edges List<GraphEdge> childEdges = graph.getOutEdges(parent).stream() .collect(Collectors.toList()); // Weigh and reduce the statuses List<StatusWithIndex> statuses = DefaultBusinessServiceStateMachine.weighEdges(childEdges); Optional<StatusWithIndices> reducedStatus = parent.getReductionFunction().reduce(statuses); if (!reducedStatus.isPresent()) { return Collections.emptySet(); } else { return reducedStatus.get().getIndices().stream() .map(childEdges::get) .collect(Collectors.toSet()); } } }
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)); }
@Override public int compare(BusinessService p1, BusinessService p2) { switch (m_order) { case Name: { return p1.getName().compareTo(p2.getName()); } case Severity: { return businessServiceManager.getOperationalStatus(p1).compareTo(businessServiceManager.getOperationalStatus(p2)); } case Level: { return Integer.compare(graph.getVertexByBusinessServiceId(p1.getId()).getLevel(), graph.getVertexByBusinessServiceId(p2.getId()).getLevel()); } default: throw new IllegalArgumentException("Order not set"); } } };
private void reduceUpdateAndPropagateVertex(BusinessServiceGraph graph, GraphVertex vertex) { if (vertex == null) { // Nothing to do here return; } // Calculate the weighed statuses from the child edges List<StatusWithIndex> statuses = weighEdges(graph.getOutEdges(vertex)); // Reduce Optional<StatusWithIndices> reducedStatus = vertex.getReductionFunction().reduce(statuses); Status newStatus; if (reducedStatus.isPresent()) { newStatus = reducedStatus.get().getStatus(); } else { newStatus = MIN_SEVERITY; } // Update and propagate updateAndPropagateVertex(graph, vertex, newStatus); }
/** * Refreshes table entries. */ public void refresh() { final com.google.common.collect.Table<Long, Optional<Long>, Boolean> expandState = getCurrentExpandState(); final BusinessServiceContainer newContainer = new BusinessServiceContainer(); if (!Strings.isNullOrEmpty(businessServiceNameFilter)) { newContainer.addContainerFilter(new BusinessServiceFilter(newContainer, businessServiceNameFilter)); } // Build a graph using all of the business services stored in the database // We don't use the existing graph, since it only contains the services know by the state machine List<BusinessService> allBusinessServices = businessServiceManager.getAllBusinessServices(); final BusinessServiceGraph graph = businessServiceManager.getGraph(allBusinessServices); // Recursively generate the table rows, starting with the roots graph.getVerticesByLevel(0).stream() .filter(v -> v.getBusinessService() != null) .sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())) .forEach(v -> newContainer.addRow(graph, v)); // Make it hierarchical Hierarchical hierarchicalContainer = createHierarchicalContainer(newContainer); // Update datasource setContainerDataSource(hierarchicalContainer); setVisibleColumns("name", "links", "edit / delete"); // reset visible columns // Restore the previous collapsed state List<BusinessServiceRow> rows = getItemIds().stream().map(itemId -> getItem(itemId).getBean()).collect(Collectors.toList()); applyExpandState(expandState, rows); }
@Override public Status getOperationalStatus(String reductionKey) { m_rwLock.readLock().lock(); try { GraphVertex vertex = m_g.getVertexByReductionKey(reductionKey); if (vertex != null) { return vertex.getStatus(); } return null; } finally { m_rwLock.readLock().unlock(); } }
@Override public int compare(BusinessService p1, BusinessService p2) { switch (m_order) { case Name: { return p1.getName().compareTo(p2.getName()); } case Severity: { return businessServiceManager.getOperationalStatus(p1).compareTo(businessServiceManager.getOperationalStatus(p2)); } case Level: { return Integer.compare(graph.getVertexByBusinessServiceId(p1.getId()).getLevel(), graph.getVertexByBusinessServiceId(p2.getId()).getLevel()); } default: throw new IllegalArgumentException("Order not set"); } } };