Search in sources :

Example 1 with VertexHopGraphProvider

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);
    }
}
Also used : GraphML(org.opennms.features.graphml.model.GraphML) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GraphMLEdge(org.opennms.features.graphml.model.GraphMLEdge) FileInputStream(java.io.FileInputStream)

Example 2 with VertexHopGraphProvider

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());
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) SemanticZoomLevelCriteria(org.opennms.features.topology.api.support.SemanticZoomLevelCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) SimpleMetaTopologyProvider(org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider) Graph(org.opennms.features.topology.api.Graph) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) Test(org.junit.Test)

Example 3 with VertexHopGraphProvider

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);
}
Also used : VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) Before(org.junit.Before)

Aggregations

VertexHopGraphProvider (org.opennms.features.topology.api.support.VertexHopGraphProvider)3 VertexRef (org.opennms.features.topology.api.topo.VertexRef)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Before (org.junit.Before)1 Test (org.junit.Test)1 GraphML (org.opennms.features.graphml.model.GraphML)1 GraphMLEdge (org.opennms.features.graphml.model.GraphMLEdge)1 GraphMLGraph (org.opennms.features.graphml.model.GraphMLGraph)1 Graph (org.opennms.features.topology.api.Graph)1 SemanticZoomLevelCriteria (org.opennms.features.topology.api.support.SemanticZoomLevelCriteria)1 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)1 Criteria (org.opennms.features.topology.api.topo.Criteria)1 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)1 Edge (org.opennms.features.topology.api.topo.Edge)1 SimpleMetaTopologyProvider (org.opennms.features.topology.api.topo.SimpleMetaTopologyProvider)1 DefaultTopologyService (org.opennms.features.topology.app.internal.service.DefaultTopologyService)1 SimpleServiceLocator (org.opennms.features.topology.app.internal.service.SimpleServiceLocator)1