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;
}
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;
}
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)));
}
}
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");
}
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");
}
Aggregations