Search in sources :

Example 31 with Criteria

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

the class SavedHistory method apply.

public void apply(GraphContainer graphContainer, Collection<HistoryOperation> operations, ServiceLocator serviceLocator) {
    LOG.debug("Applying " + toString());
    graphContainer.clearCriteria();
    // Apply the history for each registered HistoryOperation
    for (HistoryOperation operation : operations) {
        try {
            operation.applyHistory(graphContainer, m_settings);
        } catch (Throwable e) {
            LOG.warn("Failed to perform applyHistory() operation", e);
        }
    }
    // Browse through all available search providers that have a "history" functionality
    List<SearchProvider> searchProviders = serviceLocator.findServices(SearchProvider.class, null);
    for (SearchProvider searchProvider : searchProviders) {
        if (searchProvider instanceof HistoryAwareSearchProvider) {
            // Add resulting Criteria to the graph container
            for (SearchResult searchQuery : m_searchQueries) {
                if (searchProvider.getSearchProviderNamespace().equals(searchQuery.getNamespace()) || searchProvider.contributesTo(searchQuery.getNamespace())) {
                    Criteria searchCriteria = ((HistoryAwareSearchProvider) searchProvider).buildCriteriaFromQuery(searchQuery, graphContainer);
                    graphContainer.addCriteria(searchCriteria);
                }
            }
        }
    }
    // Set Vertices in Focus after all other operations are applied, otherwise the topology provider may have changed
    // which results in a graphContainer.clearCriteria()
    applyVerticesInFocus(m_focusVertices, graphContainer);
    applySavedLocations(m_locations, graphContainer.getGraph().getLayout());
    graphContainer.setSemanticZoomLevel(getSemanticZoomLevel());
    // Apply the selected vertices
    graphContainer.getSelectionManager().setSelectedVertexRefs(m_selectedVertices);
    graphContainer.getMapViewManager().setBoundingBox(getBoundingBox());
}
Also used : HistoryOperation(org.opennms.features.topology.api.HistoryOperation) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria)

Example 32 with Criteria

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

the class SearchBox method collapseIfSuggMapEmpty.

private void collapseIfSuggMapEmpty(SearchResult searchResult, GraphContainer graphContainer) {
    // A special check for categories that were added then after re-login can't collapse
    boolean isDirty = false;
    Criteria[] criteria = graphContainer.getCriteria();
    for (Criteria criterion : criteria) {
        if (criterion instanceof CollapsibleCriteria) {
            if (((CollapsibleCriteria) criterion).getLabel().equals(searchResult.getLabel())) {
                ((CollapsibleCriteria) criterion).setCollapsed(!((CollapsibleCriteria) criterion).isCollapsed());
                isDirty = true;
            }
        }
    }
    if (isDirty) {
        graphContainer.redoLayout();
    }
}
Also used : CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria)

Example 33 with Criteria

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

use of org.opennms.features.topology.api.topo.Criteria 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)

Example 35 with Criteria

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

the class PathOutageProviderTest method checkProvider.

/**
 * In this method the vertices from the {@link PathOutageProvider} are compared to the local vertices data
 * @param criteria
 */
private void checkProvider(List<VertexHopGraphProvider.VertexHopCriteria> criteria) {
    List<Vertex> vertices = this.pathOutageProvider.getVertices(Lists.newArrayList(criteria).toArray(new Criteria[criteria.size()]));
    assertEquals(vertices.size(), this.nodesMap.size());
    for (Vertex vertex : vertices) {
        Integer id = Integer.parseInt(vertex.getId());
        int levelNode = this.nodesMap.get(id);
        assertTrue(vertex instanceof PathOutageVertex);
        int levelVertex = ((PathOutageVertex) vertex).getLevel();
        assertEquals(levelNode, levelVertex);
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Criteria(org.opennms.features.topology.api.topo.Criteria)

Aggregations

Criteria (org.opennms.features.topology.api.topo.Criteria)46 VertexRef (org.opennms.features.topology.api.topo.VertexRef)21 Map (java.util.Map)15 VertexHopCriteria (org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria)15 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)15 List (java.util.List)14 Collectors (java.util.stream.Collectors)14 Status (org.opennms.features.topology.api.topo.Status)14 Lists (com.google.common.collect.Lists)11 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 StatusProvider (org.opennms.features.topology.api.topo.StatusProvider)9 Objects (java.util.Objects)8 Test (org.junit.Test)8 AlarmSummary (org.opennms.netmgt.model.alarm.AlarmSummary)8 HashSet (java.util.HashSet)7 Set (java.util.Set)7 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)7 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)7 VertexProvider (org.opennms.features.topology.api.topo.VertexProvider)7