Search in sources :

Example 21 with EdgeRef

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

the class D3LayoutTest method runD3Layout.

private D3TopoLayout<VertexRef, EdgeRef> runD3Layout(int count, Graph g, Layout graphLayout, List<Vertex> vertices) throws IOException {
    D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<>(createJungGraph(g));
    Dimension size = selectLayoutSize(m_graphContainer);
    layout.setInitializer(initializer(graphLayout, size));
    layout.setSize(size);
    try (PrintWriter out = new PrintWriter(new FileWriter("target/data" + count + ".js"))) {
        out.println("var gCenter = { x: " + size.getWidth() / 2.0 + ", y: " + size.getHeight() / 2.0 + "};");
        out.println("var data = [");
        while (!layout.done()) {
            out.println("[");
            for (int i = 0; i < vertices.size(); i++) {
                Vertex v = vertices.get(i);
                if (i + 1 == vertices.size()) {
                    out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " }");
                } else {
                    out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " },");
                }
            }
            layout.step();
            out.println("],");
        }
        out.println("];");
        LOG.info("/******** D3Layout Run **********/");
    }
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
        LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
    }
    LOG.info("/******** End D3Layout Run **********/");
    return layout;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) FileWriter(java.io.FileWriter) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point) PrintWriter(java.io.PrintWriter)

Example 22 with EdgeRef

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

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

the class D3TopoLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) 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 24 with EdgeRef

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

the class LinkdEdgeStatusProviderTest method testGetOspfLinkStatusDown.

@Test
public void testGetOspfLinkStatusDown() {
    EasyMock.expect(m_alarmDao.findMatching(EasyMock.anyObject(org.opennms.core.criteria.Criteria.class))).andReturn(createOspfDownAlarm()).anyTimes();
    List<EdgeRef> edges = getEdgeRefs();
    for (EdgeRef ref : edges) EasyMock.expect(m_edgeProvider.getEdge(ref)).andReturn(getEdgeFromRef(ref)).anyTimes();
    EasyMock.replay(m_alarmDao, m_edgeProvider);
    Map<EdgeRef, Status> statusMap = m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]);
    assertEquals(8, statusMap.size());
    assertEquals(edges.get(0), new ArrayList<EdgeRef>(statusMap.keySet()).get(0));
    assertEquals(statusMap.get(edges.get(0)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(1)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(2)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(3)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(4)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(6)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(7)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(5)).computeStatus(), "down");
}
Also used : Status(org.opennms.features.topology.api.topo.Status) ArrayList(java.util.ArrayList) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Test(org.junit.Test)

Example 25 with EdgeRef

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

the class LinkdEdgeStatusProviderTest method testGetIsisLinkStatusDown.

@Test
public void testGetIsisLinkStatusDown() {
    EasyMock.expect(m_alarmDao.findMatching(EasyMock.anyObject(org.opennms.core.criteria.Criteria.class))).andReturn(createIsIsDownAlarm()).anyTimes();
    List<EdgeRef> edges = getEdgeRefs();
    for (EdgeRef ref : edges) EasyMock.expect(m_edgeProvider.getEdge(ref)).andReturn(getEdgeFromRef(ref)).anyTimes();
    EasyMock.replay(m_alarmDao, m_edgeProvider);
    Map<EdgeRef, Status> statusMap = m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]);
    assertEquals(8, statusMap.size());
    assertEquals(edges.get(0), new ArrayList<EdgeRef>(statusMap.keySet()).get(0));
    assertEquals(statusMap.get(edges.get(0)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(1)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(2)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(4)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(5)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(6)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(7)).computeStatus(), "up");
    assertEquals(statusMap.get(edges.get(3)).computeStatus(), "down");
}
Also used : Status(org.opennms.features.topology.api.topo.Status) ArrayList(java.util.ArrayList) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Test(org.junit.Test)

Aggregations

EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)30 VertexRef (org.opennms.features.topology.api.topo.VertexRef)18 Vertex (org.opennms.features.topology.api.topo.Vertex)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Edge (org.opennms.features.topology.api.topo.Edge)11 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Status (org.opennms.features.topology.api.topo.Status)10 Point (org.opennms.features.topology.api.Point)9 Dimension (java.awt.Dimension)6 Layout (org.opennms.features.topology.api.Layout)6 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)3 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)3 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)3 HashMap (java.util.HashMap)2 Graph (org.opennms.features.topology.api.Graph)2 Predicate (com.google.common.base.Predicate)1 Lists (com.google.common.collect.Lists)1 ISOMLayout (edu.uci.ics.jung.algorithms.layout.ISOMLayout)1 UnweightedShortestPath (edu.uci.ics.jung.algorithms.shortestpath.UnweightedShortestPath)1