@Override public Void visit(BusinessServiceVertex vertex) { graphVertex.set(graph.getVertexByBusinessServiceId(vertex.getServiceId())); return null; }
@Override public Set<GraphEdge> calculateImpacting(BusinessService businessService) { m_rwLock.readLock().lock(); try { final GraphVertex vertex = m_g.getVertexByBusinessServiceId(businessService.getId()); return GraphAlgorithms.calculateImpacting(m_g, vertex); } finally { m_rwLock.readLock().unlock(); } }
@Override public List<GraphVertex> calculateRootCause(BusinessService businessService) { m_rwLock.readLock().lock(); try { final GraphVertex vertex = m_g.getVertexByBusinessServiceId(businessService.getId()); return GraphAlgorithms.calculateRootCause(m_g, vertex); } finally { m_rwLock.readLock().unlock(); } }
@Override public List<GraphVertex> calculateImpact(BusinessService businessService) { m_rwLock.readLock().lock(); try { final GraphVertex vertex = m_g.getVertexByBusinessServiceId(businessService.getId()); return calculateImpact(vertex); } finally { m_rwLock.readLock().unlock(); } }
@Override public Status getOperationalStatus(BusinessService businessService) { Objects.requireNonNull(businessService); m_rwLock.readLock().lock(); try { GraphVertex vertex = m_g.getVertexByBusinessServiceId(businessService.getId()); if (vertex != null) { return vertex.getStatus(); } return null; } finally { m_rwLock.readLock().unlock(); } }
private static Set<GraphVertex> getImpactingVertices(BusinessServiceStateMachine stateMachine, BusinessServiceGraph graph, BusinessService businessService) { // Only consider a feasible amount of edges. See NMS-8501 and NMS-8527 for more details if (graph.getOutEdges(graph.getVertexByBusinessServiceId(businessService.getId())).size() <= MAX_EDGES_FOR_IMPACTING) { return stateMachine.calculateImpacting(businessService) .stream() .map(edge -> graph.getDest(edge)) // DO NOT CONVERT to lamda method reference. See NMS-10529 .collect(Collectors.toSet()); } LOG.warn("Try to calculate impacting vertices for more than {} edges. This is currently not supported. See http://http://issues.opennms.org/browse/NMS-8527.", MAX_EDGES_FOR_IMPACTING); return Sets.newHashSet(); } }
@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"); } } };
@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"); } } };
@Override public ThresholdResultExplanation explain(BusinessService businessService, Threshold threshold) { final GraphVertex vertex = getGraph().getVertexByBusinessServiceId(businessService.getId()); // Calculate the weighed statuses from the child edges List<StatusWithIndex> statusesWithIndices = weighEdges(getGraph().getOutEdges(vertex)); List<Status> statuses = statusesWithIndices.stream() .map(StatusWithIndex::getStatus) .collect(Collectors.toList()); // Reduce Status reducedStatus = threshold.reduce(statusesWithIndices) .orElse(new StatusWithIndices(MIN_SEVERITY, Collections.emptyList())) .getStatus(); ThresholdResultExplanation explanation = new ThresholdResultExplanation(); explanation.setStatus(reducedStatus); explanation.setHitsByStatus(threshold.getHitsByStatus(statuses)); explanation.setGraphEdges(getGraph().getOutEdges(vertex)); explanation.setWeightStatuses(statuses); explanation.setFunction(threshold); Map<GraphEdge, GraphVertex> graphEdgeToGraphVertex = new HashMap<>(); for (Edge eachEdge : businessService.getEdges()) { GraphVertex vertexForEdge = getGraph().getVertexByEdgeId(eachEdge.getId()); GraphEdge graphEdge = getGraph().getGraphEdgeByEdgeId(eachEdge.getId()); if (vertexForEdge != null && graphEdge != null) { graphEdgeToGraphVertex.put(graphEdge, vertexForEdge); } } explanation.setGraphEdgeToGraphVertexMapping(graphEdgeToGraphVertex); return explanation; }
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); } }