Search in sources :

Example 1 with SimpleLeafVertex

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

the class AbstractLinkdTopologyProvider method getVertex.

protected AbstractVertex getVertex(Integer nodeId, String ip, String sysobjectId, String nodeLabel, String tooltipText) {
    AbstractVertex vertex = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_LINKD, nodeId.toString(), 0, 0);
    vertex.setIconKey(getIconName(sysobjectId));
    vertex.setLabel(nodeLabel);
    vertex.setIpAddress(ip);
    vertex.setNodeID(nodeId);
    vertex.setTooltipText(tooltipText);
    return vertex;
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex)

Example 2 with SimpleLeafVertex

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

the class EnhancedLinkdTopologyProviderTest method testConnectVertices.

@Test
public void testConnectVertices() {
    m_topologyProvider.resetContainer();
    Vertex vertexId = m_topologyProvider.addVertex(0, 0);
    assertEquals(1, m_topologyProvider.getVertices().size());
    Vertex vertex0 = m_topologyProvider.getVertices().iterator().next();
    assertEquals("v0", vertex0.getId());
    Vertex vertex1 = m_topologyProvider.addVertex(0, 0);
    assertEquals(2, m_topologyProvider.getVertices().size());
    Edge edgeId = m_topologyProvider.connectVertices(vertex0, vertex1);
    assertEquals(1, m_topologyProvider.getEdges().size());
    SimpleLeafVertex sourceLeafVert = (SimpleLeafVertex) edgeId.getSource().getVertex();
    SimpleLeafVertex targetLeafVert = (SimpleLeafVertex) edgeId.getTarget().getVertex();
    assertEquals("v0", sourceLeafVert.getId());
    assertEquals("v1", targetLeafVert.getId());
    EdgeRef[] edgeIds = m_topologyProvider.getEdgeIdsForVertex(vertexId);
    assertEquals(1, edgeIds.length);
    assertEquals(edgeId, edgeIds[0]);
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) Edge(org.opennms.features.topology.api.topo.Edge) Test(org.junit.Test)

Example 3 with SimpleLeafVertex

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

the class SFreeTopologyProvider method createERRandomTopology.

private void createERRandomTopology(int numberOfNodes, double averageNumberofNeighboors) {
    Map<Integer, SimpleLeafVertex> nodes = new HashMap<Integer, SimpleLeafVertex>();
    List<AbstractEdge> edges = new ArrayList<>();
    for (Integer i = 0; i < numberOfNodes; i++) {
        SimpleLeafVertex vertex = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(i), 0, 0);
        vertex.setIconKey("sfree.system");
        vertex.setLabel("ErdosReniyNode" + i);
        nodes.put(i, vertex);
    }
    Double z = 0.5 * (numberOfNodes - 1);
    // Double p = averageNumberofNeighboors/z;
    Random r = new Random((new Date()).getTime());
    for (Integer start = 0; start < numberOfNodes; start++) {
        for (Integer end = start + 1; end < numberOfNodes; end++) {
            if (z * r.nextDouble() < averageNumberofNeighboors) {
                String edgeId = "link:" + start + "-" + end;
                SimpleConnector source = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(start).getId() + "-" + edgeId + "-connector", nodes.get(start));
                SimpleConnector target = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(end).getId() + "-" + edgeId + "-connector", nodes.get(end));
                edges.add(new AbstractEdge(TOPOLOGY_NAMESPACE_SFREE, edgeId, source, target));
            }
        }
    }
    addVertices(nodes.values().toArray(new Vertex[] {}));
    addEdges(edges.toArray(new Edge[] {}));
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) HashMap(java.util.HashMap) SimpleConnector(org.opennms.features.topology.api.topo.SimpleConnector) ArrayList(java.util.ArrayList) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) Date(java.util.Date) Random(java.util.Random) Edge(org.opennms.features.topology.api.topo.Edge) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge)

Example 4 with SimpleLeafVertex

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

the class SFreeTopologyProvider method createBARandomTopology.

private void createBARandomTopology(int numberOfNodes, double averageNumberofNeighboors) {
    Map<Integer, SimpleLeafVertex> nodes = new HashMap<Integer, SimpleLeafVertex>();
    List<AbstractEdge> edges = new ArrayList<>();
    for (int i = 0; i < 2 * averageNumberofNeighboors; i++) {
        LOG.debug("Creating First Cluster from: {}", i);
        int j = (i + 1) % ((int) Math.round(2 * averageNumberofNeighboors));
        SimpleLeafVertex vertexi = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(i), 0, 0);
        vertexi.setIconKey("sfree.system");
        vertexi.setLabel("BarabasiAlbertNode" + i);
        if (!nodes.containsKey(i)) {
            nodes.put(i, vertexi);
            LOG.debug("Added Node: {}", vertexi.getId());
        }
        SimpleLeafVertex vertexj = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(j), 0, 0);
        vertexj.setIconKey("sfree.system");
        vertexj.setLabel("BarabasiAlbertNode" + j);
        if (!nodes.containsKey(j)) {
            nodes.put(j, vertexj);
            LOG.debug("Added Node: {}", vertexj.getId());
        }
        String edgeId = "link:" + i + "-" + j;
        SimpleConnector source = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(i).getId() + "-" + edgeId + "-connector", nodes.get(i));
        SimpleConnector target = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(j).getId() + "-" + edgeId + "-connector", nodes.get(j));
        edges.add(new AbstractEdge(TOPOLOGY_NAMESPACE_SFREE, edgeId, source, target));
        LOG.debug("Added Link: {}", edgeId);
    }
    Random r = new Random((new Date()).getTime());
    for (int i = ((int) Math.floor(2 * averageNumberofNeighboors)); i < numberOfNodes; i++) {
        SimpleLeafVertex vertexi = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(i), 0, 0);
        vertexi.setIconKey("sfree.system");
        vertexi.setLabel("BarabasiAlbertNode" + i);
        nodes.put(i, vertexi);
        LOG.debug("Adding Node: {}", i);
        for (int times = 0; times < averageNumberofNeighboors; times++) {
            AbstractEdge edge;
            // choose node to attach to
            double d = r.nextDouble() * nodes.size();
            LOG.debug("Generated random position: {}", d);
            Long j = (long) d;
            LOG.debug("Try Adding edge: {}--->{}", j, i);
            String edgeId = "link:" + i + "-" + j.intValue();
            SimpleConnector source = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(i).getId() + "-" + edgeId + "-connector", nodes.get(i));
            SimpleConnector target = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(j.intValue()).getId() + "-" + edgeId + "-connector", nodes.get(j.intValue()));
            edge = new AbstractEdge(TOPOLOGY_NAMESPACE_SFREE, edgeId, source, target);
            if (i == j.intValue())
                continue;
            edges.add(edge);
        }
    // m links added
    }
    addVertices(nodes.values().toArray(new Vertex[] {}));
    addEdges(edges.toArray(new Edge[] {}));
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) HashMap(java.util.HashMap) SimpleConnector(org.opennms.features.topology.api.topo.SimpleConnector) ArrayList(java.util.ArrayList) SimpleLeafVertex(org.opennms.features.topology.api.topo.SimpleLeafVertex) Date(java.util.Date) Random(java.util.Random) Edge(org.opennms.features.topology.api.topo.Edge) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge)

Aggregations

SimpleLeafVertex (org.opennms.features.topology.api.topo.SimpleLeafVertex)4 Edge (org.opennms.features.topology.api.topo.Edge)3 Vertex (org.opennms.features.topology.api.topo.Vertex)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)2 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)2 SimpleConnector (org.opennms.features.topology.api.topo.SimpleConnector)2 Test (org.junit.Test)1 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)1