use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method setBehaviour.
private void setBehaviour(GraphContainer graphContainerMock) {
MapViewManager mapViewManagerMock = Mockito.mock(MapViewManager.class);
SelectionManager selectionManagerMock = Mockito.mock(SelectionManager.class);
Mockito.when(mapViewManagerMock.getCurrentBoundingBox()).thenReturn(new BoundingBox(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE));
Mockito.when(selectionManagerMock.getSelectedVertexRefs()).thenReturn(new ArrayList<VertexRef>());
Mockito.when(graphContainerMock.getGraph()).thenReturn(graphMock);
Mockito.when(graphContainerMock.getSemanticZoomLevel()).thenReturn(0);
Mockito.when(graphContainerMock.getLayoutAlgorithm()).thenReturn(new CircleLayoutAlgorithm());
Mockito.when(graphContainerMock.getMapViewManager()).thenReturn(mapViewManagerMock);
Mockito.when(graphContainerMock.getSelectionManager()).thenReturn(selectionManagerMock);
Mockito.when(graphContainerMock.getTopologyServiceClient()).thenReturn(topologyServiceClientMock);
Mockito.doAnswer(invocationOnMock -> capturedCriteria.toArray(new Criteria[capturedCriteria.size()])).when(graphContainerMock).getCriteria();
Mockito.doAnswer(invocationOnMock -> {
capturedCriteria.clear();
return null;
}).when(graphContainerMock).clearCriteria();
Mockito.doAnswer(invocation -> {
if (invocation.getArguments()[0] != null && invocation.getArguments()[0] instanceof Criteria) {
capturedCriteria.add((Criteria) invocation.getArguments()[0]);
}
return null;
}).when(graphContainerMock).addCriteria(Matchers.any(Criteria.class));
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getVertexRefsBy.
@Override
public Set<VertexRef> getVertexRefsBy(SearchResult searchResult, GraphContainer container) {
LOG.debug("SearchProvider->getVertexRefsBy: called with search result: '{}'", searchResult);
org.opennms.features.topology.api.topo.Criteria criterion = findCriterion(searchResult.getId(), container);
Set<VertexRef> vertices = ((VertexHopCriteria) criterion).getVertices();
LOG.debug("SearchProvider->getVertexRefsBy: found '{}' vertices.", vertices.size());
return vertices;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProviderTest method test.
@SuppressWarnings("deprecation")
@Test
public void test() throws Exception {
assertEquals(8, m_topologyProvider.getVertices().size());
// Add v0 vertex
Vertex vertexA = m_topologyProvider.addVertex(50, 100);
assertEquals(9, m_topologyProvider.getVertices().size());
assertEquals("v0", vertexA.getId());
// LoggerFactory.getLogger(this.getClass()).debug(m_topologyProvider.getVertices().get(0).toString());
assertTrue(m_topologyProvider.containsVertexId(vertexA));
assertTrue(m_topologyProvider.containsVertexId(new DefaultVertexRef("nodes", "v0")));
assertFalse(m_topologyProvider.containsVertexId(new DefaultVertexRef("nodes", "v1")));
((AbstractVertex) vertexA).setIpAddress("10.0.0.4");
// Search by VertexRef
VertexRef vertexAref = new DefaultVertexRef(m_topologyProvider.getNamespace(), "v0");
VertexRef vertexBref = new DefaultVertexRef(m_topologyProvider.getNamespace(), "v1");
assertEquals(1, m_topologyProvider.getVertices(Collections.singletonList(vertexAref)).size());
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(vertexBref)).size());
// Add v1 vertex
Vertex vertexB = m_topologyProvider.addVertex(100, 50);
assertEquals("v1", vertexB.getId());
assertTrue(m_topologyProvider.containsVertexId(vertexB));
assertTrue(m_topologyProvider.containsVertexId("v1"));
assertEquals(1, m_topologyProvider.getVertices(Collections.singletonList(vertexBref)).size());
// Added 3 more vertices
Vertex vertexC = m_topologyProvider.addVertex(100, 150);
Vertex vertexD = m_topologyProvider.addVertex(150, 100);
Vertex vertexE = m_topologyProvider.addVertex(200, 200);
assertEquals(13, m_topologyProvider.getVertices().size());
// Add 2 groups
Vertex group1 = m_topologyProvider.addGroup("Group 1", Constants.GROUP_ICON_KEY);
Vertex group2 = m_topologyProvider.addGroup("Group 2", Constants.GROUP_ICON_KEY);
assertEquals(15, m_topologyProvider.getVertices().size());
// Link v0, v1 to Group 1 and v2, v3 to Group 2
m_topologyProvider.setParent(vertexA, group1);
m_topologyProvider.setParent(vertexB, group1);
m_topologyProvider.setParent(vertexC, group2);
m_topologyProvider.setParent(vertexD, group2);
// Connect various vertices together
m_topologyProvider.connectVertices(vertexA, vertexB);
m_topologyProvider.connectVertices(vertexA, vertexC);
m_topologyProvider.connectVertices(vertexB, vertexC);
m_topologyProvider.connectVertices(vertexB, vertexD);
m_topologyProvider.connectVertices(vertexC, vertexD);
m_topologyProvider.connectVertices(vertexA, vertexE);
m_topologyProvider.connectVertices(vertexD, vertexE);
assertEquals(1, m_topologyProvider.getVertices(Collections.singletonList(vertexAref)).size());
assertEquals(1, m_topologyProvider.getVertices(Collections.singletonList(vertexBref)).size());
assertEquals(15, m_topologyProvider.getVertices().size());
assertEquals(3, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(vertexAref)).length);
assertEquals(3, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(vertexBref)).length);
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(group1));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(group2));
assertEquals(1, m_topologyProvider.getSemanticZoomLevel(vertexA));
assertEquals(1, m_topologyProvider.getSemanticZoomLevel(vertexB));
assertEquals(1, m_topologyProvider.getSemanticZoomLevel(vertexC));
assertEquals(1, m_topologyProvider.getSemanticZoomLevel(vertexD));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexE));
m_topologyProvider.resetContainer();
// Ensure that the topology provider has been erased
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(vertexAref)).size());
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(vertexBref)).size());
assertEquals(0, m_topologyProvider.getVertices().size());
assertEquals(0, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(vertexAref)).length);
assertEquals(0, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(vertexBref)).length);
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(group1));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(group2));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexA));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexB));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexC));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexD));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexE));
m_topologyProvider.refresh();
// Ensure that all of the content has been reloaded properly
// Plain vertices should not be reloaded from the XML
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(vertexAref)).size());
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(vertexBref)).size());
// Groups should not be reloaded, because they are not persisted
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(group1)).size());
assertEquals(0, m_topologyProvider.getVertices(Collections.singletonList(group2)).size());
assertEquals(8, m_topologyProvider.getVertices().size());
assertEquals(0, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(vertexAref)).length);
assertEquals(0, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(vertexBref)).length);
assertEquals(0, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(group1)).length);
assertEquals(0, m_topologyProvider.getEdgeIdsForVertex(m_topologyProvider.getVertex(group2)).length);
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(group1));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(group2));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexA));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexB));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexC));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexD));
assertEquals(0, m_topologyProvider.getSemanticZoomLevel(vertexE));
}
use of org.opennms.features.topology.api.topo.VertexRef 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.topo.VertexRef in project opennms by OpenNMS.
the class FRLayoutTest method testFRLayout.
@Test
public void testFRLayout() {
Graph g = m_graphContainer.getGraph();
List<Vertex> vertices = new ArrayList<>(g.getDisplayVertices());
TopoFRLayout<VertexRef, EdgeRef> layout = runFRLayout(g, g.getLayout(), vertices);
Vertex v1 = vertices.get(0);
Vertex v2 = vertices.get(1);
Vertex v3 = vertices.get(2);
double distance = calcDistance(layout, v1, v2);
double distance2 = calcDistance(layout, v2, v3);
double distance3 = calcDistance(layout, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
// Run again then refactor
TopoFRLayout<VertexRef, EdgeRef> layout2 = runFRLayout(g, g.getLayout(), vertices);
distance = calcDistance(layout2, v1, v2);
distance2 = calcDistance(layout2, v2, v3);
distance3 = calcDistance(layout2, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
TopoFRLayout<VertexRef, EdgeRef> layout3 = runFRLayout(g, g.getLayout(), vertices);
distance = calcDistance(layout3, v1, v2);
distance2 = calcDistance(layout3, v2, v3);
distance3 = calcDistance(layout3, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
}
Aggregations