Search in sources :

Example 31 with Edge

use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.

the class BreadcrumbPathCalculator method getIncomingEdgeMap.

static Map<VertexRef, EdgeRef> getIncomingEdgeMap(TopologyServiceClient topologyServiceClient) {
    // Convert to JUNG graph
    // We build one big graph out of all graph providers in order to determine the shortest path between each vertex
    // when we want to calculate the SHORTEST_PATH_TO_ROOT
    final DirectedSparseGraph<VertexRef, EdgeRef> sparseGraph = new DirectedSparseGraph<>();
    topologyServiceClient.getGraphProviders().forEach(eachGraph -> {
        for (Vertex eachVertex : eachGraph.getVertices(new IgnoreHopCriteria())) {
            sparseGraph.addVertex(eachVertex);
        }
        for (EdgeRef eachEdge : eachGraph.getEdges()) {
            sparseGraph.addEdge(eachEdge, ((Edge) eachEdge).getSource().getVertex(), ((Edge) eachEdge).getTarget().getVertex());
        }
    });
    // Link the layers
    final IdGenerator idGenerator = new IdGenerator();
    sparseGraph.getVertices().forEach(eachVertex -> {
        topologyServiceClient.getOppositeVertices(eachVertex).forEach(oppositeVertex -> {
            sparseGraph.addEdge(new AbstractEdge("$$outer-space$$", "" + idGenerator.nextId(), eachVertex, oppositeVertex), eachVertex, oppositeVertex);
        });
    });
    // Create dummy root
    sparseGraph.addVertex(rootVertex);
    for (Vertex eachVertex : topologyServiceClient.getDefaultGraphProvider().getVertices(new IgnoreHopCriteria())) {
        sparseGraph.addEdge(new AbstractEdge("$$outer-space$$", "" + idGenerator.nextId(), rootVertex, eachVertex), rootVertex, eachVertex);
    }
    // Build shortest path for graph
    final UnweightedShortestPath<VertexRef, EdgeRef> shortestPath = new UnweightedShortestPath<>(sparseGraph);
    Map<VertexRef, EdgeRef> incomingEdgeMap = shortestPath.getIncomingEdgeMap(rootVertex);
    return incomingEdgeMap;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) IgnoreHopCriteria(org.opennms.features.topology.api.support.IgnoreHopCriteria) UnweightedShortestPath(edu.uci.ics.jung.algorithms.shortestpath.UnweightedShortestPath) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) DirectedSparseGraph(edu.uci.ics.jung.graph.DirectedSparseGraph)

Example 32 with Edge

use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.

the class D3LayoutTest method createJungGraph.

private SparseGraph<VertexRef, EdgeRef> createJungGraph(Graph g) {
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<>();
    Collection<Vertex> vertices = g.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = g.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    return jungGraph;
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 33 with Edge

use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.

the class FRLayoutTest method createJungGraph.

private SparseGraph<VertexRef, EdgeRef> createJungGraph(Graph g) {
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<>();
    Collection<Vertex> vertices = g.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = g.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    return jungGraph;
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 34 with Edge

use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.

the class TestGraph method visit.

@Override
public void visit(GraphVisitor visitor) throws Exception {
    visitor.visitGraph(this);
    for (Vertex v : vertices) {
        visitor.visitVertex(v);
    }
    for (Edge e : edges) {
        visitor.visitEdge(e);
    }
    visitor.completeGraph(this);
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Edge(org.opennms.features.topology.api.topo.Edge)

Example 35 with Edge

use of org.opennms.features.topology.api.topo.Edge 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

Edge (org.opennms.features.topology.api.topo.Edge)37 Vertex (org.opennms.features.topology.api.topo.Vertex)22 VertexRef (org.opennms.features.topology.api.topo.VertexRef)22 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)11 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Layout (org.opennms.features.topology.api.Layout)10 Point (org.opennms.features.topology.api.Point)8 ArrayList (java.util.ArrayList)7 Dimension (java.awt.Dimension)5 HashSet (java.util.HashSet)5 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)5 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)5 Set (java.util.Set)4 Test (org.junit.Test)4 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)4 SimpleLeafVertex (org.opennms.features.topology.api.topo.SimpleLeafVertex)4 HashMap (java.util.HashMap)3 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)3 Criteria (org.opennms.features.topology.api.topo.Criteria)3 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)2