Search in sources :

Example 71 with VertexRef

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

the class BreadcrumbCriteria method handleClick.

public void handleClick(Breadcrumb breadcrumb, GraphContainer graphContainer) {
    final GraphProvider targetGraphProvider = graphContainer.getTopologyServiceClient().getGraphProviderBy(breadcrumb.getTargetNamespace());
    if (isLeaf(breadcrumb)) {
        if (breadcrumb.getSourceVertices().isEmpty()) {
            final List<VertexRef> defaultFocus = targetGraphProvider.getDefaults().getCriteria().stream().filter(c -> c instanceof VertexHopGraphProvider.VertexHopCriteria).map(c -> ((VertexHopGraphProvider.VertexHopCriteria) c).getVertices()).flatMap(Set::stream).collect(Collectors.toList());
            handleClick(graphContainer, targetGraphProvider, defaultFocus, breadcrumb);
        } else {
            List<VertexRef> oppositeVertices = breadcrumb.getSourceVertices().stream().flatMap(sourceVertex -> getOppositeVertices(graphContainer, breadcrumb.getTargetNamespace(), sourceVertex).stream()).collect(Collectors.toList());
            handleClick(graphContainer, targetGraphProvider, oppositeVertices, breadcrumb);
        }
    } else {
        Breadcrumb next = getNext(breadcrumb);
        handleClick(graphContainer, targetGraphProvider, next.getSourceVertices(), breadcrumb);
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) Objects(java.util.Objects) Callbacks(org.opennms.features.topology.api.Callbacks) List(java.util.List) Lists(com.google.common.collect.Lists) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collections(java.util.Collections) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 72 with VertexRef

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

the class VertexHopGraphProviderTest method testCollapseEdges.

@Test
public void testCollapseEdges() {
    CollapsibleCriteria collapseMe = new CollapsibleCriteria() {

        @Override
        public void setCollapsed(boolean collapsed) {
        }

        @Override
        public boolean isCollapsed() {
            return true;
        }

        @Override
        public Set<VertexRef> getVertices() {
            Set<VertexRef> retval = new HashSet<>();
            retval.add(new DefaultVertexRef("nodes", "g2"));
            return retval;
        }

        @Override
        public String getNamespace() {
            return "nodes";
        }

        @Override
        public String getLabel() {
            return "Test Criteria";
        }

        @Override
        public String getId() {
            return "Test Criteria";
        }

        @Override
        public Vertex getCollapsedRepresentation() {
            return new AbstractVertex("category", "c");
        }
    };
    Set<Edge> edges = VertexHopGraphProvider.collapseEdges(new HashSet<Edge>(m_provider.getEdges()), new CollapsibleCriteria[] { collapseMe });
    for (Edge edge : edges) {
        assertEquals("nodes", edge.getNamespace());
        /*
			Here's the original list of edges

			.edge("e1", "g0", "g1").eLabel("edge1").eStyleName("edge")
			.edge("e2", "g0", "g2").eLabel("edge2").eStyleName("edge")
			.edge("e3", "g1", "v1").eLabel("edge3").eStyleName("edge")
			.edge("e4", "g1", "v2").eLabel("edge4").eStyleName("edge")
			.edge("e5", "g2", "v3").eLabel("edge5").eStyleName("edge")
			.edge("e6", "g2", "v4").eLabel("edge6").eStyleName("edge")
			*/
        if (edge.getId().equals("e1")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g0", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("g1", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedTarget-e2")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g0", edge.getSource().getVertex().getId());
            assertEquals("category", edge.getTarget().getVertex().getNamespace());
            assertEquals("c", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("e3")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g1", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v1", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("e4")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g1", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v2", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedSource-e5")) {
            assertEquals("category", edge.getSource().getVertex().getNamespace());
            assertEquals("c", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v3", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedSource-e6")) {
            assertEquals("category", edge.getSource().getVertex().getNamespace());
            assertEquals("c", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v4", edge.getTarget().getVertex().getId());
        } else {
            fail("Unexpected edge found: " + edge.toString());
        }
    }
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) 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) Test(org.junit.Test)

Example 73 with VertexRef

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

the class AlarmSearchProvider method getVertexRefsBy.

// FIXME so that the focus button works.???
@Override
public Set<VertexRef> getVertexRefsBy(SearchResult searchResult, GraphContainer container) {
    LOG.debug("SearchProvider.getVertexRefsBy: called with search result: '{}'", searchResult);
    Criteria criterion = findCriterion(searchResult, container);
    Set<VertexRef> vertices = ((AlarmHopCriteria) criterion).getVertices();
    LOG.debug("SearchProvider.getVertexRefsBy: found '{}' vertices.", vertices.size());
    return vertices;
}
Also used : AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 74 with VertexRef

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

the class TopologyComponent method computeBoundsForSelected.

private void computeBoundsForSelected(SelectionContext selectionContext) {
    if (selectionContext.getSelectedVertexRefs().size() > 0) {
        Collection<? extends Vertex> visible = m_graphContainer.getGraph().getDisplayVertices();
        Collection<VertexRef> selected = selectionContext.getSelectedVertexRefs();
        Collection<VertexRef> vRefs = new ArrayList<>();
        for (VertexRef vRef : selected) {
            if (visible.contains(vRef)) {
                vRefs.add(vRef);
            }
        }
        getViewManager().setBoundingBox(m_graphContainer.getGraph().getLayout().computeBoundingBox(vRefs));
    } else {
        getViewManager().setBoundingBox(m_graphContainer.getGraph().getLayout().getBounds());
    }
}
Also used : ArrayList(java.util.ArrayList) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 75 with VertexRef

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

the class PathOutageStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    final List<Integer> nodeIds = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (PathOutageVertex) v).map(v -> v.getNodeID()).collect(Collectors.toList());
    if (nodeIds.isEmpty()) {
        return new HashMap<>();
    }
    // Preparing database request
    final StringBuilder hql = new StringBuilder();
    hql.append("SELECT node.id, max(event.eventSeverity) ");
    hql.append("FROM OnmsOutage as outage ");
    hql.append("LEFT JOIN outage.monitoredService as ifservice ");
    hql.append("LEFT JOIN ifservice.ipInterface as ipinterface ");
    hql.append("LEFT JOIN ipinterface.node as node ");
    hql.append("LEFT JOIN outage.serviceLostEvent as event ");
    hql.append("WHERE node.id in (:nodeIds) ");
    hql.append("AND outage.serviceRegainedEvent is null ");
    hql.append("GROUP BY node.id");
    final List<String> paramNames = Lists.newArrayList("nodeIds");
    final List<Object> paramValues = new ArrayList();
    paramValues.add(Lists.newArrayList(nodeIds));
    final List<Object[]> retvals = this.persistenceAccessor.findUsingNamedParameters(hql.toString(), paramNames.toArray(new String[paramNames.size()]), paramValues.toArray());
    // Generating alarms map
    final Map<Integer, OnmsSeverity> mappedAlarms = new HashedMap();
    for (int i = 0; i < retvals.size(); i++) {
        final Integer nodeId = (Integer) retvals.get(i)[0];
        final Integer severity = Optional.ofNullable((Integer) retvals.get(i)[1]).orElse(OnmsSeverity.NORMAL.ordinal());
        mappedAlarms.put(nodeId, OnmsSeverity.get(severity));
    }
    final Map<VertexRef, Status> status = vertices.stream().map(v -> (PathOutageVertex) v).collect(Collectors.toMap(v -> v, v -> {
        if (!mappedAlarms.containsKey(v.getNodeID())) {
            return new DefaultStatus(OnmsSeverity.NORMAL.getLabel(), 0);
        } else {
            return new DefaultStatus(mappedAlarms.get(v.getNodeID()).getLabel(), 0);
        }
    }));
    return status;
}
Also used : Collection(java.util.Collection) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) HashedMap(org.apache.commons.collections.map.HashedMap) 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) Lists(com.google.common.collect.Lists) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Optional(java.util.Optional) 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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) HashedMap(org.apache.commons.collections.map.HashedMap) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

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