Search in sources :

Example 26 with VertexRef

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

the class ApplicationVertexTest method testHierarchy.

@Test
public void testHierarchy() {
    ApplicationVertex vertex = createVertex("100");
    vertex.addChildren(createVertex("service:1"));
    vertex.addChildren(createVertex("service:2"));
    Assert.assertEquals(true, vertex.isRoot());
    Assert.assertEquals(false, vertex.isLeaf());
    Assert.assertEquals(true, vertex.isPartOf("100"));
    Assert.assertEquals(false, vertex.isPartOf("101"));
    // Verify first level
    for (VertexRef eachRef : vertex.getChildren()) {
        Assert.assertEquals(ApplicationTopologyProvider.TOPOLOGY_NAMESPACE, eachRef.getNamespace());
        ApplicationVertex child = (ApplicationVertex) eachRef;
        Assert.assertEquals(false, child.isRoot());
        Assert.assertEquals(true, child.isLeaf());
        Assert.assertEquals(vertex, child.getRoot());
        Assert.assertEquals(vertex, child.getParent());
        Assert.assertEquals(true, child.isPartOf("100"));
        Assert.assertEquals(false, child.isPartOf("101"));
    }
}
Also used : VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 27 with VertexRef

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

the class NCSSearchProvider method getVertexRefsForEdges.

public static Set<VertexRef> getVertexRefsForEdges(NCSEdgeProvider provider, Criteria criteria) {
    Set<VertexRef> vertexRefs = new TreeSet<VertexRef>(new RefComparator());
    List<Edge> edges = provider.getEdges(criteria);
    for (Edge ncsEdge : edges) {
        vertexRefs.add(ncsEdge.getSource().getVertex());
        vertexRefs.add(ncsEdge.getTarget().getVertex());
    }
    return vertexRefs;
}
Also used : TreeSet(java.util.TreeSet) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) RefComparator(org.opennms.features.topology.api.topo.RefComparator)

Example 28 with VertexRef

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

the class EventsAlarmsOperation method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    try {
        String label = "";
        int nodeID = -1;
        if (targets != null) {
            for (final VertexRef target : targets) {
                final String labelValue = getLabelValue(operationContext, target);
                final Integer nodeValue = getNodeIdValue(operationContext, target);
                if (nodeValue != null && nodeValue > 0) {
                    label = labelValue == null ? "" : labelValue;
                    nodeID = nodeValue;
                    break;
                }
            }
        }
        final Node node = new Node(nodeID, null, label);
        final String eventUrl;
        final String alarmUrl;
        if (node.getNodeID() >= 0) {
            eventUrl = getEventsURL() + "?filter=node%3D" + node.getNodeID();
            alarmUrl = getAlarmsURL() + "?sortby=id&acktype=unacklimit=20&filter=node%3D" + node.getNodeID();
        } else {
            eventUrl = getEventsURL();
            alarmUrl = getAlarmsURL();
        }
        final URL fullEventUrl = new URL(getFullUrl(eventUrl));
        final URL fullAlarmUrl = new URL(getFullUrl(alarmUrl));
        operationContext.getMainWindow().addWindow(new EventsAlarmsWindow(node, fullEventUrl, fullAlarmUrl));
    } catch (final Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException("Failed to create event/alarm window.", e);
        }
    }
}
Also used : EventsAlarmsWindow(org.opennms.features.topology.netutils.internal.EventsAlarmsWindow) Node(org.opennms.features.topology.netutils.internal.Node) VertexRef(org.opennms.features.topology.api.topo.VertexRef) URL(java.net.URL)

Example 29 with VertexRef

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

the class PingOperation method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    final VertexRef target = targets.get(0);
    final Vertex vertex = getVertexItem(operationContext, target);
    final Optional<OnmsNode> node = getNodeIfAvailable(vertex);
    final List<String> locations = monitoringLocationDao.findAll().stream().map(eachLocation -> eachLocation.getLocationName()).collect(Collectors.toList());
    final String defaultLocation = node.isPresent() ? node.get().getLocation().getLocationName() : MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    final List<InetAddress> ipAddresses = node.isPresent() ? Lists.newArrayList(node.get().getIpInterfaces()).stream().map(eachInterface -> eachInterface.getIpAddress()).collect(Collectors.toList()) : Lists.newArrayList(InetAddressUtils.addr(vertex.getIpAddress()));
    final InetAddress defaultIp = getDefaultIp(vertex, node);
    final String caption = String.format("Ping - %s (%s)", vertex.getLabel(), vertex.getIpAddress());
    new PingWindow(pingClient, locations, ipAddresses, defaultLocation, defaultIp, caption).open();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Vertex(org.opennms.features.topology.api.topo.Vertex) Collectors(java.util.stream.Collectors) InetAddress(java.net.InetAddress) Objects(java.util.Objects) AbstractOperation(org.opennms.features.topology.api.AbstractOperation) Strings(com.google.common.base.Strings) List(java.util.List) LocationAwarePingClient(org.opennms.netmgt.icmp.proxy.LocationAwarePingClient) Lists(com.google.common.collect.Lists) OperationContext(org.opennms.features.topology.api.OperationContext) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) Optional(java.util.Optional) PingWindow(org.opennms.features.topology.netutils.internal.ping.PingWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsNode(org.opennms.netmgt.model.OnmsNode) Vertex(org.opennms.features.topology.api.topo.Vertex) OnmsNode(org.opennms.netmgt.model.OnmsNode) PingWindow(org.opennms.features.topology.netutils.internal.ping.PingWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef) InetAddress(java.net.InetAddress)

Example 30 with VertexRef

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

the class VertexHopGraphProvider method getVertices.

@Override
public List<Vertex> getVertices(Criteria... criteria) {
    // If we have a IgnoreHopCriteria, just return all existing vertices
    for (Criteria criterium : criteria) {
        try {
            IgnoreHopCriteria ignoreHopCriteria = (IgnoreHopCriteria) criterium;
            return m_delegate.getVertices();
        } catch (ClassCastException e) {
        }
    }
    // Otherwise consider vertices szl and focus nodes
    Set<VertexRef> focusNodes = getFocusNodes(criteria);
    int maxSemanticZoomLevel = getMaxSemanticZoomLevel(criteria);
    // Clear the existing semantic zoom level values
    m_semanticZoomLevels.clear();
    int semanticZoomLevel = 0;
    // If we didn't find any matching nodes among the focus nodes...
    if (focusNodes.size() < 1) {
        // ...then return an empty list of vertices
        return Collections.emptyList();
    // return allVertices;
    }
    Map<VertexRef, Set<VertexRef>> neighborMap = new HashMap<VertexRef, Set<VertexRef>>();
    List<Edge> edges = m_delegate.getEdges(criteria);
    for (Edge edge : edges) {
        VertexRef src = edge.getSource().getVertex();
        VertexRef tgt = edge.getTarget().getVertex();
        Set<VertexRef> srcNeighbors = neighborMap.get(src);
        if (srcNeighbors == null) {
            srcNeighbors = new HashSet<VertexRef>();
            neighborMap.put(src, srcNeighbors);
        }
        srcNeighbors.add(tgt);
        Set<VertexRef> tgtNeighbors = neighborMap.get(tgt);
        if (tgtNeighbors == null) {
            tgtNeighbors = new HashSet<VertexRef>();
            neighborMap.put(tgt, tgtNeighbors);
        }
        tgtNeighbors.add(src);
    }
    Set<Vertex> processed = new HashSet<Vertex>();
    Set<VertexRef> neighbors = new HashSet<VertexRef>();
    Set<VertexRef> workingSet = new HashSet<VertexRef>(focusNodes);
    // Put a limit on the SZL in case we infinite loop for some reason
    while (semanticZoomLevel <= maxSemanticZoomLevel && workingSet.size() > 0) {
        neighbors.clear();
        for (VertexRef vertexRef : workingSet) {
            // Only consider Vertex if it is actually not filtered by the criteria (which it might)
            Vertex vertex = getVertex(vertexRef, criteria);
            if (vertex != null) {
                if (m_semanticZoomLevels.containsKey(vertexRef)) {
                    throw new IllegalStateException("Calculating semantic zoom level for vertex that has already been calculated: " + vertexRef.toString());
                }
                m_semanticZoomLevels.put(vertexRef, semanticZoomLevel);
                Set<VertexRef> refs = neighborMap.get(vertexRef);
                if (refs != null) {
                    neighbors.addAll(refs);
                }
                processed.add(vertex);
            }
        }
        neighbors.removeAll(processed);
        workingSet.clear();
        workingSet.addAll(neighbors);
        // Increment the semantic zoom level
        semanticZoomLevel++;
    }
    processed = collapseVertices(processed, getCollapsedCriteria(criteria));
    return new ArrayList<Vertex>(processed);
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) 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)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)94 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)30 Vertex (org.opennms.features.topology.api.topo.Vertex)29 Point (org.opennms.features.topology.api.Point)23 Edge (org.opennms.features.topology.api.topo.Edge)22 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 List (java.util.List)13 Criteria (org.opennms.features.topology.api.topo.Criteria)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 Collectors (java.util.stream.Collectors)12 Layout (org.opennms.features.topology.api.Layout)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 GraphContainer (org.opennms.features.topology.api.GraphContainer)10 Collection (java.util.Collection)9 Map (java.util.Map)9 Set (java.util.Set)8 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)8