Search in sources :

Example 21 with VertexRef

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

the class RealUltimateLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<? extends Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    Dimension size = selectLayoutSize(graph);
    Dimension paddedSize = new Dimension((int) (size.getWidth() * .75), (int) (size.getHeight() * .75));
    doISOMLayout(graphLayout, jungGraph, size);
    doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
    doFRLayout(graphLayout, jungGraph, paddedSize, (int) (size.getWidth() / 8.0), (int) (size.getHeight() / 8.0));
    doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) NonStupidISOMLayout(org.opennms.features.topology.app.internal.jung.ISOMLayoutAlgorithm.NonStupidISOMLayout) Layout(org.opennms.features.topology.api.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Dimension(java.awt.Dimension) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 22 with VertexRef

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

the class HierarchyLayoutAlgorithm method convert.

private edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> convert(final Graph g) {
    if (!isFullyLevelAware(g)) {
        throw new IllegalStateException("The graph is not LevelAware. Cannot apply Hierarchy Layout. Aborting");
    }
    // We need to sort the elements. For this purpose we use the DirectedOrderedSparseMultigraph
    final edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> jungGraph = new DirectedOrderedSparseMultigraph<>();
    final Collection<Vertex> displayVertices = g.getDisplayVertices();
    // Sort by level
    final List<Vertex> sortedVertices = displayVertices.stream().filter(v -> v instanceof LevelAware).sorted(new Comparator<Vertex>() {

        @Override
        public int compare(Vertex o1, Vertex o2) {
            return Integer.compare(((LevelAware) o1).getLevel(), ((LevelAware) o2).getLevel());
        }
    }).collect(Collectors.toList());
    // Build the graph
    for (VertexRef v : sortedVertices) {
        jungGraph.addVertex(v);
    }
    // The order of edges does not matter
    for (Edge e : g.getDisplayEdges()) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    return jungGraph;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) DirectedOrderedSparseMultigraph(edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph) DirectedOrderedSparseMultigraph(edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) LevelAware(org.opennms.features.topology.api.topo.LevelAware)

Example 23 with VertexRef

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

the class VmwareStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    final List<AbstractVertex> vmwareVertices = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (AbstractVertex) v).collect(Collectors.toList());
    // All vertices associated with a node id
    final Map<Integer, VertexRef> nodeIdMap = vmwareVertices.stream().filter(v -> v.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // Set the result
    Map<VertexRef, Status> resultMap = Maps.newHashMap();
    for (AbstractVertex eachVertex : vmwareVertices) {
        AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
        if (alarmSummary != null) {
            resultMap.put(eachVertex, new DefaultStatus(alarmSummary.getMaxSeverity().getLabel(), 0));
        }
    }
    return resultMap;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 24 with VertexRef

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

the class GraphMLSearchProvider method onFocusSearchResult.

@Override
public void onFocusSearchResult(SearchResult searchResult, OperationContext operationContext) {
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final DefaultVertexRef vertexRef = new DefaultVertexRef(searchResult.getNamespace(), searchResult.getId(), searchResult.getLabel());
    if (graphContainer.getTopologyServiceClient().getVertex(vertexRef) == null) {
        // The vertex to add to focus is not in the current layer
        // Find the GraphProvider it belongs to
        Optional<GraphProvider> first = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(eachProvider -> eachProvider.getNamespace().equals(searchResult.getNamespace())).findFirst();
        // If there is a graph provider (which should) select it
        if (first.isPresent() && first.get().getVertex(vertexRef) != null) {
            graphContainer.selectTopologyProvider(first.get());
            graphContainer.clearCriteria();
        }
    }
    super.onFocusSearchResult(searchResult, operationContext);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Objects(java.util.Objects) GraphContainer(org.opennms.features.topology.api.GraphContainer) List(java.util.List) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) SearchResult(org.opennms.features.topology.api.topo.SearchResult) OperationContext(org.opennms.features.topology.api.OperationContext) SimpleSearchProvider(org.opennms.features.topology.api.topo.SimpleSearchProvider) Optional(java.util.Optional) SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) VertexRef(org.opennms.features.topology.api.topo.VertexRef) ArrayList(java.util.ArrayList) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider)

Example 25 with VertexRef

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

the class GraphMLVertexStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    // All vertices for the current vertexProvider
    final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
    // All vertices associated with a node id
    final Map<Integer, VertexRef> nodeIdMap = graphMLVertices.stream().filter(eachVertex -> eachVertex.getNodeID() != null).collect(Collectors.toMap(AbstractVertex::getNodeID, Function.identity()));
    // Alarm summary for each node id
    final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = getAlarmSummaries(nodeIdMap.keySet());
    // Set the result
    Map<VertexRef, Status> resultMap = Maps.newHashMap();
    for (GraphMLVertex eachVertex : graphMLVertices) {
        AlarmSummary alarmSummary = nodeIdToAlarmSummaryMap.get(eachVertex.getNodeID());
        DefaultStatus status = alarmSummary == null ? new VertexStatus(OnmsSeverity.NORMAL) : new VertexStatus(alarmSummary.getMaxSeverity(), alarmSummary.getAlarmCount());
        resultMap.put(eachVertex, status);
    }
    return resultMap;
}
Also used : AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Collection(java.util.Collection) Set(java.util.Set) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

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