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());
}
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();
}
}
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;
}
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;
}
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);
}
}
Aggregations