use of org.opennms.features.topology.api.support.VertexHopGraphProvider in project opennms by OpenNMS.
the class GraphMLMetaTopologyProvider method reload.
public void reload() throws IOException, InvalidGraphException {
graphsByNamespace.clear();
oppositeVertices.clear();
rawGraphsByNamespace.clear();
if (graphMLFile == null) {
LOG.warn("No graph defined");
return;
}
if (!graphMLFile.exists()) {
LOG.warn("No graph found at location " + graphMLFile.toString());
return;
}
try (InputStream input = new FileInputStream(graphMLFile)) {
final GraphML graphML = GraphMLReader.read(input);
validate(graphML);
for (GraphMLGraph eachGraph : graphML.getGraphs()) {
final GraphMLTopologyProvider topoProvider = new GraphMLTopologyProvider(eachGraph, m_serviceAccessor);
final VertexHopGraphProvider vertexHopGraphProvider = new VertexHopGraphProvider(topoProvider);
graphsByNamespace.put(topoProvider.getNamespace(), vertexHopGraphProvider);
rawGraphsByNamespace.put(topoProvider.getNamespace(), topoProvider);
}
for (GraphMLGraph eachGraph : graphML.getGraphs()) {
for (org.opennms.features.graphml.model.GraphMLEdge eachEdge : eachGraph.getEdges()) {
final VertexRef sourceVertex = getVertex(eachEdge.getSource());
final VertexRef targetVertex = getVertex(eachEdge.getTarget());
if (!sourceVertex.getNamespace().equals(targetVertex.getNamespace())) {
List<VertexRef> opposites = oppositeVertices.get(sourceVertex);
if (opposites == null) {
opposites = Lists.newArrayList();
oppositeVertices.put(sourceVertex, opposites);
}
opposites.add(targetVertex);
}
}
}
this.breadcrumbStrategy = getBreadcrumbStrategy(graphML);
}
}
use of org.opennms.features.topology.api.support.VertexHopGraphProvider in project opennms by OpenNMS.
the class VEProviderGraphContainerTest method testContainerWithHopProvider.
@Test
public void testContainerWithHopProvider() throws Exception {
VertexHopGraphProvider vertexHopGraphProvider = new VertexHopGraphProvider(m_graphProvider);
DefaultTopologyService topologyService = new DefaultTopologyService();
SimpleMetaTopologyProvider simpleMetaTopologyProvider = new SimpleMetaTopologyProvider(vertexHopGraphProvider);
topologyService.setServiceLocator(new SimpleServiceLocator(simpleMetaTopologyProvider));
// Wrap the test GraphProvider in a VertexHopGraphProvider
VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setSemanticZoomLevel(0);
graphContainer.setTopologyService(topologyService);
graphContainer.setMetaTopologyId(simpleMetaTopologyProvider.getId());
graphContainer.setSelectedNamespace(vertexHopGraphProvider.getNamespace());
m_graphContainer = graphContainer;
// There should be zero vertices or edges if no focus vertices are set
Graph graph = m_graphContainer.getGraph();
assertEquals(0, graph.getDisplayVertices().size());
assertEquals(0, graph.getDisplayEdges().size());
// Add one focus vertex
VertexHopGraphProvider.DefaultVertexHopCriteria hopCriteria = new VertexHopGraphProvider.DefaultVertexHopCriteria(new DefaultVertexRef("nodes", "v1"));
m_graphContainer.addCriteria(hopCriteria);
// This needs to be 2 because there is a SemanticZoomLevelCriteria in there also
assertEquals(2, m_graphContainer.getCriteria().length);
// Verify that a single vertex is in the graph
graph = m_graphContainer.getGraph();
assertEquals(1, graph.getDisplayVertices().size());
assertEquals(0, graph.getDisplayEdges().size());
expectVertex("nodes", "v1", "vertex");
graph.visit(verifier());
verify();
verifyConnectedness(graph);
reset();
// Change SZL to 1
m_graphContainer.setSemanticZoomLevel(1);
assertEquals(2, m_graphContainer.getCriteria().length);
// Focus vertex
expectVertex("nodes", "v1", "vertex");
expectVertex("nodes", "v2", "vertex");
/*
This is a problem with the VEProviderGraphContainer... it wraps a delegate GraphProvider
in a MergingGraphProvider like so:
VEProviderGraphContainer { MergingGraphProvider { VertexHopGraphProvider } } }
But for the VertexHopProvider to calculate the SZL correctly, it needs to be aware of all
edges, including those provided by the MergingGraphProvider. So we should rearrange things
so that they are laid out like:
VEProviderGraphContainer { VertexHopGraphProvider { MergingGraphProvider } } }
We should decouple the MergingGraphProvider from the VEProviderGraphContainer and then just
inject them in the correct order. When this problem is fixed, uncomment all of the lines that
are commented out in this test.
*/
//expectVertex("nodes", "v3", "vertex");
expectVertex("nodes", "v4", "vertex");
expectEdge("nodes", "e1", "edge");
//expectEdge("nodes", "e2", "edge");
//expectEdge("nodes", "e3", "edge");
expectEdge("nodes", "e4", "edge");
graph = m_graphContainer.getGraph();
//assertEquals(4, graph.getDisplayVertices().size());
//assertEquals(5, graph.getDisplayEdges().size());
assertEquals(3, graph.getDisplayVertices().size());
assertEquals(2, graph.getDisplayEdges().size());
graph.visit(verifier());
verify();
verifyConnectedness(graph);
reset();
// Add a collapsed criteria to the container
Criteria collapsibleCriteria = new TestCriteria1();
m_graphContainer.addCriteria(collapsibleCriteria);
assertEquals(3, m_graphContainer.getCriteria().length);
// Make sure that the TestCollapsibleCriteria is mapping "v2" and "v4" to the collapsed "test" vertex
Map<VertexRef, Set<Vertex>> collapsed = VertexHopGraphProvider.getMapOfVerticesToCollapsedVertices(VertexHopGraphProvider.getCollapsedCriteria(m_graphContainer.getCriteria()));
assertTrue(collapsed.containsKey(new DefaultVertexRef("nodes", "v2")));
assertTrue(collapsed.containsKey(new DefaultVertexRef("nodes", "v4")));
assertTrue(collapsed.get(new DefaultVertexRef("nodes", "v2")).equals(Collections.singleton(new DefaultVertexRef("nodes", "test"))));
assertTrue(collapsed.get(new DefaultVertexRef("nodes", "v4")).equals(Collections.singleton(new DefaultVertexRef("nodes", "test"))));
assertEquals(m_graphContainer.getGraph().getDisplayVertices().toString(), 3, m_graphContainer.getGraph().getDisplayVertices().size());
assertEquals(m_graphContainer.getTopologyServiceClient().getGraphProviderBy("nodes").getVertices(new TestCriteria1()).toString(), 3, m_graphContainer.getTopologyServiceClient().getGraphProviderBy("nodes").getVertices(new TestCriteria1()).size());
expectVertex("nodes", "v1", "vertex");
expectVertex("nodes", "v3", "vertex");
// Collapsed vertex that contains v2 and v4
expectVertex("nodes", "test", "test");
expectEdge("nodes", "collapsedTarget-e1", "edge");
expectEdge("nodes", "collapsedSource-e2", "edge");
expectEdge("nodes", "collapsedTarget-e3", "edge");
expectEdge("nodes", "collapsedSource-e4", "edge");
graph = m_graphContainer.getGraph();
assertEquals(3, graph.getDisplayVertices().size());
assertEquals(4, graph.getDisplayEdges().size());
for (Edge edge : graph.getDisplayEdges()) {
if (edge.getId().equals("collapsedTarget-e1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e2")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("v3", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedTarget-e3")) {
assertEquals("v3", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e4")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("v1", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("ncs1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("v3", edge.getTarget().getVertex().getId());
} else {
fail("Unknown edge ID: " + edge.getId());
}
}
graph.visit(verifier());
verify();
verifyConnectedness(graph);
reset();
// Remove the collapsed criteria and make sure that the state reverts correctly
m_graphContainer.removeCriteria(collapsibleCriteria);
graph = m_graphContainer.getGraph();
//assertEquals(4, graph.getDisplayVertices().size());
//assertEquals(5, graph.getDisplayEdges().size());
assertEquals(3, graph.getDisplayVertices().size());
assertEquals(2, graph.getDisplayEdges().size());
collapsibleCriteria = new TestCriteria1();
m_graphContainer.addCriteria(collapsibleCriteria);
collapsibleCriteria = new TestCriteria2();
m_graphContainer.addCriteria(collapsibleCriteria);
assertEquals(4, m_graphContainer.getCriteria().length);
graph = m_graphContainer.getGraph();
assertEquals(3, m_graphContainer.getGraph().getDisplayVertices().size());
/*
* One edge is missing because of the VertexHopGraphProvider issue mentioned above.
assertEquals(
ArrayUtils.toString(m_graphContainer.getGraph().getDisplayEdges()),
5,
m_graphContainer.getGraph().getDisplayEdges().size()
);
*/
assertEquals(4, m_graphContainer.getGraph().getDisplayEdges().size());
for (Edge edge : graph.getDisplayEdges()) {
if (edge.getId().equals("collapsedTarget-e1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsed-e2")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("collapse-v3", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsed-e3")) {
assertEquals("collapse-v3", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e4")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("v1", edge.getTarget().getVertex().getId());
/**
* This edge is not found because of the issue mentioned above.
} else if (edge.getId().equals("collapsedTarget-ncs1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("collapse-v3", edge.getTarget().getVertex().getId());
*/
} else {
fail("Unknown edge ID: " + edge.getId());
}
}
}
use of org.opennms.features.topology.api.support.VertexHopGraphProvider in project opennms by OpenNMS.
the class VertexHopGraphProviderScaleTest method setUp.
@Before
public void setUp() {
SFreeTopologyProvider baseProvider = new SFreeTopologyProvider();
baseProvider.setNodeCount(10000);
baseProvider.setConnectedness(1.5);
baseProvider.refresh();
m_vertexCount = baseProvider.getVertices().size();
m_edgeCount = baseProvider.getEdges().size();
LOG.info("Vertex Count: {}", m_vertexCount);
LOG.info("Edge Count: {}", m_edgeCount);
m_provider = new VertexHopGraphProvider(baseProvider);
}
Aggregations