Search in sources :

Example 16 with Edge

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

the class NCSEdgeProvider method getEdges.

/**
 * This factory works by using {@link NCSServiceCriteria} to construct edges based on
 * connecting all of the ServiceElements that make up a Service to each other.
 *
 * @param criteria An {@link NCSServiceCriteria} object
 */
@Override
public List<Edge> getEdges(Criteria... criteria) {
    List<Edge> retval = new ArrayList<>();
    for (Criteria criterium : criteria) {
        try {
            NCSServiceCriteria crit = (NCSServiceCriteria) criterium;
            for (Long id : crit) {
                NCSComponent service = m_dao.get(id);
                if (service == null) {
                    LoggerFactory.getLogger(this.getClass()).warn("NCSComponent not found for ID {}", id);
                } else {
                    // Check foreignsource of the subcomponents to make sure it matches the Service's foreignsource
                    NCSComponent[] subs = checkForeignSource(service.getForeignSource(), service.getSubcomponents());
                    // Connect all of the ServiceElements to one another
                    for (int i = 0; i < subs.length; i++) {
                        for (int j = i + 1; j < subs.length; j++) {
                            String foreignSource = null, foreignId = null;
                            OnmsNode sourceNode = null, targetNode = null;
                            NodeIdentification ident = subs[i].getNodeIdentification();
                            String sourceLabel = subs[i].getName();
                            if (ident != null) {
                                foreignSource = ident.getForeignSource();
                                foreignId = ident.getForeignId();
                                sourceNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
                                if (sourceNode == null) {
                                    continue;
                                }
                                if (sourceLabel == null) {
                                    sourceLabel = sourceNode.getLabel();
                                }
                            }
                            ident = subs[j].getNodeIdentification();
                            String targetLabel = subs[j].getName();
                            if (ident != null) {
                                foreignSource = ident.getForeignSource();
                                foreignId = ident.getForeignId();
                                targetNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
                                if (targetNode == null) {
                                    continue;
                                }
                                if (targetLabel == null) {
                                    targetLabel = targetNode.getLabel();
                                }
                            }
                            String sourceElementName = subs[i].getForeignSource() + "::" + subs[i].getForeignId();
                            String targetElementName = subs[j].getForeignSource() + "::" + subs[j].getForeignId();
                            retval.add(new NCSEdge(subs[i].getForeignId(), service.getName(), sourceElementName, targetElementName, new NCSVertex(String.valueOf(sourceNode.getId()), sourceLabel), new NCSVertex(String.valueOf(targetNode.getId()), targetLabel)));
                        }
                    }
                }
            }
        } catch (ClassCastException e) {
        }
    }
    return retval;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ArrayList(java.util.ArrayList) Criteria(org.opennms.features.topology.api.topo.Criteria) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) NodeIdentification(org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification) Edge(org.opennms.features.topology.api.topo.Edge) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge)

Example 17 with Edge

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

the class NCSServicePath method getEdges.

public List<Edge> getEdges() {
    List<Edge> edges = new ArrayList<>();
    if (m_vertices.size() >= 2) {
        String deviceA = m_vertices.get(0).getLabel();
        String deviceZ = m_vertices.get(m_vertices.size() - 1).getLabel();
        ListIterator<NCSVertex> iterator = m_vertices.listIterator();
        while (iterator.hasNext()) {
            NCSVertex sourceRef = iterator.next();
            if (iterator.hasNext()) {
                NCSVertex targetRef = m_vertices.get(iterator.nextIndex());
                NCSPathEdge ncsPathEdge = new NCSPathEdge(m_serviceName, deviceA, deviceZ, sourceRef, targetRef);
                ncsPathEdge.setStyleName("ncs edge direct");
                edges.add(ncsPathEdge);
            }
        }
    }
    return edges;
}
Also used : NCSVertex(org.opennms.features.topology.plugins.ncs.NCSEdgeProvider.NCSVertex) ArrayList(java.util.ArrayList) Edge(org.opennms.features.topology.api.topo.Edge) NCSPathEdge(org.opennms.features.topology.plugins.ncs.NCSPathEdgeProvider.NCSPathEdge) NCSPathEdge(org.opennms.features.topology.plugins.ncs.NCSPathEdgeProvider.NCSPathEdge)

Example 18 with Edge

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

the class ShowNCSPathOperation method getVertexRefsForNCSService.

private Collection<VertexRef> getVertexRefsForNCSService(NCSServiceCriteria storedCriteria) {
    List<Edge> edges = m_ncsEdgeProvider.getEdges(storedCriteria);
    Set<VertexRef> vertRefList = new HashSet<>();
    for (Edge edge : edges) {
        vertRefList.add(edge.getSource().getVertex());
        vertRefList.add(edge.getTarget().getVertex());
    }
    return vertRefList;
}
Also used : VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) HashSet(java.util.HashSet)

Example 19 with Edge

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

the class VertexHopGraphProvider method collapseEdges.

/**
 * This function assumes that all criteria passed in are marked as collapsed.
 * @param edges
 * @param criteria
 * @return
 */
public static Set<Edge> collapseEdges(Set<Edge> edges, CollapsibleCriteria[] criteria) {
    // Make a map of all of the vertices to their new collapsed representations
    Map<VertexRef, Set<Vertex>> vertexToCollapsedVertices = getMapOfVerticesToCollapsedVertices(criteria);
    if (vertexToCollapsedVertices.size() > 0) {
        Set<Edge> retval = new HashSet<Edge>();
        for (Edge edge : edges) {
            // Add the original edge to retval unless we replace it with an edge that points to a
            // collapsed vertex
            boolean addOriginalEdge = true;
            // If the source vertex is in the collapsed list...
            Set<Vertex> collapsedSources = vertexToCollapsedVertices.get(edge.getSource().getVertex());
            if (collapsedSources != null) {
                for (VertexRef collapsedSource : collapsedSources) {
                    // Add a new edge with the source as the collapsed vertex
                    Edge newCollapsedEdge = edge.clone();
                    newCollapsedEdge.setId("collapsedSource-" + newCollapsedEdge.getId());
                    newCollapsedEdge.getSource().setVertex(collapsedSource);
                    retval.add(newCollapsedEdge);
                }
                // Since we just added a replacement edge, don't add the original
                addOriginalEdge = false;
            }
            Set<Vertex> collapsedTargets = vertexToCollapsedVertices.get(edge.getTarget().getVertex());
            if (collapsedTargets != null) {
                for (VertexRef collapsedTarget : collapsedTargets) {
                    // Add a new edge with the target as the collapsed vertex
                    Edge newCollapsedEdge = edge.clone();
                    newCollapsedEdge.setId("collapsedTarget-" + newCollapsedEdge.getId());
                    newCollapsedEdge.getTarget().setVertex(collapsedTarget);
                    retval.add(newCollapsedEdge);
                }
                // Since we just added a replacement edge, don't add the original
                addOriginalEdge = false;
            }
            // 
            if (collapsedSources != null && collapsedTargets != null) {
                for (VertexRef collapsedEndpoint : collapsedSources) {
                    for (VertexRef collapsedTarget : collapsedTargets) {
                        // Add a new edge with the target as the collapsed vertex
                        Edge newCollapsedEdge = edge.clone();
                        newCollapsedEdge.setId("collapsed-" + newCollapsedEdge.getId());
                        newCollapsedEdge.getSource().setVertex(collapsedEndpoint);
                        newCollapsedEdge.getTarget().setVertex(collapsedTarget);
                        retval.add(newCollapsedEdge);
                    }
                }
                // Since we just added a replacement edge, don't add the original
                addOriginalEdge = false;
            }
            // Add the original edge if it wasn't replaced with an edge to a collapsed vertex
            if (addOriginalEdge) {
                retval.add(edge);
            }
        }
        return retval;
    } else {
        return edges;
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) HashSet(java.util.HashSet) Set(java.util.Set) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) HashSet(java.util.HashSet)

Example 20 with Edge

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

the class HierarchyLayoutAlgorithm method updateLayout.

/**
 * Updates the current layout by extracting the containers graph and then perform a (x,y) tranformation
 * of all vertices.
 *
 * @param graph The container of the current graph. Contains all relevant information to perform the transformation
 *                       of the {@link Graph} by changing its {@link Layout}
 */
@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    // fully level aware. See NMS-8703
    if (isFullyLevelAware(graph)) {
        final HierarchyLayout<VertexRef, Edge> treeLayout = createTreeLayout(graph);
        applyLayoutPositions(graph.getDisplayVertices(), treeLayout, graphLayout);
    } else {
        // SEE NMS-8703
        LOG.warn("The selected graph is not fully level aware. Cannot layout hierarchical. Falling back to D3 Layout");
        new D3TopoLayoutAlgorithm().updateLayout(graph);
    }
}
Also used : Layout(org.opennms.features.topology.api.Layout) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Aggregations

Edge (org.opennms.features.topology.api.topo.Edge)37 Vertex (org.opennms.features.topology.api.topo.Vertex)22 VertexRef (org.opennms.features.topology.api.topo.VertexRef)22 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)11 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Layout (org.opennms.features.topology.api.Layout)10 Point (org.opennms.features.topology.api.Point)8 ArrayList (java.util.ArrayList)7 Dimension (java.awt.Dimension)5 HashSet (java.util.HashSet)5 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)5 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)5 Set (java.util.Set)4 Test (org.junit.Test)4 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)4 SimpleLeafVertex (org.opennms.features.topology.api.topo.SimpleLeafVertex)4 HashMap (java.util.HashMap)3 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)3 Criteria (org.opennms.features.topology.api.topo.Criteria)3 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)2