use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method logCriteriaInContainer.
private void logCriteriaInContainer(GraphContainer container) {
Criteria[] criteria = container.getCriteria();
LOG.debug("SearchProvider->addVertexHopCriteria: there are now {} criteria in the GraphContainer.", criteria.length);
for (Criteria crit : criteria) {
LOG.debug("SearchProvider->addVertexHopCriteria: criterion: '{}' is in the GraphContainer.", crit);
}
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderTest method testStatusProvider.
@Test
public void testStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLVertexStatusProvider statusProvider = new GraphMLVertexStatusProvider(topologyProvider.getNamespace(), nodeIds -> Lists.newArrayList(createSummary(1, "North", OnmsSeverity.WARNING, 1), createSummary(2, "West", OnmsSeverity.MINOR, 2), createSummary(3, "South", OnmsSeverity.MAJOR, 3)));
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertEquals(Boolean.TRUE, statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<VertexRef, Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.WARNING, 1), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.MINOR, 2), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.MAJOR, 3), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.NORMAL, 0)), statusForVertices);
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method removeVertexHopCriteria.
@Override
public void removeVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
LOG.debug("SearchProvider->removeVertexHopCriteria: called with search result: '{}'", searchResult);
Criteria criterion = findCriterion(searchResult.getId(), container);
if (criterion != null) {
LOG.debug("SearchProvider->removeVertexHopCriteria: found criterion: {} for searchResult {}.", criterion, searchResult);
container.removeCriteria(criterion);
} else {
LOG.debug("SearchProvider->removeVertexHopCriteria: did not find criterion for searchResult {}.", searchResult);
}
logCriteriaInContainer(container);
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class AlarmStatusProviderTest method testGetAlarmStatus.
@Test
public void testGetAlarmStatus() {
Vertex vertex = createVertex(1);
Vertex vertex2 = createVertex(2);
Vertex vertex3 = createVertex(3);
List<VertexRef> vertexList = Lists.newArrayList(vertex, vertex2, vertex3);
EasyMock.expect(m_alarmDao.getNodeAlarmSummariesIncludeAcknowledgedOnes(EasyMock.anyObject())).andReturn(createNormalAlarmSummaryList());
EasyMock.replay(m_alarmDao);
Map<VertexRef, Status> statusMap = m_statusProvider.getStatusForVertices(m_vertexProvider, vertexList, new Criteria[0]);
assertEquals(3, statusMap.size());
assertEquals(vertex, statusMap.keySet().stream().sorted((v1, v2) -> v1.getId().compareTo(v2.getId())).collect(Collectors.toList()).get(0));
// use defined status
assertEquals("major", statusMap.get(vertex).computeStatus());
// fallback to normal
assertEquals("normal", statusMap.get(vertex2).computeStatus());
// use defined status
assertEquals("indeterminate", statusMap.get(vertex3).computeStatus());
EasyMock.verify(m_alarmDao);
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method initProvidersAndCriteria.
/**
* In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
*/
private void initProvidersAndCriteria() {
// Preparing SearchProviders
CategoryProvider vertexProvider = new CategoryProvider() {
@Override
public Collection<OnmsCategory> getAllCategories() {
return Lists.newArrayList(findCategoryByName("somename"));
}
@Override
public OnmsCategory findCategoryByName(String m_categoryName) {
OnmsCategory cat = new OnmsCategory("test", "test");
cat.setId(Integer.valueOf(idCategory));
return cat;
}
@Override
public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
return new ArrayList<>();
}
};
IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {
@Override
public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
OnmsNode node = new OnmsNode();
node.setId(Integer.valueOf(idIpLike));
String ipAddr = "127.0.0.1";
OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
return Lists.newArrayList(ipInterface);
}
};
AlarmProvider alarmProvider = new AlarmProvider() {
@Override
public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
Date eventTime = new Date();
OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
OnmsEvent event = new OnmsEvent();
OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
return Lists.newArrayList(alarm);
}
};
// Creating SearchResults to be used in testing
SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
// Initializing available (initial) SearchProviders
this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(vertexProvider));
this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
// Initializing available (initial) Criteria
this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider));
this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
Aggregations