Search in sources :

Example 96 with VertexRef

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

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

the class OSGiVerticesUpdateManagerTest method createContextWithVertRefIds.

private SelectionContext createContextWithVertRefIds(int... vertIds) {
    SelectionContext context = new DefaultSelectionManager(createGraph());
    List<VertexRef> vertices = createVertexRefsWithIds(vertIds);
    context.setSelectedVertexRefs(vertices);
    return context;
}
Also used : SelectionContext(org.opennms.features.topology.api.SelectionContext) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 98 with VertexRef

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

the class D3TopoLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 99 with VertexRef

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

the class ApplicationStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    Map<VertexRef, Status> returnMap = new HashMap<>();
    Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
    List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
    for (ApplicationStatusEntity eachRow : result) {
        DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
        statusMap.put(eachRow.getKey(), status);
    }
    // status for all known node ids
    Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
    Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
    Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
    vertexRefs.removeAll(vertexRefsRoot);
    // calculate status for children
    for (VertexRef eachVertex : vertexRefs) {
        ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
        Status alarmStatus = statusMap.get(createKey(applicationVertex));
        if (alarmStatus == null) {
            alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
        }
        returnMap.put(eachVertex, alarmStatus);
    }
    // calculate status for root
    for (VertexRef eachRoot : vertexRefsRoot) {
        ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
        OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
        int count = 0;
        for (VertexRef eachChild : eachRootApplication.getChildren()) {
            ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
            ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
            Status childStatus = statusMap.get(childKey);
            if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
                maxSeverity = createSeverity(childStatus.computeStatus());
                count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
            }
        }
        returnMap.put(eachRoot, createStatus(maxSeverity, count));
    }
    return returnMap;
}
Also used : DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 100 with VertexRef

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

the class ResourceGraphsOperation 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.intValue();
                    break;
                }
            }
        }
        final Node node = new Node(nodeID, null, label);
        final String url;
        if (node.getNodeID() >= 0) {
            url = getResourceGraphNodeURL() + "[" + node.getNodeID() + "]";
        } else {
            url = getResourceGraphListURL();
        }
        final URL fullUrl = new URL(getFullUrl(url));
        operationContext.getMainWindow().addWindow(new ResourceGraphsWindow(node, fullUrl));
    } catch (final Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException("Failed to create resource graph window.", e);
        }
    }
}
Also used : Node(org.opennms.features.topology.netutils.internal.Node) VertexRef(org.opennms.features.topology.api.topo.VertexRef) URL(java.net.URL) ResourceGraphsWindow(org.opennms.features.topology.netutils.internal.ResourceGraphsWindow)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)105 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)33 Vertex (org.opennms.features.topology.api.topo.Vertex)31 Point (org.opennms.features.topology.api.Point)23 Criteria (org.opennms.features.topology.api.topo.Criteria)22 Edge (org.opennms.features.topology.api.topo.Edge)22 Test (org.junit.Test)21 List (java.util.List)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)18 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 Map (java.util.Map)17 Status (org.opennms.features.topology.api.topo.Status)15 Collection (java.util.Collection)13 HashSet (java.util.HashSet)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 HashMap (java.util.HashMap)12 Layout (org.opennms.features.topology.api.Layout)12 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)12 Lists (com.google.common.collect.Lists)11