Search in sources :

Example 1 with GraphEdge

use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.

the class BusinessServiceGraphImpl method addBusinessServiceVertex.

private GraphVertex addBusinessServiceVertex(BusinessService businessService) {
    // Use an existing vertex if we already created one
    GraphVertex businessServiceVertex = m_verticesByBusinessServiceId.get(businessService.getId());
    if (businessServiceVertex != null) {
        return businessServiceVertex;
    }
    // Create
    businessServiceVertex = new GraphVertexImpl(businessService.getReduceFunction(), businessService);
    // Add
    addVertex(businessServiceVertex);
    // Index
    m_verticesByBusinessServiceId.put(businessService.getId(), businessServiceVertex);
    for (Edge edge : businessService.getEdges()) {
        // Create the edge
        GraphEdge graphEdge = new GraphEdgeImpl(edge);
        // Use an existing vertex if we already created one
        final GraphVertex[] vertexForEdge = { getExistingVertex(edge) };
        // If we couldn't find an existing vertex, create one
        if (vertexForEdge[0] == null) {
            edge.accept(new EdgeVisitor<Void>() {

                @Override
                public Void visit(ChildEdge edge) {
                    vertexForEdge[0] = addBusinessServiceVertex(edge.getChild());
                    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]);
                    // SPECIAL CASE: Map the reductions keys to the intermediary vertex using the Identity map
                    for (String reductionKey : edge.getReductionKeys()) {
                        GraphVertex reductionKeyVertex = m_verticesByReductionKey.get(reductionKey);
                        if (reductionKeyVertex == null) {
                            // not already added
                            reductionKeyVertex = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, reductionKey);
                            addVertex(reductionKeyVertex);
                            m_verticesByReductionKey.put(reductionKey, reductionKeyVertex);
                        }
                        // Always add an edge
                        GraphEdgeImpl intermediaryEdge = new GraphEdgeImpl(MAP_IDENTITY);
                        addEdge(intermediaryEdge, vertexForEdge[0], reductionKeyVertex);
                    }
                    return null;
                }

                @Override
                public Void visit(ReductionKeyEdge edge) {
                    String reductionKey = edge.getReductionKey();
                    vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getReductionKey());
                    addVertex(vertexForEdge[0]);
                    m_verticesByReductionKey.put(reductionKey, vertexForEdge[0]);
                    return null;
                }
            });
        }
        // Link and index
        addEdge(graphEdge, businessServiceVertex, vertexForEdge[0]);
        m_verticesByEdgeId.put(edge.getId(), vertexForEdge[0]);
        m_edgesByEdgeId.put(edge.getId(), graphEdge);
    }
    return businessServiceVertex;
}
Also used : ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 2 with GraphEdge

use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method renderGraphToPng.

@Override
public void renderGraphToPng(File tempFile) {
    m_rwLock.readLock().lock();
    try {
        Layout<GraphVertex, GraphEdge> layout = new KKLayout<GraphVertex, GraphEdge>(m_g);
        // Size of the layout
        layout.setSize(new Dimension(1024, 1024));
        VisualizationImageServer<GraphVertex, GraphEdge> vv = new VisualizationImageServer<GraphVertex, GraphEdge>(layout, layout.getSize());
        // Viewing area size
        vv.setPreferredSize(new Dimension(1200, 1200));
        vv.getRenderContext().setVertexLabelTransformer(new Transformer<GraphVertex, String>() {

            @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";
            }
        });
        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<GraphEdge, String>() {

            @Override
            public String transform(GraphEdge edge) {
                return String.format("%s", edge.getMapFunction().getClass().getSimpleName());
            }
        });
        // Create the buffered image
        BufferedImage image = (BufferedImage) vv.getImage(new Point2D.Double(vv.getGraphLayout().getSize().getWidth() / 2, vv.getGraphLayout().getSize().getHeight() / 2), new Dimension(vv.getGraphLayout().getSize()));
        // Render
        try {
            ImageIO.write(image, "png", tempFile);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    } finally {
        m_rwLock.readLock().unlock();
    }
}
Also used : KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Dimension(java.awt.Dimension) IOException(java.io.IOException) IpService(org.opennms.netmgt.bsm.service.model.IpService) BufferedImage(java.awt.image.BufferedImage) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 3 with GraphEdge

use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachine method updateAndPropagateVertex.

private void updateAndPropagateVertex(BusinessServiceGraph graph, GraphVertex vertex, Status newStatus) {
    if (vertex == null) {
        // Nothing to do here
        return;
    }
    // Apply lower bound
    newStatus = newStatus.isLessThan(MIN_SEVERITY) ? MIN_SEVERITY : newStatus;
    // Update the status if necessary
    Status previousStatus = vertex.getStatus();
    if (previousStatus.equals(newStatus)) {
        // The status hasn't changed, there's nothing to propagate
        return;
    }
    vertex.setStatus(newStatus);
    // Notify the listeners
    onStatusUpdated(graph, vertex, previousStatus);
    // Update the edges with the mapped status
    List<GraphEdge> updatedEges = Lists.newArrayList();
    for (GraphEdge edge : graph.getInEdges(vertex)) {
        Status mappedStatus = newStatus;
        if (newStatus.isGreaterThan(MIN_SEVERITY)) {
            // Only apply the map function when the status is > the minimum
            mappedStatus = edge.getMapFunction().map(newStatus).orElse(MIN_SEVERITY);
        } else {
            mappedStatus = newStatus;
        }
        if (mappedStatus.equals(edge.getStatus())) {
            // The status hasn't changed
            continue;
        }
        // Update the status and add it to the list of edges to propagate
        edge.setStatus(mappedStatus);
        updatedEges.add(edge);
    }
    // Propagate once all of the edges have been updated
    for (GraphEdge edge : updatedEges) {
        reduceUpdateAndPropagateVertex(graph, graph.getOpposite(vertex, edge));
    }
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Example 4 with GraphEdge

use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.

the class BusinessServicesStatusProvider method getStatus.

public static org.opennms.netmgt.bsm.service.model.Status getStatus(BusinessServiceStateMachine stateMachine, BusinessServiceEdge edge) {
    final BusinessServiceGraph graph = stateMachine.getGraph();
    // We need both the source and target vertices to find the edge in the graph
    final GraphVertex source = getGraphVertex(edge.getBusinessServiceSource(), stateMachine.getGraph());
    final GraphVertex target = getGraphVertex(edge.getBusinessServiceTarget(), stateMachine.getGraph());
    final GraphEdge graphEdge = graph.findEdge(source, target);
    return graphEdge != null ? graphEdge.getStatus() : null;
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 5 with GraphEdge

use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.

the class BusinessServicesTopologyProvider method addVertex.

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);
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) Edge(org.opennms.features.topology.api.topo.Edge) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge)

Aggregations

GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)8 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)7 Status (org.opennms.netmgt.bsm.service.model.Status)3 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)3 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)2 VisualizationImageServer (edu.uci.ics.jung.visualization.VisualizationImageServer)2 Dimension (java.awt.Dimension)2 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 StatusWithIndex (org.opennms.netmgt.bsm.service.model.StatusWithIndex)2 StatusWithIndices (org.opennms.netmgt.bsm.service.model.StatusWithIndices)2 ThresholdResultExplanation (org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation)2 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)2 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1 Point2D (java.awt.geom.Point2D)1