Search in sources :

Example 16 with DefaultVertexRef

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

the class AlarmHopCriteria method createVertices.

private Set<VertexRef> createVertices(List<OnmsAlarm> alarms) {
    Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
    for (OnmsAlarm alarm : alarms) {
        OnmsNode node = alarm.getNode();
        if (node == null) {
            continue;
        }
        vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
    }
    return vertices;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) TreeSet(java.util.TreeSet) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) RefComparator(org.opennms.features.topology.api.topo.RefComparator)

Example 17 with DefaultVertexRef

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

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

the class VEProviderGraphContainerTest method expectVertex.

private void expectVertex(String namespace, String vertexId, String styles) {
    DefaultVertexRef vertexRef = new DefaultVertexRef(namespace, vertexId);
    m_expectedVertices.add(vertexRef);
    m_expectedVertexStyles.put(vertexRef, styles);
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef)

Example 19 with DefaultVertexRef

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

the class ManualLayoutAlgorithmTest method verifyLayoutCoordinatesHavePriority.

/*
     * If persisted layout is defined, verify that it has priority.
     */
@Test
public void verifyLayoutCoordinatesHavePriority() {
    final GraphProvider graphProvider = new SimpleGraphBuilder("dummy").vertex("vertex1").vX(1).vY(1).get();
    final ManualTest test = new ManualTest(graphProvider);
    final LayoutEntity persistedLayout = new LayoutEntity();
    int x = 5;
    int y = 5;
    for (VertexRef eachVertex : graphProvider.getVertices()) {
        VertexPositionEntity vertexPositionEntity = new VertexPositionEntity();
        vertexPositionEntity.setVertexRef(LayoutManager.toVertexRefEntity(eachVertex));
        vertexPositionEntity.setPosition(new PointEntity(x++, y++));
        persistedLayout.addVertexPosition(vertexPositionEntity);
    }
    Mockito.when(test.layoutManager.loadLayout(test.graph)).thenReturn(persistedLayout);
    new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
    Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "vertex1"), new Point(5, 5)).build(), test.layout.getLocations());
}
Also used : VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point) Test(org.junit.Test)

Example 20 with DefaultVertexRef

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

the class SearchBox method removeIfSpecialURLCase.

private void removeIfSpecialURLCase(SearchResult searchResult, GraphContainer graphContainer) {
    DefaultVertexRef vertexRef = new DefaultVertexRef(searchResult.getNamespace(), searchResult.getId(), searchResult.getLabel());
    DefaultVertexHopCriteria criteria = new DefaultVertexHopCriteria(vertexRef);
    graphContainer.removeCriteria(criteria);
}
Also used : DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef)

Aggregations

DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)27 VertexRef (org.opennms.features.topology.api.topo.VertexRef)19 Test (org.junit.Test)10 Point (org.opennms.features.topology.api.Point)6 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)4 RefComparator (org.opennms.features.topology.api.topo.RefComparator)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)3 VertexHopGraphProvider (org.opennms.features.topology.api.support.VertexHopGraphProvider)3 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)3 Vertex (org.opennms.features.topology.api.topo.Vertex)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2